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