21 #ifndef _PAM_PKCS11_OSSL_COMPAT_H
22 #define _PAM_PKCS11_OSSL_COMPAT_H
29 #include <openssl/opensslv.h>
30 #include <openssl/opensslconf.h>
50 #if OPENSSL_VERSION_NUMBER <= 0x009070dfL
54 #define EVP_CIPHER_CTX_new() ({ \
55 EVP_CIPHER_CTX * tmp = NULL; \
56 tmp = OPENSSL_malloc(sizeof(struct evp_cipher_ctx_st)); \
58 EVP_CIPHER_CTX_init(tmp); \
63 #define EVP_CIPHER_CTX_free(x) ({ \
65 EVP_CIPHER_CTX_cleanup(x); \
79 #if OPENSSL_VERSION_NUMBER < 0x10001000L
80 #define EVP_PKEY_base_id(x) (x->type)
83 #if OPENSSL_VERSION_NUMBER < 0x10100000L
84 #define RSA_PKCS1_OpenSSL RSA_PKCS1_SSLeay
85 #define OPENSSL_malloc_init CRYPTO_malloc_init
87 #define EVP_PKEY_get0_RSA(x) (x->pkey.rsa)
88 #define EVP_PKEY_get0_DSA(x) (x->pkey.dsa)
89 #define X509_get_extension_flags(x) (x->ex_flags)
90 #define X509_get_key_usage(x) (x->ex_kusage)
91 #define X509_get_extended_key_usage(x) (x->ex_xkusage)
92 #define EVP_MD_CTX_new EVP_MD_CTX_create
93 #define EVP_MD_CTX_free EVP_MD_CTX_destroy
94 #define EVP_PKEY_up_ref(user_key) CRYPTO_add(&user_key->references, 1, CRYPTO_LOCK_EVP_PKEY)
95 #define X509_up_ref(cert) CRYPTO_add(&cert->references, 1, CRYPTO_LOCK_X509)
96 #define X509_get0_tbs_sigalg(x) (x->cert_info->key->algor)
97 #define X509_OBJECT_get0_X509(x) (x->data.x509)
98 #define X509_OBJECT_get0_X509_CRL(x) (x->data.crl)
100 #define X509_OBJECT_free(x) ({ \
102 X509_OBJECT_free_contents(x); \
116 #if OPENSSL_VERSION_NUMBER < 0x10100000L
119 # if !defined(inline) && !defined(__cplusplus)
120 # if defined(__STDC_VERSION__) && __STDC_VERSION__>=199901L
122 # define pam_pkcs11_ossl_inline inline
123 # elif defined(__GNUC__) && __GNUC__>=2
124 # define pam_pkcs11_ossl_inline __inline__
125 # elif defined(_MSC_VER)
126 # define pam_pkcs11_ossl_inline __inline
128 # define pam_pkcs11_ossl_inline
131 # define pam_pkcs11_ossl_inline inline
135 #if OPENSSL_VERSION_NUMBER < 0x10100000L
137 #define RSA_bits(R) (BN_num_bits(R->n))
139 #include <openssl/bn.h>
140 #ifndef OPENSSL_NO_RSA
141 #include <openssl/rsa.h>
143 #ifndef OPENSSL_NO_DSA
144 #include <openssl/dsa.h>
148 #ifndef OPENSSL_NO_RSA
152 if (n == NULL || e == NULL)
167 if (p == NULL || q == NULL)
180 if (dmp1 == NULL || dmq1 == NULL || iqmp == NULL)
212 const BIGNUM **dmp1,
const BIGNUM **dmq1,
const BIGNUM **iqmp)
224 #ifndef OPENSSL_NO_DSA
238 *pub_key = d->pub_key;
239 if (priv_key != NULL)
240 *priv_key = d->priv_key;
248 #define RSA_set0_key(R, N, E, D) \
251 if (!(N) || !(E)) { \
265 #define RSA_set0_factors(R, P, Q) \
280 #define RSA_set0_crt_params(R, DMP1, DMQ1, IQMP) \
283 if (!DMP1 || !DMQ1 || !IQMP) { \
297 #define RSA_get0_key(R, N, E, D) { \
301 if (n) *(n) = R->n; \
302 if (e) *(e) = R->e; \
303 if (d) *(d) = R->d; \
306 #define RSA_get0_factors(R, P, Q) {\
309 if (p) *(p) = R->p; \
310 if (q) *(q) = R->q; \
313 #define RSA_get0_crt_params(R, DMP1, DMQ1, IQMP) { \
314 BIGNUM **dmp1 = DMP1; \
315 BIGNUM **dmq1 = DMQ1; \
316 BIGNUM **iqmp = IQMP; \
317 if (dmp1) *(dmp1) = R->dmp1; \
318 if (dmq1) *(dmq1) = R->dmq1; \
319 if (iqmp) *(iqmp) = R->iqmp; \
322 #define DSA_get0_key(D, PUB, PRIV) { \
323 BIGNUM **pub = PUB; \
324 BIGNUM **priv = PRIV; \
325 if (pub) *(pub) = D->pub_key; \
326 if (priv) *(priv) = D->priv_key; \
329 #define DSA_get0_pqg(D, P, Q, G) { \
333 if (p) *(p) = D->p; \
334 if (q) *(q) = D->q; \
335 if (g) *(g) = D->g; \
static pam_pkcs11_ossl_inline int RSA_set0_factors(RSA *r, BIGNUM *p, BIGNUM *q)
static pam_pkcs11_ossl_inline void RSA_get0_factors(const RSA *r, const BIGNUM **p, const BIGNUM **q)
static pam_pkcs11_ossl_inline void DSA_get0_key(const DSA *d, const BIGNUM **pub_key, const BIGNUM **priv_key)
#define pam_pkcs11_ossl_inline
static pam_pkcs11_ossl_inline int RSA_set0_key(RSA *r, BIGNUM *n, BIGNUM *e, BIGNUM *d)
static pam_pkcs11_ossl_inline void RSA_get0_key(const RSA *r, const BIGNUM **n, const BIGNUM **e, const BIGNUM **d)
static pam_pkcs11_ossl_inline int RSA_set0_crt_params(RSA *r, BIGNUM *dmp1, BIGNUM *dmq1, BIGNUM *iqmp)
static pam_pkcs11_ossl_inline void DSA_get0_pqg(const DSA *d, const BIGNUM **p, const BIGNUM **q, const BIGNUM **g)
static pam_pkcs11_ossl_inline void RSA_get0_crt_params(const RSA *r, const BIGNUM **dmp1, const BIGNUM **dmq1, const BIGNUM **iqmp)