34#ifndef OPENSSL_COMPAT_H_
35#define OPENSSL_COMPAT_H_
43#include <openssl/rsa.h>
44#include <openssl/ssl.h>
45#include <openssl/x509.h>
46#include <openssl/err.h>
49#if OPENSSL_VERSION_NUMBER < 0x10101000L && !defined(ENABLE_CRYPTO_WOLFSSL)
50#define SSL_CTX_set1_groups SSL_CTX_set1_curves
54#if defined(LIBRESSL_VERSION_NUMBER) && LIBRESSL_VERSION_NUMBER < 0x3050000fL
61X509_OBJECT_free(X509_OBJECT *obj)
65 X509_OBJECT_free_contents(obj);
70#define EVP_CTRL_AEAD_SET_TAG EVP_CTRL_GCM_SET_TAG
71#define EVP_CTRL_AEAD_GET_TAG EVP_CTRL_GCM_GET_TAG
74#if defined(LIBRESSL_VERSION_NUMBER)
75#define RSA_F_RSA_OSSL_PRIVATE_ENCRYPT RSA_F_RSA_EAY_PRIVATE_ENCRYPT
78#if defined(LIBRESSL_VERSION_NUMBER) && LIBRESSL_VERSION_NUMBER < 0x3050400fL \
79 || defined(OPENSSL_IS_AWSLC)
80#define SSL_get_peer_tmp_key SSL_get_server_tmp_key
84#if OPENSSL_VERSION_NUMBER < 0x30000000L && !defined(OPENSSL_NO_EC)
92 const EC_KEY *ec = EVP_PKEY_get0_EC_KEY(pkey);
97 const EC_GROUP *group = EC_KEY_get0_group(ec);
98 int nid = EC_GROUP_get_curve_name(group);
104 const char *curve = OBJ_nid2sn(nid);
107 curve =
"(error fetching curve name)";
113 *gname_len = strlen(curve);
118#if OPENSSL_VERSION_NUMBER < 0x30000000L
119#define EVP_MD_get0_name EVP_MD_name
120#define EVP_CIPHER_get0_name EVP_CIPHER_name
121#define EVP_CIPHER_CTX_get_mode EVP_CIPHER_CTX_mode
124#define SSL_CTX_new_ex(libctx, propq, method) SSL_CTX_new((method))
132static inline const EVP_CIPHER *
137 return EVP_get_cipherbyname(algorithm);
140static inline const EVP_MD *
145 return EVP_get_digestbyname(algorithm);
160static inline unsigned long
161ERR_get_error_all(
const char **file,
int *line,
const char **func,
const char **data,
int *flags)
163 static const char *empty =
"";
165 unsigned long err = ERR_get_error_line_data(file, line, data, flags);
171#if OPENSSL_VERSION_NUMBER < 0x30500000 \
172 && (!defined(LIBRESSL_VERSION_NUMBER) || LIBRESSL_VERSION_NUMBER > 0x3050400fL)
177 if (SSL_get_peer_signature_nid(ssl, &peer_sig_nid) && peer_sig_nid != NID_undef)
179 *sigalg = OBJ_nid2sn(peer_sig_nid);
184#elif defined(LIBRESSL_VERSION_NUMBER) && LIBRESSL_VERSION_NUMBER <= 0x3050400fL
196#if OPENSSL_VERSION_NUMBER < 0x30200000L && OPENSSL_VERSION_NUMBER >= 0x30000000L
197static inline const char *
198SSL_get0_group_name(SSL *s)
200 int nid = SSL_get_negotiated_group(s);
201 return SSL_group_to_name(s, nid);
static void strncpynt(char *dest, const char *src, size_t maxlen)
static void EVP_CIPHER_free(const EVP_CIPHER *cipher)
static int SSL_get0_peer_signature_name(SSL *ssl, const char **sigalg)
static const EVP_CIPHER * EVP_CIPHER_fetch(void *ctx, const char *algorithm, const char *properties)
static unsigned long ERR_get_error_all(const char **file, int *line, const char **func, const char **data, int *flags)
static void EVP_MD_free(const EVP_MD *md)
static const EVP_MD * EVP_MD_fetch(void *ctx, const char *algorithm, const char *properties)
static int EVP_PKEY_get_group_name(EVP_PKEY *pkey, char *gname, size_t gname_sz, size_t *gname_len)