blob: 8917551d314ebae99bb03d16dd5b30149b7c9b66 [file] [log] [blame]
Adam Langleyd0592972015-03-30 14:49:51 -07001/* $Id: openssl-compat.h,v 1.31 2014/08/29 18:18:29 djm Exp $ */
Greg Hartmanbd77cf72015-02-25 13:21:06 -08002
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
Adam Langleyd0592972015-03-30 14:49:51 -070019#ifndef _OPENSSL_COMPAT_H
20#define _OPENSSL_COMPAT_H
21
Greg Hartmanbd77cf72015-02-25 13:21:06 -080022#include "includes.h"
Adam Langleyd0592972015-03-30 14:49:51 -070023#ifdef WITH_OPENSSL
24
Greg Hartmanbd77cf72015-02-25 13:21:06 -080025#include <openssl/opensslv.h>
26#include <openssl/evp.h>
27#include <openssl/rsa.h>
28#include <openssl/dsa.h>
29
Adam Langleyd0592972015-03-30 14:49:51 -070030int ssh_compatible_openssl(long, long);
31
32#if (OPENSSL_VERSION_NUMBER <= 0x0090805fL)
33# error OpenSSL 0.9.8f or greater is required
Greg Hartmanbd77cf72015-02-25 13:21:06 -080034#endif
35
Adam Langleyd0592972015-03-30 14:49:51 -070036#if OPENSSL_VERSION_NUMBER < 0x10000001L
Greg Hartmanbd77cf72015-02-25 13:21:06 -080037# define LIBCRYPTO_EVP_INL_TYPE unsigned int
38#else
39# define LIBCRYPTO_EVP_INL_TYPE size_t
40#endif
41
Adam Langleyd0592972015-03-30 14:49:51 -070042#ifndef OPENSSL_RSA_MAX_MODULUS_BITS
43# define OPENSSL_RSA_MAX_MODULUS_BITS 16384
44#endif
45#ifndef OPENSSL_DSA_MAX_MODULUS_BITS
46# define OPENSSL_DSA_MAX_MODULUS_BITS 10000
Greg Hartmanbd77cf72015-02-25 13:21:06 -080047#endif
48
Adam Langleyd0592972015-03-30 14:49:51 -070049#ifndef OPENSSL_HAVE_EVPCTR
50# define EVP_aes_128_ctr evp_aes_128_ctr
51# define EVP_aes_192_ctr evp_aes_128_ctr
52# define EVP_aes_256_ctr evp_aes_128_ctr
53const EVP_CIPHER *evp_aes_128_ctr(void);
54void ssh_aes_ctr_iv(EVP_CIPHER_CTX *, int, u_char *, size_t);
Greg Hartmanbd77cf72015-02-25 13:21:06 -080055#endif
56
Adam Langleyd0592972015-03-30 14:49:51 -070057/* Avoid some #ifdef. Code that uses these is unreachable without GCM */
58#if !defined(OPENSSL_HAVE_EVPGCM) && !defined(EVP_CTRL_GCM_SET_IV_FIXED)
59# define EVP_CTRL_GCM_SET_IV_FIXED -1
60# define EVP_CTRL_GCM_IV_GEN -1
61# define EVP_CTRL_GCM_SET_TAG -1
62# define EVP_CTRL_GCM_GET_TAG -1
63#endif
64
65/* Replace missing EVP_CIPHER_CTX_ctrl() with something that returns failure */
66#ifndef HAVE_EVP_CIPHER_CTX_CTRL
67# ifdef OPENSSL_HAVE_EVPGCM
68# error AES-GCM enabled without EVP_CIPHER_CTX_ctrl /* shouldn't happen */
Greg Hartmanbd77cf72015-02-25 13:21:06 -080069# else
Adam Langleyd0592972015-03-30 14:49:51 -070070# define EVP_CIPHER_CTX_ctrl(a,b,c,d) (0)
Greg Hartmanbd77cf72015-02-25 13:21:06 -080071# endif
72#endif
73
Greg Hartmanbd77cf72015-02-25 13:21:06 -080074/*
75 * We overload some of the OpenSSL crypto functions with ssh_* equivalents
Adam Langleyd0592972015-03-30 14:49:51 -070076 * to automatically handle OpenSSL engine initialisation.
Greg Hartmanbd77cf72015-02-25 13:21:06 -080077 *
78 * In order for the compat library to call the real functions, it must
79 * define SSH_DONT_OVERLOAD_OPENSSL_FUNCS before including this file and
80 * implement the ssh_* equivalents.
81 */
82#ifndef SSH_DONT_OVERLOAD_OPENSSL_FUNCS
83
Greg Hartmanbd77cf72015-02-25 13:21:06 -080084# ifdef USE_OPENSSL_ENGINE
85# ifdef OpenSSL_add_all_algorithms
86# undef OpenSSL_add_all_algorithms
87# endif
88# define OpenSSL_add_all_algorithms() ssh_OpenSSL_add_all_algorithms()
89# endif
90
Greg Hartmanbd77cf72015-02-25 13:21:06 -080091void ssh_OpenSSL_add_all_algorithms(void);
Adam Langleyd0592972015-03-30 14:49:51 -070092
Greg Hartmanbd77cf72015-02-25 13:21:06 -080093#endif /* SSH_DONT_OVERLOAD_OPENSSL_FUNCS */
94
Adam Langleyd0592972015-03-30 14:49:51 -070095#endif /* WITH_OPENSSL */
96#endif /* _OPENSSL_COMPAT_H */