|
27 | 27 | #include <openssl/engine.h> |
28 | 28 | #endif |
29 | 29 |
|
30 | | -/* OpenSSL compatibility functions and macros */ |
31 | | -#if PHP_OPENSSL_API_VERSION < 0x10100 |
32 | | - |
33 | | -#define EVP_PKEY_get0_RSA(_pkey) _pkey->pkey.rsa |
34 | | -#define EVP_PKEY_get0_DH(_pkey) _pkey->pkey.dh |
35 | | -#define EVP_PKEY_get0_DSA(_pkey) _pkey->pkey.dsa |
36 | | -#define EVP_PKEY_get0_EC_KEY(_pkey) _pkey->pkey.ec |
37 | | - |
38 | | -static int RSA_set0_key(RSA *r, BIGNUM *n, BIGNUM *e, BIGNUM *d) |
39 | | -{ |
40 | | - r->n = n; |
41 | | - r->e = e; |
42 | | - r->d = d; |
43 | | - |
44 | | - return 1; |
45 | | -} |
46 | | - |
47 | | -static int RSA_set0_factors(RSA *r, BIGNUM *p, BIGNUM *q) |
48 | | -{ |
49 | | - r->p = p; |
50 | | - r->q = q; |
51 | | - |
52 | | - return 1; |
53 | | -} |
54 | | - |
55 | | -static int RSA_set0_crt_params(RSA *r, BIGNUM *dmp1, BIGNUM *dmq1, BIGNUM *iqmp) |
56 | | -{ |
57 | | - r->dmp1 = dmp1; |
58 | | - r->dmq1 = dmq1; |
59 | | - r->iqmp = iqmp; |
60 | | - |
61 | | - return 1; |
62 | | -} |
63 | | - |
64 | | -static void RSA_get0_key(const RSA *r, const BIGNUM **n, const BIGNUM **e, const BIGNUM **d) |
65 | | -{ |
66 | | - *n = r->n; |
67 | | - *e = r->e; |
68 | | - *d = r->d; |
69 | | -} |
70 | | - |
71 | | -static void RSA_get0_factors(const RSA *r, const BIGNUM **p, const BIGNUM **q) |
72 | | -{ |
73 | | - *p = r->p; |
74 | | - *q = r->q; |
75 | | -} |
76 | | - |
77 | | -static void RSA_get0_crt_params(const RSA *r, const BIGNUM **dmp1, const BIGNUM **dmq1, const BIGNUM **iqmp) |
78 | | -{ |
79 | | - *dmp1 = r->dmp1; |
80 | | - *dmq1 = r->dmq1; |
81 | | - *iqmp = r->iqmp; |
82 | | -} |
83 | | - |
84 | | -static void DH_get0_pqg(const DH *dh, const BIGNUM **p, const BIGNUM **q, const BIGNUM **g) |
85 | | -{ |
86 | | - *p = dh->p; |
87 | | - *q = dh->q; |
88 | | - *g = dh->g; |
89 | | -} |
90 | | - |
91 | | -static int DH_set0_pqg(DH *dh, BIGNUM *p, BIGNUM *q, BIGNUM *g) |
92 | | -{ |
93 | | - dh->p = p; |
94 | | - dh->q = q; |
95 | | - dh->g = g; |
96 | | - |
97 | | - return 1; |
98 | | -} |
99 | | - |
100 | | -static void DH_get0_key(const DH *dh, const BIGNUM **pub_key, const BIGNUM **priv_key) |
101 | | -{ |
102 | | - *pub_key = dh->pub_key; |
103 | | - *priv_key = dh->priv_key; |
104 | | -} |
105 | | - |
106 | | -static int DH_set0_key(DH *dh, BIGNUM *pub_key, BIGNUM *priv_key) |
107 | | -{ |
108 | | - dh->pub_key = pub_key; |
109 | | - dh->priv_key = priv_key; |
110 | | - |
111 | | - return 1; |
112 | | -} |
113 | | - |
114 | | -static void DSA_get0_pqg(const DSA *d, const BIGNUM **p, const BIGNUM **q, const BIGNUM **g) |
115 | | -{ |
116 | | - *p = d->p; |
117 | | - *q = d->q; |
118 | | - *g = d->g; |
119 | | -} |
120 | | - |
121 | | -int DSA_set0_pqg(DSA *d, BIGNUM *p, BIGNUM *q, BIGNUM *g) |
122 | | -{ |
123 | | - d->p = p; |
124 | | - d->q = q; |
125 | | - d->g = g; |
126 | | - |
127 | | - return 1; |
128 | | -} |
129 | | - |
130 | | -static void DSA_get0_key(const DSA *d, const BIGNUM **pub_key, const BIGNUM **priv_key) |
131 | | -{ |
132 | | - *pub_key = d->pub_key; |
133 | | - *priv_key = d->priv_key; |
134 | | -} |
135 | | - |
136 | | -int DSA_set0_key(DSA *d, BIGNUM *pub_key, BIGNUM *priv_key) |
137 | | -{ |
138 | | - d->pub_key = pub_key; |
139 | | - d->priv_key = priv_key; |
140 | | - |
141 | | - return 1; |
142 | | -} |
143 | | - |
144 | | -static const unsigned char *ASN1_STRING_get0_data(const ASN1_STRING *asn1) |
145 | | -{ |
146 | | - return M_ASN1_STRING_data(asn1); |
147 | | -} |
148 | | - |
149 | | -static int EVP_PKEY_up_ref(EVP_PKEY *pkey) |
150 | | -{ |
151 | | - return CRYPTO_add(&pkey->references, 1, CRYPTO_LOCK_EVP_PKEY); |
152 | | -} |
153 | | - |
154 | | -#if PHP_OPENSSL_API_VERSION < 0x10002 |
155 | | - |
156 | | -static int X509_get_signature_nid(const X509 *x) |
157 | | -{ |
158 | | - return OBJ_obj2nid(x->sig_alg->algorithm); |
159 | | -} |
160 | | - |
161 | | -#endif |
162 | | - |
163 | | -#define OpenSSL_version SSLeay_version |
164 | | -#define OPENSSL_VERSION SSLEAY_VERSION |
165 | | -#define X509_getm_notBefore X509_get_notBefore |
166 | | -#define X509_getm_notAfter X509_get_notAfter |
167 | | -#define EVP_CIPHER_CTX_reset EVP_CIPHER_CTX_cleanup |
168 | | - |
169 | | -#endif |
170 | | - |
171 | 30 | void php_openssl_backend_shutdown(void) |
172 | 31 | { |
173 | | - #ifdef LIBRESSL_VERSION_NUMBER |
| 32 | +#ifdef LIBRESSL_VERSION_NUMBER |
174 | 33 | EVP_cleanup(); |
175 | 34 |
|
176 | 35 | /* prevent accessing locking callback from unloaded extension */ |
177 | 36 | CRYPTO_set_locking_callback(NULL); |
178 | 37 |
|
179 | | -#ifndef OPENSSL_NO_ENGINE |
180 | 38 | /* Free engine list initialized by OPENSSL_config */ |
181 | 39 | ENGINE_cleanup(); |
182 | | -#endif |
183 | 40 |
|
184 | 41 | /* free allocated error strings */ |
185 | 42 | ERR_free_strings(); |
|
0 commit comments