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