1 1.1 christos /* $NetBSD: libssl_compat.h,v 1.2 2020/05/25 20:47:19 christos Exp $ */ 2 1.1 christos 3 1.1 christos /* 4 1.1 christos * libssl_compat.h -- OpenSSL v1.1 compatibility shims 5 1.1 christos * 6 1.1 christos * --------------------------------------------------------------------- 7 1.1 christos * 8 1.1 christos * Written by Juergen Perlinger <perlinger (at) ntp.org> for the NTP project 9 1.1 christos * 10 1.1 christos * Based on an idea by Kurt Roeckx <kurt (at) roeckx.be> 11 1.1 christos * 12 1.1 christos * --------------------------------------------------------------------- 13 1.1 christos * This is a clean room implementation of shim functions that have 14 1.1 christos * counterparts in the OpenSSL v1.1 API but not in earlier versions. 15 1.1 christos * 16 1.1 christos * If the OpenSSL version used for compilation needs the shims (that is, 17 1.1 christos * does not provide the new functions) the names of these functions are 18 1.1 christos * redirected to our shims. 19 1.1 christos * --------------------------------------------------------------------- 20 1.1 christos */ 21 1.1 christos 22 1.1 christos #ifndef NTP_LIBSSL_COMPAT_H 23 1.1 christos #define NTP_LIBSSL_COMPAT_H 24 1.1 christos 25 1.1 christos #include "openssl/evp.h" 26 1.1 christos #include "openssl/dsa.h" 27 1.1 christos #include "openssl/rsa.h" 28 1.1 christos 29 1.2 christos #ifndef OPENSSL_VERSION_NUMBER 30 1.2 christos #define OPENSSL_VERSION_NUMBER SSLEAY_VERSION_NUMBER 31 1.2 christos #endif 32 1.2 christos 33 1.2 christos #ifndef OPENSSL_VERSION_TEXT 34 1.2 christos #define OPENSSL_VERSION_TEXT SSLEAY_VERSION_TEXT 35 1.2 christos #endif 36 1.2 christos 37 1.2 christos #ifndef OPENSSL_VERSION 38 1.2 christos #define OPENSSL_VERSION SSLEAY_VERSION 39 1.2 christos #endif 40 1.2 christos 41 1.1 christos /* ----------------------------------------------------------------- */ 42 1.1 christos #if OPENSSL_VERSION_NUMBER < 0x10100000L 43 1.1 christos /* ----------------------------------------------------------------- */ 44 1.1 christos 45 1.1 christos # include <openssl/objects.h> 46 1.1 christos # include <openssl/x509.h> 47 1.1 christos 48 1.1 christos /* shim the new-style API on an old-style OpenSSL */ 49 1.1 christos 50 1.1 christos extern BN_GENCB* sslshimBN_GENCB_new(void); 51 1.1 christos extern void sslshimBN_GENCB_free(BN_GENCB*); 52 1.1 christos 53 1.1 christos extern EVP_MD_CTX* sslshim_EVP_MD_CTX_new(void); 54 1.1 christos extern void sslshim_EVP_MD_CTX_free(EVP_MD_CTX *ctx); 55 1.1 christos 56 1.1 christos extern int sslshim_EVP_PKEY_id(const EVP_PKEY * pkey); 57 1.1 christos extern int sslshim_EVP_PKEY_base_id(const EVP_PKEY * pkey); 58 1.1 christos extern RSA* sslshim_EVP_PKEY_get0_RSA(EVP_PKEY * pkey); 59 1.1 christos extern DSA* sslshim_EVP_PKEY_get0_DSA(EVP_PKEY * pkey); 60 1.1 christos 61 1.1 christos extern void sslshim_RSA_get0_key(const RSA *prsa, const BIGNUM **pn, 62 1.1 christos const BIGNUM **pe, const BIGNUM **pd); 63 1.1 christos extern int sslshim_RSA_set0_key(RSA *prsa, BIGNUM *n, 64 1.1 christos BIGNUM *e, BIGNUM *d); 65 1.1 christos extern void sslshim_RSA_get0_factors(const RSA *prsa, const BIGNUM **pp, 66 1.1 christos const BIGNUM **pq); 67 1.1 christos extern int sslshim_RSA_set0_factors(RSA *prsar, BIGNUM *p, BIGNUM *q); 68 1.1 christos extern int sslshim_RSA_set0_crt_params(RSA *prsa, BIGNUM *dmp1, 69 1.1 christos BIGNUM *dmq1, BIGNUM *iqmp); 70 1.1 christos 71 1.1 christos extern void sslshim_DSA_SIG_get0(const DSA_SIG *psig, const BIGNUM **pr, 72 1.1 christos const BIGNUM **ps); 73 1.1 christos extern int sslshim_DSA_SIG_set0(DSA_SIG *psig, BIGNUM *r, BIGNUM *s); 74 1.1 christos extern void sslshim_DSA_get0_pqg(const DSA *pdsa, const BIGNUM **pp, 75 1.1 christos const BIGNUM **pq, const BIGNUM **pg); 76 1.1 christos extern int sslshim_DSA_set0_pqg(DSA *pdsa, BIGNUM *p, BIGNUM *q, BIGNUM *g); 77 1.1 christos extern void sslshim_DSA_get0_key(const DSA *pdsa, const BIGNUM **ppub_key, 78 1.1 christos const BIGNUM **ppriv_key); 79 1.1 christos extern int sslshim_DSA_set0_key(DSA *pdsa, BIGNUM *pub_key, 80 1.1 christos BIGNUM *priv_key); 81 1.1 christos 82 1.1 christos extern int sslshim_X509_get_signature_nid(const X509 *x); 83 1.1 christos 84 1.1 christos #define BN_GENCB_new sslshimBN_GENCB_new 85 1.1 christos #define BN_GENCB_free sslshimBN_GENCB_free 86 1.1 christos 87 1.1 christos #define EVP_MD_CTX_new sslshim_EVP_MD_CTX_new 88 1.1 christos #define EVP_MD_CTX_free sslshim_EVP_MD_CTX_free 89 1.1 christos 90 1.1 christos #define EVP_PKEY_id sslshim_EVP_PKEY_id 91 1.1 christos #define EVP_PKEY_base_id sslshim_EVP_PKEY_base_id 92 1.1 christos #define EVP_PKEY_get0_RSA sslshim_EVP_PKEY_get0_RSA 93 1.1 christos #define EVP_PKEY_get0_DSA sslshim_EVP_PKEY_get0_DSA 94 1.1 christos 95 1.1 christos #define RSA_get0_key sslshim_RSA_get0_key 96 1.1 christos #define RSA_set0_key sslshim_RSA_set0_key 97 1.1 christos #define RSA_get0_factors sslshim_RSA_get0_factors 98 1.1 christos #define RSA_set0_factors sslshim_RSA_set0_factors 99 1.1 christos #define RSA_set0_crt_params sslshim_RSA_set0_crt_params 100 1.1 christos 101 1.1 christos #define DSA_SIG_get0 sslshim_DSA_SIG_get0 102 1.1 christos #define DSA_SIG_set0 sslshim_DSA_SIG_set0 103 1.1 christos #define DSA_get0_pqg sslshim_DSA_get0_pqg 104 1.1 christos #define DSA_set0_pqg sslshim_DSA_set0_pqg 105 1.1 christos #define DSA_get0_key sslshim_DSA_get0_key 106 1.1 christos #define DSA_set0_key sslshim_DSA_set0_key 107 1.1 christos 108 1.1 christos #define X509_get_signature_nid sslshim_X509_get_signature_nid 109 1.1 christos 110 1.2 christos #define OpenSSL_version_num SSLeay 111 1.2 christos #define OpenSSL_version SSLeay_version 112 1.2 christos #define X509_get0_notBefore X509_get_notBefore 113 1.2 christos #define X509_getm_notBefore X509_get_notBefore 114 1.2 christos #define X509_get0_notAfter X509_get_notAfter 115 1.2 christos #define X509_getm_notAfter X509_get_notAfter 116 1.2 christos 117 1.1 christos /* ----------------------------------------------------------------- */ 118 1.1 christos #endif /* OPENSSL_VERSION_NUMBER < v1.1.0 */ 119 1.1 christos /* ----------------------------------------------------------------- */ 120 1.1 christos 121 1.1 christos #endif /* NTP_LIBSSL_COMPAT_H */ 122