17 #ifndef _OPENSSL_COMPAT_H
18 #define _OPENSSL_COMPAT_H
23 #include <openssl/opensslv.h>
24 #include <openssl/crypto.h>
25 #include <openssl/evp.h>
26 #include <openssl/rsa.h>
27 #include <openssl/dsa.h>
28 #ifdef OPENSSL_HAS_ECC
29 #include <openssl/ecdsa.h>
31 #include <openssl/dh.h>
33 int ssh_compatible_openssl(
long,
long);
34 void ssh_libcrypto_init(
void);
36 #if (OPENSSL_VERSION_NUMBER < 0x1000100fL)
37 # error OpenSSL 1.0.1 or greater is required
40 #ifndef OPENSSL_VERSION
41 # define OPENSSL_VERSION SSLEAY_VERSION
44 #ifndef HAVE_OPENSSL_VERSION
45 # define OpenSSL_version(x) SSLeay_version(x)
48 #ifndef HAVE_OPENSSL_VERSION_NUM
49 # define OpenSSL_version_num SSLeay
52 #if OPENSSL_VERSION_NUMBER < 0x10000001L
53 # define LIBCRYPTO_EVP_INL_TYPE unsigned int
55 # define LIBCRYPTO_EVP_INL_TYPE size_t
58 #ifndef OPENSSL_RSA_MAX_MODULUS_BITS
59 # define OPENSSL_RSA_MAX_MODULUS_BITS 16384
61 #ifndef OPENSSL_DSA_MAX_MODULUS_BITS
62 # define OPENSSL_DSA_MAX_MODULUS_BITS 10000
65 #ifdef LIBRESSL_VERSION_NUMBER
66 # if LIBRESSL_VERSION_NUMBER < 0x3010000fL
67 # define HAVE_BROKEN_CHACHA20
71 #ifndef OPENSSL_HAVE_EVPCTR
72 # define EVP_aes_128_ctr evp_aes_128_ctr
73 # define EVP_aes_192_ctr evp_aes_128_ctr
74 # define EVP_aes_256_ctr evp_aes_128_ctr
75 const EVP_CIPHER *evp_aes_128_ctr(
void);
76 void ssh_aes_ctr_iv(EVP_CIPHER_CTX *,
int, u_char *,
size_t);
80 #if !defined(OPENSSL_HAVE_EVPGCM) && !defined(EVP_CTRL_GCM_SET_IV_FIXED)
81 # define EVP_CTRL_GCM_SET_IV_FIXED -1
82 # define EVP_CTRL_GCM_IV_GEN -1
83 # define EVP_CTRL_GCM_SET_TAG -1
84 # define EVP_CTRL_GCM_GET_TAG -1
88 #ifndef HAVE_EVP_CIPHER_CTX_CTRL
89 # ifdef OPENSSL_HAVE_EVPGCM
90 # error AES-GCM enabled without EVP_CIPHER_CTX_ctrl
92 # define EVP_CIPHER_CTX_ctrl(a,b,c,d) (0)
97 #ifndef HAVE_DSA_GET0_PQG
98 void DSA_get0_pqg(
const DSA *d,
const BIGNUM **p,
const BIGNUM **q,
102 #ifndef HAVE_DSA_SET0_PQG
103 int DSA_set0_pqg(DSA *d, BIGNUM *p, BIGNUM *q, BIGNUM *g);
106 #ifndef HAVE_DSA_GET0_KEY
107 void DSA_get0_key(
const DSA *d,
const BIGNUM **pub_key,
108 const BIGNUM **priv_key);
111 #ifndef HAVE_DSA_SET0_KEY
112 int DSA_set0_key(DSA *d, BIGNUM *pub_key, BIGNUM *priv_key);
115 #ifndef HAVE_EVP_CIPHER_CTX_GET_IV
116 # ifdef HAVE_EVP_CIPHER_CTX_GET_UPDATED_IV
117 # define EVP_CIPHER_CTX_get_iv EVP_CIPHER_CTX_get_updated_iv
119 int EVP_CIPHER_CTX_get_iv(
const EVP_CIPHER_CTX *ctx,
120 unsigned char *iv,
size_t len);
124 #ifndef HAVE_EVP_CIPHER_CTX_SET_IV
125 int EVP_CIPHER_CTX_set_iv(EVP_CIPHER_CTX *ctx,
126 const unsigned char *iv,
size_t len);
129 #ifndef HAVE_RSA_GET0_KEY
130 void RSA_get0_key(
const RSA *r,
const BIGNUM **n,
const BIGNUM **e,
134 #ifndef HAVE_RSA_SET0_KEY
135 int RSA_set0_key(RSA *r, BIGNUM *n, BIGNUM *e, BIGNUM *d);
138 #ifndef HAVE_RSA_GET0_CRT_PARAMS
139 void RSA_get0_crt_params(
const RSA *r,
const BIGNUM **dmp1,
const BIGNUM **dmq1,
140 const BIGNUM **iqmp);
143 #ifndef HAVE_RSA_SET0_CRT_PARAMS
144 int RSA_set0_crt_params(RSA *r, BIGNUM *dmp1, BIGNUM *dmq1, BIGNUM *iqmp);
147 #ifndef HAVE_RSA_GET0_FACTORS
148 void RSA_get0_factors(
const RSA *r,
const BIGNUM **p,
const BIGNUM **q);
151 #ifndef HAVE_RSA_SET0_FACTORS
152 int RSA_set0_factors(RSA *r, BIGNUM *p, BIGNUM *q);
156 void DSA_SIG_get0(
const DSA_SIG *sig,
const BIGNUM **pr,
const BIGNUM **ps);
160 int DSA_SIG_set0(DSA_SIG *sig, BIGNUM *r, BIGNUM *s);
163 #ifdef OPENSSL_HAS_ECC
164 #ifndef HAVE_ECDSA_SIG_GET0
165 void ECDSA_SIG_get0(
const ECDSA_SIG *sig,
const BIGNUM **pr,
const BIGNUM **ps);
168 #ifndef HAVE_ECDSA_SIG_SET0
169 int ECDSA_SIG_set0(ECDSA_SIG *sig, BIGNUM *r, BIGNUM *s);
173 #ifndef HAVE_DH_GET0_PQG
174 void DH_get0_pqg(
const DH *dh,
const BIGNUM **p,
const BIGNUM **q,
178 #ifndef HAVE_DH_SET0_PQG
179 int DH_set0_pqg(DH *dh, BIGNUM *p, BIGNUM *q, BIGNUM *g);
182 #ifndef HAVE_DH_GET0_KEY
183 void DH_get0_key(
const DH *dh,
const BIGNUM **pub_key,
const BIGNUM **priv_key);
186 #ifndef HAVE_DH_SET0_KEY
187 int DH_set0_key(DH *dh, BIGNUM *pub_key, BIGNUM *priv_key);
190 #ifndef HAVE_DH_SET_LENGTH
191 int DH_set_length(DH *dh,
long length);
194 #ifndef HAVE_RSA_METH_FREE
195 void RSA_meth_free(RSA_METHOD *meth);
198 #ifndef HAVE_RSA_METH_DUP
199 RSA_METHOD *RSA_meth_dup(
const RSA_METHOD *meth);
202 #ifndef HAVE_RSA_METH_SET1_NAME
203 int RSA_meth_set1_name(RSA_METHOD *meth,
const char *name);
206 #ifndef HAVE_RSA_METH_GET_FINISH
207 int (*RSA_meth_get_finish(
const RSA_METHOD *meth))(RSA *rsa);
210 #ifndef HAVE_RSA_METH_SET_PRIV_ENC
211 int RSA_meth_set_priv_enc(RSA_METHOD *meth,
int (*priv_enc)(
int flen,
212 const unsigned char *from,
unsigned char *to, RSA *rsa,
int padding));
215 #ifndef HAVE_RSA_METH_SET_PRIV_DEC
216 int RSA_meth_set_priv_dec(RSA_METHOD *meth,
int (*priv_dec)(
int flen,
217 const unsigned char *from,
unsigned char *to, RSA *rsa,
int padding));
220 #ifndef HAVE_RSA_METH_SET_FINISH
221 int RSA_meth_set_finish(RSA_METHOD *meth,
int (*finish)(RSA *rsa));
224 #ifndef HAVE_EVP_PKEY_GET0_RSA
225 RSA *EVP_PKEY_get0_RSA(EVP_PKEY *pkey);
228 #ifndef HAVE_EVP_MD_CTX_new
229 EVP_MD_CTX *EVP_MD_CTX_new(
void);
232 #ifndef HAVE_EVP_MD_CTX_free
233 void EVP_MD_CTX_free(EVP_MD_CTX *ctx);