blob: 9b5ccff5faafa6e7fc3536cfcb819bef1a6d680f [file] [log] [blame]
Darren Tuckerfd309862007-03-05 18:25:20 +11001/* $Id: openssl-compat.h,v 1.7 2007/03/05 07:25:20 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"
20#include <openssl/evp.h>
21
22#if OPENSSL_VERSION_NUMBER < 0x00906000L
23# define SSH_OLD_EVP
24# define EVP_CIPHER_CTX_get_app_data(e) ((e)->app_data)
25#endif
26
Darren Tucker129d0bb2005-12-19 17:40:40 +110027#if (OPENSSL_VERSION_NUMBER < 0x00907000L) || defined(OPENSSL_LOBOTOMISED_AES)
28# define USE_BUILTIN_RIJNDAEL
29#endif
30
31#ifdef USE_BUILTIN_RIJNDAEL
Darren Tuckera55ec772005-06-09 21:45:10 +100032# define EVP_aes_128_cbc evp_rijndael
33# define EVP_aes_192_cbc evp_rijndael
34# define EVP_aes_256_cbc evp_rijndael
35extern const EVP_CIPHER *evp_rijndael(void);
36extern void ssh_rijndael_iv(EVP_CIPHER_CTX *, int, u_char *, u_int);
37#endif
38
39#if !defined(EVP_CTRL_SET_ACSS_MODE)
40# if (OPENSSL_VERSION_NUMBER >= 0x00907000L)
41# define USE_CIPHER_ACSS 1
42extern const EVP_CIPHER *evp_acss(void);
43# define EVP_acss evp_acss
44# else
45# define EVP_acss NULL
46# endif
47#endif
48
Darren Tuckerfd309862007-03-05 18:25:20 +110049/* OpenSSL 0.9.8e returns cipher key len not context key len */
50#if (OPENSSL_VERSION_NUMBER == 0x0090805fL)
51# define EVP_CIPHER_CTX_key_length(c) ((c)->key_len)
52#endif
53
Darren Tuckera55ec772005-06-09 21:45:10 +100054/*
Darren Tucker41236362005-11-20 14:09:59 +110055 * We overload some of the OpenSSL crypto functions with ssh_* equivalents
56 * which cater for older and/or less featureful OpenSSL version.
57 *
58 * In order for the compat library to call the real functions, it must
59 * define SSH_DONT_OVERLOAD_OPENSSL_FUNCS before including this file and
60 * implement the ssh_* equivalents.
Darren Tuckera55ec772005-06-09 21:45:10 +100061 */
Darren Tuckerfabdb6c2006-02-20 20:17:35 +110062#ifndef SSH_DONT_OVERLOAD_OPENSSL_FUNCS
Darren Tuckera55ec772005-06-09 21:45:10 +100063
Darren Tuckerfabdb6c2006-02-20 20:17:35 +110064# ifdef SSH_OLD_EVP
Darren Tuckera55ec772005-06-09 21:45:10 +100065# ifdef EVP_Cipher
66# undef EVP_Cipher
67# endif
Darren Tuckera55ec772005-06-09 21:45:10 +100068# define EVP_CipherInit(a,b,c,d,e) ssh_EVP_CipherInit((a),(b),(c),(d),(e))
69# define EVP_Cipher(a,b,c,d) ssh_EVP_Cipher((a),(b),(c),(d))
70# define EVP_CIPHER_CTX_cleanup(a) ssh_EVP_CIPHER_CTX_cleanup((a))
Darren Tuckerfabdb6c2006-02-20 20:17:35 +110071# endif /* SSH_OLD_EVP */
72
Darren Tucker3322e0d2006-02-22 00:00:27 +110073# ifdef USE_OPENSSL_ENGINE
74# ifdef SSLeay_add_all_algorithms
75# undef SSLeay_add_all_algorithms
76# endif
77# define SSLeay_add_all_algorithms() ssh_SSLeay_add_all_algorithms()
Darren Tucker3322e0d2006-02-22 00:00:27 +110078#endif
Darren Tuckera55ec772005-06-09 21:45:10 +100079
80int ssh_EVP_CipherInit(EVP_CIPHER_CTX *, const EVP_CIPHER *, unsigned char *,
81 unsigned char *, int);
82int ssh_EVP_Cipher(EVP_CIPHER_CTX *, char *, char *, int);
83int ssh_EVP_CIPHER_CTX_cleanup(EVP_CIPHER_CTX *);
Darren Tucker94413cf2006-02-22 22:24:47 +110084void ssh_SSLeay_add_all_algorithms(void);
Darren Tuckerfabdb6c2006-02-20 20:17:35 +110085#endif /* SSH_DONT_OVERLOAD_OPENSSL_FUNCS */