xref: /illumos-gate/usr/src/lib/libkmf/plugins/kmf_openssl/common/compat.h (revision 553e44ce7e541a9e1404b1ead92be0753668710a)
1 /*
2  * Copyright 2016 The OpenSSL Project Authors. All Rights Reserved.
3  * Copyright 2018 RackTop Systems.
4  *
5  * Licensed under the OpenSSL license (the "License").  You may not use
6  * this file except in compliance with the License.  You can obtain a copy
7  * in the file LICENSE in the source distribution or at
8  * https://www.openssl.org/source/license.html
9  */
10 
11 #ifndef LIBCRYPTO_COMPAT_H
12 #define	LIBCRYPTO_COMPAT_H
13 
14 #if OPENSSL_VERSION_NUMBER < 0x10100000L || defined(LIBRESSL_VERSION_NUMBER)
15 
16 #include <openssl/rsa.h>
17 #include <openssl/dsa.h>
18 #include <openssl/ecdsa.h>
19 #include <openssl/dh.h>
20 #include <openssl/evp.h>
21 
22 int RSA_set0_key(RSA *r, BIGNUM *n, BIGNUM *e, BIGNUM *d);
23 int RSA_set0_factors(RSA *r, BIGNUM *p, BIGNUM *q);
24 int RSA_set0_crt_params(RSA *r, BIGNUM *dmp1, BIGNUM *dmq1, BIGNUM *iqmp);
25 void RSA_get0_key(const RSA *r, const BIGNUM **n, const BIGNUM **e,
26     const BIGNUM **d);
27 void RSA_get0_factors(const RSA *r, const BIGNUM **p, const BIGNUM **q);
28 void RSA_get0_crt_params(const RSA *r, const BIGNUM **dmp1,
29     const BIGNUM **dmq1, const BIGNUM **iqmp);
30 
31 void DSA_get0_pqg(const DSA *d, const BIGNUM **p, const BIGNUM **q,
32     const BIGNUM **g);
33 int DSA_set0_pqg(DSA *d, BIGNUM *p, BIGNUM *q, BIGNUM *g);
34 void DSA_get0_key(const DSA *d, const BIGNUM **pub_key,
35     const BIGNUM **priv_key);
36 int DSA_set0_key(DSA *d, BIGNUM *pub_key, BIGNUM *priv_key);
37 
38 void DSA_SIG_get0(const DSA_SIG *sig, const BIGNUM **pr, const BIGNUM **ps);
39 int DSA_SIG_set0(DSA_SIG *sig, BIGNUM *r, BIGNUM *s);
40 DSA *EVP_PKEY_get0_DSA(EVP_PKEY *pkey);
41 
42 void ECDSA_SIG_get0(const ECDSA_SIG *sig, const BIGNUM **pr, const BIGNUM **ps);
43 int ECDSA_SIG_set0(ECDSA_SIG *sig, BIGNUM *r, BIGNUM *s);
44 
45 void DH_get0_pqg(const DH *dh, const BIGNUM **p, const BIGNUM **q,
46     const BIGNUM **g);
47 int DH_set0_pqg(DH *dh, BIGNUM *p, BIGNUM *q, BIGNUM *g);
48 void DH_get0_key(const DH *dh, const BIGNUM **pub_key, const BIGNUM **priv_key);
49 int DH_set0_key(DH *dh, BIGNUM *pub_key, BIGNUM *priv_key);
50 int DH_set_length(DH *dh, long length);
51 
52 const unsigned char *EVP_CIPHER_CTX_iv(const EVP_CIPHER_CTX *ctx);
53 unsigned char *EVP_CIPHER_CTX_iv_noconst(EVP_CIPHER_CTX *ctx);
54 EVP_MD_CTX *EVP_MD_CTX_new(void);
55 void EVP_MD_CTX_free(EVP_MD_CTX *ctx);
56 #define	EVP_CIPHER_impl_ctx_size(e) e->ctx_size
57 #define	EVP_CIPHER_CTX_get_cipher_data(ctx) ctx->cipher_data
58 
59 RSA_METHOD *RSA_meth_dup(const RSA_METHOD *meth);
60 int RSA_meth_set1_name(RSA_METHOD *meth, const char *name);
61 #define	RSA_meth_get_finish(meth) meth->finish
62 int RSA_meth_set_priv_enc(RSA_METHOD *meth,
63     int (*priv_enc) (int flen, const unsigned char *from,
64     unsigned char *to, RSA *rsa, int padding));
65 int RSA_meth_set_priv_dec(RSA_METHOD *meth,
66     int (*priv_dec) (int flen, const unsigned char *from,
67     unsigned char *to, RSA *rsa, int padding));
68 int RSA_meth_set_finish(RSA_METHOD *meth, int (*finish) (RSA *rsa));
69 void RSA_meth_free(RSA_METHOD *meth);
70 
71 int RSA_bits(const RSA *r);
72 
73 RSA *EVP_PKEY_get0_RSA(EVP_PKEY *pkey);
74 
75 #define	OCSP_resp_get0_certs(bs) ((bs)->certs)
76 #define	PKCS12_SAFEBAG_get0_attr(bag, attr) PKCS12_get_attr(bag, attr)
77 #define	PKCS12_SAFEBAG_get_nid(bag) M_PKCS12_bag_type(bag)
78 #define	PKCS12_SAFEBAG_get0_p8inf(bag) ((bag)->value.keybag)
79 #define	PKCS12_SAFEBAG_get0_safes(bag) ((bag)->value.safes)
80 #define	PKCS12_SAFEBAG_create_cert PKCS12_x5092certbag
81 #define	PKCS12_SAFEBAG_create_pkcs8_encrypt PKCS12_MAKE_SHKEYBAG
82 #define	PKCS12_SAFEBAG_get_bag_nid M_PKCS12_cert_bag_type
83 #define	PKCS12_SAFEBAG_get1_cert PKCS12_certbag2x509
84 #define	X509_REVOKED_get0_serialNumber(revoke) ((revoke)->serialNumber)
85 #define	X509_CRL_get0_lastUpdate(xcrl) X509_CRL_get_lastUpdate(xcrl)
86 #define	X509_CRL_get0_nextUpdate(xcrl) X509_CRL_get_nextUpdate(xcrl)
87 #define	X509_getm_notBefore  X509_get_notBefore
88 #define	X509_getm_notAfter X509_get_notAfter
89 
90 #endif /* OPENSSL_VERSION_NUMBER || LIBRESSL_VERSION_NUMBER */
91 
92 #endif /* LIBCRYPTO_COMPAT_H */
93