1*e2f6069cSDag-Erling Smørgrav /* $Id: openssl-compat.h,v 1.15 2010/05/12 07:50:02 djm Exp $ */ 2043840dfSDag-Erling Smørgrav 3043840dfSDag-Erling Smørgrav /* 4043840dfSDag-Erling Smørgrav * Copyright (c) 2005 Darren Tucker <dtucker@zip.com.au> 5043840dfSDag-Erling Smørgrav * 6043840dfSDag-Erling Smørgrav * Permission to use, copy, modify, and distribute this software for any 7043840dfSDag-Erling Smørgrav * purpose with or without fee is hereby granted, provided that the above 8043840dfSDag-Erling Smørgrav * copyright notice and this permission notice appear in all copies. 9043840dfSDag-Erling Smørgrav * 10043840dfSDag-Erling Smørgrav * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11043840dfSDag-Erling Smørgrav * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12043840dfSDag-Erling Smørgrav * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13043840dfSDag-Erling Smørgrav * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14043840dfSDag-Erling Smørgrav * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER 15043840dfSDag-Erling Smørgrav * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING 16043840dfSDag-Erling Smørgrav * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17043840dfSDag-Erling Smørgrav */ 18043840dfSDag-Erling Smørgrav 19043840dfSDag-Erling Smørgrav #include "includes.h" 20043840dfSDag-Erling Smørgrav #include <openssl/evp.h> 21*e2f6069cSDag-Erling Smørgrav #include <openssl/rsa.h> 22*e2f6069cSDag-Erling Smørgrav #include <openssl/dsa.h> 23*e2f6069cSDag-Erling Smørgrav 24*e2f6069cSDag-Erling Smørgrav /* Only in 0.9.8 */ 25*e2f6069cSDag-Erling Smørgrav #ifndef OPENSSL_DSA_MAX_MODULUS_BITS 26*e2f6069cSDag-Erling Smørgrav # define OPENSSL_DSA_MAX_MODULUS_BITS 10000 27*e2f6069cSDag-Erling Smørgrav #endif 28*e2f6069cSDag-Erling Smørgrav #ifndef OPENSSL_RSA_MAX_MODULUS_BITS 29*e2f6069cSDag-Erling Smørgrav # define OPENSSL_RSA_MAX_MODULUS_BITS 16384 30*e2f6069cSDag-Erling Smørgrav #endif 31043840dfSDag-Erling Smørgrav 32d4af9e69SDag-Erling Smørgrav /* OPENSSL_free() is Free() in versions before OpenSSL 0.9.6 */ 33d4af9e69SDag-Erling Smørgrav #if !defined(OPENSSL_VERSION_NUMBER) || (OPENSSL_VERSION_NUMBER < 0x0090600f) 34d4af9e69SDag-Erling Smørgrav # define OPENSSL_free(x) Free(x) 35d4af9e69SDag-Erling Smørgrav #endif 36d4af9e69SDag-Erling Smørgrav 37043840dfSDag-Erling Smørgrav #if OPENSSL_VERSION_NUMBER < 0x00906000L 38043840dfSDag-Erling Smørgrav # define SSH_OLD_EVP 39043840dfSDag-Erling Smørgrav # define EVP_CIPHER_CTX_get_app_data(e) ((e)->app_data) 40043840dfSDag-Erling Smørgrav #endif 41043840dfSDag-Erling Smørgrav 42021d409fSDag-Erling Smørgrav #if (OPENSSL_VERSION_NUMBER < 0x00907000L) || defined(OPENSSL_LOBOTOMISED_AES) 43021d409fSDag-Erling Smørgrav # define USE_BUILTIN_RIJNDAEL 44021d409fSDag-Erling Smørgrav #endif 45021d409fSDag-Erling Smørgrav 46021d409fSDag-Erling Smørgrav #ifdef USE_BUILTIN_RIJNDAEL 47d4af9e69SDag-Erling Smørgrav # include "rijndael.h" 48d4af9e69SDag-Erling Smørgrav # define AES_KEY rijndael_ctx 49d4af9e69SDag-Erling Smørgrav # define AES_BLOCK_SIZE 16 50d4af9e69SDag-Erling Smørgrav # define AES_encrypt(a, b, c) rijndael_encrypt(c, a, b) 51d4af9e69SDag-Erling Smørgrav # define AES_set_encrypt_key(a, b, c) rijndael_set_key(c, (char *)a, b, 1) 52043840dfSDag-Erling Smørgrav # define EVP_aes_128_cbc evp_rijndael 53043840dfSDag-Erling Smørgrav # define EVP_aes_192_cbc evp_rijndael 54043840dfSDag-Erling Smørgrav # define EVP_aes_256_cbc evp_rijndael 55043840dfSDag-Erling Smørgrav extern const EVP_CIPHER *evp_rijndael(void); 56043840dfSDag-Erling Smørgrav extern void ssh_rijndael_iv(EVP_CIPHER_CTX *, int, u_char *, u_int); 57043840dfSDag-Erling Smørgrav #endif 58043840dfSDag-Erling Smørgrav 59043840dfSDag-Erling Smørgrav #if !defined(EVP_CTRL_SET_ACSS_MODE) 60043840dfSDag-Erling Smørgrav # if (OPENSSL_VERSION_NUMBER >= 0x00907000L) 61043840dfSDag-Erling Smørgrav # define USE_CIPHER_ACSS 1 62043840dfSDag-Erling Smørgrav extern const EVP_CIPHER *evp_acss(void); 63043840dfSDag-Erling Smørgrav # define EVP_acss evp_acss 64043840dfSDag-Erling Smørgrav # else 65043840dfSDag-Erling Smørgrav # define EVP_acss NULL 66043840dfSDag-Erling Smørgrav # endif 67043840dfSDag-Erling Smørgrav #endif 68043840dfSDag-Erling Smørgrav 69d4af9e69SDag-Erling Smørgrav /* OpenSSL 0.9.8e returns cipher key len not context key len */ 70d4af9e69SDag-Erling Smørgrav #if (OPENSSL_VERSION_NUMBER == 0x0090805fL) 71d4af9e69SDag-Erling Smørgrav # define EVP_CIPHER_CTX_key_length(c) ((c)->key_len) 72d4af9e69SDag-Erling Smørgrav #endif 73d4af9e69SDag-Erling Smørgrav 74043840dfSDag-Erling Smørgrav /* 75021d409fSDag-Erling Smørgrav * We overload some of the OpenSSL crypto functions with ssh_* equivalents 76021d409fSDag-Erling Smørgrav * which cater for older and/or less featureful OpenSSL version. 77021d409fSDag-Erling Smørgrav * 78021d409fSDag-Erling Smørgrav * In order for the compat library to call the real functions, it must 79021d409fSDag-Erling Smørgrav * define SSH_DONT_OVERLOAD_OPENSSL_FUNCS before including this file and 80021d409fSDag-Erling Smørgrav * implement the ssh_* equivalents. 81043840dfSDag-Erling Smørgrav */ 82761efaa7SDag-Erling Smørgrav #ifndef SSH_DONT_OVERLOAD_OPENSSL_FUNCS 83761efaa7SDag-Erling Smørgrav 84043840dfSDag-Erling Smørgrav # ifdef SSH_OLD_EVP 85043840dfSDag-Erling Smørgrav # ifdef EVP_Cipher 86043840dfSDag-Erling Smørgrav # undef EVP_Cipher 87043840dfSDag-Erling Smørgrav # endif 88043840dfSDag-Erling Smørgrav # define EVP_CipherInit(a,b,c,d,e) ssh_EVP_CipherInit((a),(b),(c),(d),(e)) 89043840dfSDag-Erling Smørgrav # define EVP_Cipher(a,b,c,d) ssh_EVP_Cipher((a),(b),(c),(d)) 90043840dfSDag-Erling Smørgrav # define EVP_CIPHER_CTX_cleanup(a) ssh_EVP_CIPHER_CTX_cleanup((a)) 91761efaa7SDag-Erling Smørgrav # endif /* SSH_OLD_EVP */ 92761efaa7SDag-Erling Smørgrav 937aee6ffeSDag-Erling Smørgrav # ifdef OPENSSL_EVP_DIGESTUPDATE_VOID 947aee6ffeSDag-Erling Smørgrav # define EVP_DigestUpdate(a,b,c) ssh_EVP_DigestUpdate((a),(b),(c)) 957aee6ffeSDag-Erling Smørgrav # endif 967aee6ffeSDag-Erling Smørgrav 97761efaa7SDag-Erling Smørgrav # ifdef USE_OPENSSL_ENGINE 98761efaa7SDag-Erling Smørgrav # ifdef SSLeay_add_all_algorithms 99761efaa7SDag-Erling Smørgrav # undef SSLeay_add_all_algorithms 100761efaa7SDag-Erling Smørgrav # endif 101761efaa7SDag-Erling Smørgrav # define SSLeay_add_all_algorithms() ssh_SSLeay_add_all_algorithms() 102043840dfSDag-Erling Smørgrav # endif 103043840dfSDag-Erling Smørgrav 104043840dfSDag-Erling Smørgrav int ssh_EVP_CipherInit(EVP_CIPHER_CTX *, const EVP_CIPHER *, unsigned char *, 105043840dfSDag-Erling Smørgrav unsigned char *, int); 106043840dfSDag-Erling Smørgrav int ssh_EVP_Cipher(EVP_CIPHER_CTX *, char *, char *, int); 107043840dfSDag-Erling Smørgrav int ssh_EVP_CIPHER_CTX_cleanup(EVP_CIPHER_CTX *); 108761efaa7SDag-Erling Smørgrav void ssh_SSLeay_add_all_algorithms(void); 109761efaa7SDag-Erling Smørgrav #endif /* SSH_DONT_OVERLOAD_OPENSSL_FUNCS */ 110*e2f6069cSDag-Erling Smørgrav 111