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)
99#define RSA_get0_e(x) (x->e)
100#define RSA_get0_n(x) (x->n)
101#define ECDSA_SIG_get0_r(x) (x->r)
102#define ECDSA_SIG_get0_s(x) (x->s)
103#define ASN1_STRING_get0_data(x) ASN1_STRING_data(x)
105#define X509_OBJECT_free(x) ({ \
107 X509_OBJECT_free_contents(x); \
121#if OPENSSL_VERSION_NUMBER < 0x10100000L
124# if !defined(inline) && !defined(__cplusplus)
125# if defined(__STDC_VERSION__) && __STDC_VERSION__>=199901L
127# define pam_pkcs11_ossl_inline inline
128# elif defined(__GNUC__) && __GNUC__>=2
129# define pam_pkcs11_ossl_inline __inline__
130# elif defined(_MSC_VER)
131# define pam_pkcs11_ossl_inline __inline
133# define pam_pkcs11_ossl_inline
136# define pam_pkcs11_ossl_inline inline
140#if OPENSSL_VERSION_NUMBER < 0x10100000L
142#define RSA_bits(R) (BN_num_bits(R->n))
144#include <openssl/bn.h>
145#ifndef OPENSSL_NO_RSA
146#include <openssl/rsa.h>
148#ifndef OPENSSL_NO_DSA
149#include <openssl/dsa.h>
153#ifndef OPENSSL_NO_RSA
157 if (n == NULL || e == NULL)
172 if (p == NULL || q == NULL)
185 if (dmp1 == NULL || dmq1 == NULL || iqmp == NULL)
217 const BIGNUM **dmp1,
const BIGNUM **dmq1,
const BIGNUM **iqmp)
229#ifndef OPENSSL_NO_DSA
243 *pub_key = d->pub_key;
244 if (priv_key != NULL)
245 *priv_key = d->priv_key;
253#define RSA_set0_key(R, N, E, D) \
256 if (!(N) || !(E)) { \
270#define RSA_set0_factors(R, P, Q) \
285#define RSA_set0_crt_params(R, DMP1, DMQ1, IQMP) \
288 if (!DMP1 || !DMQ1 || !IQMP) { \
302#define RSA_get0_key(R, N, E, D) { \
306 if (n) *(n) = R->n; \
307 if (e) *(e) = R->e; \
308 if (d) *(d) = R->d; \
311#define RSA_get0_factors(R, P, Q) {\
314 if (p) *(p) = R->p; \
315 if (q) *(q) = R->q; \
318#define RSA_get0_crt_params(R, DMP1, DMQ1, IQMP) { \
319 BIGNUM **dmp1 = DMP1; \
320 BIGNUM **dmq1 = DMQ1; \
321 BIGNUM **iqmp = IQMP; \
322 if (dmp1) *(dmp1) = R->dmp1; \
323 if (dmq1) *(dmq1) = R->dmq1; \
324 if (iqmp) *(iqmp) = R->iqmp; \
327#define DSA_get0_key(D, PUB, PRIV) { \
328 BIGNUM **pub = PUB; \
329 BIGNUM **priv = PRIV; \
330 if (pub) *(pub) = D->pub_key; \
331 if (priv) *(priv) = D->priv_key; \
334#define DSA_get0_pqg(D, P, Q, G) { \
338 if (p) *(p) = D->p; \
339 if (q) *(q) = D->q; \
340 if (g) *(g) = D->g; \
static pam_pkcs11_ossl_inline void DSA_get0_key(const DSA *d, const BIGNUM **pub_key, const BIGNUM **priv_key)
static pam_pkcs11_ossl_inline int RSA_set0_factors(RSA *r, BIGNUM *p, BIGNUM *q)
static pam_pkcs11_ossl_inline int RSA_set0_key(RSA *r, BIGNUM *n, BIGNUM *e, BIGNUM *d)
#define pam_pkcs11_ossl_inline
static pam_pkcs11_ossl_inline int RSA_set0_crt_params(RSA *r, BIGNUM *dmp1, BIGNUM *dmq1, BIGNUM *iqmp)
static pam_pkcs11_ossl_inline void RSA_get0_crt_params(const RSA *r, const BIGNUM **dmp1, const BIGNUM **dmq1, const BIGNUM **iqmp)
static pam_pkcs11_ossl_inline void RSA_get0_factors(const RSA *r, const BIGNUM **p, const BIGNUM **q)
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 void DSA_get0_pqg(const DSA *d, const BIGNUM **p, const BIGNUM **q, const BIGNUM **g)