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