1310419Sdelphij/*
2310419Sdelphij * libssl_compat.h -- OpenSSL v1.1 compatibility shims
3310419Sdelphij *
4310419Sdelphij * ---------------------------------------------------------------------
5310419Sdelphij *
6310419Sdelphij * Written by Juergen Perlinger <perlinger@ntp.org> for the NTP project
7310419Sdelphij *
8310419Sdelphij * Based on an idea by Kurt Roeckx <kurt@roeckx.be>
9310419Sdelphij *
10310419Sdelphij * ---------------------------------------------------------------------
11310419Sdelphij * This is a clean room implementation of shim functions that have
12310419Sdelphij * counterparts in the OpenSSL v1.1 API but not in earlier versions.
13310419Sdelphij *
14310419Sdelphij * If the OpenSSL version used for compilation needs the shims (that is,
15310419Sdelphij * does not provide the new functions) the names of these functions are
16310419Sdelphij * redirected to our shims.
17310419Sdelphij * ---------------------------------------------------------------------
18310419Sdelphij */
19310419Sdelphij
20310419Sdelphij#ifndef NTP_LIBSSL_COMPAT_H
21310419Sdelphij#define NTP_LIBSSL_COMPAT_H
22310419Sdelphij
23310419Sdelphij#include "openssl/evp.h"
24310419Sdelphij#include "openssl/dsa.h"
25310419Sdelphij#include "openssl/rsa.h"
26310419Sdelphij
27316722Sdelphij#ifndef OPENSSL_VERSION_NUMBER
28316722Sdelphij#define OPENSSL_VERSION_NUMBER SSLEAY_VERSION_NUMBER
29316722Sdelphij#endif
30316722Sdelphij
31316722Sdelphij#ifndef OPENSSL_VERSION_TEXT
32316722Sdelphij#define OPENSSL_VERSION_TEXT SSLEAY_VERSION_TEXT
33316722Sdelphij#endif
34316722Sdelphij
35316722Sdelphij#ifndef OPENSSL_VERSION
36316722Sdelphij#define OPENSSL_VERSION SSLEAY_VERSION
37316722Sdelphij#endif
38316722Sdelphij
39310419Sdelphij/* ----------------------------------------------------------------- */
40310419Sdelphij#if OPENSSL_VERSION_NUMBER < 0x10100000L
41310419Sdelphij/* ----------------------------------------------------------------- */
42310419Sdelphij
43310419Sdelphij# include <openssl/objects.h>
44310419Sdelphij# include <openssl/x509.h>
45310419Sdelphij
46310419Sdelphij/* shim the new-style API on an old-style OpenSSL */
47310419Sdelphij
48310419Sdelphijextern BN_GENCB*	sslshimBN_GENCB_new(void);
49310419Sdelphijextern void		sslshimBN_GENCB_free(BN_GENCB*);
50310419Sdelphij
51310419Sdelphijextern EVP_MD_CTX*	sslshim_EVP_MD_CTX_new(void);
52310419Sdelphijextern void		sslshim_EVP_MD_CTX_free(EVP_MD_CTX *ctx);
53310419Sdelphij
54310419Sdelphijextern int	sslshim_EVP_PKEY_id(const EVP_PKEY * pkey);
55310419Sdelphijextern int	sslshim_EVP_PKEY_base_id(const EVP_PKEY * pkey);
56310419Sdelphijextern RSA*	sslshim_EVP_PKEY_get0_RSA(EVP_PKEY * pkey);
57310419Sdelphijextern DSA*	sslshim_EVP_PKEY_get0_DSA(EVP_PKEY * pkey);
58310419Sdelphij
59310419Sdelphijextern void	sslshim_RSA_get0_key(const RSA *prsa, const BIGNUM **pn,
60310419Sdelphij				     const BIGNUM **pe, const BIGNUM **pd);
61310419Sdelphijextern int	sslshim_RSA_set0_key(RSA *prsa, BIGNUM *n,
62310419Sdelphij				     BIGNUM *e, BIGNUM *d);
63310419Sdelphijextern void	sslshim_RSA_get0_factors(const RSA *prsa, const BIGNUM **pp,
64310419Sdelphij					 const BIGNUM **pq);
65310419Sdelphijextern int 	sslshim_RSA_set0_factors(RSA *prsar, BIGNUM *p, BIGNUM *q);
66310419Sdelphijextern int	sslshim_RSA_set0_crt_params(RSA *prsa, BIGNUM *dmp1,
67310419Sdelphij					BIGNUM *dmq1, BIGNUM *iqmp);
68310419Sdelphij
69310419Sdelphijextern void	sslshim_DSA_SIG_get0(const DSA_SIG *psig, const BIGNUM **pr,
70310419Sdelphij				     const BIGNUM **ps);
71310419Sdelphijextern int	sslshim_DSA_SIG_set0(DSA_SIG *psig, BIGNUM *r, BIGNUM *s);
72310419Sdelphijextern void	sslshim_DSA_get0_pqg(const DSA *pdsa, const BIGNUM **pp,
73310419Sdelphij				 const BIGNUM **pq, const BIGNUM **pg);
74310419Sdelphijextern int	sslshim_DSA_set0_pqg(DSA *pdsa, BIGNUM *p, BIGNUM *q, BIGNUM *g);
75310419Sdelphijextern void	sslshim_DSA_get0_key(const DSA *pdsa, const BIGNUM **ppub_key,
76310419Sdelphij				 const BIGNUM **ppriv_key);
77310419Sdelphijextern int	sslshim_DSA_set0_key(DSA *pdsa, BIGNUM *pub_key,
78310419Sdelphij				     BIGNUM *priv_key);
79310419Sdelphij
80310419Sdelphijextern int	sslshim_X509_get_signature_nid(const X509 *x);
81310419Sdelphij
82310419Sdelphij#define	BN_GENCB_new		sslshimBN_GENCB_new
83310419Sdelphij#define	BN_GENCB_free		sslshimBN_GENCB_free
84310419Sdelphij
85310419Sdelphij#define EVP_MD_CTX_new		sslshim_EVP_MD_CTX_new
86310419Sdelphij#define EVP_MD_CTX_free		sslshim_EVP_MD_CTX_free
87310419Sdelphij
88310419Sdelphij#define EVP_PKEY_id		sslshim_EVP_PKEY_id
89310419Sdelphij#define EVP_PKEY_base_id	sslshim_EVP_PKEY_base_id
90310419Sdelphij#define EVP_PKEY_get0_RSA	sslshim_EVP_PKEY_get0_RSA
91310419Sdelphij#define EVP_PKEY_get0_DSA	sslshim_EVP_PKEY_get0_DSA
92310419Sdelphij
93310419Sdelphij#define RSA_get0_key		sslshim_RSA_get0_key
94310419Sdelphij#define RSA_set0_key		sslshim_RSA_set0_key
95310419Sdelphij#define RSA_get0_factors	sslshim_RSA_get0_factors
96310419Sdelphij#define RSA_set0_factors	sslshim_RSA_set0_factors
97310419Sdelphij#define RSA_set0_crt_params	sslshim_RSA_set0_crt_params
98310419Sdelphij
99310419Sdelphij#define DSA_SIG_get0		sslshim_DSA_SIG_get0
100310419Sdelphij#define DSA_SIG_set0		sslshim_DSA_SIG_set0
101310419Sdelphij#define DSA_get0_pqg		sslshim_DSA_get0_pqg
102310419Sdelphij#define DSA_set0_pqg		sslshim_DSA_set0_pqg
103310419Sdelphij#define DSA_get0_key		sslshim_DSA_get0_key
104310419Sdelphij#define DSA_set0_key		sslshim_DSA_set0_key
105310419Sdelphij
106310419Sdelphij#define X509_get_signature_nid	sslshim_X509_get_signature_nid
107310419Sdelphij
108316722Sdelphij#define OpenSSL_version_num	SSLeay
109316722Sdelphij#define OpenSSL_version		SSLeay_version
110316722Sdelphij#define X509_get0_notBefore	X509_get_notBefore
111316722Sdelphij#define X509_getm_notBefore	X509_get_notBefore
112316722Sdelphij#define X509_get0_notAfter	X509_get_notAfter
113316722Sdelphij#define X509_getm_notAfter	X509_get_notAfter
114316722Sdelphij
115310419Sdelphij/* ----------------------------------------------------------------- */
116310419Sdelphij#endif /* OPENSSL_VERSION_NUMBER < v1.1.0 */
117310419Sdelphij/* ----------------------------------------------------------------- */
118310419Sdelphij
119310419Sdelphij#endif /* NTP_LIBSSL_COMPAT_H */
120