1 /* $NetBSD: libssl_compat.h,v 1.1.1.1 2016/11/22 01:34:58 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 /* ----------------------------------------------------------------- */ 30 #if OPENSSL_VERSION_NUMBER < 0x10100000L 31 /* ----------------------------------------------------------------- */ 32 33 # include <openssl/objects.h> 34 # include <openssl/x509.h> 35 36 /* shim the new-style API on an old-style OpenSSL */ 37 38 extern BN_GENCB* sslshimBN_GENCB_new(void); 39 extern void sslshimBN_GENCB_free(BN_GENCB*); 40 41 extern EVP_MD_CTX* sslshim_EVP_MD_CTX_new(void); 42 extern void sslshim_EVP_MD_CTX_free(EVP_MD_CTX *ctx); 43 44 extern int sslshim_EVP_PKEY_id(const EVP_PKEY * pkey); 45 extern int sslshim_EVP_PKEY_base_id(const EVP_PKEY * pkey); 46 extern RSA* sslshim_EVP_PKEY_get0_RSA(EVP_PKEY * pkey); 47 extern DSA* sslshim_EVP_PKEY_get0_DSA(EVP_PKEY * pkey); 48 49 extern void sslshim_RSA_get0_key(const RSA *prsa, const BIGNUM **pn, 50 const BIGNUM **pe, const BIGNUM **pd); 51 extern int sslshim_RSA_set0_key(RSA *prsa, BIGNUM *n, 52 BIGNUM *e, BIGNUM *d); 53 extern void sslshim_RSA_get0_factors(const RSA *prsa, const BIGNUM **pp, 54 const BIGNUM **pq); 55 extern int sslshim_RSA_set0_factors(RSA *prsar, BIGNUM *p, BIGNUM *q); 56 extern int sslshim_RSA_set0_crt_params(RSA *prsa, BIGNUM *dmp1, 57 BIGNUM *dmq1, BIGNUM *iqmp); 58 59 extern void sslshim_DSA_SIG_get0(const DSA_SIG *psig, const BIGNUM **pr, 60 const BIGNUM **ps); 61 extern int sslshim_DSA_SIG_set0(DSA_SIG *psig, BIGNUM *r, BIGNUM *s); 62 extern void sslshim_DSA_get0_pqg(const DSA *pdsa, const BIGNUM **pp, 63 const BIGNUM **pq, const BIGNUM **pg); 64 extern int sslshim_DSA_set0_pqg(DSA *pdsa, BIGNUM *p, BIGNUM *q, BIGNUM *g); 65 extern void sslshim_DSA_get0_key(const DSA *pdsa, const BIGNUM **ppub_key, 66 const BIGNUM **ppriv_key); 67 extern int sslshim_DSA_set0_key(DSA *pdsa, BIGNUM *pub_key, 68 BIGNUM *priv_key); 69 70 extern int sslshim_X509_get_signature_nid(const X509 *x); 71 72 #define BN_GENCB_new sslshimBN_GENCB_new 73 #define BN_GENCB_free sslshimBN_GENCB_free 74 75 #define EVP_MD_CTX_new sslshim_EVP_MD_CTX_new 76 #define EVP_MD_CTX_free sslshim_EVP_MD_CTX_free 77 78 #define EVP_PKEY_id sslshim_EVP_PKEY_id 79 #define EVP_PKEY_base_id sslshim_EVP_PKEY_base_id 80 #define EVP_PKEY_get0_RSA sslshim_EVP_PKEY_get0_RSA 81 #define EVP_PKEY_get0_DSA sslshim_EVP_PKEY_get0_DSA 82 83 #define RSA_get0_key sslshim_RSA_get0_key 84 #define RSA_set0_key sslshim_RSA_set0_key 85 #define RSA_get0_factors sslshim_RSA_get0_factors 86 #define RSA_set0_factors sslshim_RSA_set0_factors 87 #define RSA_set0_crt_params sslshim_RSA_set0_crt_params 88 89 #define DSA_SIG_get0 sslshim_DSA_SIG_get0 90 #define DSA_SIG_set0 sslshim_DSA_SIG_set0 91 #define DSA_get0_pqg sslshim_DSA_get0_pqg 92 #define DSA_set0_pqg sslshim_DSA_set0_pqg 93 #define DSA_get0_key sslshim_DSA_get0_key 94 #define DSA_set0_key sslshim_DSA_set0_key 95 96 #define X509_get_signature_nid sslshim_X509_get_signature_nid 97 98 /* ----------------------------------------------------------------- */ 99 #endif /* OPENSSL_VERSION_NUMBER < v1.1.0 */ 100 /* ----------------------------------------------------------------- */ 101 102 #endif /* NTP_LIBSSL_COMPAT_H */ 103