2010-05-12 07:49:59 +00:00
|
|
|
/* $Id: openssl-compat.h,v 1.15 2010/05/12 07:50:02 djm Exp $ */
|
2005-06-09 11:45:10 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 2005 Darren Tucker <dtucker@zip.com.au>
|
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, and distribute this software for any
|
|
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
|
|
* copyright notice and this permission notice appear in all copies.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
|
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
|
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
|
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
* WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
|
|
|
|
* IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "includes.h"
|
|
|
|
#include <openssl/evp.h>
|
2010-05-12 07:49:59 +00:00
|
|
|
#include <openssl/rsa.h>
|
|
|
|
#include <openssl/dsa.h>
|
|
|
|
|
|
|
|
/* Only in 0.9.8 */
|
|
|
|
#ifndef OPENSSL_DSA_MAX_MODULUS_BITS
|
|
|
|
# define OPENSSL_DSA_MAX_MODULUS_BITS 10000
|
|
|
|
#endif
|
|
|
|
#ifndef OPENSSL_RSA_MAX_MODULUS_BITS
|
|
|
|
# define OPENSSL_RSA_MAX_MODULUS_BITS 16384
|
|
|
|
#endif
|
2005-06-09 11:45:10 +00:00
|
|
|
|
2008-02-28 08:22:04 +00:00
|
|
|
/* OPENSSL_free() is Free() in versions before OpenSSL 0.9.6 */
|
|
|
|
#if !defined(OPENSSL_VERSION_NUMBER) || (OPENSSL_VERSION_NUMBER < 0x0090600f)
|
|
|
|
# define OPENSSL_free(x) Free(x)
|
|
|
|
#endif
|
|
|
|
|
2005-06-09 11:45:10 +00:00
|
|
|
#if OPENSSL_VERSION_NUMBER < 0x00906000L
|
|
|
|
# define SSH_OLD_EVP
|
|
|
|
# define EVP_CIPHER_CTX_get_app_data(e) ((e)->app_data)
|
2007-06-14 13:21:32 +00:00
|
|
|
#endif
|
|
|
|
|
2007-06-14 13:38:39 +00:00
|
|
|
#if (OPENSSL_VERSION_NUMBER < 0x00907000L) || defined(OPENSSL_LOBOTOMISED_AES)
|
|
|
|
# define USE_BUILTIN_RIJNDAEL
|
|
|
|
#endif
|
|
|
|
|
2007-06-14 13:21:32 +00:00
|
|
|
#ifdef USE_BUILTIN_RIJNDAEL
|
|
|
|
# include "rijndael.h"
|
|
|
|
# define AES_KEY rijndael_ctx
|
|
|
|
# define AES_BLOCK_SIZE 16
|
|
|
|
# define AES_encrypt(a, b, c) rijndael_encrypt(c, a, b)
|
|
|
|
# define AES_set_encrypt_key(a, b, c) rijndael_set_key(c, (char *)a, b, 1)
|
2005-06-09 11:45:10 +00:00
|
|
|
# define EVP_aes_128_cbc evp_rijndael
|
|
|
|
# define EVP_aes_192_cbc evp_rijndael
|
|
|
|
# define EVP_aes_256_cbc evp_rijndael
|
|
|
|
extern const EVP_CIPHER *evp_rijndael(void);
|
|
|
|
extern void ssh_rijndael_iv(EVP_CIPHER_CTX *, int, u_char *, u_int);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if !defined(EVP_CTRL_SET_ACSS_MODE)
|
|
|
|
# if (OPENSSL_VERSION_NUMBER >= 0x00907000L)
|
|
|
|
# define USE_CIPHER_ACSS 1
|
|
|
|
extern const EVP_CIPHER *evp_acss(void);
|
|
|
|
# define EVP_acss evp_acss
|
|
|
|
# else
|
|
|
|
# define EVP_acss NULL
|
|
|
|
# endif
|
|
|
|
#endif
|
|
|
|
|
2007-03-05 07:25:20 +00:00
|
|
|
/* OpenSSL 0.9.8e returns cipher key len not context key len */
|
|
|
|
#if (OPENSSL_VERSION_NUMBER == 0x0090805fL)
|
|
|
|
# define EVP_CIPHER_CTX_key_length(c) ((c)->key_len)
|
|
|
|
#endif
|
|
|
|
|
2005-06-09 11:45:10 +00:00
|
|
|
/*
|
2005-11-20 03:09:59 +00:00
|
|
|
* We overload some of the OpenSSL crypto functions with ssh_* equivalents
|
|
|
|
* which cater for older and/or less featureful OpenSSL version.
|
|
|
|
*
|
|
|
|
* In order for the compat library to call the real functions, it must
|
|
|
|
* define SSH_DONT_OVERLOAD_OPENSSL_FUNCS before including this file and
|
|
|
|
* implement the ssh_* equivalents.
|
2005-06-09 11:45:10 +00:00
|
|
|
*/
|
2006-02-20 09:17:35 +00:00
|
|
|
#ifndef SSH_DONT_OVERLOAD_OPENSSL_FUNCS
|
2005-06-09 11:45:10 +00:00
|
|
|
|
2006-02-20 09:17:35 +00:00
|
|
|
# ifdef SSH_OLD_EVP
|
2005-06-09 11:45:10 +00:00
|
|
|
# ifdef EVP_Cipher
|
|
|
|
# undef EVP_Cipher
|
|
|
|
# endif
|
|
|
|
# define EVP_CipherInit(a,b,c,d,e) ssh_EVP_CipherInit((a),(b),(c),(d),(e))
|
|
|
|
# define EVP_Cipher(a,b,c,d) ssh_EVP_Cipher((a),(b),(c),(d))
|
|
|
|
# define EVP_CIPHER_CTX_cleanup(a) ssh_EVP_CIPHER_CTX_cleanup((a))
|
2006-02-20 09:17:35 +00:00
|
|
|
# endif /* SSH_OLD_EVP */
|
|
|
|
|
2009-03-07 11:22:35 +00:00
|
|
|
# ifdef OPENSSL_EVP_DIGESTUPDATE_VOID
|
|
|
|
# define EVP_DigestUpdate(a,b,c) ssh_EVP_DigestUpdate((a),(b),(c))
|
|
|
|
# endif
|
|
|
|
|
2006-02-21 13:00:27 +00:00
|
|
|
# ifdef USE_OPENSSL_ENGINE
|
|
|
|
# ifdef SSLeay_add_all_algorithms
|
|
|
|
# undef SSLeay_add_all_algorithms
|
|
|
|
# endif
|
2008-02-28 08:13:52 +00:00
|
|
|
# define SSLeay_add_all_algorithms() ssh_SSLeay_add_all_algorithms()
|
|
|
|
# endif
|
2005-06-09 11:45:10 +00:00
|
|
|
|
|
|
|
int ssh_EVP_CipherInit(EVP_CIPHER_CTX *, const EVP_CIPHER *, unsigned char *,
|
|
|
|
unsigned char *, int);
|
|
|
|
int ssh_EVP_Cipher(EVP_CIPHER_CTX *, char *, char *, int);
|
|
|
|
int ssh_EVP_CIPHER_CTX_cleanup(EVP_CIPHER_CTX *);
|
2006-02-22 11:24:47 +00:00
|
|
|
void ssh_SSLeay_add_all_algorithms(void);
|
2006-02-20 09:17:35 +00:00
|
|
|
#endif /* SSH_DONT_OVERLOAD_OPENSSL_FUNCS */
|
2010-05-12 07:49:59 +00:00
|
|
|
|