Darren Tucker | 3e7e15f | 2009-03-07 22:22:35 +1100 | [diff] [blame^] | 1 | /* $Id: openssl-compat.h,v 1.14 2009/03/07 11:22:35 dtucker Exp $ */ |
Darren Tucker | a55ec77 | 2005-06-09 21:45:10 +1000 | [diff] [blame] | 2 | |
| 3 | /* |
| 4 | * Copyright (c) 2005 Darren Tucker <dtucker@zip.com.au> |
| 5 | * |
| 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. |
| 9 | * |
| 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. |
| 17 | */ |
| 18 | |
| 19 | #include "includes.h" |
| 20 | #include <openssl/evp.h> |
| 21 | |
Darren Tucker | 3d295a6 | 2008-02-28 19:22:04 +1100 | [diff] [blame] | 22 | /* OPENSSL_free() is Free() in versions before OpenSSL 0.9.6 */ |
| 23 | #if !defined(OPENSSL_VERSION_NUMBER) || (OPENSSL_VERSION_NUMBER < 0x0090600f) |
| 24 | # define OPENSSL_free(x) Free(x) |
| 25 | #endif |
| 26 | |
Darren Tucker | a55ec77 | 2005-06-09 21:45:10 +1000 | [diff] [blame] | 27 | #if OPENSSL_VERSION_NUMBER < 0x00906000L |
| 28 | # define SSH_OLD_EVP |
| 29 | # define EVP_CIPHER_CTX_get_app_data(e) ((e)->app_data) |
Darren Tucker | cb52017 | 2007-06-14 23:21:32 +1000 | [diff] [blame] | 30 | #endif |
| 31 | |
Darren Tucker | a2ed755 | 2007-06-14 23:38:39 +1000 | [diff] [blame] | 32 | #if (OPENSSL_VERSION_NUMBER < 0x00907000L) || defined(OPENSSL_LOBOTOMISED_AES) |
| 33 | # define USE_BUILTIN_RIJNDAEL |
| 34 | #endif |
| 35 | |
Darren Tucker | cb52017 | 2007-06-14 23:21:32 +1000 | [diff] [blame] | 36 | #ifdef USE_BUILTIN_RIJNDAEL |
| 37 | # include "rijndael.h" |
| 38 | # define AES_KEY rijndael_ctx |
| 39 | # define AES_BLOCK_SIZE 16 |
| 40 | # define AES_encrypt(a, b, c) rijndael_encrypt(c, a, b) |
| 41 | # define AES_set_encrypt_key(a, b, c) rijndael_set_key(c, (char *)a, b, 1) |
Darren Tucker | a55ec77 | 2005-06-09 21:45:10 +1000 | [diff] [blame] | 42 | # define EVP_aes_128_cbc evp_rijndael |
| 43 | # define EVP_aes_192_cbc evp_rijndael |
| 44 | # define EVP_aes_256_cbc evp_rijndael |
| 45 | extern const EVP_CIPHER *evp_rijndael(void); |
| 46 | extern void ssh_rijndael_iv(EVP_CIPHER_CTX *, int, u_char *, u_int); |
| 47 | #endif |
| 48 | |
| 49 | #if !defined(EVP_CTRL_SET_ACSS_MODE) |
| 50 | # if (OPENSSL_VERSION_NUMBER >= 0x00907000L) |
| 51 | # define USE_CIPHER_ACSS 1 |
| 52 | extern const EVP_CIPHER *evp_acss(void); |
| 53 | # define EVP_acss evp_acss |
| 54 | # else |
| 55 | # define EVP_acss NULL |
| 56 | # endif |
| 57 | #endif |
| 58 | |
Darren Tucker | fd30986 | 2007-03-05 18:25:20 +1100 | [diff] [blame] | 59 | /* OpenSSL 0.9.8e returns cipher key len not context key len */ |
| 60 | #if (OPENSSL_VERSION_NUMBER == 0x0090805fL) |
| 61 | # define EVP_CIPHER_CTX_key_length(c) ((c)->key_len) |
| 62 | #endif |
| 63 | |
Darren Tucker | a55ec77 | 2005-06-09 21:45:10 +1000 | [diff] [blame] | 64 | /* |
Darren Tucker | 4123636 | 2005-11-20 14:09:59 +1100 | [diff] [blame] | 65 | * We overload some of the OpenSSL crypto functions with ssh_* equivalents |
| 66 | * which cater for older and/or less featureful OpenSSL version. |
| 67 | * |
| 68 | * In order for the compat library to call the real functions, it must |
| 69 | * define SSH_DONT_OVERLOAD_OPENSSL_FUNCS before including this file and |
| 70 | * implement the ssh_* equivalents. |
Darren Tucker | a55ec77 | 2005-06-09 21:45:10 +1000 | [diff] [blame] | 71 | */ |
Darren Tucker | fabdb6c | 2006-02-20 20:17:35 +1100 | [diff] [blame] | 72 | #ifndef SSH_DONT_OVERLOAD_OPENSSL_FUNCS |
Darren Tucker | a55ec77 | 2005-06-09 21:45:10 +1000 | [diff] [blame] | 73 | |
Darren Tucker | fabdb6c | 2006-02-20 20:17:35 +1100 | [diff] [blame] | 74 | # ifdef SSH_OLD_EVP |
Darren Tucker | a55ec77 | 2005-06-09 21:45:10 +1000 | [diff] [blame] | 75 | # ifdef EVP_Cipher |
| 76 | # undef EVP_Cipher |
| 77 | # endif |
Darren Tucker | a55ec77 | 2005-06-09 21:45:10 +1000 | [diff] [blame] | 78 | # define EVP_CipherInit(a,b,c,d,e) ssh_EVP_CipherInit((a),(b),(c),(d),(e)) |
| 79 | # define EVP_Cipher(a,b,c,d) ssh_EVP_Cipher((a),(b),(c),(d)) |
| 80 | # define EVP_CIPHER_CTX_cleanup(a) ssh_EVP_CIPHER_CTX_cleanup((a)) |
Darren Tucker | fabdb6c | 2006-02-20 20:17:35 +1100 | [diff] [blame] | 81 | # endif /* SSH_OLD_EVP */ |
| 82 | |
Darren Tucker | 3e7e15f | 2009-03-07 22:22:35 +1100 | [diff] [blame^] | 83 | # ifdef OPENSSL_EVP_DIGESTUPDATE_VOID |
| 84 | # define EVP_DigestUpdate(a,b,c) ssh_EVP_DigestUpdate((a),(b),(c)) |
| 85 | # endif |
| 86 | |
Darren Tucker | 3322e0d | 2006-02-22 00:00:27 +1100 | [diff] [blame] | 87 | # ifdef USE_OPENSSL_ENGINE |
| 88 | # ifdef SSLeay_add_all_algorithms |
| 89 | # undef SSLeay_add_all_algorithms |
| 90 | # endif |
Darren Tucker | bfaaf96 | 2008-02-28 19:13:52 +1100 | [diff] [blame] | 91 | # define SSLeay_add_all_algorithms() ssh_SSLeay_add_all_algorithms() |
| 92 | # endif |
Darren Tucker | a55ec77 | 2005-06-09 21:45:10 +1000 | [diff] [blame] | 93 | |
| 94 | int ssh_EVP_CipherInit(EVP_CIPHER_CTX *, const EVP_CIPHER *, unsigned char *, |
| 95 | unsigned char *, int); |
| 96 | int ssh_EVP_Cipher(EVP_CIPHER_CTX *, char *, char *, int); |
| 97 | int ssh_EVP_CIPHER_CTX_cleanup(EVP_CIPHER_CTX *); |
Darren Tucker | 94413cf | 2006-02-22 22:24:47 +1100 | [diff] [blame] | 98 | void ssh_SSLeay_add_all_algorithms(void); |
Darren Tucker | fabdb6c | 2006-02-20 20:17:35 +1100 | [diff] [blame] | 99 | #endif /* SSH_DONT_OVERLOAD_OPENSSL_FUNCS */ |