1 /* $Id: openssl-compat.c,v 1.12 2010/12/04 21:46:05 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>
31 #define SSH_DONT_OVERLOAD_OPENSSL_FUNCS
32 #include "openssl-compat.h"
36 ssh_EVP_CipherInit(EVP_CIPHER_CTX
*evp
, const EVP_CIPHER
*type
,
37 unsigned char *key
, unsigned char *iv
, int enc
)
39 EVP_CipherInit(evp
, type
, key
, iv
, enc
);
44 ssh_EVP_Cipher(EVP_CIPHER_CTX
*evp
, char *dst
, char *src
, int len
)
46 EVP_Cipher(evp
, dst
, src
, len
);
51 ssh_EVP_CIPHER_CTX_cleanup(EVP_CIPHER_CTX
*evp
)
53 EVP_CIPHER_CTX_cleanup(evp
);
58 #ifdef OPENSSL_EVP_DIGESTUPDATE_VOID
60 ssh_EVP_DigestUpdate(EVP_MD_CTX
*ctx
, const void *d
, unsigned int cnt
)
62 EVP_DigestUpdate(ctx
, d
, cnt
);
67 #ifndef HAVE_BN_IS_PRIME_EX
69 BN_is_prime_ex(const BIGNUM
*p
, int nchecks
, BN_CTX
*ctx
, void *cb
)
72 fatal("%s: callback args not supported", __func__
);
73 return BN_is_prime(p
, nchecks
, NULL
, ctx
, NULL
);
77 #ifndef HAVE_RSA_GENERATE_KEY_EX
79 RSA_generate_key_ex(RSA
*rsa
, int bits
, BIGNUM
*bn_e
, void *cb
)
81 RSA
*new_rsa
, tmp_rsa
;
85 fatal("%s: callback args not supported", __func__
);
86 e
= BN_get_word(bn_e
);
88 fatal("%s: value of e too large", __func__
);
89 new_rsa
= RSA_generate_key(bits
, e
, NULL
, NULL
);
92 /* swap rsa/new_rsa then free new_rsa */
101 #ifndef HAVE_DSA_GENERATE_PARAMETERS_EX
103 DSA_generate_parameters_ex(DSA
*dsa
, int bits
, const unsigned char *seed
,
104 int seed_len
, int *counter_ret
, unsigned long *h_ret
, void *cb
)
106 DSA
*new_dsa
, tmp_dsa
;
109 fatal("%s: callback args not supported", __func__
);
110 new_dsa
= DSA_generate_parameters(bits
, (unsigned char *)seed
, seed_len
,
111 counter_ret
, h_ret
, NULL
, NULL
);
114 /* swap dsa/new_dsa then free new_dsa */
123 #ifdef USE_OPENSSL_ENGINE
125 ssh_SSLeay_add_all_algorithms(void)
127 SSLeay_add_all_algorithms();
129 /* Enable use of crypto hardware */
130 ENGINE_load_builtin_engines();
131 ENGINE_register_all_complete();
132 OPENSSL_config(NULL
);