1d4af9e69SDag-Erling Smørgrav /* $Id: openssl-compat.h,v 1.12 2008/02/28 08:22:04 dtucker 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> 21043840dfSDag-Erling Smørgrav 22d4af9e69SDag-Erling Smørgrav /* OPENSSL_free() is Free() in versions before OpenSSL 0.9.6 */ 23d4af9e69SDag-Erling Smørgrav #if !defined(OPENSSL_VERSION_NUMBER) || (OPENSSL_VERSION_NUMBER < 0x0090600f) 24d4af9e69SDag-Erling Smørgrav # define OPENSSL_free(x) Free(x) 25d4af9e69SDag-Erling Smørgrav #endif 26d4af9e69SDag-Erling Smørgrav 27043840dfSDag-Erling Smørgrav #if OPENSSL_VERSION_NUMBER < 0x00906000L 28043840dfSDag-Erling Smørgrav # define SSH_OLD_EVP 29043840dfSDag-Erling Smørgrav # define EVP_CIPHER_CTX_get_app_data(e) ((e)->app_data) 30043840dfSDag-Erling Smørgrav #endif 31043840dfSDag-Erling Smørgrav 32021d409fSDag-Erling Smørgrav #if (OPENSSL_VERSION_NUMBER < 0x00907000L) || defined(OPENSSL_LOBOTOMISED_AES) 33021d409fSDag-Erling Smørgrav # define USE_BUILTIN_RIJNDAEL 34021d409fSDag-Erling Smørgrav #endif 35021d409fSDag-Erling Smørgrav 36021d409fSDag-Erling Smørgrav #ifdef USE_BUILTIN_RIJNDAEL 37d4af9e69SDag-Erling Smørgrav # include "rijndael.h" 38d4af9e69SDag-Erling Smørgrav # define AES_KEY rijndael_ctx 39d4af9e69SDag-Erling Smørgrav # define AES_BLOCK_SIZE 16 40d4af9e69SDag-Erling Smørgrav # define AES_encrypt(a, b, c) rijndael_encrypt(c, a, b) 41d4af9e69SDag-Erling Smørgrav # define AES_set_encrypt_key(a, b, c) rijndael_set_key(c, (char *)a, b, 1) 42043840dfSDag-Erling Smørgrav # define EVP_aes_128_cbc evp_rijndael 43043840dfSDag-Erling Smørgrav # define EVP_aes_192_cbc evp_rijndael 44043840dfSDag-Erling Smørgrav # define EVP_aes_256_cbc evp_rijndael 45043840dfSDag-Erling Smørgrav extern const EVP_CIPHER *evp_rijndael(void); 46043840dfSDag-Erling Smørgrav extern void ssh_rijndael_iv(EVP_CIPHER_CTX *, int, u_char *, u_int); 47043840dfSDag-Erling Smørgrav #endif 48043840dfSDag-Erling Smørgrav 49043840dfSDag-Erling Smørgrav #if !defined(EVP_CTRL_SET_ACSS_MODE) 50043840dfSDag-Erling Smørgrav # if (OPENSSL_VERSION_NUMBER >= 0x00907000L) 51043840dfSDag-Erling Smørgrav # define USE_CIPHER_ACSS 1 52043840dfSDag-Erling Smørgrav extern const EVP_CIPHER *evp_acss(void); 53043840dfSDag-Erling Smørgrav # define EVP_acss evp_acss 54043840dfSDag-Erling Smørgrav # else 55043840dfSDag-Erling Smørgrav # define EVP_acss NULL 56043840dfSDag-Erling Smørgrav # endif 57043840dfSDag-Erling Smørgrav #endif 58043840dfSDag-Erling Smørgrav 59d4af9e69SDag-Erling Smørgrav /* OpenSSL 0.9.8e returns cipher key len not context key len */ 60d4af9e69SDag-Erling Smørgrav #if (OPENSSL_VERSION_NUMBER == 0x0090805fL) 61d4af9e69SDag-Erling Smørgrav # define EVP_CIPHER_CTX_key_length(c) ((c)->key_len) 62d4af9e69SDag-Erling Smørgrav #endif 63d4af9e69SDag-Erling Smørgrav 64043840dfSDag-Erling Smørgrav /* 65021d409fSDag-Erling Smørgrav * We overload some of the OpenSSL crypto functions with ssh_* equivalents 66021d409fSDag-Erling Smørgrav * which cater for older and/or less featureful OpenSSL version. 67021d409fSDag-Erling Smørgrav * 68021d409fSDag-Erling Smørgrav * In order for the compat library to call the real functions, it must 69021d409fSDag-Erling Smørgrav * define SSH_DONT_OVERLOAD_OPENSSL_FUNCS before including this file and 70021d409fSDag-Erling Smørgrav * implement the ssh_* equivalents. 71043840dfSDag-Erling Smørgrav */ 72761efaa7SDag-Erling Smørgrav #ifndef SSH_DONT_OVERLOAD_OPENSSL_FUNCS 73761efaa7SDag-Erling Smørgrav 74043840dfSDag-Erling Smørgrav # ifdef SSH_OLD_EVP 75043840dfSDag-Erling Smørgrav # ifdef EVP_Cipher 76043840dfSDag-Erling Smørgrav # undef EVP_Cipher 77043840dfSDag-Erling Smørgrav # endif 78043840dfSDag-Erling Smørgrav # define EVP_CipherInit(a,b,c,d,e) ssh_EVP_CipherInit((a),(b),(c),(d),(e)) 79043840dfSDag-Erling Smørgrav # define EVP_Cipher(a,b,c,d) ssh_EVP_Cipher((a),(b),(c),(d)) 80043840dfSDag-Erling Smørgrav # define EVP_CIPHER_CTX_cleanup(a) ssh_EVP_CIPHER_CTX_cleanup((a)) 81761efaa7SDag-Erling Smørgrav # endif /* SSH_OLD_EVP */ 82761efaa7SDag-Erling Smørgrav 83761efaa7SDag-Erling Smørgrav # ifdef USE_OPENSSL_ENGINE 84761efaa7SDag-Erling Smørgrav # ifdef SSLeay_add_all_algorithms 85761efaa7SDag-Erling Smørgrav # undef SSLeay_add_all_algorithms 86761efaa7SDag-Erling Smørgrav # endif 87761efaa7SDag-Erling Smørgrav # define SSLeay_add_all_algorithms() ssh_SSLeay_add_all_algorithms() 88043840dfSDag-Erling Smørgrav # endif 89043840dfSDag-Erling Smørgrav 90043840dfSDag-Erling Smørgrav int ssh_EVP_CipherInit(EVP_CIPHER_CTX *, const EVP_CIPHER *, unsigned char *, 91043840dfSDag-Erling Smørgrav unsigned char *, int); 92043840dfSDag-Erling Smørgrav int ssh_EVP_Cipher(EVP_CIPHER_CTX *, char *, char *, int); 93043840dfSDag-Erling Smørgrav int ssh_EVP_CIPHER_CTX_cleanup(EVP_CIPHER_CTX *); 94761efaa7SDag-Erling Smørgrav void ssh_SSLeay_add_all_algorithms(void); 95761efaa7SDag-Erling Smørgrav #endif /* SSH_DONT_OVERLOAD_OPENSSL_FUNCS */ 96