Ruby  2.5.0dev(2017-10-22revision60238)
openssl_missing.h
Go to the documentation of this file.
1 /*
2  * 'OpenSSL for Ruby' project
3  * Copyright (C) 2001-2002 Michal Rokos <m.rokos@sh.cvut.cz>
4  * All rights reserved.
5  */
6 /*
7  * This program is licensed under the same licence as Ruby.
8  * (See the file 'LICENCE'.)
9  */
10 #if !defined(_OSSL_OPENSSL_MISSING_H_)
11 #define _OSSL_OPENSSL_MISSING_H_
12 
13 #include "ruby/config.h"
14 
15 /* added in 1.0.2 */
16 #if !defined(OPENSSL_NO_EC)
17 #if !defined(HAVE_EC_CURVE_NIST2NID)
18 int ossl_EC_curve_nist2nid(const char *);
19 # define EC_curve_nist2nid ossl_EC_curve_nist2nid
20 #endif
21 #endif
22 
23 #if !defined(HAVE_X509_REVOKED_DUP)
24 # define X509_REVOKED_dup(rev) (X509_REVOKED *)ASN1_dup((i2d_of_void *)i2d_X509_REVOKED, \
25  (d2i_of_void *)d2i_X509_REVOKED, (char *)(rev))
26 #endif
27 
28 #if !defined(HAVE_X509_STORE_CTX_GET0_STORE)
29 # define X509_STORE_CTX_get0_store(x) ((x)->ctx)
30 #endif
31 
32 #if !defined(HAVE_SSL_IS_SERVER)
33 # define SSL_is_server(s) ((s)->server)
34 #endif
35 
36 /* added in 1.1.0 */
37 #if !defined(HAVE_BN_GENCB_NEW)
38 # define BN_GENCB_new() ((BN_GENCB *)OPENSSL_malloc(sizeof(BN_GENCB)))
39 #endif
40 
41 #if !defined(HAVE_BN_GENCB_FREE)
42 # define BN_GENCB_free(cb) OPENSSL_free(cb)
43 #endif
44 
45 #if !defined(HAVE_BN_GENCB_GET_ARG)
46 # define BN_GENCB_get_arg(cb) (cb)->arg
47 #endif
48 
49 #if !defined(HAVE_EVP_MD_CTX_NEW)
50 # define EVP_MD_CTX_new EVP_MD_CTX_create
51 #endif
52 
53 #if !defined(HAVE_EVP_MD_CTX_FREE)
54 # define EVP_MD_CTX_free EVP_MD_CTX_destroy
55 #endif
56 
57 #if !defined(HAVE_HMAC_CTX_NEW)
58 HMAC_CTX *ossl_HMAC_CTX_new(void);
59 # define HMAC_CTX_new ossl_HMAC_CTX_new
60 #endif
61 
62 #if !defined(HAVE_HMAC_CTX_FREE)
63 void ossl_HMAC_CTX_free(HMAC_CTX *);
64 # define HMAC_CTX_free ossl_HMAC_CTX_free
65 #endif
66 
67 #if !defined(HAVE_X509_STORE_GET_EX_DATA)
68 # define X509_STORE_get_ex_data(x, idx) \
69  CRYPTO_get_ex_data(&(x)->ex_data, (idx))
70 #endif
71 
72 #if !defined(HAVE_X509_STORE_SET_EX_DATA)
73 # define X509_STORE_set_ex_data(x, idx, data) \
74  CRYPTO_set_ex_data(&(x)->ex_data, (idx), (data))
75 # define X509_STORE_get_ex_new_index(l, p, newf, dupf, freef) \
76  CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_X509_STORE, (l), (p), \
77  (newf), (dupf), (freef))
78 #endif
79 
80 #if !defined(HAVE_X509_CRL_GET0_SIGNATURE)
81 void ossl_X509_CRL_get0_signature(const X509_CRL *, const ASN1_BIT_STRING **, const X509_ALGOR **);
82 # define X509_CRL_get0_signature ossl_X509_CRL_get0_signature
83 #endif
84 
85 #if !defined(HAVE_X509_REQ_GET0_SIGNATURE)
86 void ossl_X509_REQ_get0_signature(const X509_REQ *, const ASN1_BIT_STRING **, const X509_ALGOR **);
87 # define X509_REQ_get0_signature ossl_X509_REQ_get0_signature
88 #endif
89 
90 #if !defined(HAVE_X509_REVOKED_GET0_SERIALNUMBER)
91 # define X509_REVOKED_get0_serialNumber(x) ((x)->serialNumber)
92 #endif
93 
94 #if !defined(HAVE_X509_REVOKED_GET0_REVOCATIONDATE)
95 # define X509_REVOKED_get0_revocationDate(x) ((x)->revocationDate)
96 #endif
97 
98 #if !defined(HAVE_X509_GET0_TBS_SIGALG)
99 # define X509_get0_tbs_sigalg(x) ((x)->cert_info->signature)
100 #endif
101 
102 #if !defined(HAVE_X509_STORE_CTX_GET0_UNTRUSTED)
103 # define X509_STORE_CTX_get0_untrusted(x) ((x)->untrusted)
104 #endif
105 
106 #if !defined(HAVE_X509_STORE_CTX_GET0_CERT)
107 # define X509_STORE_CTX_get0_cert(x) ((x)->cert)
108 #endif
109 
110 #if !defined(HAVE_X509_STORE_CTX_GET0_CHAIN)
111 # define X509_STORE_CTX_get0_chain(ctx) X509_STORE_CTX_get_chain(ctx)
112 #endif
113 
114 #if !defined(HAVE_OCSP_SINGLERESP_GET0_ID)
115 # define OCSP_SINGLERESP_get0_id(s) ((s)->certId)
116 #endif
117 
118 #if !defined(HAVE_SSL_CTX_GET_CIPHERS)
119 # define SSL_CTX_get_ciphers(ctx) ((ctx)->cipher_list)
120 #endif
121 
122 #if !defined(HAVE_X509_UP_REF)
123 # define X509_up_ref(x) \
124  CRYPTO_add(&(x)->references, 1, CRYPTO_LOCK_X509)
125 #endif
126 
127 #if !defined(HAVE_X509_CRL_UP_REF)
128 # define X509_CRL_up_ref(x) \
129  CRYPTO_add(&(x)->references, 1, CRYPTO_LOCK_X509_CRL);
130 #endif
131 
132 #if !defined(HAVE_X509_STORE_UP_REF)
133 # define X509_STORE_up_ref(x) \
134  CRYPTO_add(&(x)->references, 1, CRYPTO_LOCK_X509_STORE);
135 #endif
136 
137 #if !defined(HAVE_SSL_SESSION_UP_REF)
138 # define SSL_SESSION_up_ref(x) \
139  CRYPTO_add(&(x)->references, 1, CRYPTO_LOCK_SSL_SESSION);
140 #endif
141 
142 #if !defined(HAVE_EVP_PKEY_UP_REF)
143 # define EVP_PKEY_up_ref(x) \
144  CRYPTO_add(&(x)->references, 1, CRYPTO_LOCK_EVP_PKEY);
145 #endif
146 
147 #if !defined(HAVE_OPAQUE_OPENSSL)
148 #define IMPL_PKEY_GETTER(_type, _name) \
149 static inline _type *EVP_PKEY_get0_##_type(EVP_PKEY *pkey) { \
150  return pkey->pkey._name; }
151 #define IMPL_KEY_ACCESSOR2(_type, _group, a1, a2, _fail_cond) \
152 static inline void _type##_get0_##_group(_type *obj, const BIGNUM **a1, const BIGNUM **a2) { \
153  if (a1) *a1 = obj->a1; \
154  if (a2) *a2 = obj->a2; } \
155 static inline int _type##_set0_##_group(_type *obj, BIGNUM *a1, BIGNUM *a2) { \
156  if (_fail_cond) return 0; \
157  BN_clear_free(obj->a1); obj->a1 = a1; \
158  BN_clear_free(obj->a2); obj->a2 = a2; \
159  return 1; }
160 #define IMPL_KEY_ACCESSOR3(_type, _group, a1, a2, a3, _fail_cond) \
161 static inline void _type##_get0_##_group(_type *obj, const BIGNUM **a1, const BIGNUM **a2, const BIGNUM **a3) { \
162  if (a1) *a1 = obj->a1; \
163  if (a2) *a2 = obj->a2; \
164  if (a3) *a3 = obj->a3; } \
165 static inline int _type##_set0_##_group(_type *obj, BIGNUM *a1, BIGNUM *a2, BIGNUM *a3) { \
166  if (_fail_cond) return 0; \
167  BN_clear_free(obj->a1); obj->a1 = a1; \
168  BN_clear_free(obj->a2); obj->a2 = a2; \
169  BN_clear_free(obj->a3); obj->a3 = a3; \
170  return 1; }
171 
172 #if !defined(OPENSSL_NO_RSA)
173 IMPL_PKEY_GETTER(RSA, rsa)
174 IMPL_KEY_ACCESSOR3(RSA, key, n, e, d, (n == obj->n || e == obj->e || (obj->d && d == obj->d)))
175 IMPL_KEY_ACCESSOR2(RSA, factors, p, q, (p == obj->p || q == obj->q))
176 IMPL_KEY_ACCESSOR3(RSA, crt_params, dmp1, dmq1, iqmp, (dmp1 == obj->dmp1 || dmq1 == obj->dmq1 || iqmp == obj->iqmp))
177 #endif
178 
179 #if !defined(OPENSSL_NO_DSA)
180 IMPL_PKEY_GETTER(DSA, dsa)
181 IMPL_KEY_ACCESSOR2(DSA, key, pub_key, priv_key, (pub_key == obj->pub_key || (obj->priv_key && priv_key == obj->priv_key)))
182 IMPL_KEY_ACCESSOR3(DSA, pqg, p, q, g, (p == obj->p || q == obj->q || g == obj->g))
183 #endif
184 
185 #if !defined(OPENSSL_NO_DH)
186 IMPL_PKEY_GETTER(DH, dh)
187 IMPL_KEY_ACCESSOR2(DH, key, pub_key, priv_key, (pub_key == obj->pub_key || (obj->priv_key && priv_key == obj->priv_key)))
188 IMPL_KEY_ACCESSOR3(DH, pqg, p, q, g, (p == obj->p || obj->q && q == obj->q || g == obj->g))
189 static inline ENGINE *DH_get0_engine(DH *dh) { return dh->engine; }
190 #endif
191 
192 #if !defined(OPENSSL_NO_EC)
193 IMPL_PKEY_GETTER(EC_KEY, ec)
194 #endif
195 
196 #undef IMPL_PKEY_GETTER
197 #undef IMPL_KEY_ACCESSOR2
198 #undef IMPL_KEY_ACCESSOR3
199 #endif /* HAVE_OPAQUE_OPENSSL */
200 
201 #if !defined(EVP_CTRL_AEAD_GET_TAG)
202 # define EVP_CTRL_AEAD_GET_TAG EVP_CTRL_GCM_GET_TAG
203 # define EVP_CTRL_AEAD_SET_TAG EVP_CTRL_GCM_SET_TAG
204 # define EVP_CTRL_AEAD_SET_IVLEN EVP_CTRL_GCM_SET_IVLEN
205 #endif
206 
207 #if !defined(HAVE_X509_GET0_NOTBEFORE)
208 # define X509_get0_notBefore(x) X509_get_notBefore(x)
209 # define X509_get0_notAfter(x) X509_get_notAfter(x)
210 # define X509_CRL_get0_lastUpdate(x) X509_CRL_get_lastUpdate(x)
211 # define X509_CRL_get0_nextUpdate(x) X509_CRL_get_nextUpdate(x)
212 #endif
213 
214 #if !defined(HAVE_SSL_SESSION_GET_PROTOCOL_VERSION)
215 # define SSL_SESSION_get_protocol_version(s) ((s)->ssl_version)
216 #endif
217 
218 #endif /* _OSSL_OPENSSL_MISSING_H_ */
void ossl_HMAC_CTX_free(HMAC_CTX *)
#define IMPL_PKEY_GETTER(_type, _name)
void ossl_X509_REQ_get0_signature(const X509_REQ *, const ASN1_BIT_STRING **, const X509_ALGOR **)
priv_key
#define IMPL_KEY_ACCESSOR3(_type, _group, a1, a2, a3, _fail_cond)
pub_key
int ossl_EC_curve_nist2nid(const char *)
HMAC_CTX * ossl_HMAC_CTX_new(void)
void ossl_X509_CRL_get0_signature(const X509_CRL *, const ASN1_BIT_STRING **, const X509_ALGOR **)
#define IMPL_KEY_ACCESSOR2(_type, _group, a1, a2, _fail_cond)