1*a0ee8cc6SDag-Erling Smørgrav /* $Id: openssl-compat.h,v 1.31 2014/08/29 18:18:29 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 19*a0ee8cc6SDag-Erling Smørgrav #ifndef _OPENSSL_COMPAT_H 20*a0ee8cc6SDag-Erling Smørgrav #define _OPENSSL_COMPAT_H 21*a0ee8cc6SDag-Erling Smørgrav 22043840dfSDag-Erling Smørgrav #include "includes.h" 234a421b63SDag-Erling Smørgrav #include <openssl/opensslv.h> 24043840dfSDag-Erling Smørgrav #include <openssl/evp.h> 25e2f6069cSDag-Erling Smørgrav #include <openssl/rsa.h> 26e2f6069cSDag-Erling Smørgrav #include <openssl/dsa.h> 27e2f6069cSDag-Erling Smørgrav 28*a0ee8cc6SDag-Erling Smørgrav int ssh_compatible_openssl(long, long); 29043840dfSDag-Erling Smørgrav 30*a0ee8cc6SDag-Erling Smørgrav #if (OPENSSL_VERSION_NUMBER <= 0x0090805fL) 31*a0ee8cc6SDag-Erling Smørgrav # error OpenSSL 0.9.8f or greater is required 32043840dfSDag-Erling Smørgrav #endif 33043840dfSDag-Erling Smørgrav 346888a9beSDag-Erling Smørgrav #if OPENSSL_VERSION_NUMBER < 0x10000001L 354a421b63SDag-Erling Smørgrav # define LIBCRYPTO_EVP_INL_TYPE unsigned int 364a421b63SDag-Erling Smørgrav #else 374a421b63SDag-Erling Smørgrav # define LIBCRYPTO_EVP_INL_TYPE size_t 384a421b63SDag-Erling Smørgrav #endif 394a421b63SDag-Erling Smørgrav 40*a0ee8cc6SDag-Erling Smørgrav #ifndef OPENSSL_RSA_MAX_MODULUS_BITS 41*a0ee8cc6SDag-Erling Smørgrav # define OPENSSL_RSA_MAX_MODULUS_BITS 16384 42021d409fSDag-Erling Smørgrav #endif 43*a0ee8cc6SDag-Erling Smørgrav #ifndef OPENSSL_DSA_MAX_MODULUS_BITS 44*a0ee8cc6SDag-Erling Smørgrav # define OPENSSL_DSA_MAX_MODULUS_BITS 10000 45043840dfSDag-Erling Smørgrav #endif 46043840dfSDag-Erling Smørgrav 476888a9beSDag-Erling Smørgrav #ifndef OPENSSL_HAVE_EVPCTR 486888a9beSDag-Erling Smørgrav # define EVP_aes_128_ctr evp_aes_128_ctr 496888a9beSDag-Erling Smørgrav # define EVP_aes_192_ctr evp_aes_128_ctr 506888a9beSDag-Erling Smørgrav # define EVP_aes_256_ctr evp_aes_128_ctr 516888a9beSDag-Erling Smørgrav const EVP_CIPHER *evp_aes_128_ctr(void); 526888a9beSDag-Erling Smørgrav void ssh_aes_ctr_iv(EVP_CIPHER_CTX *, int, u_char *, size_t); 53043840dfSDag-Erling Smørgrav #endif 546888a9beSDag-Erling Smørgrav 556888a9beSDag-Erling Smørgrav /* Avoid some #ifdef. Code that uses these is unreachable without GCM */ 566888a9beSDag-Erling Smørgrav #if !defined(OPENSSL_HAVE_EVPGCM) && !defined(EVP_CTRL_GCM_SET_IV_FIXED) 576888a9beSDag-Erling Smørgrav # define EVP_CTRL_GCM_SET_IV_FIXED -1 586888a9beSDag-Erling Smørgrav # define EVP_CTRL_GCM_IV_GEN -1 596888a9beSDag-Erling Smørgrav # define EVP_CTRL_GCM_SET_TAG -1 606888a9beSDag-Erling Smørgrav # define EVP_CTRL_GCM_GET_TAG -1 616888a9beSDag-Erling Smørgrav #endif 626888a9beSDag-Erling Smørgrav 636888a9beSDag-Erling Smørgrav /* Replace missing EVP_CIPHER_CTX_ctrl() with something that returns failure */ 646888a9beSDag-Erling Smørgrav #ifndef HAVE_EVP_CIPHER_CTX_CTRL 656888a9beSDag-Erling Smørgrav # ifdef OPENSSL_HAVE_EVPGCM 666888a9beSDag-Erling Smørgrav # error AES-GCM enabled without EVP_CIPHER_CTX_ctrl /* shouldn't happen */ 676888a9beSDag-Erling Smørgrav # else 686888a9beSDag-Erling Smørgrav # define EVP_CIPHER_CTX_ctrl(a,b,c,d) (0) 696888a9beSDag-Erling Smørgrav # endif 706888a9beSDag-Erling Smørgrav #endif 716888a9beSDag-Erling Smørgrav 72043840dfSDag-Erling Smørgrav /* 73021d409fSDag-Erling Smørgrav * We overload some of the OpenSSL crypto functions with ssh_* equivalents 74*a0ee8cc6SDag-Erling Smørgrav * to automatically handle OpenSSL engine initialisation. 75021d409fSDag-Erling Smørgrav * 76021d409fSDag-Erling Smørgrav * In order for the compat library to call the real functions, it must 77021d409fSDag-Erling Smørgrav * define SSH_DONT_OVERLOAD_OPENSSL_FUNCS before including this file and 78021d409fSDag-Erling Smørgrav * implement the ssh_* equivalents. 79043840dfSDag-Erling Smørgrav */ 80761efaa7SDag-Erling Smørgrav #ifndef SSH_DONT_OVERLOAD_OPENSSL_FUNCS 81761efaa7SDag-Erling Smørgrav 82761efaa7SDag-Erling Smørgrav # ifdef USE_OPENSSL_ENGINE 83e146993eSDag-Erling Smørgrav # ifdef OpenSSL_add_all_algorithms 84e146993eSDag-Erling Smørgrav # undef OpenSSL_add_all_algorithms 85761efaa7SDag-Erling Smørgrav # endif 86e146993eSDag-Erling Smørgrav # define OpenSSL_add_all_algorithms() ssh_OpenSSL_add_all_algorithms() 87043840dfSDag-Erling Smørgrav # endif 88043840dfSDag-Erling Smørgrav 89e146993eSDag-Erling Smørgrav void ssh_OpenSSL_add_all_algorithms(void); 90462c32cbSDag-Erling Smørgrav 91761efaa7SDag-Erling Smørgrav #endif /* SSH_DONT_OVERLOAD_OPENSSL_FUNCS */ 92e2f6069cSDag-Erling Smørgrav 93*a0ee8cc6SDag-Erling Smørgrav #endif /* _OPENSSL_COMPAT_H */ 94