xref: /freebsd/crypto/openssh/openbsd-compat/openssl-compat.h (revision 19261079b74319502c6ffa1249920079f0f69a72)
1043840dfSDag-Erling Smørgrav /*
2043840dfSDag-Erling Smørgrav  * Copyright (c) 2005 Darren Tucker <dtucker@zip.com.au>
3043840dfSDag-Erling Smørgrav  *
4043840dfSDag-Erling Smørgrav  * Permission to use, copy, modify, and distribute this software for any
5043840dfSDag-Erling Smørgrav  * purpose with or without fee is hereby granted, provided that the above
6043840dfSDag-Erling Smørgrav  * copyright notice and this permission notice appear in all copies.
7043840dfSDag-Erling Smørgrav  *
8043840dfSDag-Erling Smørgrav  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9043840dfSDag-Erling Smørgrav  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10043840dfSDag-Erling Smørgrav  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11043840dfSDag-Erling Smørgrav  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12043840dfSDag-Erling Smørgrav  * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
13043840dfSDag-Erling Smørgrav  * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
14043840dfSDag-Erling Smørgrav  * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15043840dfSDag-Erling Smørgrav  */
16043840dfSDag-Erling Smørgrav 
17a0ee8cc6SDag-Erling Smørgrav #ifndef _OPENSSL_COMPAT_H
18a0ee8cc6SDag-Erling Smørgrav #define _OPENSSL_COMPAT_H
19a0ee8cc6SDag-Erling Smørgrav 
20043840dfSDag-Erling Smørgrav #include "includes.h"
21bc5531deSDag-Erling Smørgrav #ifdef WITH_OPENSSL
22bc5531deSDag-Erling Smørgrav 
234a421b63SDag-Erling Smørgrav #include <openssl/opensslv.h>
24*19261079SEd Maste #include <openssl/crypto.h>
25043840dfSDag-Erling Smørgrav #include <openssl/evp.h>
26e2f6069cSDag-Erling Smørgrav #include <openssl/rsa.h>
27e2f6069cSDag-Erling Smørgrav #include <openssl/dsa.h>
28*19261079SEd Maste #ifdef OPENSSL_HAS_ECC
292a01feabSEd Maste #include <openssl/ecdsa.h>
30*19261079SEd Maste #endif
312a01feabSEd Maste #include <openssl/dh.h>
32e2f6069cSDag-Erling Smørgrav 
33a0ee8cc6SDag-Erling Smørgrav int ssh_compatible_openssl(long, long);
34*19261079SEd Maste void ssh_libcrypto_init(void);
35043840dfSDag-Erling Smørgrav 
36*19261079SEd Maste #if (OPENSSL_VERSION_NUMBER < 0x1000100fL)
37*19261079SEd Maste # error OpenSSL 1.0.1 or greater is required
38*19261079SEd Maste #endif
39*19261079SEd Maste 
40*19261079SEd Maste #ifndef OPENSSL_VERSION
41*19261079SEd Maste # define OPENSSL_VERSION	SSLEAY_VERSION
42*19261079SEd Maste #endif
43*19261079SEd Maste 
44*19261079SEd Maste #ifndef HAVE_OPENSSL_VERSION
45*19261079SEd Maste # define OpenSSL_version(x)	SSLeay_version(x)
46*19261079SEd Maste #endif
47*19261079SEd Maste 
48*19261079SEd Maste #ifndef HAVE_OPENSSL_VERSION_NUM
49*19261079SEd Maste # define OpenSSL_version_num	SSLeay
50043840dfSDag-Erling Smørgrav #endif
51043840dfSDag-Erling Smørgrav 
526888a9beSDag-Erling Smørgrav #if OPENSSL_VERSION_NUMBER < 0x10000001L
534a421b63SDag-Erling Smørgrav # define LIBCRYPTO_EVP_INL_TYPE unsigned int
544a421b63SDag-Erling Smørgrav #else
554a421b63SDag-Erling Smørgrav # define LIBCRYPTO_EVP_INL_TYPE size_t
564a421b63SDag-Erling Smørgrav #endif
574a421b63SDag-Erling Smørgrav 
58a0ee8cc6SDag-Erling Smørgrav #ifndef OPENSSL_RSA_MAX_MODULUS_BITS
59a0ee8cc6SDag-Erling Smørgrav # define OPENSSL_RSA_MAX_MODULUS_BITS	16384
60021d409fSDag-Erling Smørgrav #endif
61a0ee8cc6SDag-Erling Smørgrav #ifndef OPENSSL_DSA_MAX_MODULUS_BITS
62a0ee8cc6SDag-Erling Smørgrav # define OPENSSL_DSA_MAX_MODULUS_BITS	10000
63043840dfSDag-Erling Smørgrav #endif
64043840dfSDag-Erling Smørgrav 
65*19261079SEd Maste #ifdef LIBRESSL_VERSION_NUMBER
66*19261079SEd Maste # if LIBRESSL_VERSION_NUMBER < 0x3010000fL
67*19261079SEd Maste #  define HAVE_BROKEN_CHACHA20
68*19261079SEd Maste # endif
69*19261079SEd Maste #endif
70*19261079SEd Maste 
716888a9beSDag-Erling Smørgrav #ifndef OPENSSL_HAVE_EVPCTR
726888a9beSDag-Erling Smørgrav # define EVP_aes_128_ctr evp_aes_128_ctr
736888a9beSDag-Erling Smørgrav # define EVP_aes_192_ctr evp_aes_128_ctr
746888a9beSDag-Erling Smørgrav # define EVP_aes_256_ctr evp_aes_128_ctr
756888a9beSDag-Erling Smørgrav const EVP_CIPHER *evp_aes_128_ctr(void);
766888a9beSDag-Erling Smørgrav void ssh_aes_ctr_iv(EVP_CIPHER_CTX *, int, u_char *, size_t);
77043840dfSDag-Erling Smørgrav #endif
786888a9beSDag-Erling Smørgrav 
796888a9beSDag-Erling Smørgrav /* Avoid some #ifdef. Code that uses these is unreachable without GCM */
806888a9beSDag-Erling Smørgrav #if !defined(OPENSSL_HAVE_EVPGCM) && !defined(EVP_CTRL_GCM_SET_IV_FIXED)
816888a9beSDag-Erling Smørgrav # define EVP_CTRL_GCM_SET_IV_FIXED -1
826888a9beSDag-Erling Smørgrav # define EVP_CTRL_GCM_IV_GEN -1
836888a9beSDag-Erling Smørgrav # define EVP_CTRL_GCM_SET_TAG -1
846888a9beSDag-Erling Smørgrav # define EVP_CTRL_GCM_GET_TAG -1
856888a9beSDag-Erling Smørgrav #endif
866888a9beSDag-Erling Smørgrav 
876888a9beSDag-Erling Smørgrav /* Replace missing EVP_CIPHER_CTX_ctrl() with something that returns failure */
886888a9beSDag-Erling Smørgrav #ifndef HAVE_EVP_CIPHER_CTX_CTRL
896888a9beSDag-Erling Smørgrav # ifdef OPENSSL_HAVE_EVPGCM
906888a9beSDag-Erling Smørgrav #  error AES-GCM enabled without EVP_CIPHER_CTX_ctrl /* shouldn't happen */
916888a9beSDag-Erling Smørgrav # else
926888a9beSDag-Erling Smørgrav # define EVP_CIPHER_CTX_ctrl(a,b,c,d) (0)
936888a9beSDag-Erling Smørgrav # endif
946888a9beSDag-Erling Smørgrav #endif
956888a9beSDag-Erling Smørgrav 
962a01feabSEd Maste /* LibreSSL/OpenSSL 1.1x API compat */
972a01feabSEd Maste #ifndef HAVE_DSA_GET0_PQG
982a01feabSEd Maste void DSA_get0_pqg(const DSA *d, const BIGNUM **p, const BIGNUM **q,
992a01feabSEd Maste     const BIGNUM **g);
1002a01feabSEd Maste #endif /* HAVE_DSA_GET0_PQG */
1012a01feabSEd Maste 
1022a01feabSEd Maste #ifndef HAVE_DSA_SET0_PQG
1032a01feabSEd Maste int DSA_set0_pqg(DSA *d, BIGNUM *p, BIGNUM *q, BIGNUM *g);
1042a01feabSEd Maste #endif /* HAVE_DSA_SET0_PQG */
1052a01feabSEd Maste 
1062a01feabSEd Maste #ifndef HAVE_DSA_GET0_KEY
1072a01feabSEd Maste void DSA_get0_key(const DSA *d, const BIGNUM **pub_key,
1082a01feabSEd Maste     const BIGNUM **priv_key);
1092a01feabSEd Maste #endif /* HAVE_DSA_GET0_KEY */
1102a01feabSEd Maste 
1112a01feabSEd Maste #ifndef HAVE_DSA_SET0_KEY
1122a01feabSEd Maste int DSA_set0_key(DSA *d, BIGNUM *pub_key, BIGNUM *priv_key);
1132a01feabSEd Maste #endif /* HAVE_DSA_SET0_KEY */
1142a01feabSEd Maste 
1152a01feabSEd Maste #ifndef HAVE_EVP_CIPHER_CTX_GET_IV
116*19261079SEd Maste # ifdef HAVE_EVP_CIPHER_CTX_GET_UPDATED_IV
117*19261079SEd Maste #  define EVP_CIPHER_CTX_get_iv EVP_CIPHER_CTX_get_updated_iv
118*19261079SEd Maste # else /* HAVE_EVP_CIPHER_CTX_GET_UPDATED_IV */
1192a01feabSEd Maste int EVP_CIPHER_CTX_get_iv(const EVP_CIPHER_CTX *ctx,
1202a01feabSEd Maste     unsigned char *iv, size_t len);
121*19261079SEd Maste # endif /* HAVE_EVP_CIPHER_CTX_GET_UPDATED_IV */
1222a01feabSEd Maste #endif /* HAVE_EVP_CIPHER_CTX_GET_IV */
1232a01feabSEd Maste 
1242a01feabSEd Maste #ifndef HAVE_EVP_CIPHER_CTX_SET_IV
1252a01feabSEd Maste int EVP_CIPHER_CTX_set_iv(EVP_CIPHER_CTX *ctx,
1262a01feabSEd Maste     const unsigned char *iv, size_t len);
1272a01feabSEd Maste #endif /* HAVE_EVP_CIPHER_CTX_SET_IV */
1282a01feabSEd Maste 
1292a01feabSEd Maste #ifndef HAVE_RSA_GET0_KEY
1302a01feabSEd Maste void RSA_get0_key(const RSA *r, const BIGNUM **n, const BIGNUM **e,
1312a01feabSEd Maste     const BIGNUM **d);
1322a01feabSEd Maste #endif /* HAVE_RSA_GET0_KEY */
1332a01feabSEd Maste 
1342a01feabSEd Maste #ifndef HAVE_RSA_SET0_KEY
1352a01feabSEd Maste int RSA_set0_key(RSA *r, BIGNUM *n, BIGNUM *e, BIGNUM *d);
1362a01feabSEd Maste #endif /* HAVE_RSA_SET0_KEY */
1372a01feabSEd Maste 
1382a01feabSEd Maste #ifndef HAVE_RSA_GET0_CRT_PARAMS
1392a01feabSEd Maste void RSA_get0_crt_params(const RSA *r, const BIGNUM **dmp1, const BIGNUM **dmq1,
1402a01feabSEd Maste     const BIGNUM **iqmp);
1412a01feabSEd Maste #endif /* HAVE_RSA_GET0_CRT_PARAMS */
1422a01feabSEd Maste 
1432a01feabSEd Maste #ifndef HAVE_RSA_SET0_CRT_PARAMS
1442a01feabSEd Maste int RSA_set0_crt_params(RSA *r, BIGNUM *dmp1, BIGNUM *dmq1, BIGNUM *iqmp);
1452a01feabSEd Maste #endif /* HAVE_RSA_SET0_CRT_PARAMS */
1462a01feabSEd Maste 
1472a01feabSEd Maste #ifndef HAVE_RSA_GET0_FACTORS
1482a01feabSEd Maste void RSA_get0_factors(const RSA *r, const BIGNUM **p, const BIGNUM **q);
1492a01feabSEd Maste #endif /* HAVE_RSA_GET0_FACTORS */
1502a01feabSEd Maste 
1512a01feabSEd Maste #ifndef HAVE_RSA_SET0_FACTORS
1522a01feabSEd Maste int RSA_set0_factors(RSA *r, BIGNUM *p, BIGNUM *q);
1532a01feabSEd Maste #endif /* HAVE_RSA_SET0_FACTORS */
1542a01feabSEd Maste 
1552a01feabSEd Maste #ifndef DSA_SIG_GET0
1562a01feabSEd Maste void DSA_SIG_get0(const DSA_SIG *sig, const BIGNUM **pr, const BIGNUM **ps);
1572a01feabSEd Maste #endif /* DSA_SIG_GET0 */
1582a01feabSEd Maste 
1592a01feabSEd Maste #ifndef DSA_SIG_SET0
1602a01feabSEd Maste int DSA_SIG_set0(DSA_SIG *sig, BIGNUM *r, BIGNUM *s);
1612a01feabSEd Maste #endif /* DSA_SIG_SET0 */
1622a01feabSEd Maste 
163*19261079SEd Maste #ifdef OPENSSL_HAS_ECC
1642a01feabSEd Maste #ifndef HAVE_ECDSA_SIG_GET0
1652a01feabSEd Maste void ECDSA_SIG_get0(const ECDSA_SIG *sig, const BIGNUM **pr, const BIGNUM **ps);
1662a01feabSEd Maste #endif /* HAVE_ECDSA_SIG_GET0 */
1672a01feabSEd Maste 
1682a01feabSEd Maste #ifndef HAVE_ECDSA_SIG_SET0
1692a01feabSEd Maste int ECDSA_SIG_set0(ECDSA_SIG *sig, BIGNUM *r, BIGNUM *s);
1702a01feabSEd Maste #endif /* HAVE_ECDSA_SIG_SET0 */
171*19261079SEd Maste #endif /* OPENSSL_HAS_ECC */
1722a01feabSEd Maste 
1732a01feabSEd Maste #ifndef HAVE_DH_GET0_PQG
1742a01feabSEd Maste void DH_get0_pqg(const DH *dh, const BIGNUM **p, const BIGNUM **q,
1752a01feabSEd Maste     const BIGNUM **g);
1762a01feabSEd Maste #endif /* HAVE_DH_GET0_PQG */
1772a01feabSEd Maste 
1782a01feabSEd Maste #ifndef HAVE_DH_SET0_PQG
1792a01feabSEd Maste int DH_set0_pqg(DH *dh, BIGNUM *p, BIGNUM *q, BIGNUM *g);
1802a01feabSEd Maste #endif /* HAVE_DH_SET0_PQG */
1812a01feabSEd Maste 
1822a01feabSEd Maste #ifndef HAVE_DH_GET0_KEY
1832a01feabSEd Maste void DH_get0_key(const DH *dh, const BIGNUM **pub_key, const BIGNUM **priv_key);
1842a01feabSEd Maste #endif /* HAVE_DH_GET0_KEY */
1852a01feabSEd Maste 
1862a01feabSEd Maste #ifndef HAVE_DH_SET0_KEY
1872a01feabSEd Maste int DH_set0_key(DH *dh, BIGNUM *pub_key, BIGNUM *priv_key);
1882a01feabSEd Maste #endif /* HAVE_DH_SET0_KEY */
1892a01feabSEd Maste 
1902a01feabSEd Maste #ifndef HAVE_DH_SET_LENGTH
1912a01feabSEd Maste int DH_set_length(DH *dh, long length);
1922a01feabSEd Maste #endif /* HAVE_DH_SET_LENGTH */
1932a01feabSEd Maste 
1942a01feabSEd Maste #ifndef HAVE_RSA_METH_FREE
1952a01feabSEd Maste void RSA_meth_free(RSA_METHOD *meth);
1962a01feabSEd Maste #endif /* HAVE_RSA_METH_FREE */
1972a01feabSEd Maste 
1982a01feabSEd Maste #ifndef HAVE_RSA_METH_DUP
1992a01feabSEd Maste RSA_METHOD *RSA_meth_dup(const RSA_METHOD *meth);
2002a01feabSEd Maste #endif /* HAVE_RSA_METH_DUP */
2012a01feabSEd Maste 
2022a01feabSEd Maste #ifndef HAVE_RSA_METH_SET1_NAME
2032a01feabSEd Maste int RSA_meth_set1_name(RSA_METHOD *meth, const char *name);
2042a01feabSEd Maste #endif /* HAVE_RSA_METH_SET1_NAME */
2052a01feabSEd Maste 
2062a01feabSEd Maste #ifndef HAVE_RSA_METH_GET_FINISH
2072a01feabSEd Maste int (*RSA_meth_get_finish(const RSA_METHOD *meth))(RSA *rsa);
2082a01feabSEd Maste #endif /* HAVE_RSA_METH_GET_FINISH */
2092a01feabSEd Maste 
2102a01feabSEd Maste #ifndef HAVE_RSA_METH_SET_PRIV_ENC
2112a01feabSEd Maste int RSA_meth_set_priv_enc(RSA_METHOD *meth, int (*priv_enc)(int flen,
2122a01feabSEd Maste     const unsigned char *from, unsigned char *to, RSA *rsa, int padding));
2132a01feabSEd Maste #endif /* HAVE_RSA_METH_SET_PRIV_ENC */
2142a01feabSEd Maste 
2152a01feabSEd Maste #ifndef HAVE_RSA_METH_SET_PRIV_DEC
2162a01feabSEd Maste int RSA_meth_set_priv_dec(RSA_METHOD *meth, int (*priv_dec)(int flen,
2172a01feabSEd Maste     const unsigned char *from, unsigned char *to, RSA *rsa, int padding));
2182a01feabSEd Maste #endif /* HAVE_RSA_METH_SET_PRIV_DEC */
2192a01feabSEd Maste 
2202a01feabSEd Maste #ifndef HAVE_RSA_METH_SET_FINISH
2212a01feabSEd Maste int RSA_meth_set_finish(RSA_METHOD *meth, int (*finish)(RSA *rsa));
2222a01feabSEd Maste #endif /* HAVE_RSA_METH_SET_FINISH */
2232a01feabSEd Maste 
2242a01feabSEd Maste #ifndef HAVE_EVP_PKEY_GET0_RSA
2252a01feabSEd Maste RSA *EVP_PKEY_get0_RSA(EVP_PKEY *pkey);
2262a01feabSEd Maste #endif /* HAVE_EVP_PKEY_GET0_RSA */
2272a01feabSEd Maste 
2282a01feabSEd Maste #ifndef HAVE_EVP_MD_CTX_new
2292a01feabSEd Maste EVP_MD_CTX *EVP_MD_CTX_new(void);
2302a01feabSEd Maste #endif /* HAVE_EVP_MD_CTX_new */
2312a01feabSEd Maste 
2322a01feabSEd Maste #ifndef HAVE_EVP_MD_CTX_free
2332a01feabSEd Maste void EVP_MD_CTX_free(EVP_MD_CTX *ctx);
2342a01feabSEd Maste #endif /* HAVE_EVP_MD_CTX_free */
2352a01feabSEd Maste 
236bc5531deSDag-Erling Smørgrav #endif /* WITH_OPENSSL */
237a0ee8cc6SDag-Erling Smørgrav #endif /* _OPENSSL_COMPAT_H */
238