Darren Tucker | a55ec77 | 2005-06-09 21:45:10 +1000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2005 Darren Tucker <dtucker@zip.com.au> |
| 3 | * |
| 4 | * Permission to use, copy, modify, and distribute this software for any |
| 5 | * purpose with or without fee is hereby granted, provided that the above |
| 6 | * copyright notice and this permission notice appear in all copies. |
| 7 | * |
| 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
| 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
| 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
| 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
| 12 | * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER |
| 13 | * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING |
| 14 | * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 15 | */ |
| 16 | |
Damien Miller | d7c81e2 | 2014-08-30 04:18:28 +1000 | [diff] [blame] | 17 | #ifndef _OPENSSL_COMPAT_H |
| 18 | #define _OPENSSL_COMPAT_H |
| 19 | |
Darren Tucker | a55ec77 | 2005-06-09 21:45:10 +1000 | [diff] [blame] | 20 | #include "includes.h" |
Damien Miller | 72ef7c1 | 2015-01-15 02:21:31 +1100 | [diff] [blame] | 21 | #ifdef WITH_OPENSSL |
| 22 | |
Damien Miller | 9a3d0dc | 2010-10-07 22:06:42 +1100 | [diff] [blame] | 23 | #include <openssl/opensslv.h> |
Darren Tucker | a55ec77 | 2005-06-09 21:45:10 +1000 | [diff] [blame] | 24 | #include <openssl/evp.h> |
Damien Miller | 4b1ec83 | 2010-05-12 17:49:59 +1000 | [diff] [blame] | 25 | #include <openssl/rsa.h> |
| 26 | #include <openssl/dsa.h> |
| 27 | |
Darren Tucker | 316fac6 | 2014-06-17 23:06:07 +1000 | [diff] [blame] | 28 | int ssh_compatible_openssl(long, long); |
| 29 | |
Damien Miller | 8668706 | 2014-07-02 15:28:02 +1000 | [diff] [blame] | 30 | #if (OPENSSL_VERSION_NUMBER <= 0x0090805fL) |
Damien Miller | d7c81e2 | 2014-08-30 04:18:28 +1000 | [diff] [blame] | 31 | # error OpenSSL 0.9.8f or greater is required |
Darren Tucker | cb52017 | 2007-06-14 23:21:32 +1000 | [diff] [blame] | 32 | #endif |
| 33 | |
Damien Miller | da5cc5d | 2013-01-20 22:31:29 +1100 | [diff] [blame] | 34 | #if OPENSSL_VERSION_NUMBER < 0x10000001L |
Damien Miller | 9a3d0dc | 2010-10-07 22:06:42 +1100 | [diff] [blame] | 35 | # define LIBCRYPTO_EVP_INL_TYPE unsigned int |
| 36 | #else |
| 37 | # define LIBCRYPTO_EVP_INL_TYPE size_t |
| 38 | #endif |
| 39 | |
Damien Miller | 51c77e2 | 2014-08-30 02:30:30 +1000 | [diff] [blame] | 40 | #ifndef OPENSSL_RSA_MAX_MODULUS_BITS |
| 41 | # define OPENSSL_RSA_MAX_MODULUS_BITS 16384 |
| 42 | #endif |
| 43 | #ifndef OPENSSL_DSA_MAX_MODULUS_BITS |
| 44 | # define OPENSSL_DSA_MAX_MODULUS_BITS 10000 |
| 45 | #endif |
| 46 | |
Darren Tucker | 5573171 | 2014-07-21 02:24:59 +1000 | [diff] [blame] | 47 | #ifndef OPENSSL_HAVE_EVPCTR |
Damien Miller | d7c81e2 | 2014-08-30 04:18:28 +1000 | [diff] [blame] | 48 | # define EVP_aes_128_ctr evp_aes_128_ctr |
| 49 | # define EVP_aes_192_ctr evp_aes_128_ctr |
| 50 | # define EVP_aes_256_ctr evp_aes_128_ctr |
Darren Tucker | 5573171 | 2014-07-21 02:24:59 +1000 | [diff] [blame] | 51 | const EVP_CIPHER *evp_aes_128_ctr(void); |
| 52 | void ssh_aes_ctr_iv(EVP_CIPHER_CTX *, int, u_char *, size_t); |
| 53 | #endif |
| 54 | |
Damien Miller | d522c68 | 2013-01-09 16:42:47 +1100 | [diff] [blame] | 55 | /* Avoid some #ifdef. Code that uses these is unreachable without GCM */ |
| 56 | #if !defined(OPENSSL_HAVE_EVPGCM) && !defined(EVP_CTRL_GCM_SET_IV_FIXED) |
| 57 | # define EVP_CTRL_GCM_SET_IV_FIXED -1 |
| 58 | # define EVP_CTRL_GCM_IV_GEN -1 |
| 59 | # define EVP_CTRL_GCM_SET_TAG -1 |
| 60 | # define EVP_CTRL_GCM_GET_TAG -1 |
| 61 | #endif |
| 62 | |
Damien Miller | b6f73b3 | 2013-02-11 10:39:12 +1100 | [diff] [blame] | 63 | /* Replace missing EVP_CIPHER_CTX_ctrl() with something that returns failure */ |
| 64 | #ifndef HAVE_EVP_CIPHER_CTX_CTRL |
| 65 | # ifdef OPENSSL_HAVE_EVPGCM |
| 66 | # error AES-GCM enabled without EVP_CIPHER_CTX_ctrl /* shouldn't happen */ |
| 67 | # else |
| 68 | # define EVP_CIPHER_CTX_ctrl(a,b,c,d) (0) |
| 69 | # endif |
| 70 | #endif |
| 71 | |
Darren Tucker | a55ec77 | 2005-06-09 21:45:10 +1000 | [diff] [blame] | 72 | /* |
Darren Tucker | 4123636 | 2005-11-20 14:09:59 +1100 | [diff] [blame] | 73 | * We overload some of the OpenSSL crypto functions with ssh_* equivalents |
Damien Miller | 8668706 | 2014-07-02 15:28:02 +1000 | [diff] [blame] | 74 | * to automatically handle OpenSSL engine initialisation. |
Darren Tucker | 4123636 | 2005-11-20 14:09:59 +1100 | [diff] [blame] | 75 | * |
| 76 | * In order for the compat library to call the real functions, it must |
| 77 | * define SSH_DONT_OVERLOAD_OPENSSL_FUNCS before including this file and |
| 78 | * implement the ssh_* equivalents. |
Darren Tucker | a55ec77 | 2005-06-09 21:45:10 +1000 | [diff] [blame] | 79 | */ |
Darren Tucker | fabdb6c | 2006-02-20 20:17:35 +1100 | [diff] [blame] | 80 | #ifndef SSH_DONT_OVERLOAD_OPENSSL_FUNCS |
Darren Tucker | a55ec77 | 2005-06-09 21:45:10 +1000 | [diff] [blame] | 81 | |
Darren Tucker | 3322e0d | 2006-02-22 00:00:27 +1100 | [diff] [blame] | 82 | # ifdef USE_OPENSSL_ENGINE |
Darren Tucker | d6548fe | 2011-05-10 11:13:36 +1000 | [diff] [blame] | 83 | # ifdef OpenSSL_add_all_algorithms |
| 84 | # undef OpenSSL_add_all_algorithms |
Darren Tucker | 3322e0d | 2006-02-22 00:00:27 +1100 | [diff] [blame] | 85 | # endif |
Darren Tucker | d6548fe | 2011-05-10 11:13:36 +1000 | [diff] [blame] | 86 | # define OpenSSL_add_all_algorithms() ssh_OpenSSL_add_all_algorithms() |
Darren Tucker | bfaaf96 | 2008-02-28 19:13:52 +1100 | [diff] [blame] | 87 | # endif |
Darren Tucker | a55ec77 | 2005-06-09 21:45:10 +1000 | [diff] [blame] | 88 | |
Darren Tucker | d6548fe | 2011-05-10 11:13:36 +1000 | [diff] [blame] | 89 | void ssh_OpenSSL_add_all_algorithms(void); |
Darren Tucker | e9b3ad7 | 2012-01-17 14:03:34 +1100 | [diff] [blame] | 90 | |
Darren Tucker | fabdb6c | 2006-02-20 20:17:35 +1100 | [diff] [blame] | 91 | #endif /* SSH_DONT_OVERLOAD_OPENSSL_FUNCS */ |
Damien Miller | 4b1ec83 | 2010-05-12 17:49:59 +1000 | [diff] [blame] | 92 | |
Damien Miller | 72ef7c1 | 2015-01-15 02:21:31 +1100 | [diff] [blame] | 93 | #endif /* WITH_OPENSSL */ |
Damien Miller | d7c81e2 | 2014-08-30 04:18:28 +1000 | [diff] [blame] | 94 | #endif /* _OPENSSL_COMPAT_H */ |