blob: 21002107a581beabf090bc7fcef18aec1d3c916d [file] [log] [blame]
Darren Tucker55731712014-07-21 02:24:59 +10001/* $Id: openssl-compat.h,v 1.29 2014/07/20 16:24:59 dtucker Exp $ */
Darren Tuckera55ec772005-06-09 21:45:10 +10002
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"
Damien Miller9a3d0dc2010-10-07 22:06:42 +110020#include <openssl/opensslv.h>
Darren Tuckera55ec772005-06-09 21:45:10 +100021#include <openssl/evp.h>
Damien Miller4b1ec832010-05-12 17:49:59 +100022#include <openssl/rsa.h>
23#include <openssl/dsa.h>
24
Darren Tucker316fac62014-06-17 23:06:07 +100025int ssh_compatible_openssl(long, long);
26
Damien Miller86687062014-07-02 15:28:02 +100027#if (OPENSSL_VERSION_NUMBER <= 0x0090805fL)
28#error OpenSSL 0.9.8f or greater is required
Darren Tuckercb520172007-06-14 23:21:32 +100029#endif
30
Damien Millerda5cc5d2013-01-20 22:31:29 +110031#if OPENSSL_VERSION_NUMBER < 0x10000001L
Damien Miller9a3d0dc2010-10-07 22:06:42 +110032# define LIBCRYPTO_EVP_INL_TYPE unsigned int
33#else
34# define LIBCRYPTO_EVP_INL_TYPE size_t
35#endif
36
Darren Tucker55731712014-07-21 02:24:59 +100037#ifndef OPENSSL_HAVE_EVPCTR
38#define EVP_aes_128_ctr evp_aes_128_ctr
39#define EVP_aes_192_ctr evp_aes_128_ctr
40#define EVP_aes_256_ctr evp_aes_128_ctr
41const EVP_CIPHER *evp_aes_128_ctr(void);
42void ssh_aes_ctr_iv(EVP_CIPHER_CTX *, int, u_char *, size_t);
43#endif
44
Damien Millerd522c682013-01-09 16:42:47 +110045/* Avoid some #ifdef. Code that uses these is unreachable without GCM */
46#if !defined(OPENSSL_HAVE_EVPGCM) && !defined(EVP_CTRL_GCM_SET_IV_FIXED)
47# define EVP_CTRL_GCM_SET_IV_FIXED -1
48# define EVP_CTRL_GCM_IV_GEN -1
49# define EVP_CTRL_GCM_SET_TAG -1
50# define EVP_CTRL_GCM_GET_TAG -1
51#endif
52
Damien Millerb6f73b32013-02-11 10:39:12 +110053/* Replace missing EVP_CIPHER_CTX_ctrl() with something that returns failure */
54#ifndef HAVE_EVP_CIPHER_CTX_CTRL
55# ifdef OPENSSL_HAVE_EVPGCM
56# error AES-GCM enabled without EVP_CIPHER_CTX_ctrl /* shouldn't happen */
57# else
58# define EVP_CIPHER_CTX_ctrl(a,b,c,d) (0)
59# endif
60#endif
61
Darren Tuckera55ec772005-06-09 21:45:10 +100062/*
Darren Tucker41236362005-11-20 14:09:59 +110063 * We overload some of the OpenSSL crypto functions with ssh_* equivalents
Damien Miller86687062014-07-02 15:28:02 +100064 * to automatically handle OpenSSL engine initialisation.
Darren Tucker41236362005-11-20 14:09:59 +110065 *
66 * In order for the compat library to call the real functions, it must
67 * define SSH_DONT_OVERLOAD_OPENSSL_FUNCS before including this file and
68 * implement the ssh_* equivalents.
Darren Tuckera55ec772005-06-09 21:45:10 +100069 */
Darren Tuckerfabdb6c2006-02-20 20:17:35 +110070#ifndef SSH_DONT_OVERLOAD_OPENSSL_FUNCS
Darren Tuckera55ec772005-06-09 21:45:10 +100071
Darren Tucker3322e0d2006-02-22 00:00:27 +110072# ifdef USE_OPENSSL_ENGINE
Darren Tuckerd6548fe2011-05-10 11:13:36 +100073# ifdef OpenSSL_add_all_algorithms
74# undef OpenSSL_add_all_algorithms
Darren Tucker3322e0d2006-02-22 00:00:27 +110075# endif
Darren Tuckerd6548fe2011-05-10 11:13:36 +100076# define OpenSSL_add_all_algorithms() ssh_OpenSSL_add_all_algorithms()
Darren Tuckerbfaaf962008-02-28 19:13:52 +110077# endif
Darren Tuckera55ec772005-06-09 21:45:10 +100078
Darren Tuckerd6548fe2011-05-10 11:13:36 +100079void ssh_OpenSSL_add_all_algorithms(void);
Darren Tuckere9b3ad72012-01-17 14:03:34 +110080
Darren Tuckerfabdb6c2006-02-20 20:17:35 +110081#endif /* SSH_DONT_OVERLOAD_OPENSSL_FUNCS */
Damien Miller4b1ec832010-05-12 17:49:59 +100082