blob: 3513d6011abace57e49f946cee6699e8a575865f [file] [log] [blame]
Darren Tuckera55ec772005-06-09 21:45:10 +10001/*
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 Millerd7c81e22014-08-30 04:18:28 +100017#ifndef _OPENSSL_COMPAT_H
18#define _OPENSSL_COMPAT_H
19
Darren Tuckera55ec772005-06-09 21:45:10 +100020#include "includes.h"
Damien Miller72ef7c12015-01-15 02:21:31 +110021#ifdef WITH_OPENSSL
22
Damien Miller9a3d0dc2010-10-07 22:06:42 +110023#include <openssl/opensslv.h>
Darren Tuckera55ec772005-06-09 21:45:10 +100024#include <openssl/evp.h>
Damien Miller4b1ec832010-05-12 17:49:59 +100025#include <openssl/rsa.h>
26#include <openssl/dsa.h>
27
Darren Tucker316fac62014-06-17 23:06:07 +100028int ssh_compatible_openssl(long, long);
29
Damien Miller86687062014-07-02 15:28:02 +100030#if (OPENSSL_VERSION_NUMBER <= 0x0090805fL)
Damien Millerd7c81e22014-08-30 04:18:28 +100031# error OpenSSL 0.9.8f or greater is required
Darren Tuckercb520172007-06-14 23:21:32 +100032#endif
33
Damien Millerda5cc5d2013-01-20 22:31:29 +110034#if OPENSSL_VERSION_NUMBER < 0x10000001L
Damien Miller9a3d0dc2010-10-07 22:06:42 +110035# define LIBCRYPTO_EVP_INL_TYPE unsigned int
36#else
37# define LIBCRYPTO_EVP_INL_TYPE size_t
38#endif
39
Damien Miller51c77e22014-08-30 02:30:30 +100040#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 Tucker55731712014-07-21 02:24:59 +100047#ifndef OPENSSL_HAVE_EVPCTR
Damien Millerd7c81e22014-08-30 04:18:28 +100048# 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 Tucker55731712014-07-21 02:24:59 +100051const EVP_CIPHER *evp_aes_128_ctr(void);
52void ssh_aes_ctr_iv(EVP_CIPHER_CTX *, int, u_char *, size_t);
53#endif
54
Damien Millerd522c682013-01-09 16:42:47 +110055/* 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 Millerb6f73b32013-02-11 10:39:12 +110063/* 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 Tuckera55ec772005-06-09 21:45:10 +100072/*
Darren Tucker41236362005-11-20 14:09:59 +110073 * We overload some of the OpenSSL crypto functions with ssh_* equivalents
Damien Miller86687062014-07-02 15:28:02 +100074 * to automatically handle OpenSSL engine initialisation.
Darren Tucker41236362005-11-20 14:09:59 +110075 *
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 Tuckera55ec772005-06-09 21:45:10 +100079 */
Darren Tuckerfabdb6c2006-02-20 20:17:35 +110080#ifndef SSH_DONT_OVERLOAD_OPENSSL_FUNCS
Darren Tuckera55ec772005-06-09 21:45:10 +100081
Darren Tucker3322e0d2006-02-22 00:00:27 +110082# ifdef USE_OPENSSL_ENGINE
Darren Tuckerd6548fe2011-05-10 11:13:36 +100083# ifdef OpenSSL_add_all_algorithms
84# undef OpenSSL_add_all_algorithms
Darren Tucker3322e0d2006-02-22 00:00:27 +110085# endif
Darren Tuckerd6548fe2011-05-10 11:13:36 +100086# define OpenSSL_add_all_algorithms() ssh_OpenSSL_add_all_algorithms()
Darren Tuckerbfaaf962008-02-28 19:13:52 +110087# endif
Darren Tuckera55ec772005-06-09 21:45:10 +100088
Darren Tuckerd6548fe2011-05-10 11:13:36 +100089void ssh_OpenSSL_add_all_algorithms(void);
Darren Tuckere9b3ad72012-01-17 14:03:34 +110090
Darren Tuckerfabdb6c2006-02-20 20:17:35 +110091#endif /* SSH_DONT_OVERLOAD_OPENSSL_FUNCS */
Damien Miller4b1ec832010-05-12 17:49:59 +100092
Damien Miller72ef7c12015-01-15 02:21:31 +110093#endif /* WITH_OPENSSL */
Damien Millerd7c81e22014-08-30 04:18:28 +100094#endif /* _OPENSSL_COMPAT_H */