1 /* $Id: openssl-compat.c,v 1.13 2011/01/21 22:37:06 dtucker Exp $ */
4 * Copyright (c) 2005 Darren Tucker <dtucker@zip.com.au>
6 * Permission to use, copy, modify, and distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
15 * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
16 * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
24 #ifdef USE_OPENSSL_ENGINE
25 # include <openssl/engine.h>
26 # include <openssl/conf.h>
29 #ifndef HAVE_RSA_GET_DEFAULT_METHOD
30 # include <openssl/rsa.h>
35 #define SSH_DONT_OVERLOAD_OPENSSL_FUNCS
36 #include "openssl-compat.h"
40 ssh_EVP_CipherInit(EVP_CIPHER_CTX *evp, const EVP_CIPHER *type,
41 unsigned char *key, unsigned char *iv, int enc)
43 EVP_CipherInit(evp, type, key, iv, enc);
48 ssh_EVP_Cipher(EVP_CIPHER_CTX *evp, char *dst, char *src, int len)
50 EVP_Cipher(evp, dst, src, len);
55 ssh_EVP_CIPHER_CTX_cleanup(EVP_CIPHER_CTX *evp)
57 EVP_CIPHER_CTX_cleanup(evp);
62 #ifdef OPENSSL_EVP_DIGESTUPDATE_VOID
64 ssh_EVP_DigestUpdate(EVP_MD_CTX *ctx, const void *d, unsigned int cnt)
66 EVP_DigestUpdate(ctx, d, cnt);
71 #ifndef HAVE_BN_IS_PRIME_EX
73 BN_is_prime_ex(const BIGNUM *p, int nchecks, BN_CTX *ctx, void *cb)
76 fatal("%s: callback args not supported", __func__);
77 return BN_is_prime(p, nchecks, NULL, ctx, NULL);
81 #ifndef HAVE_RSA_GENERATE_KEY_EX
83 RSA_generate_key_ex(RSA *rsa, int bits, BIGNUM *bn_e, void *cb)
85 RSA *new_rsa, tmp_rsa;
89 fatal("%s: callback args not supported", __func__);
90 e = BN_get_word(bn_e);
92 fatal("%s: value of e too large", __func__);
93 new_rsa = RSA_generate_key(bits, e, NULL, NULL);
96 /* swap rsa/new_rsa then free new_rsa */
105 #ifndef HAVE_DSA_GENERATE_PARAMETERS_EX
107 DSA_generate_parameters_ex(DSA *dsa, int bits, const unsigned char *seed,
108 int seed_len, int *counter_ret, unsigned long *h_ret, void *cb)
110 DSA *new_dsa, tmp_dsa;
113 fatal("%s: callback args not supported", __func__);
114 new_dsa = DSA_generate_parameters(bits, (unsigned char *)seed, seed_len,
115 counter_ret, h_ret, NULL, NULL);
118 /* swap dsa/new_dsa then free new_dsa */
127 #ifndef HAVE_RSA_GET_DEFAULT_METHOD
129 RSA_get_default_method(void)
131 return RSA_PKCS1_SSLeay();
135 #ifdef USE_OPENSSL_ENGINE
137 ssh_SSLeay_add_all_algorithms(void)
139 SSLeay_add_all_algorithms();
141 /* Enable use of crypto hardware */
142 ENGINE_load_builtin_engines();
143 ENGINE_register_all_complete();
144 OPENSSL_config(NULL);