blob: b7caa650c24a5a1ce0141a8d111ffce1c28483b2 [file] [log] [blame]
Damien Miller4b1ec832010-05-12 17:49:59 +10001/* $Id: openssl-compat.h,v 1.15 2010/05/12 07:50:02 djm 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"
20#include <openssl/evp.h>
Damien Miller4b1ec832010-05-12 17:49:59 +100021#include <openssl/rsa.h>
22#include <openssl/dsa.h>
23
24/* Only in 0.9.8 */
25#ifndef OPENSSL_DSA_MAX_MODULUS_BITS
26# define OPENSSL_DSA_MAX_MODULUS_BITS 10000
27#endif
28#ifndef OPENSSL_RSA_MAX_MODULUS_BITS
29# define OPENSSL_RSA_MAX_MODULUS_BITS 16384
30#endif
Darren Tuckera55ec772005-06-09 21:45:10 +100031
Darren Tucker3d295a62008-02-28 19:22:04 +110032/* OPENSSL_free() is Free() in versions before OpenSSL 0.9.6 */
33#if !defined(OPENSSL_VERSION_NUMBER) || (OPENSSL_VERSION_NUMBER < 0x0090600f)
34# define OPENSSL_free(x) Free(x)
35#endif
36
Darren Tuckera55ec772005-06-09 21:45:10 +100037#if OPENSSL_VERSION_NUMBER < 0x00906000L
38# define SSH_OLD_EVP
39# define EVP_CIPHER_CTX_get_app_data(e) ((e)->app_data)
Darren Tuckercb520172007-06-14 23:21:32 +100040#endif
41
Darren Tuckera2ed7552007-06-14 23:38:39 +100042#if (OPENSSL_VERSION_NUMBER < 0x00907000L) || defined(OPENSSL_LOBOTOMISED_AES)
43# define USE_BUILTIN_RIJNDAEL
44#endif
45
Darren Tuckercb520172007-06-14 23:21:32 +100046#ifdef USE_BUILTIN_RIJNDAEL
47# include "rijndael.h"
48# define AES_KEY rijndael_ctx
49# define AES_BLOCK_SIZE 16
50# define AES_encrypt(a, b, c) rijndael_encrypt(c, a, b)
51# define AES_set_encrypt_key(a, b, c) rijndael_set_key(c, (char *)a, b, 1)
Darren Tuckera55ec772005-06-09 21:45:10 +100052# define EVP_aes_128_cbc evp_rijndael
53# define EVP_aes_192_cbc evp_rijndael
54# define EVP_aes_256_cbc evp_rijndael
55extern const EVP_CIPHER *evp_rijndael(void);
56extern void ssh_rijndael_iv(EVP_CIPHER_CTX *, int, u_char *, u_int);
57#endif
58
59#if !defined(EVP_CTRL_SET_ACSS_MODE)
60# if (OPENSSL_VERSION_NUMBER >= 0x00907000L)
61# define USE_CIPHER_ACSS 1
62extern const EVP_CIPHER *evp_acss(void);
63# define EVP_acss evp_acss
64# else
65# define EVP_acss NULL
66# endif
67#endif
68
Darren Tuckerfd309862007-03-05 18:25:20 +110069/* OpenSSL 0.9.8e returns cipher key len not context key len */
70#if (OPENSSL_VERSION_NUMBER == 0x0090805fL)
71# define EVP_CIPHER_CTX_key_length(c) ((c)->key_len)
72#endif
73
Darren Tuckera55ec772005-06-09 21:45:10 +100074/*
Darren Tucker41236362005-11-20 14:09:59 +110075 * We overload some of the OpenSSL crypto functions with ssh_* equivalents
76 * which cater for older and/or less featureful OpenSSL version.
77 *
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.
Darren Tuckera55ec772005-06-09 21:45:10 +100081 */
Darren Tuckerfabdb6c2006-02-20 20:17:35 +110082#ifndef SSH_DONT_OVERLOAD_OPENSSL_FUNCS
Darren Tuckera55ec772005-06-09 21:45:10 +100083
Darren Tuckerfabdb6c2006-02-20 20:17:35 +110084# ifdef SSH_OLD_EVP
Darren Tuckera55ec772005-06-09 21:45:10 +100085# ifdef EVP_Cipher
86# undef EVP_Cipher
87# endif
Darren Tuckera55ec772005-06-09 21:45:10 +100088# define EVP_CipherInit(a,b,c,d,e) ssh_EVP_CipherInit((a),(b),(c),(d),(e))
89# define EVP_Cipher(a,b,c,d) ssh_EVP_Cipher((a),(b),(c),(d))
90# define EVP_CIPHER_CTX_cleanup(a) ssh_EVP_CIPHER_CTX_cleanup((a))
Darren Tuckerfabdb6c2006-02-20 20:17:35 +110091# endif /* SSH_OLD_EVP */
92
Darren Tucker3e7e15f2009-03-07 22:22:35 +110093# ifdef OPENSSL_EVP_DIGESTUPDATE_VOID
94# define EVP_DigestUpdate(a,b,c) ssh_EVP_DigestUpdate((a),(b),(c))
95# endif
96
Darren Tucker3322e0d2006-02-22 00:00:27 +110097# ifdef USE_OPENSSL_ENGINE
98# ifdef SSLeay_add_all_algorithms
99# undef SSLeay_add_all_algorithms
100# endif
Darren Tuckerbfaaf962008-02-28 19:13:52 +1100101# define SSLeay_add_all_algorithms() ssh_SSLeay_add_all_algorithms()
102# endif
Darren Tuckera55ec772005-06-09 21:45:10 +1000103
104int ssh_EVP_CipherInit(EVP_CIPHER_CTX *, const EVP_CIPHER *, unsigned char *,
105 unsigned char *, int);
106int ssh_EVP_Cipher(EVP_CIPHER_CTX *, char *, char *, int);
107int ssh_EVP_CIPHER_CTX_cleanup(EVP_CIPHER_CTX *);
Darren Tucker94413cf2006-02-22 22:24:47 +1100108void ssh_SSLeay_add_all_algorithms(void);
Darren Tuckerfabdb6c2006-02-20 20:17:35 +1100109#endif /* SSH_DONT_OVERLOAD_OPENSSL_FUNCS */
Damien Miller4b1ec832010-05-12 17:49:59 +1000110