1 /* $OpenBSD: libcrypto.h,v 1.11 2001/07/13 14:13:39 ho Exp $ */ 2 /* $EOM: libcrypto.h,v 1.16 2000/09/28 12:53:27 niklas Exp $ */ 3 4 /* 5 * Copyright (c) 1999, 2000 Niklas Hallqvist. All rights reserved. 6 * Copyright (c) 1999, 2000 Angelos D. Keromytis. All rights reserved. 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions 10 * are met: 11 * 1. Redistributions of source code must retain the above copyright 12 * notice, this list of conditions and the following disclaimer. 13 * 2. Redistributions in binary form must reproduce the above copyright 14 * notice, this list of conditions and the following disclaimer in the 15 * documentation and/or other materials provided with the distribution. 16 * 3. All advertising materials mentioning features or use of this software 17 * must display the following acknowledgement: 18 * This product includes software developed by Ericsson Radio Systems. 19 * 4. The name of the author may not be used to endorse or promote products 20 * derived from this software without specific prior written permission. 21 * 22 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 23 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 24 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 25 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 27 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 31 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 */ 33 34 /* 35 * This code was written under funding by Ericsson Radio Systems. 36 */ 37 38 #ifndef _LIBCRYPTO_H_ 39 #define _LIBCRYPTO_H_ 40 41 #ifdef USE_X509 42 43 #include <stdio.h> 44 45 /* XXX I want #include <ssl/cryptall.h> but we appear to not install meth.h */ 46 #include <openssl/ssl.h> 47 #include <openssl/bio.h> 48 #include <openssl/pem.h> 49 #include <openssl/x509_vfy.h> 50 #include <openssl/x509.h> 51 52 extern void *libcrypto; 53 54 #if defined (USE_LIBCRYPTO) 55 #if defined (HAVE_DLOPEN) 56 #define LC(sym, args) (libcrypto ? lc_ ## sym args : sym args) 57 #else 58 #define LC(sym, args) sym args 59 #endif 60 #elif defined (HAVE_DLOPEN) 61 #define LC(sym, args) lc_ ## sym args 62 #else 63 #define LC(sym, args) !!libcrypto called but no USE_LIBCRYPTO nor HAVE_DLOPEN!! 64 #endif 65 66 #ifdef HAVE_DLOPEN 67 68 /* 69 * These prototypes matches SSLeay version 0.9.0b or OpenSSL 0.9.4, if you 70 * try to load a different version than that, you are on your own. 71 */ 72 extern char *(*lc_ASN1_d2i_bio) (char *(*) (), char *(*) (), BIO *bp, 73 unsigned char **); 74 extern char *(*lc_ASN1_dup) (int (*) (), char *(*) (), char *); 75 extern long (*lc_BIO_ctrl) (BIO *bp, int, long, char *); 76 extern int (*lc_BIO_free) (BIO *a); 77 extern BIO *(*lc_BIO_new) (BIO_METHOD *type); 78 extern int (*lc_BIO_write) (BIO *, char *, int); 79 extern BIO_METHOD *(*lc_BIO_s_file) (void); 80 extern BIO_METHOD *(*lc_BIO_s_mem) (void); 81 extern BIGNUM *(*lc_BN_bin2bn) (const unsigned char *, int, BIGNUM *); 82 extern int (*lc_BN_num_bits) (const BIGNUM *); 83 extern int (*lc_BN_print_fp) (FILE *, BIGNUM *); 84 extern char *(*lc_PEM_ASN1_read_bio) (char *(*) (), char *, BIO *, char **, 85 int (*) ()); 86 extern void (*lc_RSA_free) (RSA *); 87 extern RSA *(*lc_RSA_new) (void); 88 extern RSA *(*lc_RSA_generate_key) (int, unsigned long, 89 void (*) (int, int, char *), char *); 90 extern int (*lc_RSA_private_encrypt) (int, unsigned char *, unsigned char *, 91 RSA *, int); 92 extern int (*lc_RSA_public_decrypt) (int, unsigned char *, unsigned char *, 93 RSA *, int); 94 extern int (*lc_RSA_size) (RSA *); 95 #if OPENSSL_VERSION_NUMBER >= 0x00905100L 96 extern void (*lc_OpenSSL_add_all_algorithms) (void); 97 #else 98 extern void (*lc_SSLeay_add_all_algorithms) (void); 99 #endif 100 extern int (*lc_X509_NAME_cmp) (X509_NAME *, X509_NAME *); 101 extern void (*lc_X509_OBJECT_free_contents) (X509_OBJECT *); 102 extern void (*lc_X509_STORE_CTX_cleanup) (X509_STORE_CTX *); 103 #if SSLEAY_VERSION_NUMBER >= 0x00904100L 104 extern void (*lc_X509_STORE_CTX_init) (X509_STORE_CTX *, X509_STORE *, X509 *, 105 STACK_OF (X509) *); 106 #else 107 extern void (*lc_X509_STORE_CTX_init) (X509_STORE_CTX *, X509_STORE *, X509 *, 108 STACK *); 109 #endif 110 extern int (*lc_X509_STORE_add_cert) (X509_STORE *, X509 *); 111 extern void (*lc_X509_STORE_free) (X509_STORE *); 112 extern X509_STORE *(*lc_X509_STORE_new) (void); 113 extern X509 *(*lc_X509_dup) (X509 *); 114 #if SSLEAY_VERSION_NUMBER >= 0x00904100L 115 extern X509 *(*lc_X509_find_by_subject) (STACK_OF (X509) *, X509_NAME *); 116 #else 117 extern X509 *(*lc_X509_find_by_subject) (STACK *, X509_NAME *); 118 #endif 119 extern int (*lc_X509_STORE_get_by_subject) (X509_STORE_CTX *, int, 120 X509_NAME *, X509_OBJECT *); 121 extern void (*lc_X509_free) (X509 *); 122 extern X509_EXTENSION *(*lc_X509_get_ext) (X509 *, int); 123 extern int (*lc_X509_get_ext_by_NID) (X509 *, int, int); 124 extern X509_NAME *(*lc_X509_get_issuer_name) (X509 *); 125 extern EVP_PKEY *(*lc_X509_get_pubkey) (X509 *); 126 extern X509_NAME *(*lc_X509_get_subject_name) (X509 *); 127 extern X509 *(*lc_X509_new) (void); 128 extern int (*lc_X509_verify) (X509 *, EVP_PKEY *); 129 extern char *(*lc_X509_NAME_oneline) (X509_NAME *, char *, int); 130 extern int (*lc_X509_verify_cert) (X509_STORE_CTX *); 131 extern char *(*lc_X509_verify_cert_error_string) (int); 132 extern RSA *(*lc_d2i_RSAPrivateKey) (RSA **, unsigned char **, long); 133 extern RSA *(*lc_d2i_RSAPublicKey) (RSA **, unsigned char **, long); 134 extern X509 *(*lc_d2i_X509) (X509 **, unsigned char **, long); 135 extern int (*lc_i2d_RSAPublicKey) (RSA *, unsigned char **); 136 extern int (*lc_i2d_RSAPrivateKey) (RSA *, unsigned char **); 137 extern int (*lc_i2d_X509) (X509 *, unsigned char **); 138 extern int (*lc_i2d_X509_NAME) (X509_NAME *, unsigned char **); 139 extern X509_NAME * (*lc_d2i_X509_NAME) (X509_NAME **, unsigned char **, int); 140 #if SSLEAY_VERSION_NUMBER >= 0x00904100L 141 extern void (*lc_sk_X509_free) (STACK_OF (X509) *); 142 extern STACK_OF (X509) *(*lc_sk_X509_new_null) (void); 143 #else 144 extern void (*lc_sk_free) (STACK *); 145 extern STACK *(*lc_sk_new) (int (*) ()); 146 #endif 147 148 #define lc_BIO_read_filename(b, name) \ 149 lc_BIO_ctrl (b, BIO_C_SET_FILENAME, BIO_CLOSE | BIO_FP_READ, name) 150 151 #if SSLEAY_VERSION_NUMBER >= 0x00904100L 152 #define lc_PEM_read_bio_RSAPrivateKey(bp, x, cb, u) \ 153 (RSA *)lc_PEM_ASN1_read_bio ((char *(*) ())lc_d2i_RSAPrivateKey, \ 154 PEM_STRING_RSA, bp, (char **)x, cb) 155 #define lc_PEM_read_bio_X509(bp, x, cb, u) \ 156 (X509 *)lc_PEM_ASN1_read_bio ((char *(*) ())lc_d2i_X509, PEM_STRING_X509, \ 157 bp, (char **)x, cb) 158 #else 159 #define lc_PEM_read_bio_RSAPrivateKey(bp, x, cb) \ 160 (RSA *)lc_PEM_ASN1_read_bio ((char *(*) ())lc_d2i_RSAPrivateKey, \ 161 PEM_STRING_RSA, bp, (char **)x, cb) 162 #define lc_PEM_read_bio_X509(bp, x, cb) \ 163 (X509 *)lc_PEM_ASN1_read_bio ((char *(*) ())lc_d2i_X509, PEM_STRING_X509, \ 164 bp, (char **)x, cb) 165 #endif 166 167 #define lc_RSAPublicKey_dup(rsa) \ 168 (RSA *)lc_ASN1_dup ((int (*) ())lc_i2d_RSAPublicKey, \ 169 (char *(*) ())lc_d2i_RSAPublicKey, (char *)rsa) 170 171 #define lc_X509_name_cmp(a, b) lc_X509_NAME_cmp ((a), (b)) 172 173 #define lc_d2i_X509_bio(bp, x509) \ 174 (X509 *)lc_ASN1_d2i_bio ((char *(*) ())lc_X509_new, \ 175 (char *(*) ())lc_d2i_X509, (bp), \ 176 (unsigned char **)(x509)) 177 178 #if SSLEAY_VERSION_NUMBER < 0x00904100L 179 #define lc_sk_new_null() lc_sk_new (NULL) 180 #endif 181 182 #endif 183 184 #endif 185 186 extern void libcrypto_init (void); 187 188 #endif /* _LIBCRYPTO_H_ */ 189