diff options
author | jsing <> | 2014-06-10 15:20:40 +0000 |
---|---|---|
committer | jsing <> | 2014-06-10 15:20:40 +0000 |
commit | 1f0ada29dbbd22c18c51187561c2eb01d2a776b2 (patch) | |
tree | 26b9352fb9a5ac6c506e8003ffd77006cf098bbb /src | |
parent | 3d34b57814cfdc90c98c015ae0dbd3c1862c83cd (diff) | |
download | openbsd-1f0ada29dbbd22c18c51187561c2eb01d2a776b2.tar.gz openbsd-1f0ada29dbbd22c18c51187561c2eb01d2a776b2.tar.bz2 openbsd-1f0ada29dbbd22c18c51187561c2eb01d2a776b2.zip |
KNF.
Diffstat (limited to 'src')
-rw-r--r-- | src/lib/libcrypto/engine/eng_aesni.c | 331 | ||||
-rw-r--r-- | src/lib/libcrypto/engine/eng_all.c | 16 | ||||
-rw-r--r-- | src/lib/libcrypto/engine/eng_cnf.c | 158 | ||||
-rw-r--r-- | src/lib/libcrypto/engine/eng_ctrl.c | 313 | ||||
-rw-r--r-- | src/lib/libcrypto/engine/eng_dyn.c | 346 | ||||
-rw-r--r-- | src/lib/libcrypto/engine/eng_err.c | 193 | ||||
-rw-r--r-- | src/lib/libcrypto/engine/eng_fat.c | 77 | ||||
-rw-r--r-- | src/lib/libcrypto/engine/eng_init.c | 78 | ||||
-rw-r--r-- | src/lib/libssl/src/crypto/engine/eng_aesni.c | 331 | ||||
-rw-r--r-- | src/lib/libssl/src/crypto/engine/eng_all.c | 16 | ||||
-rw-r--r-- | src/lib/libssl/src/crypto/engine/eng_cnf.c | 158 | ||||
-rw-r--r-- | src/lib/libssl/src/crypto/engine/eng_ctrl.c | 313 | ||||
-rw-r--r-- | src/lib/libssl/src/crypto/engine/eng_dyn.c | 346 | ||||
-rw-r--r-- | src/lib/libssl/src/crypto/engine/eng_err.c | 193 | ||||
-rw-r--r-- | src/lib/libssl/src/crypto/engine/eng_fat.c | 77 | ||||
-rw-r--r-- | src/lib/libssl/src/crypto/engine/eng_init.c | 78 |
16 files changed, 1512 insertions, 1512 deletions
diff --git a/src/lib/libcrypto/engine/eng_aesni.c b/src/lib/libcrypto/engine/eng_aesni.c index d547d7f465..b1eade2d63 100644 --- a/src/lib/libcrypto/engine/eng_aesni.c +++ b/src/lib/libcrypto/engine/eng_aesni.c | |||
@@ -102,7 +102,8 @@ void ENGINE_load_aesni (void) | |||
102 | /* On non-x86 CPUs it just returns. */ | 102 | /* On non-x86 CPUs it just returns. */ |
103 | #ifdef COMPILE_HW_AESNI | 103 | #ifdef COMPILE_HW_AESNI |
104 | ENGINE *toadd = ENGINE_aesni(); | 104 | ENGINE *toadd = ENGINE_aesni(); |
105 | if (!toadd) return; | 105 | if (!toadd) |
106 | return; | ||
106 | ENGINE_add (toadd); | 107 | ENGINE_add (toadd); |
107 | ENGINE_register_complete (toadd); | 108 | ENGINE_register_complete (toadd); |
108 | ENGINE_free (toadd); | 109 | ENGINE_free (toadd); |
@@ -112,32 +113,26 @@ void ENGINE_load_aesni (void) | |||
112 | 113 | ||
113 | #ifdef COMPILE_HW_AESNI | 114 | #ifdef COMPILE_HW_AESNI |
114 | int aesni_set_encrypt_key(const unsigned char *userKey, int bits, | 115 | int aesni_set_encrypt_key(const unsigned char *userKey, int bits, |
115 | AES_KEY *key); | 116 | AES_KEY *key); |
116 | int aesni_set_decrypt_key(const unsigned char *userKey, int bits, | 117 | int aesni_set_decrypt_key(const unsigned char *userKey, int bits, |
117 | AES_KEY *key); | 118 | AES_KEY *key); |
118 | 119 | ||
119 | void aesni_encrypt(const unsigned char *in, unsigned char *out, | 120 | void aesni_encrypt(const unsigned char *in, unsigned char *out, |
120 | const AES_KEY *key); | 121 | const AES_KEY *key); |
121 | void aesni_decrypt(const unsigned char *in, unsigned char *out, | 122 | void aesni_decrypt(const unsigned char *in, unsigned char *out, |
122 | const AES_KEY *key); | 123 | const AES_KEY *key); |
123 | 124 | ||
124 | void aesni_ecb_encrypt(const unsigned char *in, | 125 | void aesni_ecb_encrypt(const unsigned char *in, unsigned char *out, |
125 | unsigned char *out, | 126 | size_t length, const AES_KEY *key, int enc); |
126 | size_t length, | 127 | void aesni_cbc_encrypt(const unsigned char *in, unsigned char *out, |
127 | const AES_KEY *key, | 128 | size_t length, const AES_KEY *key, unsigned char *ivec, int enc); |
128 | int enc); | ||
129 | void aesni_cbc_encrypt(const unsigned char *in, | ||
130 | unsigned char *out, | ||
131 | size_t length, | ||
132 | const AES_KEY *key, | ||
133 | unsigned char *ivec, int enc); | ||
134 | 129 | ||
135 | /* Function for ENGINE detection and control */ | 130 | /* Function for ENGINE detection and control */ |
136 | static int aesni_init(ENGINE *e); | 131 | static int aesni_init(ENGINE *e); |
137 | 132 | ||
138 | /* Cipher Stuff */ | 133 | /* Cipher Stuff */ |
139 | static int aesni_ciphers(ENGINE *e, const EVP_CIPHER **cipher, | 134 | static int aesni_ciphers(ENGINE *e, const EVP_CIPHER **cipher, |
140 | const int **nids, int nid); | 135 | const int **nids, int nid); |
141 | 136 | ||
142 | #define AESNI_MIN_ALIGN 16 | 137 | #define AESNI_MIN_ALIGN 16 |
143 | #define AESNI_ALIGN(x) \ | 138 | #define AESNI_ALIGN(x) \ |
@@ -145,143 +140,146 @@ static int aesni_ciphers(ENGINE *e, const EVP_CIPHER **cipher, | |||
145 | 140 | ||
146 | /* Engine names */ | 141 | /* Engine names */ |
147 | static const char aesni_id[] = "aesni", | 142 | static const char aesni_id[] = "aesni", |
148 | aesni_name[] = "Intel AES-NI engine", | 143 | aesni_name[] = "Intel AES-NI engine", |
149 | no_aesni_name[] = "Intel AES-NI engine (no-aesni)"; | 144 | no_aesni_name[] = "Intel AES-NI engine (no-aesni)"; |
150 | 145 | ||
151 | 146 | ||
152 | /* The input and output encrypted as though 128bit cfb mode is being | 147 | /* The input and output encrypted as though 128bit cfb mode is being |
153 | * used. The extra state information to record how much of the | 148 | * used. The extra state information to record how much of the |
154 | * 128bit block we have used is contained in *num; | 149 | * 128bit block we have used is contained in *num; |
155 | */ | 150 | */ |
156 | static void aesni_cfb128_encrypt(const unsigned char *in, unsigned char *out, | 151 | static void |
157 | unsigned int len, const void *key, | 152 | aesni_cfb128_encrypt(const unsigned char *in, unsigned char *out, |
158 | unsigned char ivec[16], int *num, | 153 | unsigned int len, const void *key, unsigned char ivec[16], int *num, |
159 | int enc) | 154 | int enc) |
160 | { | 155 | { |
161 | unsigned int n; | 156 | unsigned int n; |
162 | size_t l = 0; | 157 | size_t l = 0; |
163 | 158 | ||
164 | assert(in && out && key && ivec && num); | 159 | assert(in && out && key && ivec && num); |
165 | 160 | ||
166 | n = *num; | 161 | n = *num; |
167 | 162 | ||
168 | if (enc) { | 163 | if (enc) { |
169 | #if !defined(OPENSSL_SMALL_FOOTPRINT) | 164 | #if !defined(OPENSSL_SMALL_FOOTPRINT) |
170 | if (16%sizeof(size_t) == 0) do { /* always true actually */ | 165 | if (16%sizeof(size_t) == 0) do { /* always true actually */ |
171 | while (n && len) { | 166 | while (n && len) { |
172 | *(out++) = ivec[n] ^= *(in++); | 167 | *(out++) = ivec[n] ^= *(in++); |
173 | --len; | 168 | --len; |
174 | n = (n+1) % 16; | 169 | n = (n + 1) % 16; |
175 | } | ||
176 | while (len>=16) { | ||
177 | aesni_encrypt(ivec, ivec, key); | ||
178 | for (n=0; n<16; n+=sizeof(size_t)) { | ||
179 | *(size_t*)(out+n) = | ||
180 | *(size_t*)(ivec+n) ^= *(size_t*)(in+n); | ||
181 | } | 170 | } |
182 | len -= 16; | 171 | while (len >= 16) { |
183 | out += 16; | 172 | aesni_encrypt(ivec, ivec, key); |
184 | in += 16; | 173 | for (n = 0; n < 16; n += sizeof(size_t)) { |
185 | } | 174 | *(size_t*)(out + n) = |
186 | n = 0; | 175 | *(size_t*)(ivec + n) ^= *(size_t*)(in + n); |
187 | if (len) { | 176 | } |
188 | aesni_encrypt(ivec, ivec, key); | 177 | len -= 16; |
189 | while (len--) { | 178 | out += 16; |
190 | out[n] = ivec[n] ^= in[n]; | 179 | in += 16; |
191 | ++n; | ||
192 | } | 180 | } |
193 | } | 181 | n = 0; |
194 | *num = n; | 182 | if (len) { |
195 | return; | 183 | aesni_encrypt(ivec, ivec, key); |
196 | } while (0); | 184 | while (len--) { |
197 | /* the rest would be commonly eliminated by x86* compiler */ | 185 | out[n] = ivec[n] ^= in[n]; |
186 | ++n; | ||
187 | } | ||
188 | } | ||
189 | *num = n; | ||
190 | return; | ||
191 | } while (0); | ||
192 | /* the rest would be commonly eliminated by x86* compiler */ | ||
198 | #endif | 193 | #endif |
199 | while (l<len) { | 194 | while (l < len) { |
200 | if (n == 0) { | 195 | if (n == 0) { |
201 | aesni_encrypt(ivec, ivec, key); | 196 | aesni_encrypt(ivec, ivec, key); |
202 | } | ||
203 | out[l] = ivec[n] ^= in[l]; | ||
204 | ++l; | ||
205 | n = (n+1) % 16; | ||
206 | } | ||
207 | *num = n; | ||
208 | } else { | ||
209 | #if !defined(OPENSSL_SMALL_FOOTPRINT) | ||
210 | if (16%sizeof(size_t) == 0) do { /* always true actually */ | ||
211 | while (n && len) { | ||
212 | unsigned char c; | ||
213 | *(out++) = ivec[n] ^ (c = *(in++)); ivec[n] = c; | ||
214 | --len; | ||
215 | n = (n+1) % 16; | ||
216 | } | ||
217 | while (len>=16) { | ||
218 | aesni_encrypt(ivec, ivec, key); | ||
219 | for (n=0; n<16; n+=sizeof(size_t)) { | ||
220 | size_t t = *(size_t*)(in+n); | ||
221 | *(size_t*)(out+n) = *(size_t*)(ivec+n) ^ t; | ||
222 | *(size_t*)(ivec+n) = t; | ||
223 | } | 197 | } |
224 | len -= 16; | 198 | out[l] = ivec[n] ^= in[l]; |
225 | out += 16; | 199 | ++l; |
226 | in += 16; | 200 | n = (n + 1) % 16; |
227 | } | 201 | } |
228 | n = 0; | 202 | *num = n; |
229 | if (len) { | 203 | } else { |
230 | aesni_encrypt(ivec, ivec, key); | 204 | #if !defined(OPENSSL_SMALL_FOOTPRINT) |
231 | while (len--) { | 205 | if (16%sizeof(size_t) == 0) do { /* always true actually */ |
206 | while (n && len) { | ||
232 | unsigned char c; | 207 | unsigned char c; |
233 | out[n] = ivec[n] ^ (c = in[n]); ivec[n] = c; | 208 | *(out++) = ivec[n] ^ (c = *(in++)); |
234 | ++n; | 209 | ivec[n] = c; |
210 | --len; | ||
211 | n = (n + 1) % 16; | ||
235 | } | 212 | } |
236 | } | 213 | while (len >= 16) { |
237 | *num = n; | 214 | aesni_encrypt(ivec, ivec, key); |
238 | return; | 215 | for (n = 0; n < 16; n += sizeof(size_t)) { |
239 | } while (0); | 216 | size_t t = *(size_t*)(in + n); |
240 | /* the rest would be commonly eliminated by x86* compiler */ | 217 | *(size_t*)(out + n) = *(size_t*)(ivec + n) ^ t; |
218 | *(size_t*)(ivec + n) = t; | ||
219 | } | ||
220 | len -= 16; | ||
221 | out += 16; | ||
222 | in += 16; | ||
223 | } | ||
224 | n = 0; | ||
225 | if (len) { | ||
226 | aesni_encrypt(ivec, ivec, key); | ||
227 | while (len--) { | ||
228 | unsigned char c; | ||
229 | out[n] = ivec[n] ^ (c = in[n]); | ||
230 | ivec[n] = c; | ||
231 | ++n; | ||
232 | } | ||
233 | } | ||
234 | *num = n; | ||
235 | return; | ||
236 | } while (0); | ||
237 | /* the rest would be commonly eliminated by x86* compiler */ | ||
241 | #endif | 238 | #endif |
242 | while (l<len) { | 239 | while (l < len) { |
243 | unsigned char c; | 240 | unsigned char c; |
244 | if (n == 0) { | 241 | if (n == 0) { |
245 | aesni_encrypt(ivec, ivec, key); | 242 | aesni_encrypt(ivec, ivec, key); |
243 | } | ||
244 | out[l] = ivec[n] ^ (c = in[l]); | ||
245 | ivec[n] = c; | ||
246 | ++l; | ||
247 | n = (n + 1) % 16; | ||
246 | } | 248 | } |
247 | out[l] = ivec[n] ^ (c = in[l]); ivec[n] = c; | 249 | *num = n; |
248 | ++l; | ||
249 | n = (n+1) % 16; | ||
250 | } | 250 | } |
251 | *num=n; | ||
252 | } | ||
253 | } | 251 | } |
254 | 252 | ||
255 | /* The input and output encrypted as though 128bit ofb mode is being | 253 | /* The input and output encrypted as though 128bit ofb mode is being |
256 | * used. The extra state information to record how much of the | 254 | * used. The extra state information to record how much of the |
257 | * 128bit block we have used is contained in *num; | 255 | * 128bit block we have used is contained in *num; |
258 | */ | 256 | */ |
259 | static void aesni_ofb128_encrypt(const unsigned char *in, unsigned char *out, | 257 | static void |
260 | unsigned int len, const void *key, | 258 | aesni_ofb128_encrypt(const unsigned char *in, unsigned char *out, |
261 | unsigned char ivec[16], int *num) | 259 | unsigned int len, const void *key, unsigned char ivec[16], int *num) |
262 | { | 260 | { |
263 | unsigned int n; | 261 | unsigned int n; |
264 | size_t l=0; | 262 | size_t l = 0; |
265 | 263 | ||
266 | assert(in && out && key && ivec && num); | 264 | assert(in && out && key && ivec && num); |
267 | 265 | ||
268 | n = *num; | 266 | n = *num; |
269 | 267 | ||
270 | #if !defined(OPENSSL_SMALL_FOOTPRINT) | 268 | #if !defined(OPENSSL_SMALL_FOOTPRINT) |
271 | if (16%sizeof(size_t) == 0) do { /* always true actually */ | 269 | if (16%sizeof(size_t) == 0) do { /* always true actually */ |
272 | while (n && len) { | 270 | while (n && len) { |
273 | *(out++) = *(in++) ^ ivec[n]; | 271 | *(out++) = *(in++) ^ ivec[n]; |
274 | --len; | 272 | --len; |
275 | n = (n+1) % 16; | 273 | n = (n + 1) % 16; |
276 | } | 274 | } |
277 | while (len>=16) { | 275 | while (len >= 16) { |
278 | aesni_encrypt(ivec, ivec, key); | 276 | aesni_encrypt(ivec, ivec, key); |
279 | for (n=0; n<16; n+=sizeof(size_t)) | 277 | for (n = 0; n < 16; n += sizeof(size_t)) |
280 | *(size_t*)(out+n) = | 278 | *(size_t*)(out + n) = |
281 | *(size_t*)(in+n) ^ *(size_t*)(ivec+n); | 279 | *(size_t*)(in + n) ^ *(size_t*)(ivec + n); |
282 | len -= 16; | 280 | len -= 16; |
283 | out += 16; | 281 | out += 16; |
284 | in += 16; | 282 | in += 16; |
285 | } | 283 | } |
286 | n = 0; | 284 | n = 0; |
287 | if (len) { | 285 | if (len) { |
@@ -293,19 +291,19 @@ static void aesni_ofb128_encrypt(const unsigned char *in, unsigned char *out, | |||
293 | } | 291 | } |
294 | *num = n; | 292 | *num = n; |
295 | return; | 293 | return; |
296 | } while(0); | 294 | } while (0); |
297 | /* the rest would be commonly eliminated by x86* compiler */ | 295 | /* the rest would be commonly eliminated by x86* compiler */ |
298 | #endif | 296 | #endif |
299 | while (l<len) { | 297 | while (l < len) { |
300 | if (n==0) { | 298 | if (n == 0) { |
301 | aesni_encrypt(ivec, ivec, key); | 299 | aesni_encrypt(ivec, ivec, key); |
302 | } | 300 | } |
303 | out[l] = in[l] ^ ivec[n]; | 301 | out[l] = in[l] ^ ivec[n]; |
304 | ++l; | 302 | ++l; |
305 | n = (n+1) % 16; | 303 | n = (n + 1) % 16; |
306 | } | 304 | } |
307 | 305 | ||
308 | *num=n; | 306 | *num = n; |
309 | } | 307 | } |
310 | /* ===== Engine "management" functions ===== */ | 308 | /* ===== Engine "management" functions ===== */ |
311 | 309 | ||
@@ -316,6 +314,7 @@ static int | |||
316 | aesni_bind_helper(ENGINE *e) | 314 | aesni_bind_helper(ENGINE *e) |
317 | { | 315 | { |
318 | int engage; | 316 | int engage; |
317 | |||
319 | if (sizeof(OPENSSL_ia32cap_P) > 4) { | 318 | if (sizeof(OPENSSL_ia32cap_P) > 4) { |
320 | engage = ((IA32CAP)OPENSSL_ia32cap_P >> 57) & 1; | 319 | engage = ((IA32CAP)OPENSSL_ia32cap_P >> 57) & 1; |
321 | } else { | 320 | } else { |
@@ -326,10 +325,8 @@ aesni_bind_helper(ENGINE *e) | |||
326 | /* Register everything or return with an error */ | 325 | /* Register everything or return with an error */ |
327 | if (!ENGINE_set_id(e, aesni_id) || | 326 | if (!ENGINE_set_id(e, aesni_id) || |
328 | !ENGINE_set_name(e, engage ? aesni_name : no_aesni_name) || | 327 | !ENGINE_set_name(e, engage ? aesni_name : no_aesni_name) || |
329 | |||
330 | !ENGINE_set_init_function(e, aesni_init) || | 328 | !ENGINE_set_init_function(e, aesni_init) || |
331 | (engage && !ENGINE_set_ciphers (e, aesni_ciphers)) | 329 | (engage && !ENGINE_set_ciphers (e, aesni_ciphers))) |
332 | ) | ||
333 | return 0; | 330 | return 0; |
334 | 331 | ||
335 | /* Everything looks good */ | 332 | /* Everything looks good */ |
@@ -403,60 +400,72 @@ static int aesni_cipher_nids[] = { | |||
403 | NID_aes_256_ofb, | 400 | NID_aes_256_ofb, |
404 | }; | 401 | }; |
405 | static int aesni_cipher_nids_num = | 402 | static int aesni_cipher_nids_num = |
406 | (sizeof(aesni_cipher_nids)/sizeof(aesni_cipher_nids[0])); | 403 | (sizeof(aesni_cipher_nids) / sizeof(aesni_cipher_nids[0])); |
407 | 404 | ||
408 | typedef struct | 405 | typedef struct { |
409 | { | ||
410 | AES_KEY ks; | 406 | AES_KEY ks; |
411 | unsigned int _pad1[3]; | 407 | unsigned int _pad1[3]; |
412 | } AESNI_KEY; | 408 | } AESNI_KEY; |
413 | 409 | ||
414 | static int | 410 | static int |
415 | aesni_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *user_key, | 411 | aesni_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *user_key, |
416 | const unsigned char *iv, int enc) | 412 | const unsigned char *iv, int enc) |
417 | { | 413 | { |
418 | int ret; | 414 | int ret; |
419 | AES_KEY *key = AESNI_ALIGN(ctx->cipher_data); | 415 | AES_KEY *key = AESNI_ALIGN(ctx->cipher_data); |
420 | 416 | ||
421 | if ((ctx->cipher->flags & EVP_CIPH_MODE) == EVP_CIPH_CFB_MODE | 417 | if ((ctx->cipher->flags & EVP_CIPH_MODE) == EVP_CIPH_CFB_MODE || |
422 | || (ctx->cipher->flags & EVP_CIPH_MODE) == EVP_CIPH_OFB_MODE | 418 | (ctx->cipher->flags & EVP_CIPH_MODE) == EVP_CIPH_OFB_MODE || |
423 | || enc) | 419 | enc) |
424 | ret=aesni_set_encrypt_key(user_key, ctx->key_len * 8, key); | 420 | ret = aesni_set_encrypt_key(user_key, ctx->key_len * 8, key); |
425 | else | 421 | else |
426 | ret=aesni_set_decrypt_key(user_key, ctx->key_len * 8, key); | 422 | ret = aesni_set_decrypt_key(user_key, ctx->key_len * 8, key); |
427 | 423 | ||
428 | if(ret < 0) { | 424 | if (ret < 0) { |
429 | EVPerr(EVP_F_AESNI_INIT_KEY,EVP_R_AES_KEY_SETUP_FAILED); | 425 | EVPerr(EVP_F_AESNI_INIT_KEY, EVP_R_AES_KEY_SETUP_FAILED); |
430 | return 0; | 426 | return 0; |
431 | } | 427 | } |
432 | 428 | ||
433 | return 1; | 429 | return 1; |
434 | } | 430 | } |
435 | 431 | ||
436 | static int aesni_cipher_ecb(EVP_CIPHER_CTX *ctx, unsigned char *out, | 432 | static int |
437 | const unsigned char *in, size_t inl) | 433 | aesni_cipher_ecb(EVP_CIPHER_CTX *ctx, unsigned char *out, |
438 | { AES_KEY *key = AESNI_ALIGN(ctx->cipher_data); | 434 | const unsigned char *in, size_t inl) |
435 | { | ||
436 | AES_KEY *key = AESNI_ALIGN(ctx->cipher_data); | ||
437 | |||
439 | aesni_ecb_encrypt(in, out, inl, key, ctx->encrypt); | 438 | aesni_ecb_encrypt(in, out, inl, key, ctx->encrypt); |
440 | return 1; | 439 | return 1; |
441 | } | 440 | } |
442 | static int aesni_cipher_cbc(EVP_CIPHER_CTX *ctx, unsigned char *out, | 441 | |
443 | const unsigned char *in, size_t inl) | 442 | static int |
444 | { AES_KEY *key = AESNI_ALIGN(ctx->cipher_data); | 443 | aesni_cipher_cbc(EVP_CIPHER_CTX *ctx, unsigned char *out, |
445 | aesni_cbc_encrypt(in, out, inl, key, | 444 | const unsigned char *in, size_t inl) |
446 | ctx->iv, ctx->encrypt); | 445 | { |
446 | AES_KEY *key = AESNI_ALIGN(ctx->cipher_data); | ||
447 | |||
448 | aesni_cbc_encrypt(in, out, inl, key, ctx->iv, ctx->encrypt); | ||
447 | return 1; | 449 | return 1; |
448 | } | 450 | } |
449 | static int aesni_cipher_cfb(EVP_CIPHER_CTX *ctx, unsigned char *out, | ||
450 | const unsigned char *in, size_t inl) | ||
451 | { AES_KEY *key = AESNI_ALIGN(ctx->cipher_data); | ||
452 | 451 | ||
453 | aesni_cfb128_encrypt(in, out, inl, key, ctx->iv, | 452 | static int |
454 | &ctx->num, ctx->encrypt); | 453 | aesni_cipher_cfb(EVP_CIPHER_CTX *ctx, unsigned char *out, |
454 | const unsigned char *in, size_t inl) | ||
455 | { | ||
456 | AES_KEY *key = AESNI_ALIGN(ctx->cipher_data); | ||
457 | |||
458 | aesni_cfb128_encrypt(in, out, inl, key, ctx->iv, &ctx->num, | ||
459 | ctx->encrypt); | ||
455 | return 1; | 460 | return 1; |
456 | } | 461 | } |
457 | static int aesni_cipher_ofb(EVP_CIPHER_CTX *ctx, unsigned char *out, | 462 | |
458 | const unsigned char *in, size_t inl) | 463 | static int |
459 | { AES_KEY *key = AESNI_ALIGN(ctx->cipher_data); | 464 | aesni_cipher_ofb(EVP_CIPHER_CTX *ctx, unsigned char *out, |
465 | const unsigned char *in, size_t inl) | ||
466 | { | ||
467 | AES_KEY *key = AESNI_ALIGN(ctx->cipher_data); | ||
468 | |||
460 | aesni_ofb128_encrypt(in, out, inl, key, ctx->iv, &ctx->num); | 469 | aesni_ofb128_encrypt(in, out, inl, key, ctx->iv, &ctx->num); |
461 | return 1; | 470 | return 1; |
462 | } | 471 | } |
@@ -487,24 +496,23 @@ static const EVP_CIPHER aesni_##ksize##_##lmode = { \ | |||
487 | NULL \ | 496 | NULL \ |
488 | } | 497 | } |
489 | 498 | ||
490 | DECLARE_AES_EVP(128,ecb,ECB); | 499 | DECLARE_AES_EVP(128, ecb, ECB); |
491 | DECLARE_AES_EVP(128,cbc,CBC); | 500 | DECLARE_AES_EVP(128, cbc, CBC); |
492 | DECLARE_AES_EVP(128,cfb,CFB); | 501 | DECLARE_AES_EVP(128, cfb, CFB); |
493 | DECLARE_AES_EVP(128,ofb,OFB); | 502 | DECLARE_AES_EVP(128, ofb, OFB); |
494 | 503 | ||
495 | DECLARE_AES_EVP(192,ecb,ECB); | 504 | DECLARE_AES_EVP(192, ecb, ECB); |
496 | DECLARE_AES_EVP(192,cbc,CBC); | 505 | DECLARE_AES_EVP(192, cbc, CBC); |
497 | DECLARE_AES_EVP(192,cfb,CFB); | 506 | DECLARE_AES_EVP(192, cfb, CFB); |
498 | DECLARE_AES_EVP(192,ofb,OFB); | 507 | DECLARE_AES_EVP(192, ofb, OFB); |
499 | 508 | ||
500 | DECLARE_AES_EVP(256,ecb,ECB); | 509 | DECLARE_AES_EVP(256, ecb, ECB); |
501 | DECLARE_AES_EVP(256,cbc,CBC); | 510 | DECLARE_AES_EVP(256, cbc, CBC); |
502 | DECLARE_AES_EVP(256,cfb,CFB); | 511 | DECLARE_AES_EVP(256, cfb, CFB); |
503 | DECLARE_AES_EVP(256,ofb,OFB); | 512 | DECLARE_AES_EVP(256, ofb, OFB); |
504 | 513 | ||
505 | static int | 514 | static int |
506 | aesni_ciphers (ENGINE *e, const EVP_CIPHER **cipher, | 515 | aesni_ciphers(ENGINE *e, const EVP_CIPHER **cipher, const int **nids, int nid) |
507 | const int **nids, int nid) | ||
508 | { | 516 | { |
509 | /* No specific cipher => return a list of supported nids ... */ | 517 | /* No specific cipher => return a list of supported nids ... */ |
510 | if (!cipher) { | 518 | if (!cipher) { |
@@ -563,4 +571,3 @@ aesni_ciphers (ENGINE *e, const EVP_CIPHER **cipher, | |||
563 | 571 | ||
564 | #endif /* COMPILE_HW_AESNI */ | 572 | #endif /* COMPILE_HW_AESNI */ |
565 | #endif /* !defined(OPENSSL_NO_HW) && !defined(OPENSSL_NO_HW_AESNI) && !defined(OPENSSL_NO_AES) */ | 573 | #endif /* !defined(OPENSSL_NO_HW) && !defined(OPENSSL_NO_HW_AESNI) && !defined(OPENSSL_NO_AES) */ |
566 | |||
diff --git a/src/lib/libcrypto/engine/eng_all.c b/src/lib/libcrypto/engine/eng_all.c index fd36594a0b..eb933153e1 100644 --- a/src/lib/libcrypto/engine/eng_all.c +++ b/src/lib/libcrypto/engine/eng_all.c | |||
@@ -10,7 +10,7 @@ | |||
10 | * are met: | 10 | * are met: |
11 | * | 11 | * |
12 | * 1. Redistributions of source code must retain the above copyright | 12 | * 1. Redistributions of source code must retain the above copyright |
13 | * notice, this list of conditions and the following disclaimer. | 13 | * notice, this list of conditions and the following disclaimer. |
14 | * | 14 | * |
15 | * 2. Redistributions in binary form must reproduce the above copyright | 15 | * 2. Redistributions in binary form must reproduce the above copyright |
16 | * notice, this list of conditions and the following disclaimer in | 16 | * notice, this list of conditions and the following disclaimer in |
@@ -59,8 +59,9 @@ | |||
59 | #include "cryptlib.h" | 59 | #include "cryptlib.h" |
60 | #include "eng_int.h" | 60 | #include "eng_int.h" |
61 | 61 | ||
62 | void ENGINE_load_builtin_engines(void) | 62 | void |
63 | { | 63 | ENGINE_load_builtin_engines(void) |
64 | { | ||
64 | /* Some ENGINEs need this */ | 65 | /* Some ENGINEs need this */ |
65 | OPENSSL_cpuid_setup(); | 66 | OPENSSL_cpuid_setup(); |
66 | #if 0 | 67 | #if 0 |
@@ -85,15 +86,18 @@ void ENGINE_load_builtin_engines(void) | |||
85 | #endif | 86 | #endif |
86 | #endif | 87 | #endif |
87 | ENGINE_register_all_complete(); | 88 | ENGINE_register_all_complete(); |
88 | } | 89 | } |
89 | 90 | ||
90 | #if defined(__OpenBSD__) || defined(__FreeBSD__) || defined(HAVE_CRYPTODEV) | 91 | #if defined(__OpenBSD__) || defined(__FreeBSD__) || defined(HAVE_CRYPTODEV) |
91 | void ENGINE_setup_bsd_cryptodev(void) { | 92 | void |
93 | ENGINE_setup_bsd_cryptodev(void) | ||
94 | { | ||
92 | static int bsd_cryptodev_default_loaded = 0; | 95 | static int bsd_cryptodev_default_loaded = 0; |
96 | |||
93 | if (!bsd_cryptodev_default_loaded) { | 97 | if (!bsd_cryptodev_default_loaded) { |
94 | ENGINE_load_cryptodev(); | 98 | ENGINE_load_cryptodev(); |
95 | ENGINE_register_all_complete(); | 99 | ENGINE_register_all_complete(); |
96 | } | 100 | } |
97 | bsd_cryptodev_default_loaded=1; | 101 | bsd_cryptodev_default_loaded = 1; |
98 | } | 102 | } |
99 | #endif | 103 | #endif |
diff --git a/src/lib/libcrypto/engine/eng_cnf.c b/src/lib/libcrypto/engine/eng_cnf.c index afb704e93b..c0c6b3fdc4 100644 --- a/src/lib/libcrypto/engine/eng_cnf.c +++ b/src/lib/libcrypto/engine/eng_cnf.c | |||
@@ -10,7 +10,7 @@ | |||
10 | * are met: | 10 | * are met: |
11 | * | 11 | * |
12 | * 1. Redistributions of source code must retain the above copyright | 12 | * 1. Redistributions of source code must retain the above copyright |
13 | * notice, this list of conditions and the following disclaimer. | 13 | * notice, this list of conditions and the following disclaimer. |
14 | * | 14 | * |
15 | * 2. Redistributions in binary form must reproduce the above copyright | 15 | * 2. Redistributions in binary form must reproduce the above copyright |
16 | * notice, this list of conditions and the following disclaimer in | 16 | * notice, this list of conditions and the following disclaimer in |
@@ -63,34 +63,37 @@ | |||
63 | 63 | ||
64 | /* ENGINE config module */ | 64 | /* ENGINE config module */ |
65 | 65 | ||
66 | static char *skip_dot(char *name) | 66 | static char * |
67 | { | 67 | skip_dot(char *name) |
68 | { | ||
68 | char *p; | 69 | char *p; |
70 | |||
69 | p = strchr(name, '.'); | 71 | p = strchr(name, '.'); |
70 | if (p) | 72 | if (p) |
71 | return p + 1; | 73 | return p + 1; |
72 | return name; | 74 | return name; |
73 | } | 75 | } |
74 | 76 | ||
75 | static STACK_OF(ENGINE) *initialized_engines = NULL; | 77 | static STACK_OF(ENGINE) *initialized_engines = NULL; |
76 | 78 | ||
77 | static int int_engine_init(ENGINE *e) | 79 | static int |
78 | { | 80 | int_engine_init(ENGINE *e) |
81 | { | ||
79 | if (!ENGINE_init(e)) | 82 | if (!ENGINE_init(e)) |
80 | return 0; | 83 | return 0; |
81 | if (!initialized_engines) | 84 | if (!initialized_engines) |
82 | initialized_engines = sk_ENGINE_new_null(); | 85 | initialized_engines = sk_ENGINE_new_null(); |
83 | if (!initialized_engines || !sk_ENGINE_push(initialized_engines, e)) | 86 | if (!initialized_engines || !sk_ENGINE_push(initialized_engines, e)) { |
84 | { | ||
85 | ENGINE_finish(e); | 87 | ENGINE_finish(e); |
86 | return 0; | 88 | return 0; |
87 | } | ||
88 | return 1; | ||
89 | } | 89 | } |
90 | 90 | return 1; | |
91 | } | ||
91 | 92 | ||
92 | static int int_engine_configure(char *name, char *value, const CONF *cnf) | 93 | |
93 | { | 94 | static int |
95 | int_engine_configure(char *name, char *value, const CONF *cnf) | ||
96 | { | ||
94 | int i; | 97 | int i; |
95 | int ret = 0; | 98 | int ret = 0; |
96 | long do_init = -1; | 99 | long do_init = -1; |
@@ -107,19 +110,19 @@ static int int_engine_configure(char *name, char *value, const CONF *cnf) | |||
107 | /* Value is a section containing ENGINE commands */ | 110 | /* Value is a section containing ENGINE commands */ |
108 | ecmds = NCONF_get_section(cnf, value); | 111 | ecmds = NCONF_get_section(cnf, value); |
109 | 112 | ||
110 | if (!ecmds) | 113 | if (!ecmds) { |
111 | { | 114 | ENGINEerr(ENGINE_F_INT_ENGINE_CONFIGURE, |
112 | ENGINEerr(ENGINE_F_INT_ENGINE_CONFIGURE, ENGINE_R_ENGINE_SECTION_ERROR); | 115 | ENGINE_R_ENGINE_SECTION_ERROR); |
113 | return 0; | 116 | return 0; |
114 | } | 117 | } |
115 | 118 | ||
116 | for (i = 0; i < sk_CONF_VALUE_num(ecmds); i++) | 119 | for (i = 0; i < sk_CONF_VALUE_num(ecmds); i++) { |
117 | { | ||
118 | ecmd = sk_CONF_VALUE_value(ecmds, i); | 120 | ecmd = sk_CONF_VALUE_value(ecmds, i); |
119 | ctrlname = skip_dot(ecmd->name); | 121 | ctrlname = skip_dot(ecmd->name); |
120 | ctrlvalue = ecmd->value; | 122 | ctrlvalue = ecmd->value; |
121 | #ifdef ENGINE_CONF_DEBUG | 123 | #ifdef ENGINE_CONF_DEBUG |
122 | fprintf(stderr, "ENGINE conf: doing ctrl(%s,%s)\n", ctrlname, ctrlvalue); | 124 | fprintf(stderr, "ENGINE conf: doing ctrl(%s,%s)\n", |
125 | ctrlname, ctrlvalue); | ||
123 | #endif | 126 | #endif |
124 | 127 | ||
125 | /* First handle some special pseudo ctrls */ | 128 | /* First handle some special pseudo ctrls */ |
@@ -130,8 +133,7 @@ static int int_engine_configure(char *name, char *value, const CONF *cnf) | |||
130 | else if (!strcmp(ctrlname, "soft_load")) | 133 | else if (!strcmp(ctrlname, "soft_load")) |
131 | soft = 1; | 134 | soft = 1; |
132 | /* Load a dynamic ENGINE */ | 135 | /* Load a dynamic ENGINE */ |
133 | else if (!strcmp(ctrlname, "dynamic_path")) | 136 | else if (!strcmp(ctrlname, "dynamic_path")) { |
134 | { | ||
135 | e = ENGINE_by_id("dynamic"); | 137 | e = ENGINE_by_id("dynamic"); |
136 | if (!e) | 138 | if (!e) |
137 | goto err; | 139 | goto err; |
@@ -141,119 +143,111 @@ static int int_engine_configure(char *name, char *value, const CONF *cnf) | |||
141 | goto err; | 143 | goto err; |
142 | if (!ENGINE_ctrl_cmd_string(e, "LOAD", NULL, 0)) | 144 | if (!ENGINE_ctrl_cmd_string(e, "LOAD", NULL, 0)) |
143 | goto err; | 145 | goto err; |
144 | } | 146 | } |
145 | /* ... add other pseudos here ... */ | 147 | /* ... add other pseudos here ... */ |
146 | else | 148 | else { |
147 | { | ||
148 | /* At this point we need an ENGINE structural reference | 149 | /* At this point we need an ENGINE structural reference |
149 | * if we don't already have one. | 150 | * if we don't already have one. |
150 | */ | 151 | */ |
151 | if (!e) | 152 | if (!e) { |
152 | { | ||
153 | e = ENGINE_by_id(name); | 153 | e = ENGINE_by_id(name); |
154 | if (!e && soft) | 154 | if (!e && soft) { |
155 | { | ||
156 | ERR_clear_error(); | 155 | ERR_clear_error(); |
157 | return 1; | 156 | return 1; |
158 | } | 157 | } |
159 | if (!e) | 158 | if (!e) |
160 | goto err; | 159 | goto err; |
161 | } | 160 | } |
162 | /* Allow "EMPTY" to mean no value: this allows a valid | 161 | /* Allow "EMPTY" to mean no value: this allows a valid |
163 | * "value" to be passed to ctrls of type NO_INPUT | 162 | * "value" to be passed to ctrls of type NO_INPUT |
164 | */ | 163 | */ |
165 | if (!strcmp(ctrlvalue, "EMPTY")) | 164 | if (!strcmp(ctrlvalue, "EMPTY")) |
166 | ctrlvalue = NULL; | 165 | ctrlvalue = NULL; |
167 | if (!strcmp(ctrlname, "init")) | 166 | if (!strcmp(ctrlname, "init")) { |
168 | { | 167 | if (!NCONF_get_number_e(cnf, value, "init", |
169 | if (!NCONF_get_number_e(cnf, value, "init", &do_init)) | 168 | &do_init)) |
170 | goto err; | 169 | goto err; |
171 | if (do_init == 1) | 170 | if (do_init == 1) { |
172 | { | ||
173 | if (!int_engine_init(e)) | 171 | if (!int_engine_init(e)) |
174 | goto err; | 172 | goto err; |
175 | } | 173 | } else if (do_init != 0) { |
176 | else if (do_init != 0) | 174 | ENGINEerr(ENGINE_F_INT_ENGINE_CONFIGURE, |
177 | { | 175 | ENGINE_R_INVALID_INIT_VALUE); |
178 | ENGINEerr(ENGINE_F_INT_ENGINE_CONFIGURE, ENGINE_R_INVALID_INIT_VALUE); | ||
179 | goto err; | 176 | goto err; |
180 | } | ||
181 | } | 177 | } |
182 | else if (!strcmp(ctrlname, "default_algorithms")) | 178 | } |
183 | { | 179 | else if (!strcmp(ctrlname, "default_algorithms")) { |
184 | if (!ENGINE_set_default_string(e, ctrlvalue)) | 180 | if (!ENGINE_set_default_string(e, ctrlvalue)) |
185 | goto err; | 181 | goto err; |
186 | } | 182 | } else if (!ENGINE_ctrl_cmd_string(e, |
187 | else if (!ENGINE_ctrl_cmd_string(e, | 183 | ctrlname, ctrlvalue, 0)) |
188 | ctrlname, ctrlvalue, 0)) | ||
189 | goto err; | 184 | goto err; |
190 | } | ||
191 | |||
192 | |||
193 | |||
194 | } | 185 | } |
195 | if (e && (do_init == -1) && !int_engine_init(e)) | 186 | } |
196 | { | 187 | if (e && (do_init == -1) && !int_engine_init(e)) { |
197 | ecmd = NULL; | 188 | ecmd = NULL; |
198 | goto err; | 189 | goto err; |
199 | } | 190 | } |
200 | ret = 1; | 191 | ret = 1; |
201 | err: | 192 | |
202 | if (ret != 1) | 193 | err: |
203 | { | 194 | if (ret != 1) { |
204 | ENGINEerr(ENGINE_F_INT_ENGINE_CONFIGURE, ENGINE_R_ENGINE_CONFIGURATION_ERROR); | 195 | ENGINEerr(ENGINE_F_INT_ENGINE_CONFIGURE, |
196 | ENGINE_R_ENGINE_CONFIGURATION_ERROR); | ||
205 | if (ecmd) | 197 | if (ecmd) |
206 | ERR_asprintf_error_data | 198 | ERR_asprintf_error_data |
207 | ("section=%s, name=%s, value=%s", | 199 | ("section=%s, name=%s, value=%s", |
208 | ecmd->section, ecmd->name, ecmd->value); | 200 | ecmd->section, ecmd->name, ecmd->value); |
209 | } | 201 | } |
210 | if (e) | 202 | if (e) |
211 | ENGINE_free(e); | 203 | ENGINE_free(e); |
212 | return ret; | 204 | return ret; |
213 | } | 205 | } |
214 | 206 | ||
215 | 207 | ||
216 | static int int_engine_module_init(CONF_IMODULE *md, const CONF *cnf) | 208 | static int |
217 | { | 209 | int_engine_module_init(CONF_IMODULE *md, const CONF *cnf) |
210 | { | ||
218 | STACK_OF(CONF_VALUE) *elist; | 211 | STACK_OF(CONF_VALUE) *elist; |
219 | CONF_VALUE *cval; | 212 | CONF_VALUE *cval; |
220 | int i; | 213 | int i; |
214 | |||
221 | #ifdef ENGINE_CONF_DEBUG | 215 | #ifdef ENGINE_CONF_DEBUG |
222 | fprintf(stderr, "Called engine module: name %s, value %s\n", | 216 | fprintf(stderr, "Called engine module: name %s, value %s\n", |
223 | CONF_imodule_get_name(md), CONF_imodule_get_value(md)); | 217 | CONF_imodule_get_name(md), CONF_imodule_get_value(md)); |
224 | #endif | 218 | #endif |
225 | /* Value is a section containing ENGINEs to configure */ | 219 | /* Value is a section containing ENGINEs to configure */ |
226 | elist = NCONF_get_section(cnf, CONF_imodule_get_value(md)); | 220 | elist = NCONF_get_section(cnf, CONF_imodule_get_value(md)); |
227 | 221 | ||
228 | if (!elist) | 222 | if (!elist) { |
229 | { | 223 | ENGINEerr(ENGINE_F_INT_ENGINE_MODULE_INIT, |
230 | ENGINEerr(ENGINE_F_INT_ENGINE_MODULE_INIT, ENGINE_R_ENGINES_SECTION_ERROR); | 224 | ENGINE_R_ENGINES_SECTION_ERROR); |
231 | return 0; | 225 | return 0; |
232 | } | 226 | } |
233 | 227 | ||
234 | for (i = 0; i < sk_CONF_VALUE_num(elist); i++) | 228 | for (i = 0; i < sk_CONF_VALUE_num(elist); i++) { |
235 | { | ||
236 | cval = sk_CONF_VALUE_value(elist, i); | 229 | cval = sk_CONF_VALUE_value(elist, i); |
237 | if (!int_engine_configure(cval->name, cval->value, cnf)) | 230 | if (!int_engine_configure(cval->name, cval->value, cnf)) |
238 | return 0; | 231 | return 0; |
239 | } | 232 | } |
240 | 233 | ||
241 | return 1; | 234 | return 1; |
242 | } | 235 | } |
243 | 236 | ||
244 | static void int_engine_module_finish(CONF_IMODULE *md) | 237 | static void |
245 | { | 238 | int_engine_module_finish(CONF_IMODULE *md) |
239 | { | ||
246 | ENGINE *e; | 240 | ENGINE *e; |
241 | |||
247 | while ((e = sk_ENGINE_pop(initialized_engines))) | 242 | while ((e = sk_ENGINE_pop(initialized_engines))) |
248 | ENGINE_finish(e); | 243 | ENGINE_finish(e); |
249 | sk_ENGINE_free(initialized_engines); | 244 | sk_ENGINE_free(initialized_engines); |
250 | initialized_engines = NULL; | 245 | initialized_engines = NULL; |
251 | } | 246 | } |
252 | 247 | ||
253 | 248 | void | |
254 | void ENGINE_add_conf_module(void) | 249 | ENGINE_add_conf_module(void) |
255 | { | 250 | { |
256 | CONF_module_add("engines", | 251 | CONF_module_add("engines", int_engine_module_init, |
257 | int_engine_module_init, | 252 | int_engine_module_finish); |
258 | int_engine_module_finish); | 253 | } |
259 | } | ||
diff --git a/src/lib/libcrypto/engine/eng_ctrl.c b/src/lib/libcrypto/engine/eng_ctrl.c index d5017e2329..67a724202b 100644 --- a/src/lib/libcrypto/engine/eng_ctrl.c +++ b/src/lib/libcrypto/engine/eng_ctrl.c | |||
@@ -7,7 +7,7 @@ | |||
7 | * are met: | 7 | * are met: |
8 | * | 8 | * |
9 | * 1. Redistributions of source code must retain the above copyright | 9 | * 1. Redistributions of source code must retain the above copyright |
10 | * notice, this list of conditions and the following disclaimer. | 10 | * notice, this list of conditions and the following disclaimer. |
11 | * | 11 | * |
12 | * 2. Redistributions in binary form must reproduce the above copyright | 12 | * 2. Redistributions in binary form must reproduce the above copyright |
13 | * notice, this list of conditions and the following disclaimer in | 13 | * notice, this list of conditions and the following disclaimer in |
@@ -63,95 +63,92 @@ static const char *int_no_description = ""; | |||
63 | * ENGINE in question has asked us to take care of it (ie. the ENGINE did not | 63 | * ENGINE in question has asked us to take care of it (ie. the ENGINE did not |
64 | * set the ENGINE_FLAGS_MANUAL_CMD_CTRL flag. */ | 64 | * set the ENGINE_FLAGS_MANUAL_CMD_CTRL flag. */ |
65 | 65 | ||
66 | static int int_ctrl_cmd_is_null(const ENGINE_CMD_DEFN *defn) | 66 | static int |
67 | { | 67 | int_ctrl_cmd_is_null(const ENGINE_CMD_DEFN *defn) |
68 | if((defn->cmd_num == 0) || (defn->cmd_name == NULL)) | 68 | { |
69 | if ((defn->cmd_num == 0) || (defn->cmd_name == NULL)) | ||
69 | return 1; | 70 | return 1; |
70 | return 0; | 71 | return 0; |
71 | } | 72 | } |
72 | 73 | ||
73 | static int int_ctrl_cmd_by_name(const ENGINE_CMD_DEFN *defn, const char *s) | 74 | static int |
74 | { | 75 | int_ctrl_cmd_by_name(const ENGINE_CMD_DEFN *defn, const char *s) |
76 | { | ||
75 | int idx = 0; | 77 | int idx = 0; |
76 | while(!int_ctrl_cmd_is_null(defn) && (strcmp(defn->cmd_name, s) != 0)) | 78 | while (!int_ctrl_cmd_is_null(defn) && |
77 | { | 79 | (strcmp(defn->cmd_name, s) != 0)) { |
78 | idx++; | 80 | idx++; |
79 | defn++; | 81 | defn++; |
80 | } | 82 | } |
81 | if(int_ctrl_cmd_is_null(defn)) | 83 | if (int_ctrl_cmd_is_null(defn)) |
82 | /* The given name wasn't found */ | 84 | /* The given name wasn't found */ |
83 | return -1; | 85 | return -1; |
84 | return idx; | 86 | return idx; |
85 | } | 87 | } |
86 | 88 | ||
87 | static int int_ctrl_cmd_by_num(const ENGINE_CMD_DEFN *defn, unsigned int num) | 89 | static int |
88 | { | 90 | int_ctrl_cmd_by_num(const ENGINE_CMD_DEFN *defn, unsigned int num) |
91 | { | ||
89 | int idx = 0; | 92 | int idx = 0; |
90 | /* NB: It is stipulated that 'cmd_defn' lists are ordered by cmd_num. So | 93 | /* NB: It is stipulated that 'cmd_defn' lists are ordered by cmd_num. So |
91 | * our searches don't need to take any longer than necessary. */ | 94 | * our searches don't need to take any longer than necessary. */ |
92 | while(!int_ctrl_cmd_is_null(defn) && (defn->cmd_num < num)) | 95 | while (!int_ctrl_cmd_is_null(defn) && (defn->cmd_num < num)) { |
93 | { | ||
94 | idx++; | 96 | idx++; |
95 | defn++; | 97 | defn++; |
96 | } | 98 | } |
97 | if(defn->cmd_num == num) | 99 | if (defn->cmd_num == num) |
98 | return idx; | 100 | return idx; |
99 | /* The given cmd_num wasn't found */ | 101 | /* The given cmd_num wasn't found */ |
100 | return -1; | 102 | return -1; |
101 | } | 103 | } |
102 | 104 | ||
103 | static int int_ctrl_helper(ENGINE *e, int cmd, long i, void *p, | 105 | static int |
104 | void (*f)(void)) | 106 | int_ctrl_helper(ENGINE *e, int cmd, long i, void *p, void (*f)(void)) |
105 | { | 107 | { |
106 | int idx; | 108 | int idx; |
107 | int ret; | 109 | int ret; |
108 | char *s = (char *)p; | 110 | char *s = (char *)p; |
111 | |||
109 | /* Take care of the easy one first (eg. it requires no searches) */ | 112 | /* Take care of the easy one first (eg. it requires no searches) */ |
110 | if(cmd == ENGINE_CTRL_GET_FIRST_CMD_TYPE) | 113 | if (cmd == ENGINE_CTRL_GET_FIRST_CMD_TYPE) { |
111 | { | 114 | if ((e->cmd_defns == NULL) || |
112 | if((e->cmd_defns == NULL) || int_ctrl_cmd_is_null(e->cmd_defns)) | 115 | int_ctrl_cmd_is_null(e->cmd_defns)) |
113 | return 0; | 116 | return 0; |
114 | return e->cmd_defns->cmd_num; | 117 | return e->cmd_defns->cmd_num; |
115 | } | 118 | } |
116 | /* One or two commands require that "p" be a valid string buffer */ | 119 | /* One or two commands require that "p" be a valid string buffer */ |
117 | if((cmd == ENGINE_CTRL_GET_CMD_FROM_NAME) || | 120 | if ((cmd == ENGINE_CTRL_GET_CMD_FROM_NAME) || |
118 | (cmd == ENGINE_CTRL_GET_NAME_FROM_CMD) || | 121 | (cmd == ENGINE_CTRL_GET_NAME_FROM_CMD) || |
119 | (cmd == ENGINE_CTRL_GET_DESC_FROM_CMD)) | 122 | (cmd == ENGINE_CTRL_GET_DESC_FROM_CMD)) { |
120 | { | 123 | if (s == NULL) { |
121 | if(s == NULL) | ||
122 | { | ||
123 | ENGINEerr(ENGINE_F_INT_CTRL_HELPER, | 124 | ENGINEerr(ENGINE_F_INT_CTRL_HELPER, |
124 | ERR_R_PASSED_NULL_PARAMETER); | 125 | ERR_R_PASSED_NULL_PARAMETER); |
125 | return -1; | 126 | return -1; |
126 | } | ||
127 | } | 127 | } |
128 | } | ||
128 | /* Now handle cmd_name -> cmd_num conversion */ | 129 | /* Now handle cmd_name -> cmd_num conversion */ |
129 | if(cmd == ENGINE_CTRL_GET_CMD_FROM_NAME) | 130 | if (cmd == ENGINE_CTRL_GET_CMD_FROM_NAME) { |
130 | { | 131 | if ((e->cmd_defns == NULL) || |
131 | if((e->cmd_defns == NULL) || ((idx = int_ctrl_cmd_by_name( | 132 | ((idx = int_ctrl_cmd_by_name(e->cmd_defns, s)) < 0)) { |
132 | e->cmd_defns, s)) < 0)) | ||
133 | { | ||
134 | ENGINEerr(ENGINE_F_INT_CTRL_HELPER, | 133 | ENGINEerr(ENGINE_F_INT_CTRL_HELPER, |
135 | ENGINE_R_INVALID_CMD_NAME); | 134 | ENGINE_R_INVALID_CMD_NAME); |
136 | return -1; | 135 | return -1; |
137 | } | ||
138 | return e->cmd_defns[idx].cmd_num; | ||
139 | } | 136 | } |
137 | return e->cmd_defns[idx].cmd_num; | ||
138 | } | ||
140 | /* For the rest of the commands, the 'long' argument must specify a | 139 | /* For the rest of the commands, the 'long' argument must specify a |
141 | * valie command number - so we need to conduct a search. */ | 140 | * valie command number - so we need to conduct a search. */ |
142 | if((e->cmd_defns == NULL) || ((idx = int_ctrl_cmd_by_num(e->cmd_defns, | 141 | if ((e->cmd_defns == NULL) || |
143 | (unsigned int)i)) < 0)) | 142 | ((idx = int_ctrl_cmd_by_num(e->cmd_defns, (unsigned int)i)) < 0)) { |
144 | { | ||
145 | ENGINEerr(ENGINE_F_INT_CTRL_HELPER, | 143 | ENGINEerr(ENGINE_F_INT_CTRL_HELPER, |
146 | ENGINE_R_INVALID_CMD_NUMBER); | 144 | ENGINE_R_INVALID_CMD_NUMBER); |
147 | return -1; | 145 | return -1; |
148 | } | 146 | } |
149 | /* Now the logic splits depending on command type */ | 147 | /* Now the logic splits depending on command type */ |
150 | switch(cmd) | 148 | switch (cmd) { |
151 | { | ||
152 | case ENGINE_CTRL_GET_NEXT_CMD_TYPE: | 149 | case ENGINE_CTRL_GET_NEXT_CMD_TYPE: |
153 | idx++; | 150 | idx++; |
154 | if(int_ctrl_cmd_is_null(e->cmd_defns + idx)) | 151 | if (int_ctrl_cmd_is_null(e->cmd_defns + idx)) |
155 | /* end-of-list */ | 152 | /* end-of-list */ |
156 | return 0; | 153 | return 0; |
157 | else | 154 | else |
@@ -159,17 +156,17 @@ static int int_ctrl_helper(ENGINE *e, int cmd, long i, void *p, | |||
159 | case ENGINE_CTRL_GET_NAME_LEN_FROM_CMD: | 156 | case ENGINE_CTRL_GET_NAME_LEN_FROM_CMD: |
160 | return strlen(e->cmd_defns[idx].cmd_name); | 157 | return strlen(e->cmd_defns[idx].cmd_name); |
161 | case ENGINE_CTRL_GET_NAME_FROM_CMD: | 158 | case ENGINE_CTRL_GET_NAME_FROM_CMD: |
162 | ret = snprintf(s,strlen(e->cmd_defns[idx].cmd_name) + 1, | 159 | ret = snprintf(s, strlen(e->cmd_defns[idx].cmd_name) + 1, |
163 | "%s", e->cmd_defns[idx].cmd_name); | 160 | "%s", e->cmd_defns[idx].cmd_name); |
164 | if (ret >= (strlen(e->cmd_defns[idx].cmd_name) + 1)) | 161 | if (ret >= (strlen(e->cmd_defns[idx].cmd_name) + 1)) |
165 | ret = -1; | 162 | ret = -1; |
166 | return ret; | 163 | return ret; |
167 | case ENGINE_CTRL_GET_DESC_LEN_FROM_CMD: | 164 | case ENGINE_CTRL_GET_DESC_LEN_FROM_CMD: |
168 | if(e->cmd_defns[idx].cmd_desc) | 165 | if (e->cmd_defns[idx].cmd_desc) |
169 | return strlen(e->cmd_defns[idx].cmd_desc); | 166 | return strlen(e->cmd_defns[idx].cmd_desc); |
170 | return strlen(int_no_description); | 167 | return strlen(int_no_description); |
171 | case ENGINE_CTRL_GET_DESC_FROM_CMD: | 168 | case ENGINE_CTRL_GET_DESC_FROM_CMD: |
172 | if(e->cmd_defns[idx].cmd_desc) { | 169 | if (e->cmd_defns[idx].cmd_desc) { |
173 | ret = snprintf(s, | 170 | ret = snprintf(s, |
174 | strlen(e->cmd_defns[idx].cmd_desc) + 1, | 171 | strlen(e->cmd_defns[idx].cmd_desc) + 1, |
175 | "%s", e->cmd_defns[idx].cmd_desc); | 172 | "%s", e->cmd_defns[idx].cmd_desc); |
@@ -177,40 +174,40 @@ static int int_ctrl_helper(ENGINE *e, int cmd, long i, void *p, | |||
177 | ret = -1; | 174 | ret = -1; |
178 | return ret; | 175 | return ret; |
179 | } | 176 | } |
180 | ret = snprintf(s, strlen(int_no_description) + 1,"%s", | 177 | ret = snprintf(s, strlen(int_no_description) + 1, "%s", |
181 | int_no_description); | 178 | int_no_description); |
182 | if (ret >= strlen(int_no_description) + 1) | 179 | if (ret >= strlen(int_no_description) + 1) |
183 | ret = -1; | 180 | ret = -1; |
184 | return ret; | 181 | return ret; |
185 | case ENGINE_CTRL_GET_CMD_FLAGS: | 182 | case ENGINE_CTRL_GET_CMD_FLAGS: |
186 | return e->cmd_defns[idx].cmd_flags; | 183 | return e->cmd_defns[idx].cmd_flags; |
187 | } | 184 | } |
185 | |||
188 | /* Shouldn't really be here ... */ | 186 | /* Shouldn't really be here ... */ |
189 | ENGINEerr(ENGINE_F_INT_CTRL_HELPER,ENGINE_R_INTERNAL_LIST_ERROR); | 187 | ENGINEerr(ENGINE_F_INT_CTRL_HELPER, ENGINE_R_INTERNAL_LIST_ERROR); |
190 | return -1; | 188 | return -1; |
191 | } | 189 | } |
192 | 190 | ||
193 | int ENGINE_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)(void)) | 191 | int |
194 | { | 192 | ENGINE_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)(void)) |
193 | { | ||
195 | int ctrl_exists, ref_exists; | 194 | int ctrl_exists, ref_exists; |
196 | if(e == NULL) | 195 | |
197 | { | 196 | if (e == NULL) { |
198 | ENGINEerr(ENGINE_F_ENGINE_CTRL,ERR_R_PASSED_NULL_PARAMETER); | 197 | ENGINEerr(ENGINE_F_ENGINE_CTRL, ERR_R_PASSED_NULL_PARAMETER); |
199 | return 0; | 198 | return 0; |
200 | } | 199 | } |
201 | CRYPTO_w_lock(CRYPTO_LOCK_ENGINE); | 200 | CRYPTO_w_lock(CRYPTO_LOCK_ENGINE); |
202 | ref_exists = ((e->struct_ref > 0) ? 1 : 0); | 201 | ref_exists = ((e->struct_ref > 0) ? 1 : 0); |
203 | CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE); | 202 | CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE); |
204 | ctrl_exists = ((e->ctrl == NULL) ? 0 : 1); | 203 | ctrl_exists = ((e->ctrl == NULL) ? 0 : 1); |
205 | if(!ref_exists) | 204 | if (!ref_exists) { |
206 | { | 205 | ENGINEerr(ENGINE_F_ENGINE_CTRL, ENGINE_R_NO_REFERENCE); |
207 | ENGINEerr(ENGINE_F_ENGINE_CTRL,ENGINE_R_NO_REFERENCE); | ||
208 | return 0; | 206 | return 0; |
209 | } | 207 | } |
210 | /* Intercept any "root-level" commands before trying to hand them on to | 208 | /* Intercept any "root-level" commands before trying to hand them on to |
211 | * ctrl() handlers. */ | 209 | * ctrl() handlers. */ |
212 | switch(cmd) | 210 | switch (cmd) { |
213 | { | ||
214 | case ENGINE_CTRL_HAS_CTRL_FUNCTION: | 211 | case ENGINE_CTRL_HAS_CTRL_FUNCTION: |
215 | return ctrl_exists; | 212 | return ctrl_exists; |
216 | case ENGINE_CTRL_GET_FIRST_CMD_TYPE: | 213 | case ENGINE_CTRL_GET_FIRST_CMD_TYPE: |
@@ -221,180 +218,172 @@ int ENGINE_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)(void)) | |||
221 | case ENGINE_CTRL_GET_DESC_LEN_FROM_CMD: | 218 | case ENGINE_CTRL_GET_DESC_LEN_FROM_CMD: |
222 | case ENGINE_CTRL_GET_DESC_FROM_CMD: | 219 | case ENGINE_CTRL_GET_DESC_FROM_CMD: |
223 | case ENGINE_CTRL_GET_CMD_FLAGS: | 220 | case ENGINE_CTRL_GET_CMD_FLAGS: |
224 | if(ctrl_exists && !(e->flags & ENGINE_FLAGS_MANUAL_CMD_CTRL)) | 221 | if (ctrl_exists && !(e->flags & ENGINE_FLAGS_MANUAL_CMD_CTRL)) |
225 | return int_ctrl_helper(e,cmd,i,p,f); | 222 | return int_ctrl_helper(e, cmd, i, p, f); |
226 | if(!ctrl_exists) | 223 | if (!ctrl_exists) { |
227 | { | 224 | ENGINEerr(ENGINE_F_ENGINE_CTRL, |
228 | ENGINEerr(ENGINE_F_ENGINE_CTRL,ENGINE_R_NO_CONTROL_FUNCTION); | 225 | ENGINE_R_NO_CONTROL_FUNCTION); |
229 | /* For these cmd-related functions, failure is indicated | 226 | /* For these cmd-related functions, failure is indicated |
230 | * by a -1 return value (because 0 is used as a valid | 227 | * by a -1 return value (because 0 is used as a valid |
231 | * return in some places). */ | 228 | * return in some places). */ |
232 | return -1; | 229 | return -1; |
233 | } | 230 | } |
234 | default: | 231 | default: |
235 | break; | 232 | break; |
236 | } | 233 | } |
237 | /* Anything else requires a ctrl() handler to exist. */ | 234 | /* Anything else requires a ctrl() handler to exist. */ |
238 | if(!ctrl_exists) | 235 | if (!ctrl_exists) { |
239 | { | 236 | ENGINEerr(ENGINE_F_ENGINE_CTRL, ENGINE_R_NO_CONTROL_FUNCTION); |
240 | ENGINEerr(ENGINE_F_ENGINE_CTRL,ENGINE_R_NO_CONTROL_FUNCTION); | ||
241 | return 0; | 237 | return 0; |
242 | } | ||
243 | return e->ctrl(e, cmd, i, p, f); | ||
244 | } | 238 | } |
239 | return e->ctrl(e, cmd, i, p, f); | ||
240 | } | ||
245 | 241 | ||
246 | int ENGINE_cmd_is_executable(ENGINE *e, int cmd) | 242 | int |
247 | { | 243 | ENGINE_cmd_is_executable(ENGINE *e, int cmd) |
244 | { | ||
248 | int flags; | 245 | int flags; |
249 | if((flags = ENGINE_ctrl(e, ENGINE_CTRL_GET_CMD_FLAGS, cmd, NULL, NULL)) < 0) | 246 | |
250 | { | 247 | if ((flags = ENGINE_ctrl(e, ENGINE_CTRL_GET_CMD_FLAGS, cmd, |
248 | NULL, NULL)) < 0) { | ||
251 | ENGINEerr(ENGINE_F_ENGINE_CMD_IS_EXECUTABLE, | 249 | ENGINEerr(ENGINE_F_ENGINE_CMD_IS_EXECUTABLE, |
252 | ENGINE_R_INVALID_CMD_NUMBER); | 250 | ENGINE_R_INVALID_CMD_NUMBER); |
253 | return 0; | 251 | return 0; |
254 | } | 252 | } |
255 | if(!(flags & ENGINE_CMD_FLAG_NO_INPUT) && | 253 | if (!(flags & ENGINE_CMD_FLAG_NO_INPUT) && |
256 | !(flags & ENGINE_CMD_FLAG_NUMERIC) && | 254 | !(flags & ENGINE_CMD_FLAG_NUMERIC) && |
257 | !(flags & ENGINE_CMD_FLAG_STRING)) | 255 | !(flags & ENGINE_CMD_FLAG_STRING)) |
258 | return 0; | 256 | return 0; |
259 | return 1; | 257 | return 1; |
260 | } | 258 | } |
261 | 259 | ||
262 | int ENGINE_ctrl_cmd(ENGINE *e, const char *cmd_name, | 260 | int |
263 | long i, void *p, void (*f)(void), int cmd_optional) | 261 | ENGINE_ctrl_cmd(ENGINE *e, const char *cmd_name, long i, void *p, |
264 | { | 262 | void (*f)(void), int cmd_optional) |
263 | { | ||
265 | int num; | 264 | int num; |
266 | 265 | ||
267 | if((e == NULL) || (cmd_name == NULL)) | 266 | if ((e == NULL) || (cmd_name == NULL)) { |
268 | { | ||
269 | ENGINEerr(ENGINE_F_ENGINE_CTRL_CMD, | 267 | ENGINEerr(ENGINE_F_ENGINE_CTRL_CMD, |
270 | ERR_R_PASSED_NULL_PARAMETER); | 268 | ERR_R_PASSED_NULL_PARAMETER); |
271 | return 0; | 269 | return 0; |
272 | } | 270 | } |
273 | if((e->ctrl == NULL) || ((num = ENGINE_ctrl(e, | 271 | if ((e->ctrl == NULL) || |
274 | ENGINE_CTRL_GET_CMD_FROM_NAME, | 272 | ((num = ENGINE_ctrl(e, ENGINE_CTRL_GET_CMD_FROM_NAME, |
275 | 0, (void *)cmd_name, NULL)) <= 0)) | 273 | 0, (void *)cmd_name, NULL)) <= 0)) { |
276 | { | ||
277 | /* If the command didn't *have* to be supported, we fake | 274 | /* If the command didn't *have* to be supported, we fake |
278 | * success. This allows certain settings to be specified for | 275 | * success. This allows certain settings to be specified for |
279 | * multiple ENGINEs and only require a change of ENGINE id | 276 | * multiple ENGINEs and only require a change of ENGINE id |
280 | * (without having to selectively apply settings). Eg. changing | 277 | * (without having to selectively apply settings). Eg. changing |
281 | * from a hardware device back to the regular software ENGINE | 278 | * from a hardware device back to the regular software ENGINE |
282 | * without editing the config file, etc. */ | 279 | * without editing the config file, etc. */ |
283 | if(cmd_optional) | 280 | if (cmd_optional) { |
284 | { | ||
285 | ERR_clear_error(); | 281 | ERR_clear_error(); |
286 | return 1; | 282 | return 1; |
287 | } | ||
288 | ENGINEerr(ENGINE_F_ENGINE_CTRL_CMD, | ||
289 | ENGINE_R_INVALID_CMD_NAME); | ||
290 | return 0; | ||
291 | } | 283 | } |
284 | ENGINEerr(ENGINE_F_ENGINE_CTRL_CMD, ENGINE_R_INVALID_CMD_NAME); | ||
285 | return 0; | ||
286 | } | ||
287 | |||
292 | /* Force the result of the control command to 0 or 1, for the reasons | 288 | /* Force the result of the control command to 0 or 1, for the reasons |
293 | * mentioned before. */ | 289 | * mentioned before. */ |
294 | if (ENGINE_ctrl(e, num, i, p, f) > 0) | 290 | if (ENGINE_ctrl(e, num, i, p, f) > 0) |
295 | return 1; | 291 | return 1; |
296 | return 0; | ||
297 | } | ||
298 | 292 | ||
299 | int ENGINE_ctrl_cmd_string(ENGINE *e, const char *cmd_name, const char *arg, | 293 | return 0; |
300 | int cmd_optional) | 294 | } |
301 | { | 295 | |
296 | int | ||
297 | ENGINE_ctrl_cmd_string(ENGINE *e, const char *cmd_name, const char *arg, | ||
298 | int cmd_optional) | ||
299 | { | ||
302 | int num, flags; | 300 | int num, flags; |
303 | long l; | 301 | long l; |
304 | char *ptr; | 302 | char *ptr; |
305 | if((e == NULL) || (cmd_name == NULL)) | 303 | |
306 | { | 304 | if ((e == NULL) || (cmd_name == NULL)) { |
307 | ENGINEerr(ENGINE_F_ENGINE_CTRL_CMD_STRING, | 305 | ENGINEerr(ENGINE_F_ENGINE_CTRL_CMD_STRING, |
308 | ERR_R_PASSED_NULL_PARAMETER); | 306 | ERR_R_PASSED_NULL_PARAMETER); |
309 | return 0; | 307 | return 0; |
310 | } | 308 | } |
311 | if((e->ctrl == NULL) || ((num = ENGINE_ctrl(e, | 309 | if ((e->ctrl == NULL) || |
312 | ENGINE_CTRL_GET_CMD_FROM_NAME, | 310 | ((num = ENGINE_ctrl(e, ENGINE_CTRL_GET_CMD_FROM_NAME, 0, |
313 | 0, (void *)cmd_name, NULL)) <= 0)) | 311 | (void *)cmd_name, NULL)) <= 0)) { |
314 | { | ||
315 | /* If the command didn't *have* to be supported, we fake | 312 | /* If the command didn't *have* to be supported, we fake |
316 | * success. This allows certain settings to be specified for | 313 | * success. This allows certain settings to be specified for |
317 | * multiple ENGINEs and only require a change of ENGINE id | 314 | * multiple ENGINEs and only require a change of ENGINE id |
318 | * (without having to selectively apply settings). Eg. changing | 315 | * (without having to selectively apply settings). Eg. changing |
319 | * from a hardware device back to the regular software ENGINE | 316 | * from a hardware device back to the regular software ENGINE |
320 | * without editing the config file, etc. */ | 317 | * without editing the config file, etc. */ |
321 | if(cmd_optional) | 318 | if (cmd_optional) { |
322 | { | ||
323 | ERR_clear_error(); | 319 | ERR_clear_error(); |
324 | return 1; | 320 | return 1; |
325 | } | 321 | } |
326 | ENGINEerr(ENGINE_F_ENGINE_CTRL_CMD_STRING, | 322 | ENGINEerr(ENGINE_F_ENGINE_CTRL_CMD_STRING, |
327 | ENGINE_R_INVALID_CMD_NAME); | 323 | ENGINE_R_INVALID_CMD_NAME); |
328 | return 0; | 324 | return 0; |
329 | } | 325 | } |
330 | if(!ENGINE_cmd_is_executable(e, num)) | 326 | if (!ENGINE_cmd_is_executable(e, num)) { |
331 | { | ||
332 | ENGINEerr(ENGINE_F_ENGINE_CTRL_CMD_STRING, | 327 | ENGINEerr(ENGINE_F_ENGINE_CTRL_CMD_STRING, |
333 | ENGINE_R_CMD_NOT_EXECUTABLE); | 328 | ENGINE_R_CMD_NOT_EXECUTABLE); |
334 | return 0; | 329 | return 0; |
335 | } | 330 | } |
336 | if((flags = ENGINE_ctrl(e, ENGINE_CTRL_GET_CMD_FLAGS, num, NULL, NULL)) < 0) | 331 | if ((flags = ENGINE_ctrl(e, ENGINE_CTRL_GET_CMD_FLAGS, num, |
337 | { | 332 | NULL, NULL)) < 0) { |
338 | /* Shouldn't happen, given that ENGINE_cmd_is_executable() | 333 | /* Shouldn't happen, given that ENGINE_cmd_is_executable() |
339 | * returned success. */ | 334 | * returned success. */ |
340 | ENGINEerr(ENGINE_F_ENGINE_CTRL_CMD_STRING, | 335 | ENGINEerr(ENGINE_F_ENGINE_CTRL_CMD_STRING, |
341 | ENGINE_R_INTERNAL_LIST_ERROR); | 336 | ENGINE_R_INTERNAL_LIST_ERROR); |
342 | return 0; | 337 | return 0; |
343 | } | 338 | } |
344 | /* If the command takes no input, there must be no input. And vice | 339 | /* If the command takes no input, there must be no input. And vice |
345 | * versa. */ | 340 | * versa. */ |
346 | if(flags & ENGINE_CMD_FLAG_NO_INPUT) | 341 | if (flags & ENGINE_CMD_FLAG_NO_INPUT) { |
347 | { | 342 | if (arg != NULL) { |
348 | if(arg != NULL) | ||
349 | { | ||
350 | ENGINEerr(ENGINE_F_ENGINE_CTRL_CMD_STRING, | 343 | ENGINEerr(ENGINE_F_ENGINE_CTRL_CMD_STRING, |
351 | ENGINE_R_COMMAND_TAKES_NO_INPUT); | 344 | ENGINE_R_COMMAND_TAKES_NO_INPUT); |
352 | return 0; | 345 | return 0; |
353 | } | 346 | } |
354 | /* We deliberately force the result of ENGINE_ctrl() to 0 or 1 | 347 | /* We deliberately force the result of ENGINE_ctrl() to 0 or 1 |
355 | * rather than returning it as "return data". This is to ensure | 348 | * rather than returning it as "return data". This is to ensure |
356 | * usage of these commands is consistent across applications and | 349 | * usage of these commands is consistent across applications and |
357 | * that certain applications don't understand it one way, and | 350 | * that certain applications don't understand it one way, and |
358 | * others another. */ | 351 | * others another. */ |
359 | if(ENGINE_ctrl(e, num, 0, (void *)arg, NULL) > 0) | 352 | if (ENGINE_ctrl(e, num, 0, (void *)arg, NULL) > 0) |
360 | return 1; | 353 | return 1; |
361 | return 0; | 354 | return 0; |
362 | } | 355 | } |
363 | /* So, we require input */ | 356 | /* So, we require input */ |
364 | if(arg == NULL) | 357 | if (arg == NULL) { |
365 | { | ||
366 | ENGINEerr(ENGINE_F_ENGINE_CTRL_CMD_STRING, | 358 | ENGINEerr(ENGINE_F_ENGINE_CTRL_CMD_STRING, |
367 | ENGINE_R_COMMAND_TAKES_INPUT); | 359 | ENGINE_R_COMMAND_TAKES_INPUT); |
368 | return 0; | 360 | return 0; |
369 | } | 361 | } |
370 | /* If it takes string input, that's easy */ | 362 | /* If it takes string input, that's easy */ |
371 | if(flags & ENGINE_CMD_FLAG_STRING) | 363 | if (flags & ENGINE_CMD_FLAG_STRING) { |
372 | { | ||
373 | /* Same explanation as above */ | 364 | /* Same explanation as above */ |
374 | if(ENGINE_ctrl(e, num, 0, (void *)arg, NULL) > 0) | 365 | if (ENGINE_ctrl(e, num, 0, (void *)arg, NULL) > 0) |
375 | return 1; | 366 | return 1; |
376 | return 0; | 367 | return 0; |
377 | } | 368 | } |
378 | /* If it doesn't take numeric either, then it is unsupported for use in | 369 | /* If it doesn't take numeric either, then it is unsupported for use in |
379 | * a config-setting situation, which is what this function is for. This | 370 | * a config-setting situation, which is what this function is for. This |
380 | * should never happen though, because ENGINE_cmd_is_executable() was | 371 | * should never happen though, because ENGINE_cmd_is_executable() was |
381 | * used. */ | 372 | * used. */ |
382 | if(!(flags & ENGINE_CMD_FLAG_NUMERIC)) | 373 | if (!(flags & ENGINE_CMD_FLAG_NUMERIC)) { |
383 | { | ||
384 | ENGINEerr(ENGINE_F_ENGINE_CTRL_CMD_STRING, | 374 | ENGINEerr(ENGINE_F_ENGINE_CTRL_CMD_STRING, |
385 | ENGINE_R_INTERNAL_LIST_ERROR); | 375 | ENGINE_R_INTERNAL_LIST_ERROR); |
386 | return 0; | 376 | return 0; |
387 | } | 377 | } |
388 | l = strtol(arg, &ptr, 10); | 378 | l = strtol(arg, &ptr, 10); |
389 | if((arg == ptr) || (*ptr != '\0')) | 379 | if ((arg == ptr) || (*ptr != '\0')) { |
390 | { | ||
391 | ENGINEerr(ENGINE_F_ENGINE_CTRL_CMD_STRING, | 380 | ENGINEerr(ENGINE_F_ENGINE_CTRL_CMD_STRING, |
392 | ENGINE_R_ARGUMENT_IS_NOT_A_NUMBER); | 381 | ENGINE_R_ARGUMENT_IS_NOT_A_NUMBER); |
393 | return 0; | 382 | return 0; |
394 | } | 383 | } |
395 | /* Force the result of the control command to 0 or 1, for the reasons | 384 | /* Force the result of the control command to 0 or 1, for the reasons |
396 | * mentioned before. */ | 385 | * mentioned before. */ |
397 | if(ENGINE_ctrl(e, num, l, NULL, NULL) > 0) | 386 | if (ENGINE_ctrl(e, num, l, NULL, NULL) > 0) |
398 | return 1; | 387 | return 1; |
399 | return 0; | 388 | return 0; |
400 | } | 389 | } |
diff --git a/src/lib/libcrypto/engine/eng_dyn.c b/src/lib/libcrypto/engine/eng_dyn.c index e2de4603ee..0abb390b53 100644 --- a/src/lib/libcrypto/engine/eng_dyn.c +++ b/src/lib/libcrypto/engine/eng_dyn.c | |||
@@ -10,7 +10,7 @@ | |||
10 | * are met: | 10 | * are met: |
11 | * | 11 | * |
12 | * 1. Redistributions of source code must retain the above copyright | 12 | * 1. Redistributions of source code must retain the above copyright |
13 | * notice, this list of conditions and the following disclaimer. | 13 | * notice, this list of conditions and the following disclaimer. |
14 | * | 14 | * |
15 | * 2. Redistributions in binary form must reproduce the above copyright | 15 | * 2. Redistributions in binary form must reproduce the above copyright |
16 | * notice, this list of conditions and the following disclaimer in | 16 | * notice, this list of conditions and the following disclaimer in |
@@ -84,45 +84,52 @@ static int dynamic_load(ENGINE *e, dynamic_data_ctx *ctx); | |||
84 | static const char *engine_dynamic_id = "dynamic"; | 84 | static const char *engine_dynamic_id = "dynamic"; |
85 | static const char *engine_dynamic_name = "Dynamic engine loading support"; | 85 | static const char *engine_dynamic_name = "Dynamic engine loading support"; |
86 | static const ENGINE_CMD_DEFN dynamic_cmd_defns[] = { | 86 | static const ENGINE_CMD_DEFN dynamic_cmd_defns[] = { |
87 | {DYNAMIC_CMD_SO_PATH, | 87 | { |
88 | DYNAMIC_CMD_SO_PATH, | ||
88 | "SO_PATH", | 89 | "SO_PATH", |
89 | "Specifies the path to the new ENGINE shared library", | 90 | "Specifies the path to the new ENGINE shared library", |
90 | ENGINE_CMD_FLAG_STRING}, | 91 | ENGINE_CMD_FLAG_STRING}, |
91 | {DYNAMIC_CMD_NO_VCHECK, | 92 | { |
93 | DYNAMIC_CMD_NO_VCHECK, | ||
92 | "NO_VCHECK", | 94 | "NO_VCHECK", |
93 | "Specifies to continue even if version checking fails (boolean)", | 95 | "Specifies to continue even if version checking fails (boolean)", |
94 | ENGINE_CMD_FLAG_NUMERIC}, | 96 | ENGINE_CMD_FLAG_NUMERIC}, |
95 | {DYNAMIC_CMD_ID, | 97 | { |
98 | DYNAMIC_CMD_ID, | ||
96 | "ID", | 99 | "ID", |
97 | "Specifies an ENGINE id name for loading", | 100 | "Specifies an ENGINE id name for loading", |
98 | ENGINE_CMD_FLAG_STRING}, | 101 | ENGINE_CMD_FLAG_STRING}, |
99 | {DYNAMIC_CMD_LIST_ADD, | 102 | { |
103 | DYNAMIC_CMD_LIST_ADD, | ||
100 | "LIST_ADD", | 104 | "LIST_ADD", |
101 | "Whether to add a loaded ENGINE to the internal list (0=no,1=yes,2=mandatory)", | 105 | "Whether to add a loaded ENGINE to the internal list (0=no,1=yes,2=mandatory)", |
102 | ENGINE_CMD_FLAG_NUMERIC}, | 106 | ENGINE_CMD_FLAG_NUMERIC}, |
103 | {DYNAMIC_CMD_DIR_LOAD, | 107 | { |
108 | DYNAMIC_CMD_DIR_LOAD, | ||
104 | "DIR_LOAD", | 109 | "DIR_LOAD", |
105 | "Specifies whether to load from 'DIR_ADD' directories (0=no,1=yes,2=mandatory)", | 110 | "Specifies whether to load from 'DIR_ADD' directories (0=no,1=yes,2=mandatory)", |
106 | ENGINE_CMD_FLAG_NUMERIC}, | 111 | ENGINE_CMD_FLAG_NUMERIC}, |
107 | {DYNAMIC_CMD_DIR_ADD, | 112 | { |
113 | DYNAMIC_CMD_DIR_ADD, | ||
108 | "DIR_ADD", | 114 | "DIR_ADD", |
109 | "Adds a directory from which ENGINEs can be loaded", | 115 | "Adds a directory from which ENGINEs can be loaded", |
110 | ENGINE_CMD_FLAG_STRING}, | 116 | ENGINE_CMD_FLAG_STRING}, |
111 | {DYNAMIC_CMD_LOAD, | 117 | { |
118 | DYNAMIC_CMD_LOAD, | ||
112 | "LOAD", | 119 | "LOAD", |
113 | "Load up the ENGINE specified by other settings", | 120 | "Load up the ENGINE specified by other settings", |
114 | ENGINE_CMD_FLAG_NO_INPUT}, | 121 | ENGINE_CMD_FLAG_NO_INPUT}, |
122 | |||
115 | {0, NULL, NULL, 0} | 123 | {0, NULL, NULL, 0} |
116 | }; | 124 | }; |
117 | static const ENGINE_CMD_DEFN dynamic_cmd_defns_empty[] = { | 125 | static const ENGINE_CMD_DEFN dynamic_cmd_defns_empty[] = { |
118 | {0, NULL, NULL, 0} | 126 | {0, NULL, NULL, 0} |
119 | }; | 127 | }; |
120 | 128 | ||
121 | /* Loading code stores state inside the ENGINE structure via the "ex_data" | 129 | /* Loading code stores state inside the ENGINE structure via the "ex_data" |
122 | * element. We load all our state into a single structure and use that as a | 130 | * element. We load all our state into a single structure and use that as a |
123 | * single context in the "ex_data" stack. */ | 131 | * single context in the "ex_data" stack. */ |
124 | struct st_dynamic_data_ctx | 132 | struct st_dynamic_data_ctx { |
125 | { | ||
126 | /* The DSO object we load that supplies the ENGINE code */ | 133 | /* The DSO object we load that supplies the ENGINE code */ |
127 | DSO *dynamic_dso; | 134 | DSO *dynamic_dso; |
128 | /* The function pointer to the version checking shared library function */ | 135 | /* The function pointer to the version checking shared library function */ |
@@ -147,13 +154,18 @@ struct st_dynamic_data_ctx | |||
147 | int dir_load; | 154 | int dir_load; |
148 | /* A stack of directories from which ENGINEs could be loaded */ | 155 | /* A stack of directories from which ENGINEs could be loaded */ |
149 | STACK_OF(OPENSSL_STRING) *dirs; | 156 | STACK_OF(OPENSSL_STRING) *dirs; |
150 | }; | 157 | }; |
151 | 158 | ||
152 | /* This is the "ex_data" index we obtain and reserve for use with our context | 159 | /* This is the "ex_data" index we obtain and reserve for use with our context |
153 | * structure. */ | 160 | * structure. */ |
154 | static int dynamic_ex_data_idx = -1; | 161 | static int dynamic_ex_data_idx = -1; |
155 | 162 | ||
156 | static void int_free_str(char *s) { free(s); } | 163 | static void |
164 | int_free_str(char *s) | ||
165 | { | ||
166 | free(s); | ||
167 | } | ||
168 | |||
157 | /* Because our ex_data element may or may not get allocated depending on whether | 169 | /* Because our ex_data element may or may not get allocated depending on whether |
158 | * a "first-use" occurs before the ENGINE is freed, we have a memory leak | 170 | * a "first-use" occurs before the ENGINE is freed, we have a memory leak |
159 | * problem to solve. We can't declare a "new" handler for the ex_data as we | 171 | * problem to solve. We can't declare a "new" handler for the ex_data as we |
@@ -161,35 +173,36 @@ static void int_free_str(char *s) { free(s); } | |||
161 | * is a bug in the design of CRYPTO_EX_DATA). As such, we just declare a "free" | 173 | * is a bug in the design of CRYPTO_EX_DATA). As such, we just declare a "free" |
162 | * handler and that will get called if an ENGINE is being destroyed and there | 174 | * handler and that will get called if an ENGINE is being destroyed and there |
163 | * was an ex_data element corresponding to our context type. */ | 175 | * was an ex_data element corresponding to our context type. */ |
164 | static void dynamic_data_ctx_free_func(void *parent, void *ptr, | 176 | static void |
165 | CRYPTO_EX_DATA *ad, int idx, long argl, void *argp) | 177 | dynamic_data_ctx_free_func(void *parent, void *ptr, CRYPTO_EX_DATA *ad, |
166 | { | 178 | int idx, long argl, void *argp) |
167 | if(ptr) | 179 | { |
168 | { | 180 | if (ptr) { |
169 | dynamic_data_ctx *ctx = (dynamic_data_ctx *)ptr; | 181 | dynamic_data_ctx *ctx = (dynamic_data_ctx *)ptr; |
170 | if(ctx->dynamic_dso) | 182 | if (ctx->dynamic_dso) |
171 | DSO_free(ctx->dynamic_dso); | 183 | DSO_free(ctx->dynamic_dso); |
172 | free((void *)ctx->DYNAMIC_LIBNAME); | 184 | free((void *)ctx->DYNAMIC_LIBNAME); |
173 | free((void *)ctx->engine_id); | 185 | free((void *)ctx->engine_id); |
174 | if(ctx->dirs) | 186 | if (ctx->dirs) |
175 | sk_OPENSSL_STRING_pop_free(ctx->dirs, int_free_str); | 187 | sk_OPENSSL_STRING_pop_free(ctx->dirs, int_free_str); |
176 | free(ctx); | 188 | free(ctx); |
177 | } | ||
178 | } | 189 | } |
190 | } | ||
179 | 191 | ||
180 | /* Construct the per-ENGINE context. We create it blindly and then use a lock to | 192 | /* Construct the per-ENGINE context. We create it blindly and then use a lock to |
181 | * check for a race - if so, all but one of the threads "racing" will have | 193 | * check for a race - if so, all but one of the threads "racing" will have |
182 | * wasted their time. The alternative involves creating everything inside the | 194 | * wasted their time. The alternative involves creating everything inside the |
183 | * lock which is far worse. */ | 195 | * lock which is far worse. */ |
184 | static int dynamic_set_data_ctx(ENGINE *e, dynamic_data_ctx **ctx) | 196 | static int |
185 | { | 197 | dynamic_set_data_ctx(ENGINE *e, dynamic_data_ctx **ctx) |
198 | { | ||
186 | dynamic_data_ctx *c; | 199 | dynamic_data_ctx *c; |
200 | |||
187 | c = malloc(sizeof(dynamic_data_ctx)); | 201 | c = malloc(sizeof(dynamic_data_ctx)); |
188 | if(!c) | 202 | if (!c) { |
189 | { | 203 | ENGINEerr(ENGINE_F_DYNAMIC_SET_DATA_CTX, ERR_R_MALLOC_FAILURE); |
190 | ENGINEerr(ENGINE_F_DYNAMIC_SET_DATA_CTX,ERR_R_MALLOC_FAILURE); | ||
191 | return 0; | 204 | return 0; |
192 | } | 205 | } |
193 | memset(c, 0, sizeof(dynamic_data_ctx)); | 206 | memset(c, 0, sizeof(dynamic_data_ctx)); |
194 | c->dynamic_dso = NULL; | 207 | c->dynamic_dso = NULL; |
195 | c->v_check = NULL; | 208 | c->v_check = NULL; |
@@ -202,89 +215,92 @@ static int dynamic_set_data_ctx(ENGINE *e, dynamic_data_ctx **ctx) | |||
202 | c->DYNAMIC_F2 = "bind_engine"; | 215 | c->DYNAMIC_F2 = "bind_engine"; |
203 | c->dir_load = 1; | 216 | c->dir_load = 1; |
204 | c->dirs = sk_OPENSSL_STRING_new_null(); | 217 | c->dirs = sk_OPENSSL_STRING_new_null(); |
205 | if(!c->dirs) | 218 | if (!c->dirs) { |
206 | { | 219 | ENGINEerr(ENGINE_F_DYNAMIC_SET_DATA_CTX, ERR_R_MALLOC_FAILURE); |
207 | ENGINEerr(ENGINE_F_DYNAMIC_SET_DATA_CTX,ERR_R_MALLOC_FAILURE); | ||
208 | free(c); | 220 | free(c); |
209 | return 0; | 221 | return 0; |
210 | } | 222 | } |
211 | CRYPTO_w_lock(CRYPTO_LOCK_ENGINE); | 223 | CRYPTO_w_lock(CRYPTO_LOCK_ENGINE); |
212 | if((*ctx = (dynamic_data_ctx *)ENGINE_get_ex_data(e, | 224 | if ((*ctx = (dynamic_data_ctx *)ENGINE_get_ex_data(e, |
213 | dynamic_ex_data_idx)) == NULL) | 225 | dynamic_ex_data_idx)) == NULL) { |
214 | { | ||
215 | /* Good, we're the first */ | 226 | /* Good, we're the first */ |
216 | ENGINE_set_ex_data(e, dynamic_ex_data_idx, c); | 227 | ENGINE_set_ex_data(e, dynamic_ex_data_idx, c); |
217 | *ctx = c; | 228 | *ctx = c; |
218 | c = NULL; | 229 | c = NULL; |
219 | } | 230 | } |
220 | CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE); | 231 | CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE); |
221 | /* If we lost the race to set the context, c is non-NULL and *ctx is the | 232 | /* If we lost the race to set the context, c is non-NULL and *ctx is the |
222 | * context of the thread that won. */ | 233 | * context of the thread that won. */ |
223 | free(c); | 234 | free(c); |
224 | return 1; | 235 | return 1; |
225 | } | 236 | } |
226 | 237 | ||
227 | /* This function retrieves the context structure from an ENGINE's "ex_data", or | 238 | /* This function retrieves the context structure from an ENGINE's "ex_data", or |
228 | * if it doesn't exist yet, sets it up. */ | 239 | * if it doesn't exist yet, sets it up. */ |
229 | static dynamic_data_ctx *dynamic_get_data_ctx(ENGINE *e) | 240 | static dynamic_data_ctx * |
230 | { | 241 | dynamic_get_data_ctx(ENGINE *e) |
242 | { | ||
231 | dynamic_data_ctx *ctx; | 243 | dynamic_data_ctx *ctx; |
232 | if(dynamic_ex_data_idx < 0) | 244 | if (dynamic_ex_data_idx < 0) { |
233 | { | ||
234 | /* Create and register the ENGINE ex_data, and associate our | 245 | /* Create and register the ENGINE ex_data, and associate our |
235 | * "free" function with it to ensure any allocated contexts get | 246 | * "free" function with it to ensure any allocated contexts get |
236 | * freed when an ENGINE goes underground. */ | 247 | * freed when an ENGINE goes underground. */ |
237 | int new_idx = ENGINE_get_ex_new_index(0, NULL, NULL, NULL, | 248 | int new_idx = ENGINE_get_ex_new_index(0, NULL, NULL, NULL, |
238 | dynamic_data_ctx_free_func); | 249 | dynamic_data_ctx_free_func); |
239 | if(new_idx == -1) | 250 | if (new_idx == -1) { |
240 | { | 251 | ENGINEerr(ENGINE_F_DYNAMIC_GET_DATA_CTX, |
241 | ENGINEerr(ENGINE_F_DYNAMIC_GET_DATA_CTX,ENGINE_R_NO_INDEX); | 252 | ENGINE_R_NO_INDEX); |
242 | return NULL; | 253 | return NULL; |
243 | } | 254 | } |
244 | CRYPTO_w_lock(CRYPTO_LOCK_ENGINE); | 255 | CRYPTO_w_lock(CRYPTO_LOCK_ENGINE); |
245 | /* Avoid a race by checking again inside this lock */ | 256 | /* Avoid a race by checking again inside this lock */ |
246 | if(dynamic_ex_data_idx < 0) | 257 | if (dynamic_ex_data_idx < 0) { |
247 | { | ||
248 | /* Good, someone didn't beat us to it */ | 258 | /* Good, someone didn't beat us to it */ |
249 | dynamic_ex_data_idx = new_idx; | 259 | dynamic_ex_data_idx = new_idx; |
250 | new_idx = -1; | 260 | new_idx = -1; |
251 | } | 261 | } |
252 | CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE); | 262 | CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE); |
253 | /* In theory we could "give back" the index here if | 263 | /* In theory we could "give back" the index here if |
254 | * (new_idx>-1), but it's not possible and wouldn't gain us much | 264 | * (new_idx>-1), but it's not possible and wouldn't gain us much |
255 | * if it were. */ | 265 | * if it were. */ |
256 | } | 266 | } |
257 | ctx = (dynamic_data_ctx *)ENGINE_get_ex_data(e, dynamic_ex_data_idx); | 267 | ctx = (dynamic_data_ctx *)ENGINE_get_ex_data(e, dynamic_ex_data_idx); |
258 | /* Check if the context needs to be created */ | 268 | /* Check if the context needs to be created */ |
259 | if((ctx == NULL) && !dynamic_set_data_ctx(e, &ctx)) | 269 | if ((ctx == NULL) && !dynamic_set_data_ctx(e, &ctx)) |
260 | /* "set_data" will set errors if necessary */ | 270 | /* "set_data" will set errors if necessary */ |
261 | return NULL; | 271 | return NULL; |
262 | return ctx; | 272 | return ctx; |
263 | } | 273 | } |
264 | 274 | ||
265 | static ENGINE *engine_dynamic(void) | 275 | static ENGINE * |
266 | { | 276 | engine_dynamic(void) |
277 | { | ||
267 | ENGINE *ret = ENGINE_new(); | 278 | ENGINE *ret = ENGINE_new(); |
268 | if(!ret) | 279 | |
280 | if (!ret) | ||
269 | return NULL; | 281 | return NULL; |
270 | if(!ENGINE_set_id(ret, engine_dynamic_id) || | 282 | |
271 | !ENGINE_set_name(ret, engine_dynamic_name) || | 283 | if (!ENGINE_set_id(ret, engine_dynamic_id) || |
272 | !ENGINE_set_init_function(ret, dynamic_init) || | 284 | !ENGINE_set_name(ret, engine_dynamic_name) || |
273 | !ENGINE_set_finish_function(ret, dynamic_finish) || | 285 | !ENGINE_set_init_function(ret, dynamic_init) || |
274 | !ENGINE_set_ctrl_function(ret, dynamic_ctrl) || | 286 | !ENGINE_set_finish_function(ret, dynamic_finish) || |
275 | !ENGINE_set_flags(ret, ENGINE_FLAGS_BY_ID_COPY) || | 287 | !ENGINE_set_ctrl_function(ret, dynamic_ctrl) || |
276 | !ENGINE_set_cmd_defns(ret, dynamic_cmd_defns)) | 288 | !ENGINE_set_flags(ret, ENGINE_FLAGS_BY_ID_COPY) || |
277 | { | 289 | !ENGINE_set_cmd_defns(ret, dynamic_cmd_defns)) { |
278 | ENGINE_free(ret); | 290 | ENGINE_free(ret); |
279 | return NULL; | 291 | return NULL; |
280 | } | ||
281 | return ret; | ||
282 | } | 292 | } |
293 | return ret; | ||
294 | } | ||
283 | 295 | ||
284 | void ENGINE_load_dynamic(void) | 296 | void |
285 | { | 297 | ENGINE_load_dynamic(void) |
298 | { | ||
286 | ENGINE *toadd = engine_dynamic(); | 299 | ENGINE *toadd = engine_dynamic(); |
287 | if(!toadd) return; | 300 | |
301 | if (!toadd) | ||
302 | return; | ||
303 | |||
288 | ENGINE_add(toadd); | 304 | ENGINE_add(toadd); |
289 | /* If the "add" worked, it gets a structural reference. So either way, | 305 | /* If the "add" worked, it gets a structural reference. So either way, |
290 | * we release our just-created reference. */ | 306 | * we release our just-created reference. */ |
@@ -293,48 +309,47 @@ void ENGINE_load_dynamic(void) | |||
293 | * already added (eg. someone calling ENGINE_load_blah then calling | 309 | * already added (eg. someone calling ENGINE_load_blah then calling |
294 | * ENGINE_load_builtin_engines() perhaps). */ | 310 | * ENGINE_load_builtin_engines() perhaps). */ |
295 | ERR_clear_error(); | 311 | ERR_clear_error(); |
296 | } | 312 | } |
297 | 313 | ||
298 | static int dynamic_init(ENGINE *e) | 314 | static int |
299 | { | 315 | dynamic_init(ENGINE *e) |
316 | { | ||
300 | /* We always return failure - the "dyanamic" engine itself can't be used | 317 | /* We always return failure - the "dyanamic" engine itself can't be used |
301 | * for anything. */ | 318 | * for anything. */ |
302 | return 0; | 319 | return 0; |
303 | } | 320 | } |
304 | 321 | ||
305 | static int dynamic_finish(ENGINE *e) | 322 | static int |
306 | { | 323 | dynamic_finish(ENGINE *e) |
324 | { | ||
307 | /* This should never be called on account of "dynamic_init" always | 325 | /* This should never be called on account of "dynamic_init" always |
308 | * failing. */ | 326 | * failing. */ |
309 | return 0; | 327 | return 0; |
310 | } | 328 | } |
311 | 329 | ||
312 | static int dynamic_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)(void)) | 330 | static int |
313 | { | 331 | dynamic_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)(void)) |
332 | { | ||
314 | dynamic_data_ctx *ctx = dynamic_get_data_ctx(e); | 333 | dynamic_data_ctx *ctx = dynamic_get_data_ctx(e); |
315 | int initialised; | 334 | int initialised; |
316 | 335 | ||
317 | if(!ctx) | 336 | if (!ctx) { |
318 | { | 337 | ENGINEerr(ENGINE_F_DYNAMIC_CTRL, ENGINE_R_NOT_LOADED); |
319 | ENGINEerr(ENGINE_F_DYNAMIC_CTRL,ENGINE_R_NOT_LOADED); | ||
320 | return 0; | 338 | return 0; |
321 | } | 339 | } |
322 | initialised = ((ctx->dynamic_dso == NULL) ? 0 : 1); | 340 | initialised = ((ctx->dynamic_dso == NULL) ? 0 : 1); |
323 | /* All our control commands require the ENGINE to be uninitialised */ | 341 | /* All our control commands require the ENGINE to be uninitialised */ |
324 | if(initialised) | 342 | if (initialised) { |
325 | { | 343 | ENGINEerr(ENGINE_F_DYNAMIC_CTRL, ENGINE_R_ALREADY_LOADED); |
326 | ENGINEerr(ENGINE_F_DYNAMIC_CTRL, | ||
327 | ENGINE_R_ALREADY_LOADED); | ||
328 | return 0; | 344 | return 0; |
329 | } | 345 | } |
330 | switch(cmd) | 346 | switch (cmd) { |
331 | { | ||
332 | case DYNAMIC_CMD_SO_PATH: | 347 | case DYNAMIC_CMD_SO_PATH: |
333 | /* a NULL 'p' or a string of zero-length is the same thing */ | 348 | /* a NULL 'p' or a string of zero-length is the same thing */ |
334 | if(p && (strlen((const char *)p) < 1)) | 349 | if (p && (strlen((const char *)p) < 1)) |
335 | p = NULL; | 350 | p = NULL; |
336 | free((void *)ctx->DYNAMIC_LIBNAME); | 351 | free((void *)ctx->DYNAMIC_LIBNAME); |
337 | if(p) | 352 | if (p) |
338 | ctx->DYNAMIC_LIBNAME = BUF_strdup(p); | 353 | ctx->DYNAMIC_LIBNAME = BUF_strdup(p); |
339 | else | 354 | else |
340 | ctx->DYNAMIC_LIBNAME = NULL; | 355 | ctx->DYNAMIC_LIBNAME = NULL; |
@@ -344,145 +359,138 @@ static int dynamic_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)(void)) | |||
344 | return 1; | 359 | return 1; |
345 | case DYNAMIC_CMD_ID: | 360 | case DYNAMIC_CMD_ID: |
346 | /* a NULL 'p' or a string of zero-length is the same thing */ | 361 | /* a NULL 'p' or a string of zero-length is the same thing */ |
347 | if(p && (strlen((const char *)p) < 1)) | 362 | if (p && (strlen((const char *)p) < 1)) |
348 | p = NULL; | 363 | p = NULL; |
349 | free((void *)ctx->engine_id); | 364 | free((void *)ctx->engine_id); |
350 | if(p) | 365 | if (p) |
351 | ctx->engine_id = BUF_strdup(p); | 366 | ctx->engine_id = BUF_strdup(p); |
352 | else | 367 | else |
353 | ctx->engine_id = NULL; | 368 | ctx->engine_id = NULL; |
354 | return (ctx->engine_id ? 1 : 0); | 369 | return (ctx->engine_id ? 1 : 0); |
355 | case DYNAMIC_CMD_LIST_ADD: | 370 | case DYNAMIC_CMD_LIST_ADD: |
356 | if((i < 0) || (i > 2)) | 371 | if ((i < 0) || (i > 2)) { |
357 | { | ||
358 | ENGINEerr(ENGINE_F_DYNAMIC_CTRL, | 372 | ENGINEerr(ENGINE_F_DYNAMIC_CTRL, |
359 | ENGINE_R_INVALID_ARGUMENT); | 373 | ENGINE_R_INVALID_ARGUMENT); |
360 | return 0; | 374 | return 0; |
361 | } | 375 | } |
362 | ctx->list_add_value = (int)i; | 376 | ctx->list_add_value = (int)i; |
363 | return 1; | 377 | return 1; |
364 | case DYNAMIC_CMD_LOAD: | 378 | case DYNAMIC_CMD_LOAD: |
365 | return dynamic_load(e, ctx); | 379 | return dynamic_load(e, ctx); |
366 | case DYNAMIC_CMD_DIR_LOAD: | 380 | case DYNAMIC_CMD_DIR_LOAD: |
367 | if((i < 0) || (i > 2)) | 381 | if ((i < 0) || (i > 2)) { |
368 | { | ||
369 | ENGINEerr(ENGINE_F_DYNAMIC_CTRL, | 382 | ENGINEerr(ENGINE_F_DYNAMIC_CTRL, |
370 | ENGINE_R_INVALID_ARGUMENT); | 383 | ENGINE_R_INVALID_ARGUMENT); |
371 | return 0; | 384 | return 0; |
372 | } | 385 | } |
373 | ctx->dir_load = (int)i; | 386 | ctx->dir_load = (int)i; |
374 | return 1; | 387 | return 1; |
375 | case DYNAMIC_CMD_DIR_ADD: | 388 | case DYNAMIC_CMD_DIR_ADD: |
376 | /* a NULL 'p' or a string of zero-length is the same thing */ | 389 | /* a NULL 'p' or a string of zero-length is the same thing */ |
377 | if(!p || (strlen((const char *)p) < 1)) | 390 | if (!p || (strlen((const char *)p) < 1)) { |
378 | { | ||
379 | ENGINEerr(ENGINE_F_DYNAMIC_CTRL, | 391 | ENGINEerr(ENGINE_F_DYNAMIC_CTRL, |
380 | ENGINE_R_INVALID_ARGUMENT); | 392 | ENGINE_R_INVALID_ARGUMENT); |
381 | return 0; | 393 | return 0; |
382 | } | 394 | } |
383 | { | 395 | { |
384 | char *tmp_str = BUF_strdup(p); | 396 | char *tmp_str = BUF_strdup(p); |
385 | if(!tmp_str) | 397 | if (!tmp_str) { |
386 | { | 398 | ENGINEerr(ENGINE_F_DYNAMIC_CTRL, |
387 | ENGINEerr(ENGINE_F_DYNAMIC_CTRL, | 399 | ERR_R_MALLOC_FAILURE); |
388 | ERR_R_MALLOC_FAILURE); | 400 | return 0; |
389 | return 0; | ||
390 | } | 401 | } |
391 | sk_OPENSSL_STRING_insert(ctx->dirs, tmp_str, -1); | 402 | sk_OPENSSL_STRING_insert(ctx->dirs, tmp_str, -1); |
392 | } | 403 | } |
393 | return 1; | 404 | return 1; |
394 | default: | 405 | default: |
395 | break; | 406 | break; |
396 | } | ||
397 | ENGINEerr(ENGINE_F_DYNAMIC_CTRL,ENGINE_R_CTRL_COMMAND_NOT_IMPLEMENTED); | ||
398 | return 0; | ||
399 | } | 407 | } |
408 | ENGINEerr(ENGINE_F_DYNAMIC_CTRL, ENGINE_R_CTRL_COMMAND_NOT_IMPLEMENTED); | ||
409 | return 0; | ||
410 | } | ||
400 | 411 | ||
401 | static int int_load(dynamic_data_ctx *ctx) | 412 | static int |
402 | { | 413 | int_load(dynamic_data_ctx *ctx) |
414 | { | ||
403 | int num, loop; | 415 | int num, loop; |
416 | |||
404 | /* Unless told not to, try a direct load */ | 417 | /* Unless told not to, try a direct load */ |
405 | if((ctx->dir_load != 2) && (DSO_load(ctx->dynamic_dso, | 418 | if ((ctx->dir_load != 2) && (DSO_load(ctx->dynamic_dso, |
406 | ctx->DYNAMIC_LIBNAME, NULL, 0)) != NULL) | 419 | ctx->DYNAMIC_LIBNAME, NULL, 0)) != NULL) |
407 | return 1; | 420 | return 1; |
408 | /* If we're not allowed to use 'dirs' or we have none, fail */ | 421 | /* If we're not allowed to use 'dirs' or we have none, fail */ |
409 | if(!ctx->dir_load || (num = sk_OPENSSL_STRING_num(ctx->dirs)) < 1) | 422 | if (!ctx->dir_load || (num = sk_OPENSSL_STRING_num(ctx->dirs)) < 1) |
410 | return 0; | 423 | return 0; |
411 | for(loop = 0; loop < num; loop++) | 424 | for (loop = 0; loop < num; loop++) { |
412 | { | ||
413 | const char *s = sk_OPENSSL_STRING_value(ctx->dirs, loop); | 425 | const char *s = sk_OPENSSL_STRING_value(ctx->dirs, loop); |
414 | char *merge = DSO_merge(ctx->dynamic_dso, ctx->DYNAMIC_LIBNAME, s); | 426 | char *merge = DSO_merge(ctx->dynamic_dso, |
415 | if(!merge) | 427 | ctx->DYNAMIC_LIBNAME, s); |
428 | if (!merge) | ||
416 | return 0; | 429 | return 0; |
417 | if(DSO_load(ctx->dynamic_dso, merge, NULL, 0)) | 430 | if (DSO_load(ctx->dynamic_dso, merge, NULL, 0)) { |
418 | { | ||
419 | /* Found what we're looking for */ | 431 | /* Found what we're looking for */ |
420 | free(merge); | 432 | free(merge); |
421 | return 1; | 433 | return 1; |
422 | } | ||
423 | free(merge); | ||
424 | } | 434 | } |
425 | return 0; | 435 | free(merge); |
426 | } | 436 | } |
437 | return 0; | ||
438 | } | ||
427 | 439 | ||
428 | static int dynamic_load(ENGINE *e, dynamic_data_ctx *ctx) | 440 | static int |
429 | { | 441 | dynamic_load(ENGINE *e, dynamic_data_ctx *ctx) |
442 | { | ||
430 | ENGINE cpy; | 443 | ENGINE cpy; |
431 | dynamic_fns fns; | 444 | dynamic_fns fns; |
432 | 445 | ||
433 | if(!ctx->dynamic_dso) | 446 | if (!ctx->dynamic_dso) |
434 | ctx->dynamic_dso = DSO_new(); | 447 | ctx->dynamic_dso = DSO_new(); |
435 | if(!ctx->DYNAMIC_LIBNAME) | 448 | if (!ctx->DYNAMIC_LIBNAME) { |
436 | { | 449 | if (!ctx->engine_id) |
437 | if(!ctx->engine_id) | ||
438 | return 0; | 450 | return 0; |
439 | ctx->DYNAMIC_LIBNAME = | 451 | ctx->DYNAMIC_LIBNAME = DSO_convert_filename(ctx->dynamic_dso, |
440 | DSO_convert_filename(ctx->dynamic_dso, ctx->engine_id); | 452 | ctx->engine_id); |
441 | } | 453 | } |
442 | if(!int_load(ctx)) | 454 | if (!int_load(ctx)) { |
443 | { | ||
444 | ENGINEerr(ENGINE_F_DYNAMIC_LOAD, | 455 | ENGINEerr(ENGINE_F_DYNAMIC_LOAD, |
445 | ENGINE_R_DSO_NOT_FOUND); | 456 | ENGINE_R_DSO_NOT_FOUND); |
446 | DSO_free(ctx->dynamic_dso); | 457 | DSO_free(ctx->dynamic_dso); |
447 | ctx->dynamic_dso = NULL; | 458 | ctx->dynamic_dso = NULL; |
448 | return 0; | 459 | return 0; |
449 | } | 460 | } |
450 | /* We have to find a bind function otherwise it'll always end badly */ | 461 | /* We have to find a bind function otherwise it'll always end badly */ |
451 | if(!(ctx->bind_engine = (dynamic_bind_engine)DSO_bind_func( | 462 | if (!(ctx->bind_engine = (dynamic_bind_engine)DSO_bind_func( |
452 | ctx->dynamic_dso, ctx->DYNAMIC_F2))) | 463 | ctx->dynamic_dso, ctx->DYNAMIC_F2))) { |
453 | { | ||
454 | ctx->bind_engine = NULL; | 464 | ctx->bind_engine = NULL; |
455 | DSO_free(ctx->dynamic_dso); | 465 | DSO_free(ctx->dynamic_dso); |
456 | ctx->dynamic_dso = NULL; | 466 | ctx->dynamic_dso = NULL; |
457 | ENGINEerr(ENGINE_F_DYNAMIC_LOAD, | 467 | ENGINEerr(ENGINE_F_DYNAMIC_LOAD, |
458 | ENGINE_R_DSO_FAILURE); | 468 | ENGINE_R_DSO_FAILURE); |
459 | return 0; | 469 | return 0; |
460 | } | 470 | } |
461 | /* Do we perform version checking? */ | 471 | /* Do we perform version checking? */ |
462 | if(!ctx->no_vcheck) | 472 | if (!ctx->no_vcheck) { |
463 | { | ||
464 | unsigned long vcheck_res = 0; | 473 | unsigned long vcheck_res = 0; |
465 | /* Now we try to find a version checking function and decide how | 474 | /* Now we try to find a version checking function and decide how |
466 | * to cope with failure if/when it fails. */ | 475 | * to cope with failure if/when it fails. */ |
467 | ctx->v_check = (dynamic_v_check_fn)DSO_bind_func( | 476 | ctx->v_check = (dynamic_v_check_fn)DSO_bind_func( |
468 | ctx->dynamic_dso, ctx->DYNAMIC_F1); | 477 | ctx->dynamic_dso, ctx->DYNAMIC_F1); |
469 | if(ctx->v_check) | 478 | if (ctx->v_check) |
470 | vcheck_res = ctx->v_check(OSSL_DYNAMIC_VERSION); | 479 | vcheck_res = ctx->v_check(OSSL_DYNAMIC_VERSION); |
471 | /* We fail if the version checker veto'd the load *or* if it is | 480 | /* We fail if the version checker veto'd the load *or* if it is |
472 | * deferring to us (by returning its version) and we think it is | 481 | * deferring to us (by returning its version) and we think it is |
473 | * too old. */ | 482 | * too old. */ |
474 | if(vcheck_res < OSSL_DYNAMIC_OLDEST) | 483 | if (vcheck_res < OSSL_DYNAMIC_OLDEST) { |
475 | { | ||
476 | /* Fail */ | 484 | /* Fail */ |
477 | ctx->bind_engine = NULL; | 485 | ctx->bind_engine = NULL; |
478 | ctx->v_check = NULL; | 486 | ctx->v_check = NULL; |
479 | DSO_free(ctx->dynamic_dso); | 487 | DSO_free(ctx->dynamic_dso); |
480 | ctx->dynamic_dso = NULL; | 488 | ctx->dynamic_dso = NULL; |
481 | ENGINEerr(ENGINE_F_DYNAMIC_LOAD, | 489 | ENGINEerr(ENGINE_F_DYNAMIC_LOAD, |
482 | ENGINE_R_VERSION_INCOMPATIBILITY); | 490 | ENGINE_R_VERSION_INCOMPATIBILITY); |
483 | return 0; | 491 | return 0; |
484 | } | ||
485 | } | 492 | } |
493 | } | ||
486 | /* First binary copy the ENGINE structure so that we can roll back if | 494 | /* First binary copy the ENGINE structure so that we can roll back if |
487 | * the hand-over fails */ | 495 | * the hand-over fails */ |
488 | memcpy(&cpy, e, sizeof(ENGINE)); | 496 | memcpy(&cpy, e, sizeof(ENGINE)); |
@@ -495,8 +503,8 @@ static int dynamic_load(ENGINE *e, dynamic_data_ctx *ctx) | |||
495 | fns.err_fns = ERR_get_implementation(); | 503 | fns.err_fns = ERR_get_implementation(); |
496 | fns.ex_data_fns = CRYPTO_get_ex_data_implementation(); | 504 | fns.ex_data_fns = CRYPTO_get_ex_data_implementation(); |
497 | CRYPTO_get_mem_functions(&fns.mem_fns.malloc_cb, | 505 | CRYPTO_get_mem_functions(&fns.mem_fns.malloc_cb, |
498 | &fns.mem_fns.realloc_cb, | 506 | &fns.mem_fns.realloc_cb, |
499 | &fns.mem_fns.free_cb); | 507 | &fns.mem_fns.free_cb); |
500 | fns.lock_fns.lock_locking_cb = CRYPTO_get_locking_callback(); | 508 | fns.lock_fns.lock_locking_cb = CRYPTO_get_locking_callback(); |
501 | fns.lock_fns.lock_add_lock_cb = CRYPTO_get_add_lock_callback(); | 509 | fns.lock_fns.lock_add_lock_cb = CRYPTO_get_add_lock_callback(); |
502 | fns.lock_fns.dynlock_create_cb = CRYPTO_get_dynlock_create_callback(); | 510 | fns.lock_fns.dynlock_create_cb = CRYPTO_get_dynlock_create_callback(); |
@@ -507,37 +515,33 @@ static int dynamic_load(ENGINE *e, dynamic_data_ctx *ctx) | |||
507 | engine_set_all_null(e); | 515 | engine_set_all_null(e); |
508 | 516 | ||
509 | /* Try to bind the ENGINE onto our own ENGINE structure */ | 517 | /* Try to bind the ENGINE onto our own ENGINE structure */ |
510 | if(!ctx->bind_engine(e, ctx->engine_id, &fns)) | 518 | if (!ctx->bind_engine(e, ctx->engine_id, &fns)) { |
511 | { | ||
512 | ctx->bind_engine = NULL; | 519 | ctx->bind_engine = NULL; |
513 | ctx->v_check = NULL; | 520 | ctx->v_check = NULL; |
514 | DSO_free(ctx->dynamic_dso); | 521 | DSO_free(ctx->dynamic_dso); |
515 | ctx->dynamic_dso = NULL; | 522 | ctx->dynamic_dso = NULL; |
516 | ENGINEerr(ENGINE_F_DYNAMIC_LOAD,ENGINE_R_INIT_FAILED); | 523 | ENGINEerr(ENGINE_F_DYNAMIC_LOAD, ENGINE_R_INIT_FAILED); |
517 | /* Copy the original ENGINE structure back */ | 524 | /* Copy the original ENGINE structure back */ |
518 | memcpy(e, &cpy, sizeof(ENGINE)); | 525 | memcpy(e, &cpy, sizeof(ENGINE)); |
519 | return 0; | 526 | return 0; |
520 | } | 527 | } |
521 | /* Do we try to add this ENGINE to the internal list too? */ | 528 | /* Do we try to add this ENGINE to the internal list too? */ |
522 | if(ctx->list_add_value > 0) | 529 | if (ctx->list_add_value > 0) { |
523 | { | 530 | if (!ENGINE_add(e)) { |
524 | if(!ENGINE_add(e)) | ||
525 | { | ||
526 | /* Do we tolerate this or fail? */ | 531 | /* Do we tolerate this or fail? */ |
527 | if(ctx->list_add_value > 1) | 532 | if (ctx->list_add_value > 1) { |
528 | { | ||
529 | /* Fail - NB: By this time, it's too late to | 533 | /* Fail - NB: By this time, it's too late to |
530 | * rollback, and trying to do so allows the | 534 | * rollback, and trying to do so allows the |
531 | * bind_engine() code to have created leaks. We | 535 | * bind_engine() code to have created leaks. We |
532 | * just have to fail where we are, after the | 536 | * just have to fail where we are, after the |
533 | * ENGINE has changed. */ | 537 | * ENGINE has changed. */ |
534 | ENGINEerr(ENGINE_F_DYNAMIC_LOAD, | 538 | ENGINEerr(ENGINE_F_DYNAMIC_LOAD, |
535 | ENGINE_R_CONFLICTING_ENGINE_ID); | 539 | ENGINE_R_CONFLICTING_ENGINE_ID); |
536 | return 0; | 540 | return 0; |
537 | } | 541 | } |
538 | /* Tolerate */ | 542 | /* Tolerate */ |
539 | ERR_clear_error(); | 543 | ERR_clear_error(); |
540 | } | ||
541 | } | 544 | } |
542 | return 1; | ||
543 | } | 545 | } |
546 | return 1; | ||
547 | } | ||
diff --git a/src/lib/libcrypto/engine/eng_err.c b/src/lib/libcrypto/engine/eng_err.c index 81c70acfa8..baf2b3d92d 100644 --- a/src/lib/libcrypto/engine/eng_err.c +++ b/src/lib/libcrypto/engine/eng_err.c | |||
@@ -7,7 +7,7 @@ | |||
7 | * are met: | 7 | * are met: |
8 | * | 8 | * |
9 | * 1. Redistributions of source code must retain the above copyright | 9 | * 1. Redistributions of source code must retain the above copyright |
10 | * notice, this list of conditions and the following disclaimer. | 10 | * notice, this list of conditions and the following disclaimer. |
11 | * | 11 | * |
12 | * 2. Redistributions in binary form must reproduce the above copyright | 12 | * 2. Redistributions in binary form must reproduce the above copyright |
13 | * notice, this list of conditions and the following disclaimer in | 13 | * notice, this list of conditions and the following disclaimer in |
@@ -68,106 +68,103 @@ | |||
68 | #define ERR_FUNC(func) ERR_PACK(ERR_LIB_ENGINE,func,0) | 68 | #define ERR_FUNC(func) ERR_PACK(ERR_LIB_ENGINE,func,0) |
69 | #define ERR_REASON(reason) ERR_PACK(ERR_LIB_ENGINE,0,reason) | 69 | #define ERR_REASON(reason) ERR_PACK(ERR_LIB_ENGINE,0,reason) |
70 | 70 | ||
71 | static ERR_STRING_DATA ENGINE_str_functs[]= | 71 | static ERR_STRING_DATA ENGINE_str_functs[]= { |
72 | { | 72 | {ERR_FUNC(ENGINE_F_DYNAMIC_CTRL), "DYNAMIC_CTRL"}, |
73 | {ERR_FUNC(ENGINE_F_DYNAMIC_CTRL), "DYNAMIC_CTRL"}, | 73 | {ERR_FUNC(ENGINE_F_DYNAMIC_GET_DATA_CTX), "DYNAMIC_GET_DATA_CTX"}, |
74 | {ERR_FUNC(ENGINE_F_DYNAMIC_GET_DATA_CTX), "DYNAMIC_GET_DATA_CTX"}, | 74 | {ERR_FUNC(ENGINE_F_DYNAMIC_LOAD), "DYNAMIC_LOAD"}, |
75 | {ERR_FUNC(ENGINE_F_DYNAMIC_LOAD), "DYNAMIC_LOAD"}, | 75 | {ERR_FUNC(ENGINE_F_DYNAMIC_SET_DATA_CTX), "DYNAMIC_SET_DATA_CTX"}, |
76 | {ERR_FUNC(ENGINE_F_DYNAMIC_SET_DATA_CTX), "DYNAMIC_SET_DATA_CTX"}, | 76 | {ERR_FUNC(ENGINE_F_ENGINE_ADD), "ENGINE_add"}, |
77 | {ERR_FUNC(ENGINE_F_ENGINE_ADD), "ENGINE_add"}, | 77 | {ERR_FUNC(ENGINE_F_ENGINE_BY_ID), "ENGINE_by_id"}, |
78 | {ERR_FUNC(ENGINE_F_ENGINE_BY_ID), "ENGINE_by_id"}, | 78 | {ERR_FUNC(ENGINE_F_ENGINE_CMD_IS_EXECUTABLE), "ENGINE_cmd_is_executable"}, |
79 | {ERR_FUNC(ENGINE_F_ENGINE_CMD_IS_EXECUTABLE), "ENGINE_cmd_is_executable"}, | 79 | {ERR_FUNC(ENGINE_F_ENGINE_CTRL), "ENGINE_ctrl"}, |
80 | {ERR_FUNC(ENGINE_F_ENGINE_CTRL), "ENGINE_ctrl"}, | 80 | {ERR_FUNC(ENGINE_F_ENGINE_CTRL_CMD), "ENGINE_ctrl_cmd"}, |
81 | {ERR_FUNC(ENGINE_F_ENGINE_CTRL_CMD), "ENGINE_ctrl_cmd"}, | 81 | {ERR_FUNC(ENGINE_F_ENGINE_CTRL_CMD_STRING), "ENGINE_ctrl_cmd_string"}, |
82 | {ERR_FUNC(ENGINE_F_ENGINE_CTRL_CMD_STRING), "ENGINE_ctrl_cmd_string"}, | 82 | {ERR_FUNC(ENGINE_F_ENGINE_FINISH), "ENGINE_finish"}, |
83 | {ERR_FUNC(ENGINE_F_ENGINE_FINISH), "ENGINE_finish"}, | 83 | {ERR_FUNC(ENGINE_F_ENGINE_FREE_UTIL), "ENGINE_FREE_UTIL"}, |
84 | {ERR_FUNC(ENGINE_F_ENGINE_FREE_UTIL), "ENGINE_FREE_UTIL"}, | 84 | {ERR_FUNC(ENGINE_F_ENGINE_GET_CIPHER), "ENGINE_get_cipher"}, |
85 | {ERR_FUNC(ENGINE_F_ENGINE_GET_CIPHER), "ENGINE_get_cipher"}, | 85 | {ERR_FUNC(ENGINE_F_ENGINE_GET_DEFAULT_TYPE), "ENGINE_GET_DEFAULT_TYPE"}, |
86 | {ERR_FUNC(ENGINE_F_ENGINE_GET_DEFAULT_TYPE), "ENGINE_GET_DEFAULT_TYPE"}, | 86 | {ERR_FUNC(ENGINE_F_ENGINE_GET_DIGEST), "ENGINE_get_digest"}, |
87 | {ERR_FUNC(ENGINE_F_ENGINE_GET_DIGEST), "ENGINE_get_digest"}, | 87 | {ERR_FUNC(ENGINE_F_ENGINE_GET_NEXT), "ENGINE_get_next"}, |
88 | {ERR_FUNC(ENGINE_F_ENGINE_GET_NEXT), "ENGINE_get_next"}, | 88 | {ERR_FUNC(ENGINE_F_ENGINE_GET_PKEY_ASN1_METH), "ENGINE_get_pkey_asn1_meth"}, |
89 | {ERR_FUNC(ENGINE_F_ENGINE_GET_PKEY_ASN1_METH), "ENGINE_get_pkey_asn1_meth"}, | 89 | {ERR_FUNC(ENGINE_F_ENGINE_GET_PKEY_METH), "ENGINE_get_pkey_meth"}, |
90 | {ERR_FUNC(ENGINE_F_ENGINE_GET_PKEY_METH), "ENGINE_get_pkey_meth"}, | 90 | {ERR_FUNC(ENGINE_F_ENGINE_GET_PREV), "ENGINE_get_prev"}, |
91 | {ERR_FUNC(ENGINE_F_ENGINE_GET_PREV), "ENGINE_get_prev"}, | 91 | {ERR_FUNC(ENGINE_F_ENGINE_INIT), "ENGINE_init"}, |
92 | {ERR_FUNC(ENGINE_F_ENGINE_INIT), "ENGINE_init"}, | 92 | {ERR_FUNC(ENGINE_F_ENGINE_LIST_ADD), "ENGINE_LIST_ADD"}, |
93 | {ERR_FUNC(ENGINE_F_ENGINE_LIST_ADD), "ENGINE_LIST_ADD"}, | 93 | {ERR_FUNC(ENGINE_F_ENGINE_LIST_REMOVE), "ENGINE_LIST_REMOVE"}, |
94 | {ERR_FUNC(ENGINE_F_ENGINE_LIST_REMOVE), "ENGINE_LIST_REMOVE"}, | 94 | {ERR_FUNC(ENGINE_F_ENGINE_LOAD_PRIVATE_KEY), "ENGINE_load_private_key"}, |
95 | {ERR_FUNC(ENGINE_F_ENGINE_LOAD_PRIVATE_KEY), "ENGINE_load_private_key"}, | 95 | {ERR_FUNC(ENGINE_F_ENGINE_LOAD_PUBLIC_KEY), "ENGINE_load_public_key"}, |
96 | {ERR_FUNC(ENGINE_F_ENGINE_LOAD_PUBLIC_KEY), "ENGINE_load_public_key"}, | 96 | {ERR_FUNC(ENGINE_F_ENGINE_LOAD_SSL_CLIENT_CERT), "ENGINE_load_ssl_client_cert"}, |
97 | {ERR_FUNC(ENGINE_F_ENGINE_LOAD_SSL_CLIENT_CERT), "ENGINE_load_ssl_client_cert"}, | 97 | {ERR_FUNC(ENGINE_F_ENGINE_NEW), "ENGINE_new"}, |
98 | {ERR_FUNC(ENGINE_F_ENGINE_NEW), "ENGINE_new"}, | 98 | {ERR_FUNC(ENGINE_F_ENGINE_REMOVE), "ENGINE_remove"}, |
99 | {ERR_FUNC(ENGINE_F_ENGINE_REMOVE), "ENGINE_remove"}, | 99 | {ERR_FUNC(ENGINE_F_ENGINE_SET_DEFAULT_STRING), "ENGINE_set_default_string"}, |
100 | {ERR_FUNC(ENGINE_F_ENGINE_SET_DEFAULT_STRING), "ENGINE_set_default_string"}, | 100 | {ERR_FUNC(ENGINE_F_ENGINE_SET_DEFAULT_TYPE), "ENGINE_SET_DEFAULT_TYPE"}, |
101 | {ERR_FUNC(ENGINE_F_ENGINE_SET_DEFAULT_TYPE), "ENGINE_SET_DEFAULT_TYPE"}, | 101 | {ERR_FUNC(ENGINE_F_ENGINE_SET_ID), "ENGINE_set_id"}, |
102 | {ERR_FUNC(ENGINE_F_ENGINE_SET_ID), "ENGINE_set_id"}, | 102 | {ERR_FUNC(ENGINE_F_ENGINE_SET_NAME), "ENGINE_set_name"}, |
103 | {ERR_FUNC(ENGINE_F_ENGINE_SET_NAME), "ENGINE_set_name"}, | 103 | {ERR_FUNC(ENGINE_F_ENGINE_TABLE_REGISTER), "ENGINE_TABLE_REGISTER"}, |
104 | {ERR_FUNC(ENGINE_F_ENGINE_TABLE_REGISTER), "ENGINE_TABLE_REGISTER"}, | 104 | {ERR_FUNC(ENGINE_F_ENGINE_UNLOAD_KEY), "ENGINE_UNLOAD_KEY"}, |
105 | {ERR_FUNC(ENGINE_F_ENGINE_UNLOAD_KEY), "ENGINE_UNLOAD_KEY"}, | 105 | {ERR_FUNC(ENGINE_F_ENGINE_UNLOCKED_FINISH), "ENGINE_UNLOCKED_FINISH"}, |
106 | {ERR_FUNC(ENGINE_F_ENGINE_UNLOCKED_FINISH), "ENGINE_UNLOCKED_FINISH"}, | 106 | {ERR_FUNC(ENGINE_F_ENGINE_UP_REF), "ENGINE_up_ref"}, |
107 | {ERR_FUNC(ENGINE_F_ENGINE_UP_REF), "ENGINE_up_ref"}, | 107 | {ERR_FUNC(ENGINE_F_INT_CTRL_HELPER), "INT_CTRL_HELPER"}, |
108 | {ERR_FUNC(ENGINE_F_INT_CTRL_HELPER), "INT_CTRL_HELPER"}, | 108 | {ERR_FUNC(ENGINE_F_INT_ENGINE_CONFIGURE), "INT_ENGINE_CONFIGURE"}, |
109 | {ERR_FUNC(ENGINE_F_INT_ENGINE_CONFIGURE), "INT_ENGINE_CONFIGURE"}, | 109 | {ERR_FUNC(ENGINE_F_INT_ENGINE_MODULE_INIT), "INT_ENGINE_MODULE_INIT"}, |
110 | {ERR_FUNC(ENGINE_F_INT_ENGINE_MODULE_INIT), "INT_ENGINE_MODULE_INIT"}, | 110 | {ERR_FUNC(ENGINE_F_LOG_MESSAGE), "LOG_MESSAGE"}, |
111 | {ERR_FUNC(ENGINE_F_LOG_MESSAGE), "LOG_MESSAGE"}, | 111 | {0, NULL} |
112 | {0,NULL} | 112 | }; |
113 | }; | ||
114 | 113 | ||
115 | static ERR_STRING_DATA ENGINE_str_reasons[]= | 114 | static ERR_STRING_DATA ENGINE_str_reasons[]= { |
116 | { | 115 | {ERR_REASON(ENGINE_R_ALREADY_LOADED) , "already loaded"}, |
117 | {ERR_REASON(ENGINE_R_ALREADY_LOADED) ,"already loaded"}, | 116 | {ERR_REASON(ENGINE_R_ARGUMENT_IS_NOT_A_NUMBER), "argument is not a number"}, |
118 | {ERR_REASON(ENGINE_R_ARGUMENT_IS_NOT_A_NUMBER),"argument is not a number"}, | 117 | {ERR_REASON(ENGINE_R_CMD_NOT_EXECUTABLE) , "cmd not executable"}, |
119 | {ERR_REASON(ENGINE_R_CMD_NOT_EXECUTABLE) ,"cmd not executable"}, | 118 | {ERR_REASON(ENGINE_R_COMMAND_TAKES_INPUT), "command takes input"}, |
120 | {ERR_REASON(ENGINE_R_COMMAND_TAKES_INPUT),"command takes input"}, | 119 | {ERR_REASON(ENGINE_R_COMMAND_TAKES_NO_INPUT), "command takes no input"}, |
121 | {ERR_REASON(ENGINE_R_COMMAND_TAKES_NO_INPUT),"command takes no input"}, | 120 | {ERR_REASON(ENGINE_R_CONFLICTING_ENGINE_ID), "conflicting engine id"}, |
122 | {ERR_REASON(ENGINE_R_CONFLICTING_ENGINE_ID),"conflicting engine id"}, | 121 | {ERR_REASON(ENGINE_R_CTRL_COMMAND_NOT_IMPLEMENTED), "ctrl command not implemented"}, |
123 | {ERR_REASON(ENGINE_R_CTRL_COMMAND_NOT_IMPLEMENTED),"ctrl command not implemented"}, | 122 | {ERR_REASON(ENGINE_R_DH_NOT_IMPLEMENTED) , "dh not implemented"}, |
124 | {ERR_REASON(ENGINE_R_DH_NOT_IMPLEMENTED) ,"dh not implemented"}, | 123 | {ERR_REASON(ENGINE_R_DSA_NOT_IMPLEMENTED), "dsa not implemented"}, |
125 | {ERR_REASON(ENGINE_R_DSA_NOT_IMPLEMENTED),"dsa not implemented"}, | 124 | {ERR_REASON(ENGINE_R_DSO_FAILURE) , "DSO failure"}, |
126 | {ERR_REASON(ENGINE_R_DSO_FAILURE) ,"DSO failure"}, | 125 | {ERR_REASON(ENGINE_R_DSO_NOT_FOUND) , "dso not found"}, |
127 | {ERR_REASON(ENGINE_R_DSO_NOT_FOUND) ,"dso not found"}, | 126 | {ERR_REASON(ENGINE_R_ENGINES_SECTION_ERROR), "engines section error"}, |
128 | {ERR_REASON(ENGINE_R_ENGINES_SECTION_ERROR),"engines section error"}, | 127 | {ERR_REASON(ENGINE_R_ENGINE_CONFIGURATION_ERROR), "engine configuration error"}, |
129 | {ERR_REASON(ENGINE_R_ENGINE_CONFIGURATION_ERROR),"engine configuration error"}, | 128 | {ERR_REASON(ENGINE_R_ENGINE_IS_NOT_IN_LIST), "engine is not in the list"}, |
130 | {ERR_REASON(ENGINE_R_ENGINE_IS_NOT_IN_LIST),"engine is not in the list"}, | 129 | {ERR_REASON(ENGINE_R_ENGINE_SECTION_ERROR), "engine section error"}, |
131 | {ERR_REASON(ENGINE_R_ENGINE_SECTION_ERROR),"engine section error"}, | 130 | {ERR_REASON(ENGINE_R_FAILED_LOADING_PRIVATE_KEY), "failed loading private key"}, |
132 | {ERR_REASON(ENGINE_R_FAILED_LOADING_PRIVATE_KEY),"failed loading private key"}, | 131 | {ERR_REASON(ENGINE_R_FAILED_LOADING_PUBLIC_KEY), "failed loading public key"}, |
133 | {ERR_REASON(ENGINE_R_FAILED_LOADING_PUBLIC_KEY),"failed loading public key"}, | 132 | {ERR_REASON(ENGINE_R_FINISH_FAILED) , "finish failed"}, |
134 | {ERR_REASON(ENGINE_R_FINISH_FAILED) ,"finish failed"}, | 133 | {ERR_REASON(ENGINE_R_GET_HANDLE_FAILED) , "could not obtain hardware handle"}, |
135 | {ERR_REASON(ENGINE_R_GET_HANDLE_FAILED) ,"could not obtain hardware handle"}, | 134 | {ERR_REASON(ENGINE_R_ID_OR_NAME_MISSING) , "'id' or 'name' missing"}, |
136 | {ERR_REASON(ENGINE_R_ID_OR_NAME_MISSING) ,"'id' or 'name' missing"}, | 135 | {ERR_REASON(ENGINE_R_INIT_FAILED) , "init failed"}, |
137 | {ERR_REASON(ENGINE_R_INIT_FAILED) ,"init failed"}, | 136 | {ERR_REASON(ENGINE_R_INTERNAL_LIST_ERROR), "internal list error"}, |
138 | {ERR_REASON(ENGINE_R_INTERNAL_LIST_ERROR),"internal list error"}, | 137 | {ERR_REASON(ENGINE_R_INVALID_ARGUMENT) , "invalid argument"}, |
139 | {ERR_REASON(ENGINE_R_INVALID_ARGUMENT) ,"invalid argument"}, | 138 | {ERR_REASON(ENGINE_R_INVALID_CMD_NAME) , "invalid cmd name"}, |
140 | {ERR_REASON(ENGINE_R_INVALID_CMD_NAME) ,"invalid cmd name"}, | 139 | {ERR_REASON(ENGINE_R_INVALID_CMD_NUMBER) , "invalid cmd number"}, |
141 | {ERR_REASON(ENGINE_R_INVALID_CMD_NUMBER) ,"invalid cmd number"}, | 140 | {ERR_REASON(ENGINE_R_INVALID_INIT_VALUE) , "invalid init value"}, |
142 | {ERR_REASON(ENGINE_R_INVALID_INIT_VALUE) ,"invalid init value"}, | 141 | {ERR_REASON(ENGINE_R_INVALID_STRING) , "invalid string"}, |
143 | {ERR_REASON(ENGINE_R_INVALID_STRING) ,"invalid string"}, | 142 | {ERR_REASON(ENGINE_R_NOT_INITIALISED) , "not initialised"}, |
144 | {ERR_REASON(ENGINE_R_NOT_INITIALISED) ,"not initialised"}, | 143 | {ERR_REASON(ENGINE_R_NOT_LOADED) , "not loaded"}, |
145 | {ERR_REASON(ENGINE_R_NOT_LOADED) ,"not loaded"}, | 144 | {ERR_REASON(ENGINE_R_NO_CONTROL_FUNCTION), "no control function"}, |
146 | {ERR_REASON(ENGINE_R_NO_CONTROL_FUNCTION),"no control function"}, | 145 | {ERR_REASON(ENGINE_R_NO_INDEX) , "no index"}, |
147 | {ERR_REASON(ENGINE_R_NO_INDEX) ,"no index"}, | 146 | {ERR_REASON(ENGINE_R_NO_LOAD_FUNCTION) , "no load function"}, |
148 | {ERR_REASON(ENGINE_R_NO_LOAD_FUNCTION) ,"no load function"}, | 147 | {ERR_REASON(ENGINE_R_NO_REFERENCE) , "no reference"}, |
149 | {ERR_REASON(ENGINE_R_NO_REFERENCE) ,"no reference"}, | 148 | {ERR_REASON(ENGINE_R_NO_SUCH_ENGINE) , "no such engine"}, |
150 | {ERR_REASON(ENGINE_R_NO_SUCH_ENGINE) ,"no such engine"}, | 149 | {ERR_REASON(ENGINE_R_NO_UNLOAD_FUNCTION) , "no unload function"}, |
151 | {ERR_REASON(ENGINE_R_NO_UNLOAD_FUNCTION) ,"no unload function"}, | 150 | {ERR_REASON(ENGINE_R_PROVIDE_PARAMETERS) , "provide parameters"}, |
152 | {ERR_REASON(ENGINE_R_PROVIDE_PARAMETERS) ,"provide parameters"}, | 151 | {ERR_REASON(ENGINE_R_RSA_NOT_IMPLEMENTED), "rsa not implemented"}, |
153 | {ERR_REASON(ENGINE_R_RSA_NOT_IMPLEMENTED),"rsa not implemented"}, | 152 | {ERR_REASON(ENGINE_R_UNIMPLEMENTED_CIPHER), "unimplemented cipher"}, |
154 | {ERR_REASON(ENGINE_R_UNIMPLEMENTED_CIPHER),"unimplemented cipher"}, | 153 | {ERR_REASON(ENGINE_R_UNIMPLEMENTED_DIGEST), "unimplemented digest"}, |
155 | {ERR_REASON(ENGINE_R_UNIMPLEMENTED_DIGEST),"unimplemented digest"}, | 154 | {ERR_REASON(ENGINE_R_UNIMPLEMENTED_PUBLIC_KEY_METHOD), "unimplemented public key method"}, |
156 | {ERR_REASON(ENGINE_R_UNIMPLEMENTED_PUBLIC_KEY_METHOD),"unimplemented public key method"}, | 155 | {ERR_REASON(ENGINE_R_VERSION_INCOMPATIBILITY), "version incompatibility"}, |
157 | {ERR_REASON(ENGINE_R_VERSION_INCOMPATIBILITY),"version incompatibility"}, | 156 | {0, NULL} |
158 | {0,NULL} | 157 | }; |
159 | }; | ||
160 | 158 | ||
161 | #endif | 159 | #endif |
162 | 160 | ||
163 | void ERR_load_ENGINE_strings(void) | 161 | void |
164 | { | 162 | ERR_load_ENGINE_strings(void) |
163 | { | ||
165 | #ifndef OPENSSL_NO_ERR | 164 | #ifndef OPENSSL_NO_ERR |
166 | 165 | if (ERR_func_error_string(ENGINE_str_functs[0].error) == NULL) { | |
167 | if (ERR_func_error_string(ENGINE_str_functs[0].error) == NULL) | 166 | ERR_load_strings(0, ENGINE_str_functs); |
168 | { | 167 | ERR_load_strings(0, ENGINE_str_reasons); |
169 | ERR_load_strings(0,ENGINE_str_functs); | ||
170 | ERR_load_strings(0,ENGINE_str_reasons); | ||
171 | } | ||
172 | #endif | ||
173 | } | 168 | } |
169 | #endif | ||
170 | } | ||
diff --git a/src/lib/libcrypto/engine/eng_fat.c b/src/lib/libcrypto/engine/eng_fat.c index e01067566e..f5ad01b80e 100644 --- a/src/lib/libcrypto/engine/eng_fat.c +++ b/src/lib/libcrypto/engine/eng_fat.c | |||
@@ -7,7 +7,7 @@ | |||
7 | * are met: | 7 | * are met: |
8 | * | 8 | * |
9 | * 1. Redistributions of source code must retain the above copyright | 9 | * 1. Redistributions of source code must retain the above copyright |
10 | * notice, this list of conditions and the following disclaimer. | 10 | * notice, this list of conditions and the following disclaimer. |
11 | * | 11 | * |
12 | * 2. Redistributions in binary form must reproduce the above copyright | 12 | * 2. Redistributions in binary form must reproduce the above copyright |
13 | * notice, this list of conditions and the following disclaimer in | 13 | * notice, this list of conditions and the following disclaimer in |
@@ -54,55 +54,58 @@ | |||
54 | */ | 54 | */ |
55 | /* ==================================================================== | 55 | /* ==================================================================== |
56 | * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED. | 56 | * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED. |
57 | * ECDH support in OpenSSL originally developed by | 57 | * ECDH support in OpenSSL originally developed by |
58 | * SUN MICROSYSTEMS, INC., and contributed to the OpenSSL project. | 58 | * SUN MICROSYSTEMS, INC., and contributed to the OpenSSL project. |
59 | */ | 59 | */ |
60 | 60 | ||
61 | #include "eng_int.h" | 61 | #include "eng_int.h" |
62 | #include <openssl/conf.h> | 62 | #include <openssl/conf.h> |
63 | 63 | ||
64 | int ENGINE_set_default(ENGINE *e, unsigned int flags) | 64 | int |
65 | { | 65 | ENGINE_set_default(ENGINE *e, unsigned int flags) |
66 | if((flags & ENGINE_METHOD_CIPHERS) && !ENGINE_set_default_ciphers(e)) | 66 | { |
67 | if ((flags & ENGINE_METHOD_CIPHERS) && !ENGINE_set_default_ciphers(e)) | ||
67 | return 0; | 68 | return 0; |
68 | if((flags & ENGINE_METHOD_DIGESTS) && !ENGINE_set_default_digests(e)) | 69 | if ((flags & ENGINE_METHOD_DIGESTS) && !ENGINE_set_default_digests(e)) |
69 | return 0; | 70 | return 0; |
70 | #ifndef OPENSSL_NO_RSA | 71 | #ifndef OPENSSL_NO_RSA |
71 | if((flags & ENGINE_METHOD_RSA) && !ENGINE_set_default_RSA(e)) | 72 | if ((flags & ENGINE_METHOD_RSA) && !ENGINE_set_default_RSA(e)) |
72 | return 0; | 73 | return 0; |
73 | #endif | 74 | #endif |
74 | #ifndef OPENSSL_NO_DSA | 75 | #ifndef OPENSSL_NO_DSA |
75 | if((flags & ENGINE_METHOD_DSA) && !ENGINE_set_default_DSA(e)) | 76 | if ((flags & ENGINE_METHOD_DSA) && !ENGINE_set_default_DSA(e)) |
76 | return 0; | 77 | return 0; |
77 | #endif | 78 | #endif |
78 | #ifndef OPENSSL_NO_DH | 79 | #ifndef OPENSSL_NO_DH |
79 | if((flags & ENGINE_METHOD_DH) && !ENGINE_set_default_DH(e)) | 80 | if ((flags & ENGINE_METHOD_DH) && !ENGINE_set_default_DH(e)) |
80 | return 0; | 81 | return 0; |
81 | #endif | 82 | #endif |
82 | #ifndef OPENSSL_NO_ECDH | 83 | #ifndef OPENSSL_NO_ECDH |
83 | if((flags & ENGINE_METHOD_ECDH) && !ENGINE_set_default_ECDH(e)) | 84 | if ((flags & ENGINE_METHOD_ECDH) && !ENGINE_set_default_ECDH(e)) |
84 | return 0; | 85 | return 0; |
85 | #endif | 86 | #endif |
86 | #ifndef OPENSSL_NO_ECDSA | 87 | #ifndef OPENSSL_NO_ECDSA |
87 | if((flags & ENGINE_METHOD_ECDSA) && !ENGINE_set_default_ECDSA(e)) | 88 | if ((flags & ENGINE_METHOD_ECDSA) && !ENGINE_set_default_ECDSA(e)) |
88 | return 0; | 89 | return 0; |
89 | #endif | 90 | #endif |
90 | if((flags & ENGINE_METHOD_RAND) && !ENGINE_set_default_RAND(e)) | 91 | if ((flags & ENGINE_METHOD_RAND) && !ENGINE_set_default_RAND(e)) |
91 | return 0; | 92 | return 0; |
92 | if((flags & ENGINE_METHOD_PKEY_METHS) | 93 | if ((flags & ENGINE_METHOD_PKEY_METHS) && |
93 | && !ENGINE_set_default_pkey_meths(e)) | 94 | !ENGINE_set_default_pkey_meths(e)) |
94 | return 0; | 95 | return 0; |
95 | if((flags & ENGINE_METHOD_PKEY_ASN1_METHS) | 96 | if ((flags & ENGINE_METHOD_PKEY_ASN1_METHS) && |
96 | && !ENGINE_set_default_pkey_asn1_meths(e)) | 97 | !ENGINE_set_default_pkey_asn1_meths(e)) |
97 | return 0; | 98 | return 0; |
98 | return 1; | 99 | return 1; |
99 | } | 100 | } |
100 | 101 | ||
101 | /* Set default algorithms using a string */ | 102 | /* Set default algorithms using a string */ |
102 | 103 | ||
103 | static int int_def_cb(const char *alg, int len, void *arg) | 104 | static int |
104 | { | 105 | int_def_cb(const char *alg, int len, void *arg) |
106 | { | ||
105 | unsigned int *pflags = arg; | 107 | unsigned int *pflags = arg; |
108 | |||
106 | if (!strncmp(alg, "ALL", len)) | 109 | if (!strncmp(alg, "ALL", len)) |
107 | *pflags |= ENGINE_METHOD_ALL; | 110 | *pflags |= ENGINE_METHOD_ALL; |
108 | else if (!strncmp(alg, "RSA", len)) | 111 | else if (!strncmp(alg, "RSA", len)) |
@@ -123,7 +126,7 @@ static int int_def_cb(const char *alg, int len, void *arg) | |||
123 | *pflags |= ENGINE_METHOD_DIGESTS; | 126 | *pflags |= ENGINE_METHOD_DIGESTS; |
124 | else if (!strncmp(alg, "PKEY", len)) | 127 | else if (!strncmp(alg, "PKEY", len)) |
125 | *pflags |= | 128 | *pflags |= |
126 | ENGINE_METHOD_PKEY_METHS|ENGINE_METHOD_PKEY_ASN1_METHS; | 129 | ENGINE_METHOD_PKEY_METHS|ENGINE_METHOD_PKEY_ASN1_METHS; |
127 | else if (!strncmp(alg, "PKEY_CRYPTO", len)) | 130 | else if (!strncmp(alg, "PKEY_CRYPTO", len)) |
128 | *pflags |= ENGINE_METHOD_PKEY_METHS; | 131 | *pflags |= ENGINE_METHOD_PKEY_METHS; |
129 | else if (!strncmp(alg, "PKEY_ASN1", len)) | 132 | else if (!strncmp(alg, "PKEY_ASN1", len)) |
@@ -131,24 +134,25 @@ static int int_def_cb(const char *alg, int len, void *arg) | |||
131 | else | 134 | else |
132 | return 0; | 135 | return 0; |
133 | return 1; | 136 | return 1; |
134 | } | 137 | } |
135 | 138 | ||
136 | 139 | int | |
137 | int ENGINE_set_default_string(ENGINE *e, const char *def_list) | 140 | ENGINE_set_default_string(ENGINE *e, const char *def_list) |
138 | { | 141 | { |
139 | unsigned int flags = 0; | 142 | unsigned int flags = 0; |
140 | if (!CONF_parse_list(def_list, ',', 1, int_def_cb, &flags)) | 143 | |
141 | { | 144 | if (!CONF_parse_list(def_list, ',', 1, int_def_cb, &flags)) { |
142 | ENGINEerr(ENGINE_F_ENGINE_SET_DEFAULT_STRING, | 145 | ENGINEerr(ENGINE_F_ENGINE_SET_DEFAULT_STRING, |
143 | ENGINE_R_INVALID_STRING); | 146 | ENGINE_R_INVALID_STRING); |
144 | ERR_asprintf_error_data("str=%s",def_list); | 147 | ERR_asprintf_error_data("str=%s",def_list); |
145 | return 0; | 148 | return 0; |
146 | } | ||
147 | return ENGINE_set_default(e, flags); | ||
148 | } | 149 | } |
150 | return ENGINE_set_default(e, flags); | ||
151 | } | ||
149 | 152 | ||
150 | int ENGINE_register_complete(ENGINE *e) | 153 | int |
151 | { | 154 | ENGINE_register_complete(ENGINE *e) |
155 | { | ||
152 | ENGINE_register_ciphers(e); | 156 | ENGINE_register_ciphers(e); |
153 | ENGINE_register_digests(e); | 157 | ENGINE_register_digests(e); |
154 | #ifndef OPENSSL_NO_RSA | 158 | #ifndef OPENSSL_NO_RSA |
@@ -169,14 +173,15 @@ int ENGINE_register_complete(ENGINE *e) | |||
169 | ENGINE_register_RAND(e); | 173 | ENGINE_register_RAND(e); |
170 | ENGINE_register_pkey_meths(e); | 174 | ENGINE_register_pkey_meths(e); |
171 | return 1; | 175 | return 1; |
172 | } | 176 | } |
173 | 177 | ||
174 | int ENGINE_register_all_complete(void) | 178 | int |
175 | { | 179 | ENGINE_register_all_complete(void) |
180 | { | ||
176 | ENGINE *e; | 181 | ENGINE *e; |
177 | 182 | ||
178 | for(e=ENGINE_get_first() ; e ; e=ENGINE_get_next(e)) | 183 | for (e = ENGINE_get_first(); e; e = ENGINE_get_next(e)) |
179 | if (!(e->flags & ENGINE_FLAGS_NO_REGISTER_ALL)) | 184 | if (!(e->flags & ENGINE_FLAGS_NO_REGISTER_ALL)) |
180 | ENGINE_register_complete(e); | 185 | ENGINE_register_complete(e); |
181 | return 1; | 186 | return 1; |
182 | } | 187 | } |
diff --git a/src/lib/libcrypto/engine/eng_init.c b/src/lib/libcrypto/engine/eng_init.c index 870c456668..540f8957ca 100644 --- a/src/lib/libcrypto/engine/eng_init.c +++ b/src/lib/libcrypto/engine/eng_init.c | |||
@@ -7,7 +7,7 @@ | |||
7 | * are met: | 7 | * are met: |
8 | * | 8 | * |
9 | * 1. Redistributions of source code must retain the above copyright | 9 | * 1. Redistributions of source code must retain the above copyright |
10 | * notice, this list of conditions and the following disclaimer. | 10 | * notice, this list of conditions and the following disclaimer. |
11 | * | 11 | * |
12 | * 2. Redistributions in binary form must reproduce the above copyright | 12 | * 2. Redistributions in binary form must reproduce the above copyright |
13 | * notice, this list of conditions and the following disclaimer in | 13 | * notice, this list of conditions and the following disclaimer in |
@@ -57,30 +57,31 @@ | |||
57 | 57 | ||
58 | /* Initialise a engine type for use (or up its functional reference count | 58 | /* Initialise a engine type for use (or up its functional reference count |
59 | * if it's already in use). This version is only used internally. */ | 59 | * if it's already in use). This version is only used internally. */ |
60 | int engine_unlocked_init(ENGINE *e) | 60 | int |
61 | { | 61 | engine_unlocked_init(ENGINE *e) |
62 | { | ||
62 | int to_return = 1; | 63 | int to_return = 1; |
63 | 64 | ||
64 | if((e->funct_ref == 0) && e->init) | 65 | if ((e->funct_ref == 0) && e->init) |
65 | /* This is the first functional reference and the engine | 66 | /* This is the first functional reference and the engine |
66 | * requires initialisation so we do it now. */ | 67 | * requires initialisation so we do it now. */ |
67 | to_return = e->init(e); | 68 | to_return = e->init(e); |
68 | if(to_return) | 69 | if (to_return) { |
69 | { | ||
70 | /* OK, we return a functional reference which is also a | 70 | /* OK, we return a functional reference which is also a |
71 | * structural reference. */ | 71 | * structural reference. */ |
72 | e->struct_ref++; | 72 | e->struct_ref++; |
73 | e->funct_ref++; | 73 | e->funct_ref++; |
74 | engine_ref_debug(e, 0, 1) | 74 | engine_ref_debug(e, 0, 1) |
75 | engine_ref_debug(e, 1, 1) | 75 | engine_ref_debug(e, 1, 1) |
76 | } | ||
77 | return to_return; | ||
78 | } | 76 | } |
77 | return to_return; | ||
78 | } | ||
79 | 79 | ||
80 | /* Free a functional reference to a engine type. This version is only used | 80 | /* Free a functional reference to a engine type. This version is only used |
81 | * internally. */ | 81 | * internally. */ |
82 | int engine_unlocked_finish(ENGINE *e, int unlock_for_handlers) | 82 | int |
83 | { | 83 | engine_unlocked_finish(ENGINE *e, int unlock_for_handlers) |
84 | { | ||
84 | int to_return = 1; | 85 | int to_return = 1; |
85 | 86 | ||
86 | /* Reduce the functional reference count here so if it's the terminating | 87 | /* Reduce the functional reference count here so if it's the terminating |
@@ -91,58 +92,57 @@ int engine_unlocked_finish(ENGINE *e, int unlock_for_handlers) | |||
91 | * 2 to 0 without either calling finish(). */ | 92 | * 2 to 0 without either calling finish(). */ |
92 | e->funct_ref--; | 93 | e->funct_ref--; |
93 | engine_ref_debug(e, 1, -1); | 94 | engine_ref_debug(e, 1, -1); |
94 | if((e->funct_ref == 0) && e->finish) | 95 | if ((e->funct_ref == 0) && e->finish) { |
95 | { | 96 | if (unlock_for_handlers) |
96 | if(unlock_for_handlers) | ||
97 | CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE); | 97 | CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE); |
98 | to_return = e->finish(e); | 98 | to_return = e->finish(e); |
99 | if(unlock_for_handlers) | 99 | if (unlock_for_handlers) |
100 | CRYPTO_w_lock(CRYPTO_LOCK_ENGINE); | 100 | CRYPTO_w_lock(CRYPTO_LOCK_ENGINE); |
101 | if(!to_return) | 101 | if (!to_return) |
102 | return 0; | 102 | return 0; |
103 | } | 103 | } |
104 | 104 | ||
105 | /* Release the structural reference too */ | 105 | /* Release the structural reference too */ |
106 | if(!engine_free_util(e, 0)) | 106 | if (!engine_free_util(e, 0)) { |
107 | { | 107 | ENGINEerr(ENGINE_F_ENGINE_UNLOCKED_FINISH, |
108 | ENGINEerr(ENGINE_F_ENGINE_UNLOCKED_FINISH,ENGINE_R_FINISH_FAILED); | 108 | ENGINE_R_FINISH_FAILED); |
109 | return 0; | 109 | return 0; |
110 | } | ||
111 | return to_return; | ||
112 | } | 110 | } |
111 | return to_return; | ||
112 | } | ||
113 | 113 | ||
114 | /* The API (locked) version of "init" */ | 114 | /* The API (locked) version of "init" */ |
115 | int ENGINE_init(ENGINE *e) | 115 | int |
116 | { | 116 | ENGINE_init(ENGINE *e) |
117 | { | ||
117 | int ret; | 118 | int ret; |
118 | if(e == NULL) | 119 | |
119 | { | 120 | if (e == NULL) { |
120 | ENGINEerr(ENGINE_F_ENGINE_INIT,ERR_R_PASSED_NULL_PARAMETER); | 121 | ENGINEerr(ENGINE_F_ENGINE_INIT, ERR_R_PASSED_NULL_PARAMETER); |
121 | return 0; | 122 | return 0; |
122 | } | 123 | } |
123 | CRYPTO_w_lock(CRYPTO_LOCK_ENGINE); | 124 | CRYPTO_w_lock(CRYPTO_LOCK_ENGINE); |
124 | ret = engine_unlocked_init(e); | 125 | ret = engine_unlocked_init(e); |
125 | CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE); | 126 | CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE); |
126 | return ret; | 127 | return ret; |
127 | } | 128 | } |
128 | 129 | ||
129 | /* The API (locked) version of "finish" */ | 130 | /* The API (locked) version of "finish" */ |
130 | int ENGINE_finish(ENGINE *e) | 131 | int |
131 | { | 132 | ENGINE_finish(ENGINE *e) |
133 | { | ||
132 | int to_return = 1; | 134 | int to_return = 1; |
133 | 135 | ||
134 | if(e == NULL) | 136 | if (e == NULL) { |
135 | { | 137 | ENGINEerr(ENGINE_F_ENGINE_FINISH, ERR_R_PASSED_NULL_PARAMETER); |
136 | ENGINEerr(ENGINE_F_ENGINE_FINISH,ERR_R_PASSED_NULL_PARAMETER); | ||
137 | return 0; | 138 | return 0; |
138 | } | 139 | } |
139 | CRYPTO_w_lock(CRYPTO_LOCK_ENGINE); | 140 | CRYPTO_w_lock(CRYPTO_LOCK_ENGINE); |
140 | to_return = engine_unlocked_finish(e, 1); | 141 | to_return = engine_unlocked_finish(e, 1); |
141 | CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE); | 142 | CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE); |
142 | if(!to_return) | 143 | if (!to_return) { |
143 | { | 144 | ENGINEerr(ENGINE_F_ENGINE_FINISH, ENGINE_R_FINISH_FAILED); |
144 | ENGINEerr(ENGINE_F_ENGINE_FINISH,ENGINE_R_FINISH_FAILED); | ||
145 | return 0; | 145 | return 0; |
146 | } | ||
147 | return to_return; | ||
148 | } | 146 | } |
147 | return to_return; | ||
148 | } | ||
diff --git a/src/lib/libssl/src/crypto/engine/eng_aesni.c b/src/lib/libssl/src/crypto/engine/eng_aesni.c index d547d7f465..b1eade2d63 100644 --- a/src/lib/libssl/src/crypto/engine/eng_aesni.c +++ b/src/lib/libssl/src/crypto/engine/eng_aesni.c | |||
@@ -102,7 +102,8 @@ void ENGINE_load_aesni (void) | |||
102 | /* On non-x86 CPUs it just returns. */ | 102 | /* On non-x86 CPUs it just returns. */ |
103 | #ifdef COMPILE_HW_AESNI | 103 | #ifdef COMPILE_HW_AESNI |
104 | ENGINE *toadd = ENGINE_aesni(); | 104 | ENGINE *toadd = ENGINE_aesni(); |
105 | if (!toadd) return; | 105 | if (!toadd) |
106 | return; | ||
106 | ENGINE_add (toadd); | 107 | ENGINE_add (toadd); |
107 | ENGINE_register_complete (toadd); | 108 | ENGINE_register_complete (toadd); |
108 | ENGINE_free (toadd); | 109 | ENGINE_free (toadd); |
@@ -112,32 +113,26 @@ void ENGINE_load_aesni (void) | |||
112 | 113 | ||
113 | #ifdef COMPILE_HW_AESNI | 114 | #ifdef COMPILE_HW_AESNI |
114 | int aesni_set_encrypt_key(const unsigned char *userKey, int bits, | 115 | int aesni_set_encrypt_key(const unsigned char *userKey, int bits, |
115 | AES_KEY *key); | 116 | AES_KEY *key); |
116 | int aesni_set_decrypt_key(const unsigned char *userKey, int bits, | 117 | int aesni_set_decrypt_key(const unsigned char *userKey, int bits, |
117 | AES_KEY *key); | 118 | AES_KEY *key); |
118 | 119 | ||
119 | void aesni_encrypt(const unsigned char *in, unsigned char *out, | 120 | void aesni_encrypt(const unsigned char *in, unsigned char *out, |
120 | const AES_KEY *key); | 121 | const AES_KEY *key); |
121 | void aesni_decrypt(const unsigned char *in, unsigned char *out, | 122 | void aesni_decrypt(const unsigned char *in, unsigned char *out, |
122 | const AES_KEY *key); | 123 | const AES_KEY *key); |
123 | 124 | ||
124 | void aesni_ecb_encrypt(const unsigned char *in, | 125 | void aesni_ecb_encrypt(const unsigned char *in, unsigned char *out, |
125 | unsigned char *out, | 126 | size_t length, const AES_KEY *key, int enc); |
126 | size_t length, | 127 | void aesni_cbc_encrypt(const unsigned char *in, unsigned char *out, |
127 | const AES_KEY *key, | 128 | size_t length, const AES_KEY *key, unsigned char *ivec, int enc); |
128 | int enc); | ||
129 | void aesni_cbc_encrypt(const unsigned char *in, | ||
130 | unsigned char *out, | ||
131 | size_t length, | ||
132 | const AES_KEY *key, | ||
133 | unsigned char *ivec, int enc); | ||
134 | 129 | ||
135 | /* Function for ENGINE detection and control */ | 130 | /* Function for ENGINE detection and control */ |
136 | static int aesni_init(ENGINE *e); | 131 | static int aesni_init(ENGINE *e); |
137 | 132 | ||
138 | /* Cipher Stuff */ | 133 | /* Cipher Stuff */ |
139 | static int aesni_ciphers(ENGINE *e, const EVP_CIPHER **cipher, | 134 | static int aesni_ciphers(ENGINE *e, const EVP_CIPHER **cipher, |
140 | const int **nids, int nid); | 135 | const int **nids, int nid); |
141 | 136 | ||
142 | #define AESNI_MIN_ALIGN 16 | 137 | #define AESNI_MIN_ALIGN 16 |
143 | #define AESNI_ALIGN(x) \ | 138 | #define AESNI_ALIGN(x) \ |
@@ -145,143 +140,146 @@ static int aesni_ciphers(ENGINE *e, const EVP_CIPHER **cipher, | |||
145 | 140 | ||
146 | /* Engine names */ | 141 | /* Engine names */ |
147 | static const char aesni_id[] = "aesni", | 142 | static const char aesni_id[] = "aesni", |
148 | aesni_name[] = "Intel AES-NI engine", | 143 | aesni_name[] = "Intel AES-NI engine", |
149 | no_aesni_name[] = "Intel AES-NI engine (no-aesni)"; | 144 | no_aesni_name[] = "Intel AES-NI engine (no-aesni)"; |
150 | 145 | ||
151 | 146 | ||
152 | /* The input and output encrypted as though 128bit cfb mode is being | 147 | /* The input and output encrypted as though 128bit cfb mode is being |
153 | * used. The extra state information to record how much of the | 148 | * used. The extra state information to record how much of the |
154 | * 128bit block we have used is contained in *num; | 149 | * 128bit block we have used is contained in *num; |
155 | */ | 150 | */ |
156 | static void aesni_cfb128_encrypt(const unsigned char *in, unsigned char *out, | 151 | static void |
157 | unsigned int len, const void *key, | 152 | aesni_cfb128_encrypt(const unsigned char *in, unsigned char *out, |
158 | unsigned char ivec[16], int *num, | 153 | unsigned int len, const void *key, unsigned char ivec[16], int *num, |
159 | int enc) | 154 | int enc) |
160 | { | 155 | { |
161 | unsigned int n; | 156 | unsigned int n; |
162 | size_t l = 0; | 157 | size_t l = 0; |
163 | 158 | ||
164 | assert(in && out && key && ivec && num); | 159 | assert(in && out && key && ivec && num); |
165 | 160 | ||
166 | n = *num; | 161 | n = *num; |
167 | 162 | ||
168 | if (enc) { | 163 | if (enc) { |
169 | #if !defined(OPENSSL_SMALL_FOOTPRINT) | 164 | #if !defined(OPENSSL_SMALL_FOOTPRINT) |
170 | if (16%sizeof(size_t) == 0) do { /* always true actually */ | 165 | if (16%sizeof(size_t) == 0) do { /* always true actually */ |
171 | while (n && len) { | 166 | while (n && len) { |
172 | *(out++) = ivec[n] ^= *(in++); | 167 | *(out++) = ivec[n] ^= *(in++); |
173 | --len; | 168 | --len; |
174 | n = (n+1) % 16; | 169 | n = (n + 1) % 16; |
175 | } | ||
176 | while (len>=16) { | ||
177 | aesni_encrypt(ivec, ivec, key); | ||
178 | for (n=0; n<16; n+=sizeof(size_t)) { | ||
179 | *(size_t*)(out+n) = | ||
180 | *(size_t*)(ivec+n) ^= *(size_t*)(in+n); | ||
181 | } | 170 | } |
182 | len -= 16; | 171 | while (len >= 16) { |
183 | out += 16; | 172 | aesni_encrypt(ivec, ivec, key); |
184 | in += 16; | 173 | for (n = 0; n < 16; n += sizeof(size_t)) { |
185 | } | 174 | *(size_t*)(out + n) = |
186 | n = 0; | 175 | *(size_t*)(ivec + n) ^= *(size_t*)(in + n); |
187 | if (len) { | 176 | } |
188 | aesni_encrypt(ivec, ivec, key); | 177 | len -= 16; |
189 | while (len--) { | 178 | out += 16; |
190 | out[n] = ivec[n] ^= in[n]; | 179 | in += 16; |
191 | ++n; | ||
192 | } | 180 | } |
193 | } | 181 | n = 0; |
194 | *num = n; | 182 | if (len) { |
195 | return; | 183 | aesni_encrypt(ivec, ivec, key); |
196 | } while (0); | 184 | while (len--) { |
197 | /* the rest would be commonly eliminated by x86* compiler */ | 185 | out[n] = ivec[n] ^= in[n]; |
186 | ++n; | ||
187 | } | ||
188 | } | ||
189 | *num = n; | ||
190 | return; | ||
191 | } while (0); | ||
192 | /* the rest would be commonly eliminated by x86* compiler */ | ||
198 | #endif | 193 | #endif |
199 | while (l<len) { | 194 | while (l < len) { |
200 | if (n == 0) { | 195 | if (n == 0) { |
201 | aesni_encrypt(ivec, ivec, key); | 196 | aesni_encrypt(ivec, ivec, key); |
202 | } | ||
203 | out[l] = ivec[n] ^= in[l]; | ||
204 | ++l; | ||
205 | n = (n+1) % 16; | ||
206 | } | ||
207 | *num = n; | ||
208 | } else { | ||
209 | #if !defined(OPENSSL_SMALL_FOOTPRINT) | ||
210 | if (16%sizeof(size_t) == 0) do { /* always true actually */ | ||
211 | while (n && len) { | ||
212 | unsigned char c; | ||
213 | *(out++) = ivec[n] ^ (c = *(in++)); ivec[n] = c; | ||
214 | --len; | ||
215 | n = (n+1) % 16; | ||
216 | } | ||
217 | while (len>=16) { | ||
218 | aesni_encrypt(ivec, ivec, key); | ||
219 | for (n=0; n<16; n+=sizeof(size_t)) { | ||
220 | size_t t = *(size_t*)(in+n); | ||
221 | *(size_t*)(out+n) = *(size_t*)(ivec+n) ^ t; | ||
222 | *(size_t*)(ivec+n) = t; | ||
223 | } | 197 | } |
224 | len -= 16; | 198 | out[l] = ivec[n] ^= in[l]; |
225 | out += 16; | 199 | ++l; |
226 | in += 16; | 200 | n = (n + 1) % 16; |
227 | } | 201 | } |
228 | n = 0; | 202 | *num = n; |
229 | if (len) { | 203 | } else { |
230 | aesni_encrypt(ivec, ivec, key); | 204 | #if !defined(OPENSSL_SMALL_FOOTPRINT) |
231 | while (len--) { | 205 | if (16%sizeof(size_t) == 0) do { /* always true actually */ |
206 | while (n && len) { | ||
232 | unsigned char c; | 207 | unsigned char c; |
233 | out[n] = ivec[n] ^ (c = in[n]); ivec[n] = c; | 208 | *(out++) = ivec[n] ^ (c = *(in++)); |
234 | ++n; | 209 | ivec[n] = c; |
210 | --len; | ||
211 | n = (n + 1) % 16; | ||
235 | } | 212 | } |
236 | } | 213 | while (len >= 16) { |
237 | *num = n; | 214 | aesni_encrypt(ivec, ivec, key); |
238 | return; | 215 | for (n = 0; n < 16; n += sizeof(size_t)) { |
239 | } while (0); | 216 | size_t t = *(size_t*)(in + n); |
240 | /* the rest would be commonly eliminated by x86* compiler */ | 217 | *(size_t*)(out + n) = *(size_t*)(ivec + n) ^ t; |
218 | *(size_t*)(ivec + n) = t; | ||
219 | } | ||
220 | len -= 16; | ||
221 | out += 16; | ||
222 | in += 16; | ||
223 | } | ||
224 | n = 0; | ||
225 | if (len) { | ||
226 | aesni_encrypt(ivec, ivec, key); | ||
227 | while (len--) { | ||
228 | unsigned char c; | ||
229 | out[n] = ivec[n] ^ (c = in[n]); | ||
230 | ivec[n] = c; | ||
231 | ++n; | ||
232 | } | ||
233 | } | ||
234 | *num = n; | ||
235 | return; | ||
236 | } while (0); | ||
237 | /* the rest would be commonly eliminated by x86* compiler */ | ||
241 | #endif | 238 | #endif |
242 | while (l<len) { | 239 | while (l < len) { |
243 | unsigned char c; | 240 | unsigned char c; |
244 | if (n == 0) { | 241 | if (n == 0) { |
245 | aesni_encrypt(ivec, ivec, key); | 242 | aesni_encrypt(ivec, ivec, key); |
243 | } | ||
244 | out[l] = ivec[n] ^ (c = in[l]); | ||
245 | ivec[n] = c; | ||
246 | ++l; | ||
247 | n = (n + 1) % 16; | ||
246 | } | 248 | } |
247 | out[l] = ivec[n] ^ (c = in[l]); ivec[n] = c; | 249 | *num = n; |
248 | ++l; | ||
249 | n = (n+1) % 16; | ||
250 | } | 250 | } |
251 | *num=n; | ||
252 | } | ||
253 | } | 251 | } |
254 | 252 | ||
255 | /* The input and output encrypted as though 128bit ofb mode is being | 253 | /* The input and output encrypted as though 128bit ofb mode is being |
256 | * used. The extra state information to record how much of the | 254 | * used. The extra state information to record how much of the |
257 | * 128bit block we have used is contained in *num; | 255 | * 128bit block we have used is contained in *num; |
258 | */ | 256 | */ |
259 | static void aesni_ofb128_encrypt(const unsigned char *in, unsigned char *out, | 257 | static void |
260 | unsigned int len, const void *key, | 258 | aesni_ofb128_encrypt(const unsigned char *in, unsigned char *out, |
261 | unsigned char ivec[16], int *num) | 259 | unsigned int len, const void *key, unsigned char ivec[16], int *num) |
262 | { | 260 | { |
263 | unsigned int n; | 261 | unsigned int n; |
264 | size_t l=0; | 262 | size_t l = 0; |
265 | 263 | ||
266 | assert(in && out && key && ivec && num); | 264 | assert(in && out && key && ivec && num); |
267 | 265 | ||
268 | n = *num; | 266 | n = *num; |
269 | 267 | ||
270 | #if !defined(OPENSSL_SMALL_FOOTPRINT) | 268 | #if !defined(OPENSSL_SMALL_FOOTPRINT) |
271 | if (16%sizeof(size_t) == 0) do { /* always true actually */ | 269 | if (16%sizeof(size_t) == 0) do { /* always true actually */ |
272 | while (n && len) { | 270 | while (n && len) { |
273 | *(out++) = *(in++) ^ ivec[n]; | 271 | *(out++) = *(in++) ^ ivec[n]; |
274 | --len; | 272 | --len; |
275 | n = (n+1) % 16; | 273 | n = (n + 1) % 16; |
276 | } | 274 | } |
277 | while (len>=16) { | 275 | while (len >= 16) { |
278 | aesni_encrypt(ivec, ivec, key); | 276 | aesni_encrypt(ivec, ivec, key); |
279 | for (n=0; n<16; n+=sizeof(size_t)) | 277 | for (n = 0; n < 16; n += sizeof(size_t)) |
280 | *(size_t*)(out+n) = | 278 | *(size_t*)(out + n) = |
281 | *(size_t*)(in+n) ^ *(size_t*)(ivec+n); | 279 | *(size_t*)(in + n) ^ *(size_t*)(ivec + n); |
282 | len -= 16; | 280 | len -= 16; |
283 | out += 16; | 281 | out += 16; |
284 | in += 16; | 282 | in += 16; |
285 | } | 283 | } |
286 | n = 0; | 284 | n = 0; |
287 | if (len) { | 285 | if (len) { |
@@ -293,19 +291,19 @@ static void aesni_ofb128_encrypt(const unsigned char *in, unsigned char *out, | |||
293 | } | 291 | } |
294 | *num = n; | 292 | *num = n; |
295 | return; | 293 | return; |
296 | } while(0); | 294 | } while (0); |
297 | /* the rest would be commonly eliminated by x86* compiler */ | 295 | /* the rest would be commonly eliminated by x86* compiler */ |
298 | #endif | 296 | #endif |
299 | while (l<len) { | 297 | while (l < len) { |
300 | if (n==0) { | 298 | if (n == 0) { |
301 | aesni_encrypt(ivec, ivec, key); | 299 | aesni_encrypt(ivec, ivec, key); |
302 | } | 300 | } |
303 | out[l] = in[l] ^ ivec[n]; | 301 | out[l] = in[l] ^ ivec[n]; |
304 | ++l; | 302 | ++l; |
305 | n = (n+1) % 16; | 303 | n = (n + 1) % 16; |
306 | } | 304 | } |
307 | 305 | ||
308 | *num=n; | 306 | *num = n; |
309 | } | 307 | } |
310 | /* ===== Engine "management" functions ===== */ | 308 | /* ===== Engine "management" functions ===== */ |
311 | 309 | ||
@@ -316,6 +314,7 @@ static int | |||
316 | aesni_bind_helper(ENGINE *e) | 314 | aesni_bind_helper(ENGINE *e) |
317 | { | 315 | { |
318 | int engage; | 316 | int engage; |
317 | |||
319 | if (sizeof(OPENSSL_ia32cap_P) > 4) { | 318 | if (sizeof(OPENSSL_ia32cap_P) > 4) { |
320 | engage = ((IA32CAP)OPENSSL_ia32cap_P >> 57) & 1; | 319 | engage = ((IA32CAP)OPENSSL_ia32cap_P >> 57) & 1; |
321 | } else { | 320 | } else { |
@@ -326,10 +325,8 @@ aesni_bind_helper(ENGINE *e) | |||
326 | /* Register everything or return with an error */ | 325 | /* Register everything or return with an error */ |
327 | if (!ENGINE_set_id(e, aesni_id) || | 326 | if (!ENGINE_set_id(e, aesni_id) || |
328 | !ENGINE_set_name(e, engage ? aesni_name : no_aesni_name) || | 327 | !ENGINE_set_name(e, engage ? aesni_name : no_aesni_name) || |
329 | |||
330 | !ENGINE_set_init_function(e, aesni_init) || | 328 | !ENGINE_set_init_function(e, aesni_init) || |
331 | (engage && !ENGINE_set_ciphers (e, aesni_ciphers)) | 329 | (engage && !ENGINE_set_ciphers (e, aesni_ciphers))) |
332 | ) | ||
333 | return 0; | 330 | return 0; |
334 | 331 | ||
335 | /* Everything looks good */ | 332 | /* Everything looks good */ |
@@ -403,60 +400,72 @@ static int aesni_cipher_nids[] = { | |||
403 | NID_aes_256_ofb, | 400 | NID_aes_256_ofb, |
404 | }; | 401 | }; |
405 | static int aesni_cipher_nids_num = | 402 | static int aesni_cipher_nids_num = |
406 | (sizeof(aesni_cipher_nids)/sizeof(aesni_cipher_nids[0])); | 403 | (sizeof(aesni_cipher_nids) / sizeof(aesni_cipher_nids[0])); |
407 | 404 | ||
408 | typedef struct | 405 | typedef struct { |
409 | { | ||
410 | AES_KEY ks; | 406 | AES_KEY ks; |
411 | unsigned int _pad1[3]; | 407 | unsigned int _pad1[3]; |
412 | } AESNI_KEY; | 408 | } AESNI_KEY; |
413 | 409 | ||
414 | static int | 410 | static int |
415 | aesni_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *user_key, | 411 | aesni_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *user_key, |
416 | const unsigned char *iv, int enc) | 412 | const unsigned char *iv, int enc) |
417 | { | 413 | { |
418 | int ret; | 414 | int ret; |
419 | AES_KEY *key = AESNI_ALIGN(ctx->cipher_data); | 415 | AES_KEY *key = AESNI_ALIGN(ctx->cipher_data); |
420 | 416 | ||
421 | if ((ctx->cipher->flags & EVP_CIPH_MODE) == EVP_CIPH_CFB_MODE | 417 | if ((ctx->cipher->flags & EVP_CIPH_MODE) == EVP_CIPH_CFB_MODE || |
422 | || (ctx->cipher->flags & EVP_CIPH_MODE) == EVP_CIPH_OFB_MODE | 418 | (ctx->cipher->flags & EVP_CIPH_MODE) == EVP_CIPH_OFB_MODE || |
423 | || enc) | 419 | enc) |
424 | ret=aesni_set_encrypt_key(user_key, ctx->key_len * 8, key); | 420 | ret = aesni_set_encrypt_key(user_key, ctx->key_len * 8, key); |
425 | else | 421 | else |
426 | ret=aesni_set_decrypt_key(user_key, ctx->key_len * 8, key); | 422 | ret = aesni_set_decrypt_key(user_key, ctx->key_len * 8, key); |
427 | 423 | ||
428 | if(ret < 0) { | 424 | if (ret < 0) { |
429 | EVPerr(EVP_F_AESNI_INIT_KEY,EVP_R_AES_KEY_SETUP_FAILED); | 425 | EVPerr(EVP_F_AESNI_INIT_KEY, EVP_R_AES_KEY_SETUP_FAILED); |
430 | return 0; | 426 | return 0; |
431 | } | 427 | } |
432 | 428 | ||
433 | return 1; | 429 | return 1; |
434 | } | 430 | } |
435 | 431 | ||
436 | static int aesni_cipher_ecb(EVP_CIPHER_CTX *ctx, unsigned char *out, | 432 | static int |
437 | const unsigned char *in, size_t inl) | 433 | aesni_cipher_ecb(EVP_CIPHER_CTX *ctx, unsigned char *out, |
438 | { AES_KEY *key = AESNI_ALIGN(ctx->cipher_data); | 434 | const unsigned char *in, size_t inl) |
435 | { | ||
436 | AES_KEY *key = AESNI_ALIGN(ctx->cipher_data); | ||
437 | |||
439 | aesni_ecb_encrypt(in, out, inl, key, ctx->encrypt); | 438 | aesni_ecb_encrypt(in, out, inl, key, ctx->encrypt); |
440 | return 1; | 439 | return 1; |
441 | } | 440 | } |
442 | static int aesni_cipher_cbc(EVP_CIPHER_CTX *ctx, unsigned char *out, | 441 | |
443 | const unsigned char *in, size_t inl) | 442 | static int |
444 | { AES_KEY *key = AESNI_ALIGN(ctx->cipher_data); | 443 | aesni_cipher_cbc(EVP_CIPHER_CTX *ctx, unsigned char *out, |
445 | aesni_cbc_encrypt(in, out, inl, key, | 444 | const unsigned char *in, size_t inl) |
446 | ctx->iv, ctx->encrypt); | 445 | { |
446 | AES_KEY *key = AESNI_ALIGN(ctx->cipher_data); | ||
447 | |||
448 | aesni_cbc_encrypt(in, out, inl, key, ctx->iv, ctx->encrypt); | ||
447 | return 1; | 449 | return 1; |
448 | } | 450 | } |
449 | static int aesni_cipher_cfb(EVP_CIPHER_CTX *ctx, unsigned char *out, | ||
450 | const unsigned char *in, size_t inl) | ||
451 | { AES_KEY *key = AESNI_ALIGN(ctx->cipher_data); | ||
452 | 451 | ||
453 | aesni_cfb128_encrypt(in, out, inl, key, ctx->iv, | 452 | static int |
454 | &ctx->num, ctx->encrypt); | 453 | aesni_cipher_cfb(EVP_CIPHER_CTX *ctx, unsigned char *out, |
454 | const unsigned char *in, size_t inl) | ||
455 | { | ||
456 | AES_KEY *key = AESNI_ALIGN(ctx->cipher_data); | ||
457 | |||
458 | aesni_cfb128_encrypt(in, out, inl, key, ctx->iv, &ctx->num, | ||
459 | ctx->encrypt); | ||
455 | return 1; | 460 | return 1; |
456 | } | 461 | } |
457 | static int aesni_cipher_ofb(EVP_CIPHER_CTX *ctx, unsigned char *out, | 462 | |
458 | const unsigned char *in, size_t inl) | 463 | static int |
459 | { AES_KEY *key = AESNI_ALIGN(ctx->cipher_data); | 464 | aesni_cipher_ofb(EVP_CIPHER_CTX *ctx, unsigned char *out, |
465 | const unsigned char *in, size_t inl) | ||
466 | { | ||
467 | AES_KEY *key = AESNI_ALIGN(ctx->cipher_data); | ||
468 | |||
460 | aesni_ofb128_encrypt(in, out, inl, key, ctx->iv, &ctx->num); | 469 | aesni_ofb128_encrypt(in, out, inl, key, ctx->iv, &ctx->num); |
461 | return 1; | 470 | return 1; |
462 | } | 471 | } |
@@ -487,24 +496,23 @@ static const EVP_CIPHER aesni_##ksize##_##lmode = { \ | |||
487 | NULL \ | 496 | NULL \ |
488 | } | 497 | } |
489 | 498 | ||
490 | DECLARE_AES_EVP(128,ecb,ECB); | 499 | DECLARE_AES_EVP(128, ecb, ECB); |
491 | DECLARE_AES_EVP(128,cbc,CBC); | 500 | DECLARE_AES_EVP(128, cbc, CBC); |
492 | DECLARE_AES_EVP(128,cfb,CFB); | 501 | DECLARE_AES_EVP(128, cfb, CFB); |
493 | DECLARE_AES_EVP(128,ofb,OFB); | 502 | DECLARE_AES_EVP(128, ofb, OFB); |
494 | 503 | ||
495 | DECLARE_AES_EVP(192,ecb,ECB); | 504 | DECLARE_AES_EVP(192, ecb, ECB); |
496 | DECLARE_AES_EVP(192,cbc,CBC); | 505 | DECLARE_AES_EVP(192, cbc, CBC); |
497 | DECLARE_AES_EVP(192,cfb,CFB); | 506 | DECLARE_AES_EVP(192, cfb, CFB); |
498 | DECLARE_AES_EVP(192,ofb,OFB); | 507 | DECLARE_AES_EVP(192, ofb, OFB); |
499 | 508 | ||
500 | DECLARE_AES_EVP(256,ecb,ECB); | 509 | DECLARE_AES_EVP(256, ecb, ECB); |
501 | DECLARE_AES_EVP(256,cbc,CBC); | 510 | DECLARE_AES_EVP(256, cbc, CBC); |
502 | DECLARE_AES_EVP(256,cfb,CFB); | 511 | DECLARE_AES_EVP(256, cfb, CFB); |
503 | DECLARE_AES_EVP(256,ofb,OFB); | 512 | DECLARE_AES_EVP(256, ofb, OFB); |
504 | 513 | ||
505 | static int | 514 | static int |
506 | aesni_ciphers (ENGINE *e, const EVP_CIPHER **cipher, | 515 | aesni_ciphers(ENGINE *e, const EVP_CIPHER **cipher, const int **nids, int nid) |
507 | const int **nids, int nid) | ||
508 | { | 516 | { |
509 | /* No specific cipher => return a list of supported nids ... */ | 517 | /* No specific cipher => return a list of supported nids ... */ |
510 | if (!cipher) { | 518 | if (!cipher) { |
@@ -563,4 +571,3 @@ aesni_ciphers (ENGINE *e, const EVP_CIPHER **cipher, | |||
563 | 571 | ||
564 | #endif /* COMPILE_HW_AESNI */ | 572 | #endif /* COMPILE_HW_AESNI */ |
565 | #endif /* !defined(OPENSSL_NO_HW) && !defined(OPENSSL_NO_HW_AESNI) && !defined(OPENSSL_NO_AES) */ | 573 | #endif /* !defined(OPENSSL_NO_HW) && !defined(OPENSSL_NO_HW_AESNI) && !defined(OPENSSL_NO_AES) */ |
566 | |||
diff --git a/src/lib/libssl/src/crypto/engine/eng_all.c b/src/lib/libssl/src/crypto/engine/eng_all.c index fd36594a0b..eb933153e1 100644 --- a/src/lib/libssl/src/crypto/engine/eng_all.c +++ b/src/lib/libssl/src/crypto/engine/eng_all.c | |||
@@ -10,7 +10,7 @@ | |||
10 | * are met: | 10 | * are met: |
11 | * | 11 | * |
12 | * 1. Redistributions of source code must retain the above copyright | 12 | * 1. Redistributions of source code must retain the above copyright |
13 | * notice, this list of conditions and the following disclaimer. | 13 | * notice, this list of conditions and the following disclaimer. |
14 | * | 14 | * |
15 | * 2. Redistributions in binary form must reproduce the above copyright | 15 | * 2. Redistributions in binary form must reproduce the above copyright |
16 | * notice, this list of conditions and the following disclaimer in | 16 | * notice, this list of conditions and the following disclaimer in |
@@ -59,8 +59,9 @@ | |||
59 | #include "cryptlib.h" | 59 | #include "cryptlib.h" |
60 | #include "eng_int.h" | 60 | #include "eng_int.h" |
61 | 61 | ||
62 | void ENGINE_load_builtin_engines(void) | 62 | void |
63 | { | 63 | ENGINE_load_builtin_engines(void) |
64 | { | ||
64 | /* Some ENGINEs need this */ | 65 | /* Some ENGINEs need this */ |
65 | OPENSSL_cpuid_setup(); | 66 | OPENSSL_cpuid_setup(); |
66 | #if 0 | 67 | #if 0 |
@@ -85,15 +86,18 @@ void ENGINE_load_builtin_engines(void) | |||
85 | #endif | 86 | #endif |
86 | #endif | 87 | #endif |
87 | ENGINE_register_all_complete(); | 88 | ENGINE_register_all_complete(); |
88 | } | 89 | } |
89 | 90 | ||
90 | #if defined(__OpenBSD__) || defined(__FreeBSD__) || defined(HAVE_CRYPTODEV) | 91 | #if defined(__OpenBSD__) || defined(__FreeBSD__) || defined(HAVE_CRYPTODEV) |
91 | void ENGINE_setup_bsd_cryptodev(void) { | 92 | void |
93 | ENGINE_setup_bsd_cryptodev(void) | ||
94 | { | ||
92 | static int bsd_cryptodev_default_loaded = 0; | 95 | static int bsd_cryptodev_default_loaded = 0; |
96 | |||
93 | if (!bsd_cryptodev_default_loaded) { | 97 | if (!bsd_cryptodev_default_loaded) { |
94 | ENGINE_load_cryptodev(); | 98 | ENGINE_load_cryptodev(); |
95 | ENGINE_register_all_complete(); | 99 | ENGINE_register_all_complete(); |
96 | } | 100 | } |
97 | bsd_cryptodev_default_loaded=1; | 101 | bsd_cryptodev_default_loaded = 1; |
98 | } | 102 | } |
99 | #endif | 103 | #endif |
diff --git a/src/lib/libssl/src/crypto/engine/eng_cnf.c b/src/lib/libssl/src/crypto/engine/eng_cnf.c index afb704e93b..c0c6b3fdc4 100644 --- a/src/lib/libssl/src/crypto/engine/eng_cnf.c +++ b/src/lib/libssl/src/crypto/engine/eng_cnf.c | |||
@@ -10,7 +10,7 @@ | |||
10 | * are met: | 10 | * are met: |
11 | * | 11 | * |
12 | * 1. Redistributions of source code must retain the above copyright | 12 | * 1. Redistributions of source code must retain the above copyright |
13 | * notice, this list of conditions and the following disclaimer. | 13 | * notice, this list of conditions and the following disclaimer. |
14 | * | 14 | * |
15 | * 2. Redistributions in binary form must reproduce the above copyright | 15 | * 2. Redistributions in binary form must reproduce the above copyright |
16 | * notice, this list of conditions and the following disclaimer in | 16 | * notice, this list of conditions and the following disclaimer in |
@@ -63,34 +63,37 @@ | |||
63 | 63 | ||
64 | /* ENGINE config module */ | 64 | /* ENGINE config module */ |
65 | 65 | ||
66 | static char *skip_dot(char *name) | 66 | static char * |
67 | { | 67 | skip_dot(char *name) |
68 | { | ||
68 | char *p; | 69 | char *p; |
70 | |||
69 | p = strchr(name, '.'); | 71 | p = strchr(name, '.'); |
70 | if (p) | 72 | if (p) |
71 | return p + 1; | 73 | return p + 1; |
72 | return name; | 74 | return name; |
73 | } | 75 | } |
74 | 76 | ||
75 | static STACK_OF(ENGINE) *initialized_engines = NULL; | 77 | static STACK_OF(ENGINE) *initialized_engines = NULL; |
76 | 78 | ||
77 | static int int_engine_init(ENGINE *e) | 79 | static int |
78 | { | 80 | int_engine_init(ENGINE *e) |
81 | { | ||
79 | if (!ENGINE_init(e)) | 82 | if (!ENGINE_init(e)) |
80 | return 0; | 83 | return 0; |
81 | if (!initialized_engines) | 84 | if (!initialized_engines) |
82 | initialized_engines = sk_ENGINE_new_null(); | 85 | initialized_engines = sk_ENGINE_new_null(); |
83 | if (!initialized_engines || !sk_ENGINE_push(initialized_engines, e)) | 86 | if (!initialized_engines || !sk_ENGINE_push(initialized_engines, e)) { |
84 | { | ||
85 | ENGINE_finish(e); | 87 | ENGINE_finish(e); |
86 | return 0; | 88 | return 0; |
87 | } | ||
88 | return 1; | ||
89 | } | 89 | } |
90 | 90 | return 1; | |
91 | } | ||
91 | 92 | ||
92 | static int int_engine_configure(char *name, char *value, const CONF *cnf) | 93 | |
93 | { | 94 | static int |
95 | int_engine_configure(char *name, char *value, const CONF *cnf) | ||
96 | { | ||
94 | int i; | 97 | int i; |
95 | int ret = 0; | 98 | int ret = 0; |
96 | long do_init = -1; | 99 | long do_init = -1; |
@@ -107,19 +110,19 @@ static int int_engine_configure(char *name, char *value, const CONF *cnf) | |||
107 | /* Value is a section containing ENGINE commands */ | 110 | /* Value is a section containing ENGINE commands */ |
108 | ecmds = NCONF_get_section(cnf, value); | 111 | ecmds = NCONF_get_section(cnf, value); |
109 | 112 | ||
110 | if (!ecmds) | 113 | if (!ecmds) { |
111 | { | 114 | ENGINEerr(ENGINE_F_INT_ENGINE_CONFIGURE, |
112 | ENGINEerr(ENGINE_F_INT_ENGINE_CONFIGURE, ENGINE_R_ENGINE_SECTION_ERROR); | 115 | ENGINE_R_ENGINE_SECTION_ERROR); |
113 | return 0; | 116 | return 0; |
114 | } | 117 | } |
115 | 118 | ||
116 | for (i = 0; i < sk_CONF_VALUE_num(ecmds); i++) | 119 | for (i = 0; i < sk_CONF_VALUE_num(ecmds); i++) { |
117 | { | ||
118 | ecmd = sk_CONF_VALUE_value(ecmds, i); | 120 | ecmd = sk_CONF_VALUE_value(ecmds, i); |
119 | ctrlname = skip_dot(ecmd->name); | 121 | ctrlname = skip_dot(ecmd->name); |
120 | ctrlvalue = ecmd->value; | 122 | ctrlvalue = ecmd->value; |
121 | #ifdef ENGINE_CONF_DEBUG | 123 | #ifdef ENGINE_CONF_DEBUG |
122 | fprintf(stderr, "ENGINE conf: doing ctrl(%s,%s)\n", ctrlname, ctrlvalue); | 124 | fprintf(stderr, "ENGINE conf: doing ctrl(%s,%s)\n", |
125 | ctrlname, ctrlvalue); | ||
123 | #endif | 126 | #endif |
124 | 127 | ||
125 | /* First handle some special pseudo ctrls */ | 128 | /* First handle some special pseudo ctrls */ |
@@ -130,8 +133,7 @@ static int int_engine_configure(char *name, char *value, const CONF *cnf) | |||
130 | else if (!strcmp(ctrlname, "soft_load")) | 133 | else if (!strcmp(ctrlname, "soft_load")) |
131 | soft = 1; | 134 | soft = 1; |
132 | /* Load a dynamic ENGINE */ | 135 | /* Load a dynamic ENGINE */ |
133 | else if (!strcmp(ctrlname, "dynamic_path")) | 136 | else if (!strcmp(ctrlname, "dynamic_path")) { |
134 | { | ||
135 | e = ENGINE_by_id("dynamic"); | 137 | e = ENGINE_by_id("dynamic"); |
136 | if (!e) | 138 | if (!e) |
137 | goto err; | 139 | goto err; |
@@ -141,119 +143,111 @@ static int int_engine_configure(char *name, char *value, const CONF *cnf) | |||
141 | goto err; | 143 | goto err; |
142 | if (!ENGINE_ctrl_cmd_string(e, "LOAD", NULL, 0)) | 144 | if (!ENGINE_ctrl_cmd_string(e, "LOAD", NULL, 0)) |
143 | goto err; | 145 | goto err; |
144 | } | 146 | } |
145 | /* ... add other pseudos here ... */ | 147 | /* ... add other pseudos here ... */ |
146 | else | 148 | else { |
147 | { | ||
148 | /* At this point we need an ENGINE structural reference | 149 | /* At this point we need an ENGINE structural reference |
149 | * if we don't already have one. | 150 | * if we don't already have one. |
150 | */ | 151 | */ |
151 | if (!e) | 152 | if (!e) { |
152 | { | ||
153 | e = ENGINE_by_id(name); | 153 | e = ENGINE_by_id(name); |
154 | if (!e && soft) | 154 | if (!e && soft) { |
155 | { | ||
156 | ERR_clear_error(); | 155 | ERR_clear_error(); |
157 | return 1; | 156 | return 1; |
158 | } | 157 | } |
159 | if (!e) | 158 | if (!e) |
160 | goto err; | 159 | goto err; |
161 | } | 160 | } |
162 | /* Allow "EMPTY" to mean no value: this allows a valid | 161 | /* Allow "EMPTY" to mean no value: this allows a valid |
163 | * "value" to be passed to ctrls of type NO_INPUT | 162 | * "value" to be passed to ctrls of type NO_INPUT |
164 | */ | 163 | */ |
165 | if (!strcmp(ctrlvalue, "EMPTY")) | 164 | if (!strcmp(ctrlvalue, "EMPTY")) |
166 | ctrlvalue = NULL; | 165 | ctrlvalue = NULL; |
167 | if (!strcmp(ctrlname, "init")) | 166 | if (!strcmp(ctrlname, "init")) { |
168 | { | 167 | if (!NCONF_get_number_e(cnf, value, "init", |
169 | if (!NCONF_get_number_e(cnf, value, "init", &do_init)) | 168 | &do_init)) |
170 | goto err; | 169 | goto err; |
171 | if (do_init == 1) | 170 | if (do_init == 1) { |
172 | { | ||
173 | if (!int_engine_init(e)) | 171 | if (!int_engine_init(e)) |
174 | goto err; | 172 | goto err; |
175 | } | 173 | } else if (do_init != 0) { |
176 | else if (do_init != 0) | 174 | ENGINEerr(ENGINE_F_INT_ENGINE_CONFIGURE, |
177 | { | 175 | ENGINE_R_INVALID_INIT_VALUE); |
178 | ENGINEerr(ENGINE_F_INT_ENGINE_CONFIGURE, ENGINE_R_INVALID_INIT_VALUE); | ||
179 | goto err; | 176 | goto err; |
180 | } | ||
181 | } | 177 | } |
182 | else if (!strcmp(ctrlname, "default_algorithms")) | 178 | } |
183 | { | 179 | else if (!strcmp(ctrlname, "default_algorithms")) { |
184 | if (!ENGINE_set_default_string(e, ctrlvalue)) | 180 | if (!ENGINE_set_default_string(e, ctrlvalue)) |
185 | goto err; | 181 | goto err; |
186 | } | 182 | } else if (!ENGINE_ctrl_cmd_string(e, |
187 | else if (!ENGINE_ctrl_cmd_string(e, | 183 | ctrlname, ctrlvalue, 0)) |
188 | ctrlname, ctrlvalue, 0)) | ||
189 | goto err; | 184 | goto err; |
190 | } | ||
191 | |||
192 | |||
193 | |||
194 | } | 185 | } |
195 | if (e && (do_init == -1) && !int_engine_init(e)) | 186 | } |
196 | { | 187 | if (e && (do_init == -1) && !int_engine_init(e)) { |
197 | ecmd = NULL; | 188 | ecmd = NULL; |
198 | goto err; | 189 | goto err; |
199 | } | 190 | } |
200 | ret = 1; | 191 | ret = 1; |
201 | err: | 192 | |
202 | if (ret != 1) | 193 | err: |
203 | { | 194 | if (ret != 1) { |
204 | ENGINEerr(ENGINE_F_INT_ENGINE_CONFIGURE, ENGINE_R_ENGINE_CONFIGURATION_ERROR); | 195 | ENGINEerr(ENGINE_F_INT_ENGINE_CONFIGURE, |
196 | ENGINE_R_ENGINE_CONFIGURATION_ERROR); | ||
205 | if (ecmd) | 197 | if (ecmd) |
206 | ERR_asprintf_error_data | 198 | ERR_asprintf_error_data |
207 | ("section=%s, name=%s, value=%s", | 199 | ("section=%s, name=%s, value=%s", |
208 | ecmd->section, ecmd->name, ecmd->value); | 200 | ecmd->section, ecmd->name, ecmd->value); |
209 | } | 201 | } |
210 | if (e) | 202 | if (e) |
211 | ENGINE_free(e); | 203 | ENGINE_free(e); |
212 | return ret; | 204 | return ret; |
213 | } | 205 | } |
214 | 206 | ||
215 | 207 | ||
216 | static int int_engine_module_init(CONF_IMODULE *md, const CONF *cnf) | 208 | static int |
217 | { | 209 | int_engine_module_init(CONF_IMODULE *md, const CONF *cnf) |
210 | { | ||
218 | STACK_OF(CONF_VALUE) *elist; | 211 | STACK_OF(CONF_VALUE) *elist; |
219 | CONF_VALUE *cval; | 212 | CONF_VALUE *cval; |
220 | int i; | 213 | int i; |
214 | |||
221 | #ifdef ENGINE_CONF_DEBUG | 215 | #ifdef ENGINE_CONF_DEBUG |
222 | fprintf(stderr, "Called engine module: name %s, value %s\n", | 216 | fprintf(stderr, "Called engine module: name %s, value %s\n", |
223 | CONF_imodule_get_name(md), CONF_imodule_get_value(md)); | 217 | CONF_imodule_get_name(md), CONF_imodule_get_value(md)); |
224 | #endif | 218 | #endif |
225 | /* Value is a section containing ENGINEs to configure */ | 219 | /* Value is a section containing ENGINEs to configure */ |
226 | elist = NCONF_get_section(cnf, CONF_imodule_get_value(md)); | 220 | elist = NCONF_get_section(cnf, CONF_imodule_get_value(md)); |
227 | 221 | ||
228 | if (!elist) | 222 | if (!elist) { |
229 | { | 223 | ENGINEerr(ENGINE_F_INT_ENGINE_MODULE_INIT, |
230 | ENGINEerr(ENGINE_F_INT_ENGINE_MODULE_INIT, ENGINE_R_ENGINES_SECTION_ERROR); | 224 | ENGINE_R_ENGINES_SECTION_ERROR); |
231 | return 0; | 225 | return 0; |
232 | } | 226 | } |
233 | 227 | ||
234 | for (i = 0; i < sk_CONF_VALUE_num(elist); i++) | 228 | for (i = 0; i < sk_CONF_VALUE_num(elist); i++) { |
235 | { | ||
236 | cval = sk_CONF_VALUE_value(elist, i); | 229 | cval = sk_CONF_VALUE_value(elist, i); |
237 | if (!int_engine_configure(cval->name, cval->value, cnf)) | 230 | if (!int_engine_configure(cval->name, cval->value, cnf)) |
238 | return 0; | 231 | return 0; |
239 | } | 232 | } |
240 | 233 | ||
241 | return 1; | 234 | return 1; |
242 | } | 235 | } |
243 | 236 | ||
244 | static void int_engine_module_finish(CONF_IMODULE *md) | 237 | static void |
245 | { | 238 | int_engine_module_finish(CONF_IMODULE *md) |
239 | { | ||
246 | ENGINE *e; | 240 | ENGINE *e; |
241 | |||
247 | while ((e = sk_ENGINE_pop(initialized_engines))) | 242 | while ((e = sk_ENGINE_pop(initialized_engines))) |
248 | ENGINE_finish(e); | 243 | ENGINE_finish(e); |
249 | sk_ENGINE_free(initialized_engines); | 244 | sk_ENGINE_free(initialized_engines); |
250 | initialized_engines = NULL; | 245 | initialized_engines = NULL; |
251 | } | 246 | } |
252 | 247 | ||
253 | 248 | void | |
254 | void ENGINE_add_conf_module(void) | 249 | ENGINE_add_conf_module(void) |
255 | { | 250 | { |
256 | CONF_module_add("engines", | 251 | CONF_module_add("engines", int_engine_module_init, |
257 | int_engine_module_init, | 252 | int_engine_module_finish); |
258 | int_engine_module_finish); | 253 | } |
259 | } | ||
diff --git a/src/lib/libssl/src/crypto/engine/eng_ctrl.c b/src/lib/libssl/src/crypto/engine/eng_ctrl.c index d5017e2329..67a724202b 100644 --- a/src/lib/libssl/src/crypto/engine/eng_ctrl.c +++ b/src/lib/libssl/src/crypto/engine/eng_ctrl.c | |||
@@ -7,7 +7,7 @@ | |||
7 | * are met: | 7 | * are met: |
8 | * | 8 | * |
9 | * 1. Redistributions of source code must retain the above copyright | 9 | * 1. Redistributions of source code must retain the above copyright |
10 | * notice, this list of conditions and the following disclaimer. | 10 | * notice, this list of conditions and the following disclaimer. |
11 | * | 11 | * |
12 | * 2. Redistributions in binary form must reproduce the above copyright | 12 | * 2. Redistributions in binary form must reproduce the above copyright |
13 | * notice, this list of conditions and the following disclaimer in | 13 | * notice, this list of conditions and the following disclaimer in |
@@ -63,95 +63,92 @@ static const char *int_no_description = ""; | |||
63 | * ENGINE in question has asked us to take care of it (ie. the ENGINE did not | 63 | * ENGINE in question has asked us to take care of it (ie. the ENGINE did not |
64 | * set the ENGINE_FLAGS_MANUAL_CMD_CTRL flag. */ | 64 | * set the ENGINE_FLAGS_MANUAL_CMD_CTRL flag. */ |
65 | 65 | ||
66 | static int int_ctrl_cmd_is_null(const ENGINE_CMD_DEFN *defn) | 66 | static int |
67 | { | 67 | int_ctrl_cmd_is_null(const ENGINE_CMD_DEFN *defn) |
68 | if((defn->cmd_num == 0) || (defn->cmd_name == NULL)) | 68 | { |
69 | if ((defn->cmd_num == 0) || (defn->cmd_name == NULL)) | ||
69 | return 1; | 70 | return 1; |
70 | return 0; | 71 | return 0; |
71 | } | 72 | } |
72 | 73 | ||
73 | static int int_ctrl_cmd_by_name(const ENGINE_CMD_DEFN *defn, const char *s) | 74 | static int |
74 | { | 75 | int_ctrl_cmd_by_name(const ENGINE_CMD_DEFN *defn, const char *s) |
76 | { | ||
75 | int idx = 0; | 77 | int idx = 0; |
76 | while(!int_ctrl_cmd_is_null(defn) && (strcmp(defn->cmd_name, s) != 0)) | 78 | while (!int_ctrl_cmd_is_null(defn) && |
77 | { | 79 | (strcmp(defn->cmd_name, s) != 0)) { |
78 | idx++; | 80 | idx++; |
79 | defn++; | 81 | defn++; |
80 | } | 82 | } |
81 | if(int_ctrl_cmd_is_null(defn)) | 83 | if (int_ctrl_cmd_is_null(defn)) |
82 | /* The given name wasn't found */ | 84 | /* The given name wasn't found */ |
83 | return -1; | 85 | return -1; |
84 | return idx; | 86 | return idx; |
85 | } | 87 | } |
86 | 88 | ||
87 | static int int_ctrl_cmd_by_num(const ENGINE_CMD_DEFN *defn, unsigned int num) | 89 | static int |
88 | { | 90 | int_ctrl_cmd_by_num(const ENGINE_CMD_DEFN *defn, unsigned int num) |
91 | { | ||
89 | int idx = 0; | 92 | int idx = 0; |
90 | /* NB: It is stipulated that 'cmd_defn' lists are ordered by cmd_num. So | 93 | /* NB: It is stipulated that 'cmd_defn' lists are ordered by cmd_num. So |
91 | * our searches don't need to take any longer than necessary. */ | 94 | * our searches don't need to take any longer than necessary. */ |
92 | while(!int_ctrl_cmd_is_null(defn) && (defn->cmd_num < num)) | 95 | while (!int_ctrl_cmd_is_null(defn) && (defn->cmd_num < num)) { |
93 | { | ||
94 | idx++; | 96 | idx++; |
95 | defn++; | 97 | defn++; |
96 | } | 98 | } |
97 | if(defn->cmd_num == num) | 99 | if (defn->cmd_num == num) |
98 | return idx; | 100 | return idx; |
99 | /* The given cmd_num wasn't found */ | 101 | /* The given cmd_num wasn't found */ |
100 | return -1; | 102 | return -1; |
101 | } | 103 | } |
102 | 104 | ||
103 | static int int_ctrl_helper(ENGINE *e, int cmd, long i, void *p, | 105 | static int |
104 | void (*f)(void)) | 106 | int_ctrl_helper(ENGINE *e, int cmd, long i, void *p, void (*f)(void)) |
105 | { | 107 | { |
106 | int idx; | 108 | int idx; |
107 | int ret; | 109 | int ret; |
108 | char *s = (char *)p; | 110 | char *s = (char *)p; |
111 | |||
109 | /* Take care of the easy one first (eg. it requires no searches) */ | 112 | /* Take care of the easy one first (eg. it requires no searches) */ |
110 | if(cmd == ENGINE_CTRL_GET_FIRST_CMD_TYPE) | 113 | if (cmd == ENGINE_CTRL_GET_FIRST_CMD_TYPE) { |
111 | { | 114 | if ((e->cmd_defns == NULL) || |
112 | if((e->cmd_defns == NULL) || int_ctrl_cmd_is_null(e->cmd_defns)) | 115 | int_ctrl_cmd_is_null(e->cmd_defns)) |
113 | return 0; | 116 | return 0; |
114 | return e->cmd_defns->cmd_num; | 117 | return e->cmd_defns->cmd_num; |
115 | } | 118 | } |
116 | /* One or two commands require that "p" be a valid string buffer */ | 119 | /* One or two commands require that "p" be a valid string buffer */ |
117 | if((cmd == ENGINE_CTRL_GET_CMD_FROM_NAME) || | 120 | if ((cmd == ENGINE_CTRL_GET_CMD_FROM_NAME) || |
118 | (cmd == ENGINE_CTRL_GET_NAME_FROM_CMD) || | 121 | (cmd == ENGINE_CTRL_GET_NAME_FROM_CMD) || |
119 | (cmd == ENGINE_CTRL_GET_DESC_FROM_CMD)) | 122 | (cmd == ENGINE_CTRL_GET_DESC_FROM_CMD)) { |
120 | { | 123 | if (s == NULL) { |
121 | if(s == NULL) | ||
122 | { | ||
123 | ENGINEerr(ENGINE_F_INT_CTRL_HELPER, | 124 | ENGINEerr(ENGINE_F_INT_CTRL_HELPER, |
124 | ERR_R_PASSED_NULL_PARAMETER); | 125 | ERR_R_PASSED_NULL_PARAMETER); |
125 | return -1; | 126 | return -1; |
126 | } | ||
127 | } | 127 | } |
128 | } | ||
128 | /* Now handle cmd_name -> cmd_num conversion */ | 129 | /* Now handle cmd_name -> cmd_num conversion */ |
129 | if(cmd == ENGINE_CTRL_GET_CMD_FROM_NAME) | 130 | if (cmd == ENGINE_CTRL_GET_CMD_FROM_NAME) { |
130 | { | 131 | if ((e->cmd_defns == NULL) || |
131 | if((e->cmd_defns == NULL) || ((idx = int_ctrl_cmd_by_name( | 132 | ((idx = int_ctrl_cmd_by_name(e->cmd_defns, s)) < 0)) { |
132 | e->cmd_defns, s)) < 0)) | ||
133 | { | ||
134 | ENGINEerr(ENGINE_F_INT_CTRL_HELPER, | 133 | ENGINEerr(ENGINE_F_INT_CTRL_HELPER, |
135 | ENGINE_R_INVALID_CMD_NAME); | 134 | ENGINE_R_INVALID_CMD_NAME); |
136 | return -1; | 135 | return -1; |
137 | } | ||
138 | return e->cmd_defns[idx].cmd_num; | ||
139 | } | 136 | } |
137 | return e->cmd_defns[idx].cmd_num; | ||
138 | } | ||
140 | /* For the rest of the commands, the 'long' argument must specify a | 139 | /* For the rest of the commands, the 'long' argument must specify a |
141 | * valie command number - so we need to conduct a search. */ | 140 | * valie command number - so we need to conduct a search. */ |
142 | if((e->cmd_defns == NULL) || ((idx = int_ctrl_cmd_by_num(e->cmd_defns, | 141 | if ((e->cmd_defns == NULL) || |
143 | (unsigned int)i)) < 0)) | 142 | ((idx = int_ctrl_cmd_by_num(e->cmd_defns, (unsigned int)i)) < 0)) { |
144 | { | ||
145 | ENGINEerr(ENGINE_F_INT_CTRL_HELPER, | 143 | ENGINEerr(ENGINE_F_INT_CTRL_HELPER, |
146 | ENGINE_R_INVALID_CMD_NUMBER); | 144 | ENGINE_R_INVALID_CMD_NUMBER); |
147 | return -1; | 145 | return -1; |
148 | } | 146 | } |
149 | /* Now the logic splits depending on command type */ | 147 | /* Now the logic splits depending on command type */ |
150 | switch(cmd) | 148 | switch (cmd) { |
151 | { | ||
152 | case ENGINE_CTRL_GET_NEXT_CMD_TYPE: | 149 | case ENGINE_CTRL_GET_NEXT_CMD_TYPE: |
153 | idx++; | 150 | idx++; |
154 | if(int_ctrl_cmd_is_null(e->cmd_defns + idx)) | 151 | if (int_ctrl_cmd_is_null(e->cmd_defns + idx)) |
155 | /* end-of-list */ | 152 | /* end-of-list */ |
156 | return 0; | 153 | return 0; |
157 | else | 154 | else |
@@ -159,17 +156,17 @@ static int int_ctrl_helper(ENGINE *e, int cmd, long i, void *p, | |||
159 | case ENGINE_CTRL_GET_NAME_LEN_FROM_CMD: | 156 | case ENGINE_CTRL_GET_NAME_LEN_FROM_CMD: |
160 | return strlen(e->cmd_defns[idx].cmd_name); | 157 | return strlen(e->cmd_defns[idx].cmd_name); |
161 | case ENGINE_CTRL_GET_NAME_FROM_CMD: | 158 | case ENGINE_CTRL_GET_NAME_FROM_CMD: |
162 | ret = snprintf(s,strlen(e->cmd_defns[idx].cmd_name) + 1, | 159 | ret = snprintf(s, strlen(e->cmd_defns[idx].cmd_name) + 1, |
163 | "%s", e->cmd_defns[idx].cmd_name); | 160 | "%s", e->cmd_defns[idx].cmd_name); |
164 | if (ret >= (strlen(e->cmd_defns[idx].cmd_name) + 1)) | 161 | if (ret >= (strlen(e->cmd_defns[idx].cmd_name) + 1)) |
165 | ret = -1; | 162 | ret = -1; |
166 | return ret; | 163 | return ret; |
167 | case ENGINE_CTRL_GET_DESC_LEN_FROM_CMD: | 164 | case ENGINE_CTRL_GET_DESC_LEN_FROM_CMD: |
168 | if(e->cmd_defns[idx].cmd_desc) | 165 | if (e->cmd_defns[idx].cmd_desc) |
169 | return strlen(e->cmd_defns[idx].cmd_desc); | 166 | return strlen(e->cmd_defns[idx].cmd_desc); |
170 | return strlen(int_no_description); | 167 | return strlen(int_no_description); |
171 | case ENGINE_CTRL_GET_DESC_FROM_CMD: | 168 | case ENGINE_CTRL_GET_DESC_FROM_CMD: |
172 | if(e->cmd_defns[idx].cmd_desc) { | 169 | if (e->cmd_defns[idx].cmd_desc) { |
173 | ret = snprintf(s, | 170 | ret = snprintf(s, |
174 | strlen(e->cmd_defns[idx].cmd_desc) + 1, | 171 | strlen(e->cmd_defns[idx].cmd_desc) + 1, |
175 | "%s", e->cmd_defns[idx].cmd_desc); | 172 | "%s", e->cmd_defns[idx].cmd_desc); |
@@ -177,40 +174,40 @@ static int int_ctrl_helper(ENGINE *e, int cmd, long i, void *p, | |||
177 | ret = -1; | 174 | ret = -1; |
178 | return ret; | 175 | return ret; |
179 | } | 176 | } |
180 | ret = snprintf(s, strlen(int_no_description) + 1,"%s", | 177 | ret = snprintf(s, strlen(int_no_description) + 1, "%s", |
181 | int_no_description); | 178 | int_no_description); |
182 | if (ret >= strlen(int_no_description) + 1) | 179 | if (ret >= strlen(int_no_description) + 1) |
183 | ret = -1; | 180 | ret = -1; |
184 | return ret; | 181 | return ret; |
185 | case ENGINE_CTRL_GET_CMD_FLAGS: | 182 | case ENGINE_CTRL_GET_CMD_FLAGS: |
186 | return e->cmd_defns[idx].cmd_flags; | 183 | return e->cmd_defns[idx].cmd_flags; |
187 | } | 184 | } |
185 | |||
188 | /* Shouldn't really be here ... */ | 186 | /* Shouldn't really be here ... */ |
189 | ENGINEerr(ENGINE_F_INT_CTRL_HELPER,ENGINE_R_INTERNAL_LIST_ERROR); | 187 | ENGINEerr(ENGINE_F_INT_CTRL_HELPER, ENGINE_R_INTERNAL_LIST_ERROR); |
190 | return -1; | 188 | return -1; |
191 | } | 189 | } |
192 | 190 | ||
193 | int ENGINE_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)(void)) | 191 | int |
194 | { | 192 | ENGINE_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)(void)) |
193 | { | ||
195 | int ctrl_exists, ref_exists; | 194 | int ctrl_exists, ref_exists; |
196 | if(e == NULL) | 195 | |
197 | { | 196 | if (e == NULL) { |
198 | ENGINEerr(ENGINE_F_ENGINE_CTRL,ERR_R_PASSED_NULL_PARAMETER); | 197 | ENGINEerr(ENGINE_F_ENGINE_CTRL, ERR_R_PASSED_NULL_PARAMETER); |
199 | return 0; | 198 | return 0; |
200 | } | 199 | } |
201 | CRYPTO_w_lock(CRYPTO_LOCK_ENGINE); | 200 | CRYPTO_w_lock(CRYPTO_LOCK_ENGINE); |
202 | ref_exists = ((e->struct_ref > 0) ? 1 : 0); | 201 | ref_exists = ((e->struct_ref > 0) ? 1 : 0); |
203 | CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE); | 202 | CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE); |
204 | ctrl_exists = ((e->ctrl == NULL) ? 0 : 1); | 203 | ctrl_exists = ((e->ctrl == NULL) ? 0 : 1); |
205 | if(!ref_exists) | 204 | if (!ref_exists) { |
206 | { | 205 | ENGINEerr(ENGINE_F_ENGINE_CTRL, ENGINE_R_NO_REFERENCE); |
207 | ENGINEerr(ENGINE_F_ENGINE_CTRL,ENGINE_R_NO_REFERENCE); | ||
208 | return 0; | 206 | return 0; |
209 | } | 207 | } |
210 | /* Intercept any "root-level" commands before trying to hand them on to | 208 | /* Intercept any "root-level" commands before trying to hand them on to |
211 | * ctrl() handlers. */ | 209 | * ctrl() handlers. */ |
212 | switch(cmd) | 210 | switch (cmd) { |
213 | { | ||
214 | case ENGINE_CTRL_HAS_CTRL_FUNCTION: | 211 | case ENGINE_CTRL_HAS_CTRL_FUNCTION: |
215 | return ctrl_exists; | 212 | return ctrl_exists; |
216 | case ENGINE_CTRL_GET_FIRST_CMD_TYPE: | 213 | case ENGINE_CTRL_GET_FIRST_CMD_TYPE: |
@@ -221,180 +218,172 @@ int ENGINE_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)(void)) | |||
221 | case ENGINE_CTRL_GET_DESC_LEN_FROM_CMD: | 218 | case ENGINE_CTRL_GET_DESC_LEN_FROM_CMD: |
222 | case ENGINE_CTRL_GET_DESC_FROM_CMD: | 219 | case ENGINE_CTRL_GET_DESC_FROM_CMD: |
223 | case ENGINE_CTRL_GET_CMD_FLAGS: | 220 | case ENGINE_CTRL_GET_CMD_FLAGS: |
224 | if(ctrl_exists && !(e->flags & ENGINE_FLAGS_MANUAL_CMD_CTRL)) | 221 | if (ctrl_exists && !(e->flags & ENGINE_FLAGS_MANUAL_CMD_CTRL)) |
225 | return int_ctrl_helper(e,cmd,i,p,f); | 222 | return int_ctrl_helper(e, cmd, i, p, f); |
226 | if(!ctrl_exists) | 223 | if (!ctrl_exists) { |
227 | { | 224 | ENGINEerr(ENGINE_F_ENGINE_CTRL, |
228 | ENGINEerr(ENGINE_F_ENGINE_CTRL,ENGINE_R_NO_CONTROL_FUNCTION); | 225 | ENGINE_R_NO_CONTROL_FUNCTION); |
229 | /* For these cmd-related functions, failure is indicated | 226 | /* For these cmd-related functions, failure is indicated |
230 | * by a -1 return value (because 0 is used as a valid | 227 | * by a -1 return value (because 0 is used as a valid |
231 | * return in some places). */ | 228 | * return in some places). */ |
232 | return -1; | 229 | return -1; |
233 | } | 230 | } |
234 | default: | 231 | default: |
235 | break; | 232 | break; |
236 | } | 233 | } |
237 | /* Anything else requires a ctrl() handler to exist. */ | 234 | /* Anything else requires a ctrl() handler to exist. */ |
238 | if(!ctrl_exists) | 235 | if (!ctrl_exists) { |
239 | { | 236 | ENGINEerr(ENGINE_F_ENGINE_CTRL, ENGINE_R_NO_CONTROL_FUNCTION); |
240 | ENGINEerr(ENGINE_F_ENGINE_CTRL,ENGINE_R_NO_CONTROL_FUNCTION); | ||
241 | return 0; | 237 | return 0; |
242 | } | ||
243 | return e->ctrl(e, cmd, i, p, f); | ||
244 | } | 238 | } |
239 | return e->ctrl(e, cmd, i, p, f); | ||
240 | } | ||
245 | 241 | ||
246 | int ENGINE_cmd_is_executable(ENGINE *e, int cmd) | 242 | int |
247 | { | 243 | ENGINE_cmd_is_executable(ENGINE *e, int cmd) |
244 | { | ||
248 | int flags; | 245 | int flags; |
249 | if((flags = ENGINE_ctrl(e, ENGINE_CTRL_GET_CMD_FLAGS, cmd, NULL, NULL)) < 0) | 246 | |
250 | { | 247 | if ((flags = ENGINE_ctrl(e, ENGINE_CTRL_GET_CMD_FLAGS, cmd, |
248 | NULL, NULL)) < 0) { | ||
251 | ENGINEerr(ENGINE_F_ENGINE_CMD_IS_EXECUTABLE, | 249 | ENGINEerr(ENGINE_F_ENGINE_CMD_IS_EXECUTABLE, |
252 | ENGINE_R_INVALID_CMD_NUMBER); | 250 | ENGINE_R_INVALID_CMD_NUMBER); |
253 | return 0; | 251 | return 0; |
254 | } | 252 | } |
255 | if(!(flags & ENGINE_CMD_FLAG_NO_INPUT) && | 253 | if (!(flags & ENGINE_CMD_FLAG_NO_INPUT) && |
256 | !(flags & ENGINE_CMD_FLAG_NUMERIC) && | 254 | !(flags & ENGINE_CMD_FLAG_NUMERIC) && |
257 | !(flags & ENGINE_CMD_FLAG_STRING)) | 255 | !(flags & ENGINE_CMD_FLAG_STRING)) |
258 | return 0; | 256 | return 0; |
259 | return 1; | 257 | return 1; |
260 | } | 258 | } |
261 | 259 | ||
262 | int ENGINE_ctrl_cmd(ENGINE *e, const char *cmd_name, | 260 | int |
263 | long i, void *p, void (*f)(void), int cmd_optional) | 261 | ENGINE_ctrl_cmd(ENGINE *e, const char *cmd_name, long i, void *p, |
264 | { | 262 | void (*f)(void), int cmd_optional) |
263 | { | ||
265 | int num; | 264 | int num; |
266 | 265 | ||
267 | if((e == NULL) || (cmd_name == NULL)) | 266 | if ((e == NULL) || (cmd_name == NULL)) { |
268 | { | ||
269 | ENGINEerr(ENGINE_F_ENGINE_CTRL_CMD, | 267 | ENGINEerr(ENGINE_F_ENGINE_CTRL_CMD, |
270 | ERR_R_PASSED_NULL_PARAMETER); | 268 | ERR_R_PASSED_NULL_PARAMETER); |
271 | return 0; | 269 | return 0; |
272 | } | 270 | } |
273 | if((e->ctrl == NULL) || ((num = ENGINE_ctrl(e, | 271 | if ((e->ctrl == NULL) || |
274 | ENGINE_CTRL_GET_CMD_FROM_NAME, | 272 | ((num = ENGINE_ctrl(e, ENGINE_CTRL_GET_CMD_FROM_NAME, |
275 | 0, (void *)cmd_name, NULL)) <= 0)) | 273 | 0, (void *)cmd_name, NULL)) <= 0)) { |
276 | { | ||
277 | /* If the command didn't *have* to be supported, we fake | 274 | /* If the command didn't *have* to be supported, we fake |
278 | * success. This allows certain settings to be specified for | 275 | * success. This allows certain settings to be specified for |
279 | * multiple ENGINEs and only require a change of ENGINE id | 276 | * multiple ENGINEs and only require a change of ENGINE id |
280 | * (without having to selectively apply settings). Eg. changing | 277 | * (without having to selectively apply settings). Eg. changing |
281 | * from a hardware device back to the regular software ENGINE | 278 | * from a hardware device back to the regular software ENGINE |
282 | * without editing the config file, etc. */ | 279 | * without editing the config file, etc. */ |
283 | if(cmd_optional) | 280 | if (cmd_optional) { |
284 | { | ||
285 | ERR_clear_error(); | 281 | ERR_clear_error(); |
286 | return 1; | 282 | return 1; |
287 | } | ||
288 | ENGINEerr(ENGINE_F_ENGINE_CTRL_CMD, | ||
289 | ENGINE_R_INVALID_CMD_NAME); | ||
290 | return 0; | ||
291 | } | 283 | } |
284 | ENGINEerr(ENGINE_F_ENGINE_CTRL_CMD, ENGINE_R_INVALID_CMD_NAME); | ||
285 | return 0; | ||
286 | } | ||
287 | |||
292 | /* Force the result of the control command to 0 or 1, for the reasons | 288 | /* Force the result of the control command to 0 or 1, for the reasons |
293 | * mentioned before. */ | 289 | * mentioned before. */ |
294 | if (ENGINE_ctrl(e, num, i, p, f) > 0) | 290 | if (ENGINE_ctrl(e, num, i, p, f) > 0) |
295 | return 1; | 291 | return 1; |
296 | return 0; | ||
297 | } | ||
298 | 292 | ||
299 | int ENGINE_ctrl_cmd_string(ENGINE *e, const char *cmd_name, const char *arg, | 293 | return 0; |
300 | int cmd_optional) | 294 | } |
301 | { | 295 | |
296 | int | ||
297 | ENGINE_ctrl_cmd_string(ENGINE *e, const char *cmd_name, const char *arg, | ||
298 | int cmd_optional) | ||
299 | { | ||
302 | int num, flags; | 300 | int num, flags; |
303 | long l; | 301 | long l; |
304 | char *ptr; | 302 | char *ptr; |
305 | if((e == NULL) || (cmd_name == NULL)) | 303 | |
306 | { | 304 | if ((e == NULL) || (cmd_name == NULL)) { |
307 | ENGINEerr(ENGINE_F_ENGINE_CTRL_CMD_STRING, | 305 | ENGINEerr(ENGINE_F_ENGINE_CTRL_CMD_STRING, |
308 | ERR_R_PASSED_NULL_PARAMETER); | 306 | ERR_R_PASSED_NULL_PARAMETER); |
309 | return 0; | 307 | return 0; |
310 | } | 308 | } |
311 | if((e->ctrl == NULL) || ((num = ENGINE_ctrl(e, | 309 | if ((e->ctrl == NULL) || |
312 | ENGINE_CTRL_GET_CMD_FROM_NAME, | 310 | ((num = ENGINE_ctrl(e, ENGINE_CTRL_GET_CMD_FROM_NAME, 0, |
313 | 0, (void *)cmd_name, NULL)) <= 0)) | 311 | (void *)cmd_name, NULL)) <= 0)) { |
314 | { | ||
315 | /* If the command didn't *have* to be supported, we fake | 312 | /* If the command didn't *have* to be supported, we fake |
316 | * success. This allows certain settings to be specified for | 313 | * success. This allows certain settings to be specified for |
317 | * multiple ENGINEs and only require a change of ENGINE id | 314 | * multiple ENGINEs and only require a change of ENGINE id |
318 | * (without having to selectively apply settings). Eg. changing | 315 | * (without having to selectively apply settings). Eg. changing |
319 | * from a hardware device back to the regular software ENGINE | 316 | * from a hardware device back to the regular software ENGINE |
320 | * without editing the config file, etc. */ | 317 | * without editing the config file, etc. */ |
321 | if(cmd_optional) | 318 | if (cmd_optional) { |
322 | { | ||
323 | ERR_clear_error(); | 319 | ERR_clear_error(); |
324 | return 1; | 320 | return 1; |
325 | } | 321 | } |
326 | ENGINEerr(ENGINE_F_ENGINE_CTRL_CMD_STRING, | 322 | ENGINEerr(ENGINE_F_ENGINE_CTRL_CMD_STRING, |
327 | ENGINE_R_INVALID_CMD_NAME); | 323 | ENGINE_R_INVALID_CMD_NAME); |
328 | return 0; | 324 | return 0; |
329 | } | 325 | } |
330 | if(!ENGINE_cmd_is_executable(e, num)) | 326 | if (!ENGINE_cmd_is_executable(e, num)) { |
331 | { | ||
332 | ENGINEerr(ENGINE_F_ENGINE_CTRL_CMD_STRING, | 327 | ENGINEerr(ENGINE_F_ENGINE_CTRL_CMD_STRING, |
333 | ENGINE_R_CMD_NOT_EXECUTABLE); | 328 | ENGINE_R_CMD_NOT_EXECUTABLE); |
334 | return 0; | 329 | return 0; |
335 | } | 330 | } |
336 | if((flags = ENGINE_ctrl(e, ENGINE_CTRL_GET_CMD_FLAGS, num, NULL, NULL)) < 0) | 331 | if ((flags = ENGINE_ctrl(e, ENGINE_CTRL_GET_CMD_FLAGS, num, |
337 | { | 332 | NULL, NULL)) < 0) { |
338 | /* Shouldn't happen, given that ENGINE_cmd_is_executable() | 333 | /* Shouldn't happen, given that ENGINE_cmd_is_executable() |
339 | * returned success. */ | 334 | * returned success. */ |
340 | ENGINEerr(ENGINE_F_ENGINE_CTRL_CMD_STRING, | 335 | ENGINEerr(ENGINE_F_ENGINE_CTRL_CMD_STRING, |
341 | ENGINE_R_INTERNAL_LIST_ERROR); | 336 | ENGINE_R_INTERNAL_LIST_ERROR); |
342 | return 0; | 337 | return 0; |
343 | } | 338 | } |
344 | /* If the command takes no input, there must be no input. And vice | 339 | /* If the command takes no input, there must be no input. And vice |
345 | * versa. */ | 340 | * versa. */ |
346 | if(flags & ENGINE_CMD_FLAG_NO_INPUT) | 341 | if (flags & ENGINE_CMD_FLAG_NO_INPUT) { |
347 | { | 342 | if (arg != NULL) { |
348 | if(arg != NULL) | ||
349 | { | ||
350 | ENGINEerr(ENGINE_F_ENGINE_CTRL_CMD_STRING, | 343 | ENGINEerr(ENGINE_F_ENGINE_CTRL_CMD_STRING, |
351 | ENGINE_R_COMMAND_TAKES_NO_INPUT); | 344 | ENGINE_R_COMMAND_TAKES_NO_INPUT); |
352 | return 0; | 345 | return 0; |
353 | } | 346 | } |
354 | /* We deliberately force the result of ENGINE_ctrl() to 0 or 1 | 347 | /* We deliberately force the result of ENGINE_ctrl() to 0 or 1 |
355 | * rather than returning it as "return data". This is to ensure | 348 | * rather than returning it as "return data". This is to ensure |
356 | * usage of these commands is consistent across applications and | 349 | * usage of these commands is consistent across applications and |
357 | * that certain applications don't understand it one way, and | 350 | * that certain applications don't understand it one way, and |
358 | * others another. */ | 351 | * others another. */ |
359 | if(ENGINE_ctrl(e, num, 0, (void *)arg, NULL) > 0) | 352 | if (ENGINE_ctrl(e, num, 0, (void *)arg, NULL) > 0) |
360 | return 1; | 353 | return 1; |
361 | return 0; | 354 | return 0; |
362 | } | 355 | } |
363 | /* So, we require input */ | 356 | /* So, we require input */ |
364 | if(arg == NULL) | 357 | if (arg == NULL) { |
365 | { | ||
366 | ENGINEerr(ENGINE_F_ENGINE_CTRL_CMD_STRING, | 358 | ENGINEerr(ENGINE_F_ENGINE_CTRL_CMD_STRING, |
367 | ENGINE_R_COMMAND_TAKES_INPUT); | 359 | ENGINE_R_COMMAND_TAKES_INPUT); |
368 | return 0; | 360 | return 0; |
369 | } | 361 | } |
370 | /* If it takes string input, that's easy */ | 362 | /* If it takes string input, that's easy */ |
371 | if(flags & ENGINE_CMD_FLAG_STRING) | 363 | if (flags & ENGINE_CMD_FLAG_STRING) { |
372 | { | ||
373 | /* Same explanation as above */ | 364 | /* Same explanation as above */ |
374 | if(ENGINE_ctrl(e, num, 0, (void *)arg, NULL) > 0) | 365 | if (ENGINE_ctrl(e, num, 0, (void *)arg, NULL) > 0) |
375 | return 1; | 366 | return 1; |
376 | return 0; | 367 | return 0; |
377 | } | 368 | } |
378 | /* If it doesn't take numeric either, then it is unsupported for use in | 369 | /* If it doesn't take numeric either, then it is unsupported for use in |
379 | * a config-setting situation, which is what this function is for. This | 370 | * a config-setting situation, which is what this function is for. This |
380 | * should never happen though, because ENGINE_cmd_is_executable() was | 371 | * should never happen though, because ENGINE_cmd_is_executable() was |
381 | * used. */ | 372 | * used. */ |
382 | if(!(flags & ENGINE_CMD_FLAG_NUMERIC)) | 373 | if (!(flags & ENGINE_CMD_FLAG_NUMERIC)) { |
383 | { | ||
384 | ENGINEerr(ENGINE_F_ENGINE_CTRL_CMD_STRING, | 374 | ENGINEerr(ENGINE_F_ENGINE_CTRL_CMD_STRING, |
385 | ENGINE_R_INTERNAL_LIST_ERROR); | 375 | ENGINE_R_INTERNAL_LIST_ERROR); |
386 | return 0; | 376 | return 0; |
387 | } | 377 | } |
388 | l = strtol(arg, &ptr, 10); | 378 | l = strtol(arg, &ptr, 10); |
389 | if((arg == ptr) || (*ptr != '\0')) | 379 | if ((arg == ptr) || (*ptr != '\0')) { |
390 | { | ||
391 | ENGINEerr(ENGINE_F_ENGINE_CTRL_CMD_STRING, | 380 | ENGINEerr(ENGINE_F_ENGINE_CTRL_CMD_STRING, |
392 | ENGINE_R_ARGUMENT_IS_NOT_A_NUMBER); | 381 | ENGINE_R_ARGUMENT_IS_NOT_A_NUMBER); |
393 | return 0; | 382 | return 0; |
394 | } | 383 | } |
395 | /* Force the result of the control command to 0 or 1, for the reasons | 384 | /* Force the result of the control command to 0 or 1, for the reasons |
396 | * mentioned before. */ | 385 | * mentioned before. */ |
397 | if(ENGINE_ctrl(e, num, l, NULL, NULL) > 0) | 386 | if (ENGINE_ctrl(e, num, l, NULL, NULL) > 0) |
398 | return 1; | 387 | return 1; |
399 | return 0; | 388 | return 0; |
400 | } | 389 | } |
diff --git a/src/lib/libssl/src/crypto/engine/eng_dyn.c b/src/lib/libssl/src/crypto/engine/eng_dyn.c index e2de4603ee..0abb390b53 100644 --- a/src/lib/libssl/src/crypto/engine/eng_dyn.c +++ b/src/lib/libssl/src/crypto/engine/eng_dyn.c | |||
@@ -10,7 +10,7 @@ | |||
10 | * are met: | 10 | * are met: |
11 | * | 11 | * |
12 | * 1. Redistributions of source code must retain the above copyright | 12 | * 1. Redistributions of source code must retain the above copyright |
13 | * notice, this list of conditions and the following disclaimer. | 13 | * notice, this list of conditions and the following disclaimer. |
14 | * | 14 | * |
15 | * 2. Redistributions in binary form must reproduce the above copyright | 15 | * 2. Redistributions in binary form must reproduce the above copyright |
16 | * notice, this list of conditions and the following disclaimer in | 16 | * notice, this list of conditions and the following disclaimer in |
@@ -84,45 +84,52 @@ static int dynamic_load(ENGINE *e, dynamic_data_ctx *ctx); | |||
84 | static const char *engine_dynamic_id = "dynamic"; | 84 | static const char *engine_dynamic_id = "dynamic"; |
85 | static const char *engine_dynamic_name = "Dynamic engine loading support"; | 85 | static const char *engine_dynamic_name = "Dynamic engine loading support"; |
86 | static const ENGINE_CMD_DEFN dynamic_cmd_defns[] = { | 86 | static const ENGINE_CMD_DEFN dynamic_cmd_defns[] = { |
87 | {DYNAMIC_CMD_SO_PATH, | 87 | { |
88 | DYNAMIC_CMD_SO_PATH, | ||
88 | "SO_PATH", | 89 | "SO_PATH", |
89 | "Specifies the path to the new ENGINE shared library", | 90 | "Specifies the path to the new ENGINE shared library", |
90 | ENGINE_CMD_FLAG_STRING}, | 91 | ENGINE_CMD_FLAG_STRING}, |
91 | {DYNAMIC_CMD_NO_VCHECK, | 92 | { |
93 | DYNAMIC_CMD_NO_VCHECK, | ||
92 | "NO_VCHECK", | 94 | "NO_VCHECK", |
93 | "Specifies to continue even if version checking fails (boolean)", | 95 | "Specifies to continue even if version checking fails (boolean)", |
94 | ENGINE_CMD_FLAG_NUMERIC}, | 96 | ENGINE_CMD_FLAG_NUMERIC}, |
95 | {DYNAMIC_CMD_ID, | 97 | { |
98 | DYNAMIC_CMD_ID, | ||
96 | "ID", | 99 | "ID", |
97 | "Specifies an ENGINE id name for loading", | 100 | "Specifies an ENGINE id name for loading", |
98 | ENGINE_CMD_FLAG_STRING}, | 101 | ENGINE_CMD_FLAG_STRING}, |
99 | {DYNAMIC_CMD_LIST_ADD, | 102 | { |
103 | DYNAMIC_CMD_LIST_ADD, | ||
100 | "LIST_ADD", | 104 | "LIST_ADD", |
101 | "Whether to add a loaded ENGINE to the internal list (0=no,1=yes,2=mandatory)", | 105 | "Whether to add a loaded ENGINE to the internal list (0=no,1=yes,2=mandatory)", |
102 | ENGINE_CMD_FLAG_NUMERIC}, | 106 | ENGINE_CMD_FLAG_NUMERIC}, |
103 | {DYNAMIC_CMD_DIR_LOAD, | 107 | { |
108 | DYNAMIC_CMD_DIR_LOAD, | ||
104 | "DIR_LOAD", | 109 | "DIR_LOAD", |
105 | "Specifies whether to load from 'DIR_ADD' directories (0=no,1=yes,2=mandatory)", | 110 | "Specifies whether to load from 'DIR_ADD' directories (0=no,1=yes,2=mandatory)", |
106 | ENGINE_CMD_FLAG_NUMERIC}, | 111 | ENGINE_CMD_FLAG_NUMERIC}, |
107 | {DYNAMIC_CMD_DIR_ADD, | 112 | { |
113 | DYNAMIC_CMD_DIR_ADD, | ||
108 | "DIR_ADD", | 114 | "DIR_ADD", |
109 | "Adds a directory from which ENGINEs can be loaded", | 115 | "Adds a directory from which ENGINEs can be loaded", |
110 | ENGINE_CMD_FLAG_STRING}, | 116 | ENGINE_CMD_FLAG_STRING}, |
111 | {DYNAMIC_CMD_LOAD, | 117 | { |
118 | DYNAMIC_CMD_LOAD, | ||
112 | "LOAD", | 119 | "LOAD", |
113 | "Load up the ENGINE specified by other settings", | 120 | "Load up the ENGINE specified by other settings", |
114 | ENGINE_CMD_FLAG_NO_INPUT}, | 121 | ENGINE_CMD_FLAG_NO_INPUT}, |
122 | |||
115 | {0, NULL, NULL, 0} | 123 | {0, NULL, NULL, 0} |
116 | }; | 124 | }; |
117 | static const ENGINE_CMD_DEFN dynamic_cmd_defns_empty[] = { | 125 | static const ENGINE_CMD_DEFN dynamic_cmd_defns_empty[] = { |
118 | {0, NULL, NULL, 0} | 126 | {0, NULL, NULL, 0} |
119 | }; | 127 | }; |
120 | 128 | ||
121 | /* Loading code stores state inside the ENGINE structure via the "ex_data" | 129 | /* Loading code stores state inside the ENGINE structure via the "ex_data" |
122 | * element. We load all our state into a single structure and use that as a | 130 | * element. We load all our state into a single structure and use that as a |
123 | * single context in the "ex_data" stack. */ | 131 | * single context in the "ex_data" stack. */ |
124 | struct st_dynamic_data_ctx | 132 | struct st_dynamic_data_ctx { |
125 | { | ||
126 | /* The DSO object we load that supplies the ENGINE code */ | 133 | /* The DSO object we load that supplies the ENGINE code */ |
127 | DSO *dynamic_dso; | 134 | DSO *dynamic_dso; |
128 | /* The function pointer to the version checking shared library function */ | 135 | /* The function pointer to the version checking shared library function */ |
@@ -147,13 +154,18 @@ struct st_dynamic_data_ctx | |||
147 | int dir_load; | 154 | int dir_load; |
148 | /* A stack of directories from which ENGINEs could be loaded */ | 155 | /* A stack of directories from which ENGINEs could be loaded */ |
149 | STACK_OF(OPENSSL_STRING) *dirs; | 156 | STACK_OF(OPENSSL_STRING) *dirs; |
150 | }; | 157 | }; |
151 | 158 | ||
152 | /* This is the "ex_data" index we obtain and reserve for use with our context | 159 | /* This is the "ex_data" index we obtain and reserve for use with our context |
153 | * structure. */ | 160 | * structure. */ |
154 | static int dynamic_ex_data_idx = -1; | 161 | static int dynamic_ex_data_idx = -1; |
155 | 162 | ||
156 | static void int_free_str(char *s) { free(s); } | 163 | static void |
164 | int_free_str(char *s) | ||
165 | { | ||
166 | free(s); | ||
167 | } | ||
168 | |||
157 | /* Because our ex_data element may or may not get allocated depending on whether | 169 | /* Because our ex_data element may or may not get allocated depending on whether |
158 | * a "first-use" occurs before the ENGINE is freed, we have a memory leak | 170 | * a "first-use" occurs before the ENGINE is freed, we have a memory leak |
159 | * problem to solve. We can't declare a "new" handler for the ex_data as we | 171 | * problem to solve. We can't declare a "new" handler for the ex_data as we |
@@ -161,35 +173,36 @@ static void int_free_str(char *s) { free(s); } | |||
161 | * is a bug in the design of CRYPTO_EX_DATA). As such, we just declare a "free" | 173 | * is a bug in the design of CRYPTO_EX_DATA). As such, we just declare a "free" |
162 | * handler and that will get called if an ENGINE is being destroyed and there | 174 | * handler and that will get called if an ENGINE is being destroyed and there |
163 | * was an ex_data element corresponding to our context type. */ | 175 | * was an ex_data element corresponding to our context type. */ |
164 | static void dynamic_data_ctx_free_func(void *parent, void *ptr, | 176 | static void |
165 | CRYPTO_EX_DATA *ad, int idx, long argl, void *argp) | 177 | dynamic_data_ctx_free_func(void *parent, void *ptr, CRYPTO_EX_DATA *ad, |
166 | { | 178 | int idx, long argl, void *argp) |
167 | if(ptr) | 179 | { |
168 | { | 180 | if (ptr) { |
169 | dynamic_data_ctx *ctx = (dynamic_data_ctx *)ptr; | 181 | dynamic_data_ctx *ctx = (dynamic_data_ctx *)ptr; |
170 | if(ctx->dynamic_dso) | 182 | if (ctx->dynamic_dso) |
171 | DSO_free(ctx->dynamic_dso); | 183 | DSO_free(ctx->dynamic_dso); |
172 | free((void *)ctx->DYNAMIC_LIBNAME); | 184 | free((void *)ctx->DYNAMIC_LIBNAME); |
173 | free((void *)ctx->engine_id); | 185 | free((void *)ctx->engine_id); |
174 | if(ctx->dirs) | 186 | if (ctx->dirs) |
175 | sk_OPENSSL_STRING_pop_free(ctx->dirs, int_free_str); | 187 | sk_OPENSSL_STRING_pop_free(ctx->dirs, int_free_str); |
176 | free(ctx); | 188 | free(ctx); |
177 | } | ||
178 | } | 189 | } |
190 | } | ||
179 | 191 | ||
180 | /* Construct the per-ENGINE context. We create it blindly and then use a lock to | 192 | /* Construct the per-ENGINE context. We create it blindly and then use a lock to |
181 | * check for a race - if so, all but one of the threads "racing" will have | 193 | * check for a race - if so, all but one of the threads "racing" will have |
182 | * wasted their time. The alternative involves creating everything inside the | 194 | * wasted their time. The alternative involves creating everything inside the |
183 | * lock which is far worse. */ | 195 | * lock which is far worse. */ |
184 | static int dynamic_set_data_ctx(ENGINE *e, dynamic_data_ctx **ctx) | 196 | static int |
185 | { | 197 | dynamic_set_data_ctx(ENGINE *e, dynamic_data_ctx **ctx) |
198 | { | ||
186 | dynamic_data_ctx *c; | 199 | dynamic_data_ctx *c; |
200 | |||
187 | c = malloc(sizeof(dynamic_data_ctx)); | 201 | c = malloc(sizeof(dynamic_data_ctx)); |
188 | if(!c) | 202 | if (!c) { |
189 | { | 203 | ENGINEerr(ENGINE_F_DYNAMIC_SET_DATA_CTX, ERR_R_MALLOC_FAILURE); |
190 | ENGINEerr(ENGINE_F_DYNAMIC_SET_DATA_CTX,ERR_R_MALLOC_FAILURE); | ||
191 | return 0; | 204 | return 0; |
192 | } | 205 | } |
193 | memset(c, 0, sizeof(dynamic_data_ctx)); | 206 | memset(c, 0, sizeof(dynamic_data_ctx)); |
194 | c->dynamic_dso = NULL; | 207 | c->dynamic_dso = NULL; |
195 | c->v_check = NULL; | 208 | c->v_check = NULL; |
@@ -202,89 +215,92 @@ static int dynamic_set_data_ctx(ENGINE *e, dynamic_data_ctx **ctx) | |||
202 | c->DYNAMIC_F2 = "bind_engine"; | 215 | c->DYNAMIC_F2 = "bind_engine"; |
203 | c->dir_load = 1; | 216 | c->dir_load = 1; |
204 | c->dirs = sk_OPENSSL_STRING_new_null(); | 217 | c->dirs = sk_OPENSSL_STRING_new_null(); |
205 | if(!c->dirs) | 218 | if (!c->dirs) { |
206 | { | 219 | ENGINEerr(ENGINE_F_DYNAMIC_SET_DATA_CTX, ERR_R_MALLOC_FAILURE); |
207 | ENGINEerr(ENGINE_F_DYNAMIC_SET_DATA_CTX,ERR_R_MALLOC_FAILURE); | ||
208 | free(c); | 220 | free(c); |
209 | return 0; | 221 | return 0; |
210 | } | 222 | } |
211 | CRYPTO_w_lock(CRYPTO_LOCK_ENGINE); | 223 | CRYPTO_w_lock(CRYPTO_LOCK_ENGINE); |
212 | if((*ctx = (dynamic_data_ctx *)ENGINE_get_ex_data(e, | 224 | if ((*ctx = (dynamic_data_ctx *)ENGINE_get_ex_data(e, |
213 | dynamic_ex_data_idx)) == NULL) | 225 | dynamic_ex_data_idx)) == NULL) { |
214 | { | ||
215 | /* Good, we're the first */ | 226 | /* Good, we're the first */ |
216 | ENGINE_set_ex_data(e, dynamic_ex_data_idx, c); | 227 | ENGINE_set_ex_data(e, dynamic_ex_data_idx, c); |
217 | *ctx = c; | 228 | *ctx = c; |
218 | c = NULL; | 229 | c = NULL; |
219 | } | 230 | } |
220 | CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE); | 231 | CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE); |
221 | /* If we lost the race to set the context, c is non-NULL and *ctx is the | 232 | /* If we lost the race to set the context, c is non-NULL and *ctx is the |
222 | * context of the thread that won. */ | 233 | * context of the thread that won. */ |
223 | free(c); | 234 | free(c); |
224 | return 1; | 235 | return 1; |
225 | } | 236 | } |
226 | 237 | ||
227 | /* This function retrieves the context structure from an ENGINE's "ex_data", or | 238 | /* This function retrieves the context structure from an ENGINE's "ex_data", or |
228 | * if it doesn't exist yet, sets it up. */ | 239 | * if it doesn't exist yet, sets it up. */ |
229 | static dynamic_data_ctx *dynamic_get_data_ctx(ENGINE *e) | 240 | static dynamic_data_ctx * |
230 | { | 241 | dynamic_get_data_ctx(ENGINE *e) |
242 | { | ||
231 | dynamic_data_ctx *ctx; | 243 | dynamic_data_ctx *ctx; |
232 | if(dynamic_ex_data_idx < 0) | 244 | if (dynamic_ex_data_idx < 0) { |
233 | { | ||
234 | /* Create and register the ENGINE ex_data, and associate our | 245 | /* Create and register the ENGINE ex_data, and associate our |
235 | * "free" function with it to ensure any allocated contexts get | 246 | * "free" function with it to ensure any allocated contexts get |
236 | * freed when an ENGINE goes underground. */ | 247 | * freed when an ENGINE goes underground. */ |
237 | int new_idx = ENGINE_get_ex_new_index(0, NULL, NULL, NULL, | 248 | int new_idx = ENGINE_get_ex_new_index(0, NULL, NULL, NULL, |
238 | dynamic_data_ctx_free_func); | 249 | dynamic_data_ctx_free_func); |
239 | if(new_idx == -1) | 250 | if (new_idx == -1) { |
240 | { | 251 | ENGINEerr(ENGINE_F_DYNAMIC_GET_DATA_CTX, |
241 | ENGINEerr(ENGINE_F_DYNAMIC_GET_DATA_CTX,ENGINE_R_NO_INDEX); | 252 | ENGINE_R_NO_INDEX); |
242 | return NULL; | 253 | return NULL; |
243 | } | 254 | } |
244 | CRYPTO_w_lock(CRYPTO_LOCK_ENGINE); | 255 | CRYPTO_w_lock(CRYPTO_LOCK_ENGINE); |
245 | /* Avoid a race by checking again inside this lock */ | 256 | /* Avoid a race by checking again inside this lock */ |
246 | if(dynamic_ex_data_idx < 0) | 257 | if (dynamic_ex_data_idx < 0) { |
247 | { | ||
248 | /* Good, someone didn't beat us to it */ | 258 | /* Good, someone didn't beat us to it */ |
249 | dynamic_ex_data_idx = new_idx; | 259 | dynamic_ex_data_idx = new_idx; |
250 | new_idx = -1; | 260 | new_idx = -1; |
251 | } | 261 | } |
252 | CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE); | 262 | CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE); |
253 | /* In theory we could "give back" the index here if | 263 | /* In theory we could "give back" the index here if |
254 | * (new_idx>-1), but it's not possible and wouldn't gain us much | 264 | * (new_idx>-1), but it's not possible and wouldn't gain us much |
255 | * if it were. */ | 265 | * if it were. */ |
256 | } | 266 | } |
257 | ctx = (dynamic_data_ctx *)ENGINE_get_ex_data(e, dynamic_ex_data_idx); | 267 | ctx = (dynamic_data_ctx *)ENGINE_get_ex_data(e, dynamic_ex_data_idx); |
258 | /* Check if the context needs to be created */ | 268 | /* Check if the context needs to be created */ |
259 | if((ctx == NULL) && !dynamic_set_data_ctx(e, &ctx)) | 269 | if ((ctx == NULL) && !dynamic_set_data_ctx(e, &ctx)) |
260 | /* "set_data" will set errors if necessary */ | 270 | /* "set_data" will set errors if necessary */ |
261 | return NULL; | 271 | return NULL; |
262 | return ctx; | 272 | return ctx; |
263 | } | 273 | } |
264 | 274 | ||
265 | static ENGINE *engine_dynamic(void) | 275 | static ENGINE * |
266 | { | 276 | engine_dynamic(void) |
277 | { | ||
267 | ENGINE *ret = ENGINE_new(); | 278 | ENGINE *ret = ENGINE_new(); |
268 | if(!ret) | 279 | |
280 | if (!ret) | ||
269 | return NULL; | 281 | return NULL; |
270 | if(!ENGINE_set_id(ret, engine_dynamic_id) || | 282 | |
271 | !ENGINE_set_name(ret, engine_dynamic_name) || | 283 | if (!ENGINE_set_id(ret, engine_dynamic_id) || |
272 | !ENGINE_set_init_function(ret, dynamic_init) || | 284 | !ENGINE_set_name(ret, engine_dynamic_name) || |
273 | !ENGINE_set_finish_function(ret, dynamic_finish) || | 285 | !ENGINE_set_init_function(ret, dynamic_init) || |
274 | !ENGINE_set_ctrl_function(ret, dynamic_ctrl) || | 286 | !ENGINE_set_finish_function(ret, dynamic_finish) || |
275 | !ENGINE_set_flags(ret, ENGINE_FLAGS_BY_ID_COPY) || | 287 | !ENGINE_set_ctrl_function(ret, dynamic_ctrl) || |
276 | !ENGINE_set_cmd_defns(ret, dynamic_cmd_defns)) | 288 | !ENGINE_set_flags(ret, ENGINE_FLAGS_BY_ID_COPY) || |
277 | { | 289 | !ENGINE_set_cmd_defns(ret, dynamic_cmd_defns)) { |
278 | ENGINE_free(ret); | 290 | ENGINE_free(ret); |
279 | return NULL; | 291 | return NULL; |
280 | } | ||
281 | return ret; | ||
282 | } | 292 | } |
293 | return ret; | ||
294 | } | ||
283 | 295 | ||
284 | void ENGINE_load_dynamic(void) | 296 | void |
285 | { | 297 | ENGINE_load_dynamic(void) |
298 | { | ||
286 | ENGINE *toadd = engine_dynamic(); | 299 | ENGINE *toadd = engine_dynamic(); |
287 | if(!toadd) return; | 300 | |
301 | if (!toadd) | ||
302 | return; | ||
303 | |||
288 | ENGINE_add(toadd); | 304 | ENGINE_add(toadd); |
289 | /* If the "add" worked, it gets a structural reference. So either way, | 305 | /* If the "add" worked, it gets a structural reference. So either way, |
290 | * we release our just-created reference. */ | 306 | * we release our just-created reference. */ |
@@ -293,48 +309,47 @@ void ENGINE_load_dynamic(void) | |||
293 | * already added (eg. someone calling ENGINE_load_blah then calling | 309 | * already added (eg. someone calling ENGINE_load_blah then calling |
294 | * ENGINE_load_builtin_engines() perhaps). */ | 310 | * ENGINE_load_builtin_engines() perhaps). */ |
295 | ERR_clear_error(); | 311 | ERR_clear_error(); |
296 | } | 312 | } |
297 | 313 | ||
298 | static int dynamic_init(ENGINE *e) | 314 | static int |
299 | { | 315 | dynamic_init(ENGINE *e) |
316 | { | ||
300 | /* We always return failure - the "dyanamic" engine itself can't be used | 317 | /* We always return failure - the "dyanamic" engine itself can't be used |
301 | * for anything. */ | 318 | * for anything. */ |
302 | return 0; | 319 | return 0; |
303 | } | 320 | } |
304 | 321 | ||
305 | static int dynamic_finish(ENGINE *e) | 322 | static int |
306 | { | 323 | dynamic_finish(ENGINE *e) |
324 | { | ||
307 | /* This should never be called on account of "dynamic_init" always | 325 | /* This should never be called on account of "dynamic_init" always |
308 | * failing. */ | 326 | * failing. */ |
309 | return 0; | 327 | return 0; |
310 | } | 328 | } |
311 | 329 | ||
312 | static int dynamic_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)(void)) | 330 | static int |
313 | { | 331 | dynamic_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)(void)) |
332 | { | ||
314 | dynamic_data_ctx *ctx = dynamic_get_data_ctx(e); | 333 | dynamic_data_ctx *ctx = dynamic_get_data_ctx(e); |
315 | int initialised; | 334 | int initialised; |
316 | 335 | ||
317 | if(!ctx) | 336 | if (!ctx) { |
318 | { | 337 | ENGINEerr(ENGINE_F_DYNAMIC_CTRL, ENGINE_R_NOT_LOADED); |
319 | ENGINEerr(ENGINE_F_DYNAMIC_CTRL,ENGINE_R_NOT_LOADED); | ||
320 | return 0; | 338 | return 0; |
321 | } | 339 | } |
322 | initialised = ((ctx->dynamic_dso == NULL) ? 0 : 1); | 340 | initialised = ((ctx->dynamic_dso == NULL) ? 0 : 1); |
323 | /* All our control commands require the ENGINE to be uninitialised */ | 341 | /* All our control commands require the ENGINE to be uninitialised */ |
324 | if(initialised) | 342 | if (initialised) { |
325 | { | 343 | ENGINEerr(ENGINE_F_DYNAMIC_CTRL, ENGINE_R_ALREADY_LOADED); |
326 | ENGINEerr(ENGINE_F_DYNAMIC_CTRL, | ||
327 | ENGINE_R_ALREADY_LOADED); | ||
328 | return 0; | 344 | return 0; |
329 | } | 345 | } |
330 | switch(cmd) | 346 | switch (cmd) { |
331 | { | ||
332 | case DYNAMIC_CMD_SO_PATH: | 347 | case DYNAMIC_CMD_SO_PATH: |
333 | /* a NULL 'p' or a string of zero-length is the same thing */ | 348 | /* a NULL 'p' or a string of zero-length is the same thing */ |
334 | if(p && (strlen((const char *)p) < 1)) | 349 | if (p && (strlen((const char *)p) < 1)) |
335 | p = NULL; | 350 | p = NULL; |
336 | free((void *)ctx->DYNAMIC_LIBNAME); | 351 | free((void *)ctx->DYNAMIC_LIBNAME); |
337 | if(p) | 352 | if (p) |
338 | ctx->DYNAMIC_LIBNAME = BUF_strdup(p); | 353 | ctx->DYNAMIC_LIBNAME = BUF_strdup(p); |
339 | else | 354 | else |
340 | ctx->DYNAMIC_LIBNAME = NULL; | 355 | ctx->DYNAMIC_LIBNAME = NULL; |
@@ -344,145 +359,138 @@ static int dynamic_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)(void)) | |||
344 | return 1; | 359 | return 1; |
345 | case DYNAMIC_CMD_ID: | 360 | case DYNAMIC_CMD_ID: |
346 | /* a NULL 'p' or a string of zero-length is the same thing */ | 361 | /* a NULL 'p' or a string of zero-length is the same thing */ |
347 | if(p && (strlen((const char *)p) < 1)) | 362 | if (p && (strlen((const char *)p) < 1)) |
348 | p = NULL; | 363 | p = NULL; |
349 | free((void *)ctx->engine_id); | 364 | free((void *)ctx->engine_id); |
350 | if(p) | 365 | if (p) |
351 | ctx->engine_id = BUF_strdup(p); | 366 | ctx->engine_id = BUF_strdup(p); |
352 | else | 367 | else |
353 | ctx->engine_id = NULL; | 368 | ctx->engine_id = NULL; |
354 | return (ctx->engine_id ? 1 : 0); | 369 | return (ctx->engine_id ? 1 : 0); |
355 | case DYNAMIC_CMD_LIST_ADD: | 370 | case DYNAMIC_CMD_LIST_ADD: |
356 | if((i < 0) || (i > 2)) | 371 | if ((i < 0) || (i > 2)) { |
357 | { | ||
358 | ENGINEerr(ENGINE_F_DYNAMIC_CTRL, | 372 | ENGINEerr(ENGINE_F_DYNAMIC_CTRL, |
359 | ENGINE_R_INVALID_ARGUMENT); | 373 | ENGINE_R_INVALID_ARGUMENT); |
360 | return 0; | 374 | return 0; |
361 | } | 375 | } |
362 | ctx->list_add_value = (int)i; | 376 | ctx->list_add_value = (int)i; |
363 | return 1; | 377 | return 1; |
364 | case DYNAMIC_CMD_LOAD: | 378 | case DYNAMIC_CMD_LOAD: |
365 | return dynamic_load(e, ctx); | 379 | return dynamic_load(e, ctx); |
366 | case DYNAMIC_CMD_DIR_LOAD: | 380 | case DYNAMIC_CMD_DIR_LOAD: |
367 | if((i < 0) || (i > 2)) | 381 | if ((i < 0) || (i > 2)) { |
368 | { | ||
369 | ENGINEerr(ENGINE_F_DYNAMIC_CTRL, | 382 | ENGINEerr(ENGINE_F_DYNAMIC_CTRL, |
370 | ENGINE_R_INVALID_ARGUMENT); | 383 | ENGINE_R_INVALID_ARGUMENT); |
371 | return 0; | 384 | return 0; |
372 | } | 385 | } |
373 | ctx->dir_load = (int)i; | 386 | ctx->dir_load = (int)i; |
374 | return 1; | 387 | return 1; |
375 | case DYNAMIC_CMD_DIR_ADD: | 388 | case DYNAMIC_CMD_DIR_ADD: |
376 | /* a NULL 'p' or a string of zero-length is the same thing */ | 389 | /* a NULL 'p' or a string of zero-length is the same thing */ |
377 | if(!p || (strlen((const char *)p) < 1)) | 390 | if (!p || (strlen((const char *)p) < 1)) { |
378 | { | ||
379 | ENGINEerr(ENGINE_F_DYNAMIC_CTRL, | 391 | ENGINEerr(ENGINE_F_DYNAMIC_CTRL, |
380 | ENGINE_R_INVALID_ARGUMENT); | 392 | ENGINE_R_INVALID_ARGUMENT); |
381 | return 0; | 393 | return 0; |
382 | } | 394 | } |
383 | { | 395 | { |
384 | char *tmp_str = BUF_strdup(p); | 396 | char *tmp_str = BUF_strdup(p); |
385 | if(!tmp_str) | 397 | if (!tmp_str) { |
386 | { | 398 | ENGINEerr(ENGINE_F_DYNAMIC_CTRL, |
387 | ENGINEerr(ENGINE_F_DYNAMIC_CTRL, | 399 | ERR_R_MALLOC_FAILURE); |
388 | ERR_R_MALLOC_FAILURE); | 400 | return 0; |
389 | return 0; | ||
390 | } | 401 | } |
391 | sk_OPENSSL_STRING_insert(ctx->dirs, tmp_str, -1); | 402 | sk_OPENSSL_STRING_insert(ctx->dirs, tmp_str, -1); |
392 | } | 403 | } |
393 | return 1; | 404 | return 1; |
394 | default: | 405 | default: |
395 | break; | 406 | break; |
396 | } | ||
397 | ENGINEerr(ENGINE_F_DYNAMIC_CTRL,ENGINE_R_CTRL_COMMAND_NOT_IMPLEMENTED); | ||
398 | return 0; | ||
399 | } | 407 | } |
408 | ENGINEerr(ENGINE_F_DYNAMIC_CTRL, ENGINE_R_CTRL_COMMAND_NOT_IMPLEMENTED); | ||
409 | return 0; | ||
410 | } | ||
400 | 411 | ||
401 | static int int_load(dynamic_data_ctx *ctx) | 412 | static int |
402 | { | 413 | int_load(dynamic_data_ctx *ctx) |
414 | { | ||
403 | int num, loop; | 415 | int num, loop; |
416 | |||
404 | /* Unless told not to, try a direct load */ | 417 | /* Unless told not to, try a direct load */ |
405 | if((ctx->dir_load != 2) && (DSO_load(ctx->dynamic_dso, | 418 | if ((ctx->dir_load != 2) && (DSO_load(ctx->dynamic_dso, |
406 | ctx->DYNAMIC_LIBNAME, NULL, 0)) != NULL) | 419 | ctx->DYNAMIC_LIBNAME, NULL, 0)) != NULL) |
407 | return 1; | 420 | return 1; |
408 | /* If we're not allowed to use 'dirs' or we have none, fail */ | 421 | /* If we're not allowed to use 'dirs' or we have none, fail */ |
409 | if(!ctx->dir_load || (num = sk_OPENSSL_STRING_num(ctx->dirs)) < 1) | 422 | if (!ctx->dir_load || (num = sk_OPENSSL_STRING_num(ctx->dirs)) < 1) |
410 | return 0; | 423 | return 0; |
411 | for(loop = 0; loop < num; loop++) | 424 | for (loop = 0; loop < num; loop++) { |
412 | { | ||
413 | const char *s = sk_OPENSSL_STRING_value(ctx->dirs, loop); | 425 | const char *s = sk_OPENSSL_STRING_value(ctx->dirs, loop); |
414 | char *merge = DSO_merge(ctx->dynamic_dso, ctx->DYNAMIC_LIBNAME, s); | 426 | char *merge = DSO_merge(ctx->dynamic_dso, |
415 | if(!merge) | 427 | ctx->DYNAMIC_LIBNAME, s); |
428 | if (!merge) | ||
416 | return 0; | 429 | return 0; |
417 | if(DSO_load(ctx->dynamic_dso, merge, NULL, 0)) | 430 | if (DSO_load(ctx->dynamic_dso, merge, NULL, 0)) { |
418 | { | ||
419 | /* Found what we're looking for */ | 431 | /* Found what we're looking for */ |
420 | free(merge); | 432 | free(merge); |
421 | return 1; | 433 | return 1; |
422 | } | ||
423 | free(merge); | ||
424 | } | 434 | } |
425 | return 0; | 435 | free(merge); |
426 | } | 436 | } |
437 | return 0; | ||
438 | } | ||
427 | 439 | ||
428 | static int dynamic_load(ENGINE *e, dynamic_data_ctx *ctx) | 440 | static int |
429 | { | 441 | dynamic_load(ENGINE *e, dynamic_data_ctx *ctx) |
442 | { | ||
430 | ENGINE cpy; | 443 | ENGINE cpy; |
431 | dynamic_fns fns; | 444 | dynamic_fns fns; |
432 | 445 | ||
433 | if(!ctx->dynamic_dso) | 446 | if (!ctx->dynamic_dso) |
434 | ctx->dynamic_dso = DSO_new(); | 447 | ctx->dynamic_dso = DSO_new(); |
435 | if(!ctx->DYNAMIC_LIBNAME) | 448 | if (!ctx->DYNAMIC_LIBNAME) { |
436 | { | 449 | if (!ctx->engine_id) |
437 | if(!ctx->engine_id) | ||
438 | return 0; | 450 | return 0; |
439 | ctx->DYNAMIC_LIBNAME = | 451 | ctx->DYNAMIC_LIBNAME = DSO_convert_filename(ctx->dynamic_dso, |
440 | DSO_convert_filename(ctx->dynamic_dso, ctx->engine_id); | 452 | ctx->engine_id); |
441 | } | 453 | } |
442 | if(!int_load(ctx)) | 454 | if (!int_load(ctx)) { |
443 | { | ||
444 | ENGINEerr(ENGINE_F_DYNAMIC_LOAD, | 455 | ENGINEerr(ENGINE_F_DYNAMIC_LOAD, |
445 | ENGINE_R_DSO_NOT_FOUND); | 456 | ENGINE_R_DSO_NOT_FOUND); |
446 | DSO_free(ctx->dynamic_dso); | 457 | DSO_free(ctx->dynamic_dso); |
447 | ctx->dynamic_dso = NULL; | 458 | ctx->dynamic_dso = NULL; |
448 | return 0; | 459 | return 0; |
449 | } | 460 | } |
450 | /* We have to find a bind function otherwise it'll always end badly */ | 461 | /* We have to find a bind function otherwise it'll always end badly */ |
451 | if(!(ctx->bind_engine = (dynamic_bind_engine)DSO_bind_func( | 462 | if (!(ctx->bind_engine = (dynamic_bind_engine)DSO_bind_func( |
452 | ctx->dynamic_dso, ctx->DYNAMIC_F2))) | 463 | ctx->dynamic_dso, ctx->DYNAMIC_F2))) { |
453 | { | ||
454 | ctx->bind_engine = NULL; | 464 | ctx->bind_engine = NULL; |
455 | DSO_free(ctx->dynamic_dso); | 465 | DSO_free(ctx->dynamic_dso); |
456 | ctx->dynamic_dso = NULL; | 466 | ctx->dynamic_dso = NULL; |
457 | ENGINEerr(ENGINE_F_DYNAMIC_LOAD, | 467 | ENGINEerr(ENGINE_F_DYNAMIC_LOAD, |
458 | ENGINE_R_DSO_FAILURE); | 468 | ENGINE_R_DSO_FAILURE); |
459 | return 0; | 469 | return 0; |
460 | } | 470 | } |
461 | /* Do we perform version checking? */ | 471 | /* Do we perform version checking? */ |
462 | if(!ctx->no_vcheck) | 472 | if (!ctx->no_vcheck) { |
463 | { | ||
464 | unsigned long vcheck_res = 0; | 473 | unsigned long vcheck_res = 0; |
465 | /* Now we try to find a version checking function and decide how | 474 | /* Now we try to find a version checking function and decide how |
466 | * to cope with failure if/when it fails. */ | 475 | * to cope with failure if/when it fails. */ |
467 | ctx->v_check = (dynamic_v_check_fn)DSO_bind_func( | 476 | ctx->v_check = (dynamic_v_check_fn)DSO_bind_func( |
468 | ctx->dynamic_dso, ctx->DYNAMIC_F1); | 477 | ctx->dynamic_dso, ctx->DYNAMIC_F1); |
469 | if(ctx->v_check) | 478 | if (ctx->v_check) |
470 | vcheck_res = ctx->v_check(OSSL_DYNAMIC_VERSION); | 479 | vcheck_res = ctx->v_check(OSSL_DYNAMIC_VERSION); |
471 | /* We fail if the version checker veto'd the load *or* if it is | 480 | /* We fail if the version checker veto'd the load *or* if it is |
472 | * deferring to us (by returning its version) and we think it is | 481 | * deferring to us (by returning its version) and we think it is |
473 | * too old. */ | 482 | * too old. */ |
474 | if(vcheck_res < OSSL_DYNAMIC_OLDEST) | 483 | if (vcheck_res < OSSL_DYNAMIC_OLDEST) { |
475 | { | ||
476 | /* Fail */ | 484 | /* Fail */ |
477 | ctx->bind_engine = NULL; | 485 | ctx->bind_engine = NULL; |
478 | ctx->v_check = NULL; | 486 | ctx->v_check = NULL; |
479 | DSO_free(ctx->dynamic_dso); | 487 | DSO_free(ctx->dynamic_dso); |
480 | ctx->dynamic_dso = NULL; | 488 | ctx->dynamic_dso = NULL; |
481 | ENGINEerr(ENGINE_F_DYNAMIC_LOAD, | 489 | ENGINEerr(ENGINE_F_DYNAMIC_LOAD, |
482 | ENGINE_R_VERSION_INCOMPATIBILITY); | 490 | ENGINE_R_VERSION_INCOMPATIBILITY); |
483 | return 0; | 491 | return 0; |
484 | } | ||
485 | } | 492 | } |
493 | } | ||
486 | /* First binary copy the ENGINE structure so that we can roll back if | 494 | /* First binary copy the ENGINE structure so that we can roll back if |
487 | * the hand-over fails */ | 495 | * the hand-over fails */ |
488 | memcpy(&cpy, e, sizeof(ENGINE)); | 496 | memcpy(&cpy, e, sizeof(ENGINE)); |
@@ -495,8 +503,8 @@ static int dynamic_load(ENGINE *e, dynamic_data_ctx *ctx) | |||
495 | fns.err_fns = ERR_get_implementation(); | 503 | fns.err_fns = ERR_get_implementation(); |
496 | fns.ex_data_fns = CRYPTO_get_ex_data_implementation(); | 504 | fns.ex_data_fns = CRYPTO_get_ex_data_implementation(); |
497 | CRYPTO_get_mem_functions(&fns.mem_fns.malloc_cb, | 505 | CRYPTO_get_mem_functions(&fns.mem_fns.malloc_cb, |
498 | &fns.mem_fns.realloc_cb, | 506 | &fns.mem_fns.realloc_cb, |
499 | &fns.mem_fns.free_cb); | 507 | &fns.mem_fns.free_cb); |
500 | fns.lock_fns.lock_locking_cb = CRYPTO_get_locking_callback(); | 508 | fns.lock_fns.lock_locking_cb = CRYPTO_get_locking_callback(); |
501 | fns.lock_fns.lock_add_lock_cb = CRYPTO_get_add_lock_callback(); | 509 | fns.lock_fns.lock_add_lock_cb = CRYPTO_get_add_lock_callback(); |
502 | fns.lock_fns.dynlock_create_cb = CRYPTO_get_dynlock_create_callback(); | 510 | fns.lock_fns.dynlock_create_cb = CRYPTO_get_dynlock_create_callback(); |
@@ -507,37 +515,33 @@ static int dynamic_load(ENGINE *e, dynamic_data_ctx *ctx) | |||
507 | engine_set_all_null(e); | 515 | engine_set_all_null(e); |
508 | 516 | ||
509 | /* Try to bind the ENGINE onto our own ENGINE structure */ | 517 | /* Try to bind the ENGINE onto our own ENGINE structure */ |
510 | if(!ctx->bind_engine(e, ctx->engine_id, &fns)) | 518 | if (!ctx->bind_engine(e, ctx->engine_id, &fns)) { |
511 | { | ||
512 | ctx->bind_engine = NULL; | 519 | ctx->bind_engine = NULL; |
513 | ctx->v_check = NULL; | 520 | ctx->v_check = NULL; |
514 | DSO_free(ctx->dynamic_dso); | 521 | DSO_free(ctx->dynamic_dso); |
515 | ctx->dynamic_dso = NULL; | 522 | ctx->dynamic_dso = NULL; |
516 | ENGINEerr(ENGINE_F_DYNAMIC_LOAD,ENGINE_R_INIT_FAILED); | 523 | ENGINEerr(ENGINE_F_DYNAMIC_LOAD, ENGINE_R_INIT_FAILED); |
517 | /* Copy the original ENGINE structure back */ | 524 | /* Copy the original ENGINE structure back */ |
518 | memcpy(e, &cpy, sizeof(ENGINE)); | 525 | memcpy(e, &cpy, sizeof(ENGINE)); |
519 | return 0; | 526 | return 0; |
520 | } | 527 | } |
521 | /* Do we try to add this ENGINE to the internal list too? */ | 528 | /* Do we try to add this ENGINE to the internal list too? */ |
522 | if(ctx->list_add_value > 0) | 529 | if (ctx->list_add_value > 0) { |
523 | { | 530 | if (!ENGINE_add(e)) { |
524 | if(!ENGINE_add(e)) | ||
525 | { | ||
526 | /* Do we tolerate this or fail? */ | 531 | /* Do we tolerate this or fail? */ |
527 | if(ctx->list_add_value > 1) | 532 | if (ctx->list_add_value > 1) { |
528 | { | ||
529 | /* Fail - NB: By this time, it's too late to | 533 | /* Fail - NB: By this time, it's too late to |
530 | * rollback, and trying to do so allows the | 534 | * rollback, and trying to do so allows the |
531 | * bind_engine() code to have created leaks. We | 535 | * bind_engine() code to have created leaks. We |
532 | * just have to fail where we are, after the | 536 | * just have to fail where we are, after the |
533 | * ENGINE has changed. */ | 537 | * ENGINE has changed. */ |
534 | ENGINEerr(ENGINE_F_DYNAMIC_LOAD, | 538 | ENGINEerr(ENGINE_F_DYNAMIC_LOAD, |
535 | ENGINE_R_CONFLICTING_ENGINE_ID); | 539 | ENGINE_R_CONFLICTING_ENGINE_ID); |
536 | return 0; | 540 | return 0; |
537 | } | 541 | } |
538 | /* Tolerate */ | 542 | /* Tolerate */ |
539 | ERR_clear_error(); | 543 | ERR_clear_error(); |
540 | } | ||
541 | } | 544 | } |
542 | return 1; | ||
543 | } | 545 | } |
546 | return 1; | ||
547 | } | ||
diff --git a/src/lib/libssl/src/crypto/engine/eng_err.c b/src/lib/libssl/src/crypto/engine/eng_err.c index 81c70acfa8..baf2b3d92d 100644 --- a/src/lib/libssl/src/crypto/engine/eng_err.c +++ b/src/lib/libssl/src/crypto/engine/eng_err.c | |||
@@ -7,7 +7,7 @@ | |||
7 | * are met: | 7 | * are met: |
8 | * | 8 | * |
9 | * 1. Redistributions of source code must retain the above copyright | 9 | * 1. Redistributions of source code must retain the above copyright |
10 | * notice, this list of conditions and the following disclaimer. | 10 | * notice, this list of conditions and the following disclaimer. |
11 | * | 11 | * |
12 | * 2. Redistributions in binary form must reproduce the above copyright | 12 | * 2. Redistributions in binary form must reproduce the above copyright |
13 | * notice, this list of conditions and the following disclaimer in | 13 | * notice, this list of conditions and the following disclaimer in |
@@ -68,106 +68,103 @@ | |||
68 | #define ERR_FUNC(func) ERR_PACK(ERR_LIB_ENGINE,func,0) | 68 | #define ERR_FUNC(func) ERR_PACK(ERR_LIB_ENGINE,func,0) |
69 | #define ERR_REASON(reason) ERR_PACK(ERR_LIB_ENGINE,0,reason) | 69 | #define ERR_REASON(reason) ERR_PACK(ERR_LIB_ENGINE,0,reason) |
70 | 70 | ||
71 | static ERR_STRING_DATA ENGINE_str_functs[]= | 71 | static ERR_STRING_DATA ENGINE_str_functs[]= { |
72 | { | 72 | {ERR_FUNC(ENGINE_F_DYNAMIC_CTRL), "DYNAMIC_CTRL"}, |
73 | {ERR_FUNC(ENGINE_F_DYNAMIC_CTRL), "DYNAMIC_CTRL"}, | 73 | {ERR_FUNC(ENGINE_F_DYNAMIC_GET_DATA_CTX), "DYNAMIC_GET_DATA_CTX"}, |
74 | {ERR_FUNC(ENGINE_F_DYNAMIC_GET_DATA_CTX), "DYNAMIC_GET_DATA_CTX"}, | 74 | {ERR_FUNC(ENGINE_F_DYNAMIC_LOAD), "DYNAMIC_LOAD"}, |
75 | {ERR_FUNC(ENGINE_F_DYNAMIC_LOAD), "DYNAMIC_LOAD"}, | 75 | {ERR_FUNC(ENGINE_F_DYNAMIC_SET_DATA_CTX), "DYNAMIC_SET_DATA_CTX"}, |
76 | {ERR_FUNC(ENGINE_F_DYNAMIC_SET_DATA_CTX), "DYNAMIC_SET_DATA_CTX"}, | 76 | {ERR_FUNC(ENGINE_F_ENGINE_ADD), "ENGINE_add"}, |
77 | {ERR_FUNC(ENGINE_F_ENGINE_ADD), "ENGINE_add"}, | 77 | {ERR_FUNC(ENGINE_F_ENGINE_BY_ID), "ENGINE_by_id"}, |
78 | {ERR_FUNC(ENGINE_F_ENGINE_BY_ID), "ENGINE_by_id"}, | 78 | {ERR_FUNC(ENGINE_F_ENGINE_CMD_IS_EXECUTABLE), "ENGINE_cmd_is_executable"}, |
79 | {ERR_FUNC(ENGINE_F_ENGINE_CMD_IS_EXECUTABLE), "ENGINE_cmd_is_executable"}, | 79 | {ERR_FUNC(ENGINE_F_ENGINE_CTRL), "ENGINE_ctrl"}, |
80 | {ERR_FUNC(ENGINE_F_ENGINE_CTRL), "ENGINE_ctrl"}, | 80 | {ERR_FUNC(ENGINE_F_ENGINE_CTRL_CMD), "ENGINE_ctrl_cmd"}, |
81 | {ERR_FUNC(ENGINE_F_ENGINE_CTRL_CMD), "ENGINE_ctrl_cmd"}, | 81 | {ERR_FUNC(ENGINE_F_ENGINE_CTRL_CMD_STRING), "ENGINE_ctrl_cmd_string"}, |
82 | {ERR_FUNC(ENGINE_F_ENGINE_CTRL_CMD_STRING), "ENGINE_ctrl_cmd_string"}, | 82 | {ERR_FUNC(ENGINE_F_ENGINE_FINISH), "ENGINE_finish"}, |
83 | {ERR_FUNC(ENGINE_F_ENGINE_FINISH), "ENGINE_finish"}, | 83 | {ERR_FUNC(ENGINE_F_ENGINE_FREE_UTIL), "ENGINE_FREE_UTIL"}, |
84 | {ERR_FUNC(ENGINE_F_ENGINE_FREE_UTIL), "ENGINE_FREE_UTIL"}, | 84 | {ERR_FUNC(ENGINE_F_ENGINE_GET_CIPHER), "ENGINE_get_cipher"}, |
85 | {ERR_FUNC(ENGINE_F_ENGINE_GET_CIPHER), "ENGINE_get_cipher"}, | 85 | {ERR_FUNC(ENGINE_F_ENGINE_GET_DEFAULT_TYPE), "ENGINE_GET_DEFAULT_TYPE"}, |
86 | {ERR_FUNC(ENGINE_F_ENGINE_GET_DEFAULT_TYPE), "ENGINE_GET_DEFAULT_TYPE"}, | 86 | {ERR_FUNC(ENGINE_F_ENGINE_GET_DIGEST), "ENGINE_get_digest"}, |
87 | {ERR_FUNC(ENGINE_F_ENGINE_GET_DIGEST), "ENGINE_get_digest"}, | 87 | {ERR_FUNC(ENGINE_F_ENGINE_GET_NEXT), "ENGINE_get_next"}, |
88 | {ERR_FUNC(ENGINE_F_ENGINE_GET_NEXT), "ENGINE_get_next"}, | 88 | {ERR_FUNC(ENGINE_F_ENGINE_GET_PKEY_ASN1_METH), "ENGINE_get_pkey_asn1_meth"}, |
89 | {ERR_FUNC(ENGINE_F_ENGINE_GET_PKEY_ASN1_METH), "ENGINE_get_pkey_asn1_meth"}, | 89 | {ERR_FUNC(ENGINE_F_ENGINE_GET_PKEY_METH), "ENGINE_get_pkey_meth"}, |
90 | {ERR_FUNC(ENGINE_F_ENGINE_GET_PKEY_METH), "ENGINE_get_pkey_meth"}, | 90 | {ERR_FUNC(ENGINE_F_ENGINE_GET_PREV), "ENGINE_get_prev"}, |
91 | {ERR_FUNC(ENGINE_F_ENGINE_GET_PREV), "ENGINE_get_prev"}, | 91 | {ERR_FUNC(ENGINE_F_ENGINE_INIT), "ENGINE_init"}, |
92 | {ERR_FUNC(ENGINE_F_ENGINE_INIT), "ENGINE_init"}, | 92 | {ERR_FUNC(ENGINE_F_ENGINE_LIST_ADD), "ENGINE_LIST_ADD"}, |
93 | {ERR_FUNC(ENGINE_F_ENGINE_LIST_ADD), "ENGINE_LIST_ADD"}, | 93 | {ERR_FUNC(ENGINE_F_ENGINE_LIST_REMOVE), "ENGINE_LIST_REMOVE"}, |
94 | {ERR_FUNC(ENGINE_F_ENGINE_LIST_REMOVE), "ENGINE_LIST_REMOVE"}, | 94 | {ERR_FUNC(ENGINE_F_ENGINE_LOAD_PRIVATE_KEY), "ENGINE_load_private_key"}, |
95 | {ERR_FUNC(ENGINE_F_ENGINE_LOAD_PRIVATE_KEY), "ENGINE_load_private_key"}, | 95 | {ERR_FUNC(ENGINE_F_ENGINE_LOAD_PUBLIC_KEY), "ENGINE_load_public_key"}, |
96 | {ERR_FUNC(ENGINE_F_ENGINE_LOAD_PUBLIC_KEY), "ENGINE_load_public_key"}, | 96 | {ERR_FUNC(ENGINE_F_ENGINE_LOAD_SSL_CLIENT_CERT), "ENGINE_load_ssl_client_cert"}, |
97 | {ERR_FUNC(ENGINE_F_ENGINE_LOAD_SSL_CLIENT_CERT), "ENGINE_load_ssl_client_cert"}, | 97 | {ERR_FUNC(ENGINE_F_ENGINE_NEW), "ENGINE_new"}, |
98 | {ERR_FUNC(ENGINE_F_ENGINE_NEW), "ENGINE_new"}, | 98 | {ERR_FUNC(ENGINE_F_ENGINE_REMOVE), "ENGINE_remove"}, |
99 | {ERR_FUNC(ENGINE_F_ENGINE_REMOVE), "ENGINE_remove"}, | 99 | {ERR_FUNC(ENGINE_F_ENGINE_SET_DEFAULT_STRING), "ENGINE_set_default_string"}, |
100 | {ERR_FUNC(ENGINE_F_ENGINE_SET_DEFAULT_STRING), "ENGINE_set_default_string"}, | 100 | {ERR_FUNC(ENGINE_F_ENGINE_SET_DEFAULT_TYPE), "ENGINE_SET_DEFAULT_TYPE"}, |
101 | {ERR_FUNC(ENGINE_F_ENGINE_SET_DEFAULT_TYPE), "ENGINE_SET_DEFAULT_TYPE"}, | 101 | {ERR_FUNC(ENGINE_F_ENGINE_SET_ID), "ENGINE_set_id"}, |
102 | {ERR_FUNC(ENGINE_F_ENGINE_SET_ID), "ENGINE_set_id"}, | 102 | {ERR_FUNC(ENGINE_F_ENGINE_SET_NAME), "ENGINE_set_name"}, |
103 | {ERR_FUNC(ENGINE_F_ENGINE_SET_NAME), "ENGINE_set_name"}, | 103 | {ERR_FUNC(ENGINE_F_ENGINE_TABLE_REGISTER), "ENGINE_TABLE_REGISTER"}, |
104 | {ERR_FUNC(ENGINE_F_ENGINE_TABLE_REGISTER), "ENGINE_TABLE_REGISTER"}, | 104 | {ERR_FUNC(ENGINE_F_ENGINE_UNLOAD_KEY), "ENGINE_UNLOAD_KEY"}, |
105 | {ERR_FUNC(ENGINE_F_ENGINE_UNLOAD_KEY), "ENGINE_UNLOAD_KEY"}, | 105 | {ERR_FUNC(ENGINE_F_ENGINE_UNLOCKED_FINISH), "ENGINE_UNLOCKED_FINISH"}, |
106 | {ERR_FUNC(ENGINE_F_ENGINE_UNLOCKED_FINISH), "ENGINE_UNLOCKED_FINISH"}, | 106 | {ERR_FUNC(ENGINE_F_ENGINE_UP_REF), "ENGINE_up_ref"}, |
107 | {ERR_FUNC(ENGINE_F_ENGINE_UP_REF), "ENGINE_up_ref"}, | 107 | {ERR_FUNC(ENGINE_F_INT_CTRL_HELPER), "INT_CTRL_HELPER"}, |
108 | {ERR_FUNC(ENGINE_F_INT_CTRL_HELPER), "INT_CTRL_HELPER"}, | 108 | {ERR_FUNC(ENGINE_F_INT_ENGINE_CONFIGURE), "INT_ENGINE_CONFIGURE"}, |
109 | {ERR_FUNC(ENGINE_F_INT_ENGINE_CONFIGURE), "INT_ENGINE_CONFIGURE"}, | 109 | {ERR_FUNC(ENGINE_F_INT_ENGINE_MODULE_INIT), "INT_ENGINE_MODULE_INIT"}, |
110 | {ERR_FUNC(ENGINE_F_INT_ENGINE_MODULE_INIT), "INT_ENGINE_MODULE_INIT"}, | 110 | {ERR_FUNC(ENGINE_F_LOG_MESSAGE), "LOG_MESSAGE"}, |
111 | {ERR_FUNC(ENGINE_F_LOG_MESSAGE), "LOG_MESSAGE"}, | 111 | {0, NULL} |
112 | {0,NULL} | 112 | }; |
113 | }; | ||
114 | 113 | ||
115 | static ERR_STRING_DATA ENGINE_str_reasons[]= | 114 | static ERR_STRING_DATA ENGINE_str_reasons[]= { |
116 | { | 115 | {ERR_REASON(ENGINE_R_ALREADY_LOADED) , "already loaded"}, |
117 | {ERR_REASON(ENGINE_R_ALREADY_LOADED) ,"already loaded"}, | 116 | {ERR_REASON(ENGINE_R_ARGUMENT_IS_NOT_A_NUMBER), "argument is not a number"}, |
118 | {ERR_REASON(ENGINE_R_ARGUMENT_IS_NOT_A_NUMBER),"argument is not a number"}, | 117 | {ERR_REASON(ENGINE_R_CMD_NOT_EXECUTABLE) , "cmd not executable"}, |
119 | {ERR_REASON(ENGINE_R_CMD_NOT_EXECUTABLE) ,"cmd not executable"}, | 118 | {ERR_REASON(ENGINE_R_COMMAND_TAKES_INPUT), "command takes input"}, |
120 | {ERR_REASON(ENGINE_R_COMMAND_TAKES_INPUT),"command takes input"}, | 119 | {ERR_REASON(ENGINE_R_COMMAND_TAKES_NO_INPUT), "command takes no input"}, |
121 | {ERR_REASON(ENGINE_R_COMMAND_TAKES_NO_INPUT),"command takes no input"}, | 120 | {ERR_REASON(ENGINE_R_CONFLICTING_ENGINE_ID), "conflicting engine id"}, |
122 | {ERR_REASON(ENGINE_R_CONFLICTING_ENGINE_ID),"conflicting engine id"}, | 121 | {ERR_REASON(ENGINE_R_CTRL_COMMAND_NOT_IMPLEMENTED), "ctrl command not implemented"}, |
123 | {ERR_REASON(ENGINE_R_CTRL_COMMAND_NOT_IMPLEMENTED),"ctrl command not implemented"}, | 122 | {ERR_REASON(ENGINE_R_DH_NOT_IMPLEMENTED) , "dh not implemented"}, |
124 | {ERR_REASON(ENGINE_R_DH_NOT_IMPLEMENTED) ,"dh not implemented"}, | 123 | {ERR_REASON(ENGINE_R_DSA_NOT_IMPLEMENTED), "dsa not implemented"}, |
125 | {ERR_REASON(ENGINE_R_DSA_NOT_IMPLEMENTED),"dsa not implemented"}, | 124 | {ERR_REASON(ENGINE_R_DSO_FAILURE) , "DSO failure"}, |
126 | {ERR_REASON(ENGINE_R_DSO_FAILURE) ,"DSO failure"}, | 125 | {ERR_REASON(ENGINE_R_DSO_NOT_FOUND) , "dso not found"}, |
127 | {ERR_REASON(ENGINE_R_DSO_NOT_FOUND) ,"dso not found"}, | 126 | {ERR_REASON(ENGINE_R_ENGINES_SECTION_ERROR), "engines section error"}, |
128 | {ERR_REASON(ENGINE_R_ENGINES_SECTION_ERROR),"engines section error"}, | 127 | {ERR_REASON(ENGINE_R_ENGINE_CONFIGURATION_ERROR), "engine configuration error"}, |
129 | {ERR_REASON(ENGINE_R_ENGINE_CONFIGURATION_ERROR),"engine configuration error"}, | 128 | {ERR_REASON(ENGINE_R_ENGINE_IS_NOT_IN_LIST), "engine is not in the list"}, |
130 | {ERR_REASON(ENGINE_R_ENGINE_IS_NOT_IN_LIST),"engine is not in the list"}, | 129 | {ERR_REASON(ENGINE_R_ENGINE_SECTION_ERROR), "engine section error"}, |
131 | {ERR_REASON(ENGINE_R_ENGINE_SECTION_ERROR),"engine section error"}, | 130 | {ERR_REASON(ENGINE_R_FAILED_LOADING_PRIVATE_KEY), "failed loading private key"}, |
132 | {ERR_REASON(ENGINE_R_FAILED_LOADING_PRIVATE_KEY),"failed loading private key"}, | 131 | {ERR_REASON(ENGINE_R_FAILED_LOADING_PUBLIC_KEY), "failed loading public key"}, |
133 | {ERR_REASON(ENGINE_R_FAILED_LOADING_PUBLIC_KEY),"failed loading public key"}, | 132 | {ERR_REASON(ENGINE_R_FINISH_FAILED) , "finish failed"}, |
134 | {ERR_REASON(ENGINE_R_FINISH_FAILED) ,"finish failed"}, | 133 | {ERR_REASON(ENGINE_R_GET_HANDLE_FAILED) , "could not obtain hardware handle"}, |
135 | {ERR_REASON(ENGINE_R_GET_HANDLE_FAILED) ,"could not obtain hardware handle"}, | 134 | {ERR_REASON(ENGINE_R_ID_OR_NAME_MISSING) , "'id' or 'name' missing"}, |
136 | {ERR_REASON(ENGINE_R_ID_OR_NAME_MISSING) ,"'id' or 'name' missing"}, | 135 | {ERR_REASON(ENGINE_R_INIT_FAILED) , "init failed"}, |
137 | {ERR_REASON(ENGINE_R_INIT_FAILED) ,"init failed"}, | 136 | {ERR_REASON(ENGINE_R_INTERNAL_LIST_ERROR), "internal list error"}, |
138 | {ERR_REASON(ENGINE_R_INTERNAL_LIST_ERROR),"internal list error"}, | 137 | {ERR_REASON(ENGINE_R_INVALID_ARGUMENT) , "invalid argument"}, |
139 | {ERR_REASON(ENGINE_R_INVALID_ARGUMENT) ,"invalid argument"}, | 138 | {ERR_REASON(ENGINE_R_INVALID_CMD_NAME) , "invalid cmd name"}, |
140 | {ERR_REASON(ENGINE_R_INVALID_CMD_NAME) ,"invalid cmd name"}, | 139 | {ERR_REASON(ENGINE_R_INVALID_CMD_NUMBER) , "invalid cmd number"}, |
141 | {ERR_REASON(ENGINE_R_INVALID_CMD_NUMBER) ,"invalid cmd number"}, | 140 | {ERR_REASON(ENGINE_R_INVALID_INIT_VALUE) , "invalid init value"}, |
142 | {ERR_REASON(ENGINE_R_INVALID_INIT_VALUE) ,"invalid init value"}, | 141 | {ERR_REASON(ENGINE_R_INVALID_STRING) , "invalid string"}, |
143 | {ERR_REASON(ENGINE_R_INVALID_STRING) ,"invalid string"}, | 142 | {ERR_REASON(ENGINE_R_NOT_INITIALISED) , "not initialised"}, |
144 | {ERR_REASON(ENGINE_R_NOT_INITIALISED) ,"not initialised"}, | 143 | {ERR_REASON(ENGINE_R_NOT_LOADED) , "not loaded"}, |
145 | {ERR_REASON(ENGINE_R_NOT_LOADED) ,"not loaded"}, | 144 | {ERR_REASON(ENGINE_R_NO_CONTROL_FUNCTION), "no control function"}, |
146 | {ERR_REASON(ENGINE_R_NO_CONTROL_FUNCTION),"no control function"}, | 145 | {ERR_REASON(ENGINE_R_NO_INDEX) , "no index"}, |
147 | {ERR_REASON(ENGINE_R_NO_INDEX) ,"no index"}, | 146 | {ERR_REASON(ENGINE_R_NO_LOAD_FUNCTION) , "no load function"}, |
148 | {ERR_REASON(ENGINE_R_NO_LOAD_FUNCTION) ,"no load function"}, | 147 | {ERR_REASON(ENGINE_R_NO_REFERENCE) , "no reference"}, |
149 | {ERR_REASON(ENGINE_R_NO_REFERENCE) ,"no reference"}, | 148 | {ERR_REASON(ENGINE_R_NO_SUCH_ENGINE) , "no such engine"}, |
150 | {ERR_REASON(ENGINE_R_NO_SUCH_ENGINE) ,"no such engine"}, | 149 | {ERR_REASON(ENGINE_R_NO_UNLOAD_FUNCTION) , "no unload function"}, |
151 | {ERR_REASON(ENGINE_R_NO_UNLOAD_FUNCTION) ,"no unload function"}, | 150 | {ERR_REASON(ENGINE_R_PROVIDE_PARAMETERS) , "provide parameters"}, |
152 | {ERR_REASON(ENGINE_R_PROVIDE_PARAMETERS) ,"provide parameters"}, | 151 | {ERR_REASON(ENGINE_R_RSA_NOT_IMPLEMENTED), "rsa not implemented"}, |
153 | {ERR_REASON(ENGINE_R_RSA_NOT_IMPLEMENTED),"rsa not implemented"}, | 152 | {ERR_REASON(ENGINE_R_UNIMPLEMENTED_CIPHER), "unimplemented cipher"}, |
154 | {ERR_REASON(ENGINE_R_UNIMPLEMENTED_CIPHER),"unimplemented cipher"}, | 153 | {ERR_REASON(ENGINE_R_UNIMPLEMENTED_DIGEST), "unimplemented digest"}, |
155 | {ERR_REASON(ENGINE_R_UNIMPLEMENTED_DIGEST),"unimplemented digest"}, | 154 | {ERR_REASON(ENGINE_R_UNIMPLEMENTED_PUBLIC_KEY_METHOD), "unimplemented public key method"}, |
156 | {ERR_REASON(ENGINE_R_UNIMPLEMENTED_PUBLIC_KEY_METHOD),"unimplemented public key method"}, | 155 | {ERR_REASON(ENGINE_R_VERSION_INCOMPATIBILITY), "version incompatibility"}, |
157 | {ERR_REASON(ENGINE_R_VERSION_INCOMPATIBILITY),"version incompatibility"}, | 156 | {0, NULL} |
158 | {0,NULL} | 157 | }; |
159 | }; | ||
160 | 158 | ||
161 | #endif | 159 | #endif |
162 | 160 | ||
163 | void ERR_load_ENGINE_strings(void) | 161 | void |
164 | { | 162 | ERR_load_ENGINE_strings(void) |
163 | { | ||
165 | #ifndef OPENSSL_NO_ERR | 164 | #ifndef OPENSSL_NO_ERR |
166 | 165 | if (ERR_func_error_string(ENGINE_str_functs[0].error) == NULL) { | |
167 | if (ERR_func_error_string(ENGINE_str_functs[0].error) == NULL) | 166 | ERR_load_strings(0, ENGINE_str_functs); |
168 | { | 167 | ERR_load_strings(0, ENGINE_str_reasons); |
169 | ERR_load_strings(0,ENGINE_str_functs); | ||
170 | ERR_load_strings(0,ENGINE_str_reasons); | ||
171 | } | ||
172 | #endif | ||
173 | } | 168 | } |
169 | #endif | ||
170 | } | ||
diff --git a/src/lib/libssl/src/crypto/engine/eng_fat.c b/src/lib/libssl/src/crypto/engine/eng_fat.c index e01067566e..f5ad01b80e 100644 --- a/src/lib/libssl/src/crypto/engine/eng_fat.c +++ b/src/lib/libssl/src/crypto/engine/eng_fat.c | |||
@@ -7,7 +7,7 @@ | |||
7 | * are met: | 7 | * are met: |
8 | * | 8 | * |
9 | * 1. Redistributions of source code must retain the above copyright | 9 | * 1. Redistributions of source code must retain the above copyright |
10 | * notice, this list of conditions and the following disclaimer. | 10 | * notice, this list of conditions and the following disclaimer. |
11 | * | 11 | * |
12 | * 2. Redistributions in binary form must reproduce the above copyright | 12 | * 2. Redistributions in binary form must reproduce the above copyright |
13 | * notice, this list of conditions and the following disclaimer in | 13 | * notice, this list of conditions and the following disclaimer in |
@@ -54,55 +54,58 @@ | |||
54 | */ | 54 | */ |
55 | /* ==================================================================== | 55 | /* ==================================================================== |
56 | * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED. | 56 | * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED. |
57 | * ECDH support in OpenSSL originally developed by | 57 | * ECDH support in OpenSSL originally developed by |
58 | * SUN MICROSYSTEMS, INC., and contributed to the OpenSSL project. | 58 | * SUN MICROSYSTEMS, INC., and contributed to the OpenSSL project. |
59 | */ | 59 | */ |
60 | 60 | ||
61 | #include "eng_int.h" | 61 | #include "eng_int.h" |
62 | #include <openssl/conf.h> | 62 | #include <openssl/conf.h> |
63 | 63 | ||
64 | int ENGINE_set_default(ENGINE *e, unsigned int flags) | 64 | int |
65 | { | 65 | ENGINE_set_default(ENGINE *e, unsigned int flags) |
66 | if((flags & ENGINE_METHOD_CIPHERS) && !ENGINE_set_default_ciphers(e)) | 66 | { |
67 | if ((flags & ENGINE_METHOD_CIPHERS) && !ENGINE_set_default_ciphers(e)) | ||
67 | return 0; | 68 | return 0; |
68 | if((flags & ENGINE_METHOD_DIGESTS) && !ENGINE_set_default_digests(e)) | 69 | if ((flags & ENGINE_METHOD_DIGESTS) && !ENGINE_set_default_digests(e)) |
69 | return 0; | 70 | return 0; |
70 | #ifndef OPENSSL_NO_RSA | 71 | #ifndef OPENSSL_NO_RSA |
71 | if((flags & ENGINE_METHOD_RSA) && !ENGINE_set_default_RSA(e)) | 72 | if ((flags & ENGINE_METHOD_RSA) && !ENGINE_set_default_RSA(e)) |
72 | return 0; | 73 | return 0; |
73 | #endif | 74 | #endif |
74 | #ifndef OPENSSL_NO_DSA | 75 | #ifndef OPENSSL_NO_DSA |
75 | if((flags & ENGINE_METHOD_DSA) && !ENGINE_set_default_DSA(e)) | 76 | if ((flags & ENGINE_METHOD_DSA) && !ENGINE_set_default_DSA(e)) |
76 | return 0; | 77 | return 0; |
77 | #endif | 78 | #endif |
78 | #ifndef OPENSSL_NO_DH | 79 | #ifndef OPENSSL_NO_DH |
79 | if((flags & ENGINE_METHOD_DH) && !ENGINE_set_default_DH(e)) | 80 | if ((flags & ENGINE_METHOD_DH) && !ENGINE_set_default_DH(e)) |
80 | return 0; | 81 | return 0; |
81 | #endif | 82 | #endif |
82 | #ifndef OPENSSL_NO_ECDH | 83 | #ifndef OPENSSL_NO_ECDH |
83 | if((flags & ENGINE_METHOD_ECDH) && !ENGINE_set_default_ECDH(e)) | 84 | if ((flags & ENGINE_METHOD_ECDH) && !ENGINE_set_default_ECDH(e)) |
84 | return 0; | 85 | return 0; |
85 | #endif | 86 | #endif |
86 | #ifndef OPENSSL_NO_ECDSA | 87 | #ifndef OPENSSL_NO_ECDSA |
87 | if((flags & ENGINE_METHOD_ECDSA) && !ENGINE_set_default_ECDSA(e)) | 88 | if ((flags & ENGINE_METHOD_ECDSA) && !ENGINE_set_default_ECDSA(e)) |
88 | return 0; | 89 | return 0; |
89 | #endif | 90 | #endif |
90 | if((flags & ENGINE_METHOD_RAND) && !ENGINE_set_default_RAND(e)) | 91 | if ((flags & ENGINE_METHOD_RAND) && !ENGINE_set_default_RAND(e)) |
91 | return 0; | 92 | return 0; |
92 | if((flags & ENGINE_METHOD_PKEY_METHS) | 93 | if ((flags & ENGINE_METHOD_PKEY_METHS) && |
93 | && !ENGINE_set_default_pkey_meths(e)) | 94 | !ENGINE_set_default_pkey_meths(e)) |
94 | return 0; | 95 | return 0; |
95 | if((flags & ENGINE_METHOD_PKEY_ASN1_METHS) | 96 | if ((flags & ENGINE_METHOD_PKEY_ASN1_METHS) && |
96 | && !ENGINE_set_default_pkey_asn1_meths(e)) | 97 | !ENGINE_set_default_pkey_asn1_meths(e)) |
97 | return 0; | 98 | return 0; |
98 | return 1; | 99 | return 1; |
99 | } | 100 | } |
100 | 101 | ||
101 | /* Set default algorithms using a string */ | 102 | /* Set default algorithms using a string */ |
102 | 103 | ||
103 | static int int_def_cb(const char *alg, int len, void *arg) | 104 | static int |
104 | { | 105 | int_def_cb(const char *alg, int len, void *arg) |
106 | { | ||
105 | unsigned int *pflags = arg; | 107 | unsigned int *pflags = arg; |
108 | |||
106 | if (!strncmp(alg, "ALL", len)) | 109 | if (!strncmp(alg, "ALL", len)) |
107 | *pflags |= ENGINE_METHOD_ALL; | 110 | *pflags |= ENGINE_METHOD_ALL; |
108 | else if (!strncmp(alg, "RSA", len)) | 111 | else if (!strncmp(alg, "RSA", len)) |
@@ -123,7 +126,7 @@ static int int_def_cb(const char *alg, int len, void *arg) | |||
123 | *pflags |= ENGINE_METHOD_DIGESTS; | 126 | *pflags |= ENGINE_METHOD_DIGESTS; |
124 | else if (!strncmp(alg, "PKEY", len)) | 127 | else if (!strncmp(alg, "PKEY", len)) |
125 | *pflags |= | 128 | *pflags |= |
126 | ENGINE_METHOD_PKEY_METHS|ENGINE_METHOD_PKEY_ASN1_METHS; | 129 | ENGINE_METHOD_PKEY_METHS|ENGINE_METHOD_PKEY_ASN1_METHS; |
127 | else if (!strncmp(alg, "PKEY_CRYPTO", len)) | 130 | else if (!strncmp(alg, "PKEY_CRYPTO", len)) |
128 | *pflags |= ENGINE_METHOD_PKEY_METHS; | 131 | *pflags |= ENGINE_METHOD_PKEY_METHS; |
129 | else if (!strncmp(alg, "PKEY_ASN1", len)) | 132 | else if (!strncmp(alg, "PKEY_ASN1", len)) |
@@ -131,24 +134,25 @@ static int int_def_cb(const char *alg, int len, void *arg) | |||
131 | else | 134 | else |
132 | return 0; | 135 | return 0; |
133 | return 1; | 136 | return 1; |
134 | } | 137 | } |
135 | 138 | ||
136 | 139 | int | |
137 | int ENGINE_set_default_string(ENGINE *e, const char *def_list) | 140 | ENGINE_set_default_string(ENGINE *e, const char *def_list) |
138 | { | 141 | { |
139 | unsigned int flags = 0; | 142 | unsigned int flags = 0; |
140 | if (!CONF_parse_list(def_list, ',', 1, int_def_cb, &flags)) | 143 | |
141 | { | 144 | if (!CONF_parse_list(def_list, ',', 1, int_def_cb, &flags)) { |
142 | ENGINEerr(ENGINE_F_ENGINE_SET_DEFAULT_STRING, | 145 | ENGINEerr(ENGINE_F_ENGINE_SET_DEFAULT_STRING, |
143 | ENGINE_R_INVALID_STRING); | 146 | ENGINE_R_INVALID_STRING); |
144 | ERR_asprintf_error_data("str=%s",def_list); | 147 | ERR_asprintf_error_data("str=%s",def_list); |
145 | return 0; | 148 | return 0; |
146 | } | ||
147 | return ENGINE_set_default(e, flags); | ||
148 | } | 149 | } |
150 | return ENGINE_set_default(e, flags); | ||
151 | } | ||
149 | 152 | ||
150 | int ENGINE_register_complete(ENGINE *e) | 153 | int |
151 | { | 154 | ENGINE_register_complete(ENGINE *e) |
155 | { | ||
152 | ENGINE_register_ciphers(e); | 156 | ENGINE_register_ciphers(e); |
153 | ENGINE_register_digests(e); | 157 | ENGINE_register_digests(e); |
154 | #ifndef OPENSSL_NO_RSA | 158 | #ifndef OPENSSL_NO_RSA |
@@ -169,14 +173,15 @@ int ENGINE_register_complete(ENGINE *e) | |||
169 | ENGINE_register_RAND(e); | 173 | ENGINE_register_RAND(e); |
170 | ENGINE_register_pkey_meths(e); | 174 | ENGINE_register_pkey_meths(e); |
171 | return 1; | 175 | return 1; |
172 | } | 176 | } |
173 | 177 | ||
174 | int ENGINE_register_all_complete(void) | 178 | int |
175 | { | 179 | ENGINE_register_all_complete(void) |
180 | { | ||
176 | ENGINE *e; | 181 | ENGINE *e; |
177 | 182 | ||
178 | for(e=ENGINE_get_first() ; e ; e=ENGINE_get_next(e)) | 183 | for (e = ENGINE_get_first(); e; e = ENGINE_get_next(e)) |
179 | if (!(e->flags & ENGINE_FLAGS_NO_REGISTER_ALL)) | 184 | if (!(e->flags & ENGINE_FLAGS_NO_REGISTER_ALL)) |
180 | ENGINE_register_complete(e); | 185 | ENGINE_register_complete(e); |
181 | return 1; | 186 | return 1; |
182 | } | 187 | } |
diff --git a/src/lib/libssl/src/crypto/engine/eng_init.c b/src/lib/libssl/src/crypto/engine/eng_init.c index 870c456668..540f8957ca 100644 --- a/src/lib/libssl/src/crypto/engine/eng_init.c +++ b/src/lib/libssl/src/crypto/engine/eng_init.c | |||
@@ -7,7 +7,7 @@ | |||
7 | * are met: | 7 | * are met: |
8 | * | 8 | * |
9 | * 1. Redistributions of source code must retain the above copyright | 9 | * 1. Redistributions of source code must retain the above copyright |
10 | * notice, this list of conditions and the following disclaimer. | 10 | * notice, this list of conditions and the following disclaimer. |
11 | * | 11 | * |
12 | * 2. Redistributions in binary form must reproduce the above copyright | 12 | * 2. Redistributions in binary form must reproduce the above copyright |
13 | * notice, this list of conditions and the following disclaimer in | 13 | * notice, this list of conditions and the following disclaimer in |
@@ -57,30 +57,31 @@ | |||
57 | 57 | ||
58 | /* Initialise a engine type for use (or up its functional reference count | 58 | /* Initialise a engine type for use (or up its functional reference count |
59 | * if it's already in use). This version is only used internally. */ | 59 | * if it's already in use). This version is only used internally. */ |
60 | int engine_unlocked_init(ENGINE *e) | 60 | int |
61 | { | 61 | engine_unlocked_init(ENGINE *e) |
62 | { | ||
62 | int to_return = 1; | 63 | int to_return = 1; |
63 | 64 | ||
64 | if((e->funct_ref == 0) && e->init) | 65 | if ((e->funct_ref == 0) && e->init) |
65 | /* This is the first functional reference and the engine | 66 | /* This is the first functional reference and the engine |
66 | * requires initialisation so we do it now. */ | 67 | * requires initialisation so we do it now. */ |
67 | to_return = e->init(e); | 68 | to_return = e->init(e); |
68 | if(to_return) | 69 | if (to_return) { |
69 | { | ||
70 | /* OK, we return a functional reference which is also a | 70 | /* OK, we return a functional reference which is also a |
71 | * structural reference. */ | 71 | * structural reference. */ |
72 | e->struct_ref++; | 72 | e->struct_ref++; |
73 | e->funct_ref++; | 73 | e->funct_ref++; |
74 | engine_ref_debug(e, 0, 1) | 74 | engine_ref_debug(e, 0, 1) |
75 | engine_ref_debug(e, 1, 1) | 75 | engine_ref_debug(e, 1, 1) |
76 | } | ||
77 | return to_return; | ||
78 | } | 76 | } |
77 | return to_return; | ||
78 | } | ||
79 | 79 | ||
80 | /* Free a functional reference to a engine type. This version is only used | 80 | /* Free a functional reference to a engine type. This version is only used |
81 | * internally. */ | 81 | * internally. */ |
82 | int engine_unlocked_finish(ENGINE *e, int unlock_for_handlers) | 82 | int |
83 | { | 83 | engine_unlocked_finish(ENGINE *e, int unlock_for_handlers) |
84 | { | ||
84 | int to_return = 1; | 85 | int to_return = 1; |
85 | 86 | ||
86 | /* Reduce the functional reference count here so if it's the terminating | 87 | /* Reduce the functional reference count here so if it's the terminating |
@@ -91,58 +92,57 @@ int engine_unlocked_finish(ENGINE *e, int unlock_for_handlers) | |||
91 | * 2 to 0 without either calling finish(). */ | 92 | * 2 to 0 without either calling finish(). */ |
92 | e->funct_ref--; | 93 | e->funct_ref--; |
93 | engine_ref_debug(e, 1, -1); | 94 | engine_ref_debug(e, 1, -1); |
94 | if((e->funct_ref == 0) && e->finish) | 95 | if ((e->funct_ref == 0) && e->finish) { |
95 | { | 96 | if (unlock_for_handlers) |
96 | if(unlock_for_handlers) | ||
97 | CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE); | 97 | CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE); |
98 | to_return = e->finish(e); | 98 | to_return = e->finish(e); |
99 | if(unlock_for_handlers) | 99 | if (unlock_for_handlers) |
100 | CRYPTO_w_lock(CRYPTO_LOCK_ENGINE); | 100 | CRYPTO_w_lock(CRYPTO_LOCK_ENGINE); |
101 | if(!to_return) | 101 | if (!to_return) |
102 | return 0; | 102 | return 0; |
103 | } | 103 | } |
104 | 104 | ||
105 | /* Release the structural reference too */ | 105 | /* Release the structural reference too */ |
106 | if(!engine_free_util(e, 0)) | 106 | if (!engine_free_util(e, 0)) { |
107 | { | 107 | ENGINEerr(ENGINE_F_ENGINE_UNLOCKED_FINISH, |
108 | ENGINEerr(ENGINE_F_ENGINE_UNLOCKED_FINISH,ENGINE_R_FINISH_FAILED); | 108 | ENGINE_R_FINISH_FAILED); |
109 | return 0; | 109 | return 0; |
110 | } | ||
111 | return to_return; | ||
112 | } | 110 | } |
111 | return to_return; | ||
112 | } | ||
113 | 113 | ||
114 | /* The API (locked) version of "init" */ | 114 | /* The API (locked) version of "init" */ |
115 | int ENGINE_init(ENGINE *e) | 115 | int |
116 | { | 116 | ENGINE_init(ENGINE *e) |
117 | { | ||
117 | int ret; | 118 | int ret; |
118 | if(e == NULL) | 119 | |
119 | { | 120 | if (e == NULL) { |
120 | ENGINEerr(ENGINE_F_ENGINE_INIT,ERR_R_PASSED_NULL_PARAMETER); | 121 | ENGINEerr(ENGINE_F_ENGINE_INIT, ERR_R_PASSED_NULL_PARAMETER); |
121 | return 0; | 122 | return 0; |
122 | } | 123 | } |
123 | CRYPTO_w_lock(CRYPTO_LOCK_ENGINE); | 124 | CRYPTO_w_lock(CRYPTO_LOCK_ENGINE); |
124 | ret = engine_unlocked_init(e); | 125 | ret = engine_unlocked_init(e); |
125 | CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE); | 126 | CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE); |
126 | return ret; | 127 | return ret; |
127 | } | 128 | } |
128 | 129 | ||
129 | /* The API (locked) version of "finish" */ | 130 | /* The API (locked) version of "finish" */ |
130 | int ENGINE_finish(ENGINE *e) | 131 | int |
131 | { | 132 | ENGINE_finish(ENGINE *e) |
133 | { | ||
132 | int to_return = 1; | 134 | int to_return = 1; |
133 | 135 | ||
134 | if(e == NULL) | 136 | if (e == NULL) { |
135 | { | 137 | ENGINEerr(ENGINE_F_ENGINE_FINISH, ERR_R_PASSED_NULL_PARAMETER); |
136 | ENGINEerr(ENGINE_F_ENGINE_FINISH,ERR_R_PASSED_NULL_PARAMETER); | ||
137 | return 0; | 138 | return 0; |
138 | } | 139 | } |
139 | CRYPTO_w_lock(CRYPTO_LOCK_ENGINE); | 140 | CRYPTO_w_lock(CRYPTO_LOCK_ENGINE); |
140 | to_return = engine_unlocked_finish(e, 1); | 141 | to_return = engine_unlocked_finish(e, 1); |
141 | CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE); | 142 | CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE); |
142 | if(!to_return) | 143 | if (!to_return) { |
143 | { | 144 | ENGINEerr(ENGINE_F_ENGINE_FINISH, ENGINE_R_FINISH_FAILED); |
144 | ENGINEerr(ENGINE_F_ENGINE_FINISH,ENGINE_R_FINISH_FAILED); | ||
145 | return 0; | 145 | return 0; |
146 | } | ||
147 | return to_return; | ||
148 | } | 146 | } |
147 | return to_return; | ||
148 | } | ||