]>
Commit | Line | Data |
---|---|---|
5270e702 RL |
1 | /* crypto/engine/engine_list.c */ |
2 | /* Written by Geoff Thorpe (geoff@geoffthorpe.net) for the OpenSSL | |
3 | * project 2000. | |
4 | */ | |
5 | /* ==================================================================== | |
6 | * Copyright (c) 1999 The OpenSSL Project. All rights reserved. | |
7 | * | |
8 | * Redistribution and use in source and binary forms, with or without | |
9 | * modification, are permitted provided that the following conditions | |
10 | * are met: | |
11 | * | |
12 | * 1. Redistributions of source code must retain the above copyright | |
13 | * notice, this list of conditions and the following disclaimer. | |
14 | * | |
15 | * 2. Redistributions in binary form must reproduce the above copyright | |
16 | * notice, this list of conditions and the following disclaimer in | |
17 | * the documentation and/or other materials provided with the | |
18 | * distribution. | |
19 | * | |
20 | * 3. All advertising materials mentioning features or use of this | |
21 | * software must display the following acknowledgment: | |
22 | * "This product includes software developed by the OpenSSL Project | |
23 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | |
24 | * | |
25 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | |
26 | * endorse or promote products derived from this software without | |
27 | * prior written permission. For written permission, please contact | |
28 | * licensing@OpenSSL.org. | |
29 | * | |
30 | * 5. Products derived from this software may not be called "OpenSSL" | |
31 | * nor may "OpenSSL" appear in their names without prior written | |
32 | * permission of the OpenSSL Project. | |
33 | * | |
34 | * 6. Redistributions of any form whatsoever must retain the following | |
35 | * acknowledgment: | |
36 | * "This product includes software developed by the OpenSSL Project | |
37 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | |
38 | * | |
39 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | |
40 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
41 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | |
42 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | |
43 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
44 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | |
45 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | |
46 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
47 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | |
48 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |
49 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | |
50 | * OF THE POSSIBILITY OF SUCH DAMAGE. | |
51 | * ==================================================================== | |
52 | * | |
53 | * This product includes cryptographic software written by Eric Young | |
54 | * (eay@cryptsoft.com). This product includes software written by Tim | |
55 | * Hudson (tjh@cryptsoft.com). | |
56 | * | |
57 | */ | |
58 | ||
59 | #include <openssl/crypto.h> | |
60 | #include "cryptlib.h" | |
61 | #include "engine_int.h" | |
62 | #include <openssl/engine.h> | |
63 | ||
0ce5f3e4 GT |
64 | /* Weird "ex_data" handling. Some have suggested there's some problems with the |
65 | * CRYPTO_EX_DATA code (or model), but for now I'm implementing it exactly as | |
66 | * it's done in crypto/rsa/. That way the usage and documentation of that can be | |
67 | * used to assist here, and any changes or fixes made there should similarly map | |
68 | * over here quite straightforwardly. */ | |
69 | static int engine_ex_data_num = 0; | |
70 | static STACK_OF(CRYPTO_EX_DATA_FUNCS) *engine_ex_data_stack = NULL; | |
71 | ||
5270e702 RL |
72 | /* The linked-list of pointers to engine types. engine_list_head |
73 | * incorporates an implicit structural reference but engine_list_tail | |
74 | * does not - the latter is a computational niceity and only points | |
75 | * to something that is already pointed to by its predecessor in the | |
76 | * list (or engine_list_head itself). In the same way, the use of the | |
77 | * "prev" pointer in each ENGINE is to save excessive list iteration, | |
78 | * it doesn't correspond to an extra structural reference. Hence, | |
79 | * engine_list_head, and each non-null "next" pointer account for | |
80 | * the list itself assuming exactly 1 structural reference on each | |
81 | * list member. */ | |
82 | static ENGINE *engine_list_head = NULL; | |
83 | static ENGINE *engine_list_tail = NULL; | |
84 | /* A boolean switch, used to ensure we only initialise once. This | |
85 | * is needed because the engine list may genuinely become empty during | |
86 | * use (so we can't use engine_list_head as an indicator for example. */ | |
87 | static int engine_list_flag = 0; | |
88 | ||
89 | /* These static functions starting with a lower case "engine_" always | |
90 | * take place when CRYPTO_LOCK_ENGINE has been locked up. */ | |
91 | static int engine_list_add(ENGINE *e) | |
92 | { | |
93 | int conflict = 0; | |
94 | ENGINE *iterator = NULL; | |
95 | ||
96 | if(e == NULL) | |
97 | { | |
98 | ENGINEerr(ENGINE_F_ENGINE_LIST_ADD, | |
99 | ERR_R_PASSED_NULL_PARAMETER); | |
100 | return 0; | |
101 | } | |
102 | iterator = engine_list_head; | |
103 | while(iterator && !conflict) | |
104 | { | |
105 | conflict = (strcmp(iterator->id, e->id) == 0); | |
106 | iterator = iterator->next; | |
107 | } | |
108 | if(conflict) | |
109 | { | |
110 | ENGINEerr(ENGINE_F_ENGINE_LIST_ADD, | |
111 | ENGINE_R_CONFLICTING_ENGINE_ID); | |
112 | return 0; | |
113 | } | |
114 | if(engine_list_head == NULL) | |
115 | { | |
116 | /* We are adding to an empty list. */ | |
117 | if(engine_list_tail) | |
118 | { | |
119 | ENGINEerr(ENGINE_F_ENGINE_LIST_ADD, | |
120 | ENGINE_R_INTERNAL_LIST_ERROR); | |
121 | return 0; | |
122 | } | |
123 | engine_list_head = e; | |
124 | e->prev = NULL; | |
125 | } | |
126 | else | |
127 | { | |
128 | /* We are adding to the tail of an existing list. */ | |
129 | if((engine_list_tail == NULL) || | |
130 | (engine_list_tail->next != NULL)) | |
131 | { | |
132 | ENGINEerr(ENGINE_F_ENGINE_LIST_ADD, | |
133 | ENGINE_R_INTERNAL_LIST_ERROR); | |
134 | return 0; | |
135 | } | |
136 | engine_list_tail->next = e; | |
137 | e->prev = engine_list_tail; | |
138 | } | |
139 | /* Having the engine in the list assumes a structural | |
140 | * reference. */ | |
141 | e->struct_ref++; | |
b41f836e | 142 | engine_ref_debug(e, 0, 1) |
5270e702 RL |
143 | /* However it came to be, e is the last item in the list. */ |
144 | engine_list_tail = e; | |
145 | e->next = NULL; | |
146 | return 1; | |
147 | } | |
148 | ||
149 | static int engine_list_remove(ENGINE *e) | |
150 | { | |
151 | ENGINE *iterator; | |
152 | ||
153 | if(e == NULL) | |
154 | { | |
155 | ENGINEerr(ENGINE_F_ENGINE_LIST_REMOVE, | |
156 | ERR_R_PASSED_NULL_PARAMETER); | |
157 | return 0; | |
158 | } | |
159 | /* We need to check that e is in our linked list! */ | |
160 | iterator = engine_list_head; | |
161 | while(iterator && (iterator != e)) | |
162 | iterator = iterator->next; | |
163 | if(iterator == NULL) | |
164 | { | |
165 | ENGINEerr(ENGINE_F_ENGINE_LIST_REMOVE, | |
166 | ENGINE_R_ENGINE_IS_NOT_IN_LIST); | |
167 | return 0; | |
168 | } | |
169 | /* un-link e from the chain. */ | |
170 | if(e->next) | |
171 | e->next->prev = e->prev; | |
172 | if(e->prev) | |
173 | e->prev->next = e->next; | |
174 | /* Correct our head/tail if necessary. */ | |
175 | if(engine_list_head == e) | |
176 | engine_list_head = e->next; | |
177 | if(engine_list_tail == e) | |
178 | engine_list_tail = e->prev; | |
179 | /* remove our structural reference. */ | |
180 | e->struct_ref--; | |
b41f836e | 181 | engine_ref_debug(e, 0, -1) |
5270e702 RL |
182 | return 1; |
183 | } | |
184 | ||
185 | /* This check always takes place with CRYPTO_LOCK_ENGINE locked up | |
186 | * so we're synchronised, but we can't call anything that tries to | |
187 | * lock it again! :-) NB: For convenience (and code-clarity) we | |
188 | * don't output errors for failures of the engine_list_add function | |
189 | * as it will generate errors itself. */ | |
190 | static int engine_internal_check(void) | |
191 | { | |
b41f836e GT |
192 | int toret = 1; |
193 | ENGINE *def_engine; | |
5270e702 RL |
194 | if(engine_list_flag) |
195 | return 1; | |
196 | /* This is our first time up, we need to populate the list | |
197 | * with our statically compiled-in engines. */ | |
b41f836e GT |
198 | def_engine = ENGINE_openssl(); |
199 | if(!engine_list_add(def_engine)) | |
200 | toret = 0; | |
201 | else | |
202 | engine_list_flag = 1; | |
203 | #if 0 | |
204 | ENGINE_free(def_engine); | |
205 | #else | |
206 | /* We can't ENGINE_free() because the lock's already held */ | |
207 | def_engine->struct_ref--; | |
208 | engine_ref_debug(def_engine, 0, -1) | |
209 | #endif | |
5270e702 RL |
210 | return 1; |
211 | } | |
212 | ||
213 | /* Get the first/last "ENGINE" type available. */ | |
214 | ENGINE *ENGINE_get_first(void) | |
215 | { | |
216 | ENGINE *ret = NULL; | |
217 | ||
218 | CRYPTO_r_lock(CRYPTO_LOCK_ENGINE); | |
219 | if(engine_internal_check()) | |
220 | { | |
221 | ret = engine_list_head; | |
222 | if(ret) | |
b41f836e | 223 | { |
5270e702 | 224 | ret->struct_ref++; |
b41f836e GT |
225 | engine_ref_debug(ret, 0, 1) |
226 | } | |
5270e702 RL |
227 | } |
228 | CRYPTO_r_unlock(CRYPTO_LOCK_ENGINE); | |
229 | return ret; | |
230 | } | |
231 | ENGINE *ENGINE_get_last(void) | |
232 | { | |
233 | ENGINE *ret = NULL; | |
234 | ||
235 | CRYPTO_r_lock(CRYPTO_LOCK_ENGINE); | |
236 | if(engine_internal_check()) | |
237 | { | |
238 | ret = engine_list_tail; | |
239 | if(ret) | |
b41f836e | 240 | { |
5270e702 | 241 | ret->struct_ref++; |
b41f836e GT |
242 | engine_ref_debug(ret, 0, 1) |
243 | } | |
5270e702 RL |
244 | } |
245 | CRYPTO_r_unlock(CRYPTO_LOCK_ENGINE); | |
246 | return ret; | |
247 | } | |
248 | ||
249 | /* Iterate to the next/previous "ENGINE" type (NULL = end of the list). */ | |
250 | ENGINE *ENGINE_get_next(ENGINE *e) | |
251 | { | |
252 | ENGINE *ret = NULL; | |
253 | if(e == NULL) | |
254 | { | |
255 | ENGINEerr(ENGINE_F_ENGINE_GET_NEXT, | |
256 | ERR_R_PASSED_NULL_PARAMETER); | |
257 | return 0; | |
258 | } | |
259 | CRYPTO_r_lock(CRYPTO_LOCK_ENGINE); | |
260 | ret = e->next; | |
5270e702 | 261 | if(ret) |
b41f836e | 262 | { |
ea3a429e | 263 | /* Return a valid structural refernce to the next ENGINE */ |
5270e702 | 264 | ret->struct_ref++; |
b41f836e GT |
265 | engine_ref_debug(ret, 0, 1) |
266 | } | |
5270e702 | 267 | CRYPTO_r_unlock(CRYPTO_LOCK_ENGINE); |
ea3a429e GT |
268 | /* Release the structural reference to the previous ENGINE */ |
269 | ENGINE_free(e); | |
5270e702 RL |
270 | return ret; |
271 | } | |
272 | ENGINE *ENGINE_get_prev(ENGINE *e) | |
273 | { | |
274 | ENGINE *ret = NULL; | |
275 | if(e == NULL) | |
276 | { | |
277 | ENGINEerr(ENGINE_F_ENGINE_GET_PREV, | |
278 | ERR_R_PASSED_NULL_PARAMETER); | |
279 | return 0; | |
280 | } | |
281 | CRYPTO_r_lock(CRYPTO_LOCK_ENGINE); | |
282 | ret = e->prev; | |
5270e702 | 283 | if(ret) |
b41f836e | 284 | { |
ea3a429e | 285 | /* Return a valid structural reference to the next ENGINE */ |
5270e702 | 286 | ret->struct_ref++; |
b41f836e GT |
287 | engine_ref_debug(ret, 0, 1) |
288 | } | |
5270e702 | 289 | CRYPTO_r_unlock(CRYPTO_LOCK_ENGINE); |
ea3a429e GT |
290 | /* Release the structural reference to the previous ENGINE */ |
291 | ENGINE_free(e); | |
5270e702 RL |
292 | return ret; |
293 | } | |
294 | ||
295 | /* Add another "ENGINE" type into the list. */ | |
296 | int ENGINE_add(ENGINE *e) | |
297 | { | |
298 | int to_return = 1; | |
299 | if(e == NULL) | |
300 | { | |
301 | ENGINEerr(ENGINE_F_ENGINE_ADD, | |
302 | ERR_R_PASSED_NULL_PARAMETER); | |
303 | return 0; | |
304 | } | |
305 | if((e->id == NULL) || (e->name == NULL)) | |
306 | { | |
307 | ENGINEerr(ENGINE_F_ENGINE_ADD, | |
308 | ENGINE_R_ID_OR_NAME_MISSING); | |
309 | } | |
310 | CRYPTO_w_lock(CRYPTO_LOCK_ENGINE); | |
311 | if(!engine_internal_check() || !engine_list_add(e)) | |
312 | { | |
313 | ENGINEerr(ENGINE_F_ENGINE_ADD, | |
314 | ENGINE_R_INTERNAL_LIST_ERROR); | |
315 | to_return = 0; | |
316 | } | |
317 | CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE); | |
318 | return to_return; | |
319 | } | |
320 | ||
321 | /* Remove an existing "ENGINE" type from the array. */ | |
322 | int ENGINE_remove(ENGINE *e) | |
323 | { | |
324 | int to_return = 1; | |
325 | if(e == NULL) | |
326 | { | |
327 | ENGINEerr(ENGINE_F_ENGINE_REMOVE, | |
328 | ERR_R_PASSED_NULL_PARAMETER); | |
329 | return 0; | |
330 | } | |
331 | CRYPTO_w_lock(CRYPTO_LOCK_ENGINE); | |
332 | if(!engine_internal_check() || !engine_list_remove(e)) | |
333 | { | |
334 | ENGINEerr(ENGINE_F_ENGINE_REMOVE, | |
335 | ENGINE_R_INTERNAL_LIST_ERROR); | |
336 | to_return = 0; | |
337 | } | |
338 | CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE); | |
339 | return to_return; | |
340 | } | |
341 | ||
342 | ENGINE *ENGINE_by_id(const char *id) | |
343 | { | |
0ce5f3e4 | 344 | ENGINE *iterator = NULL, *cp = NULL; |
5270e702 RL |
345 | if(id == NULL) |
346 | { | |
347 | ENGINEerr(ENGINE_F_ENGINE_BY_ID, | |
348 | ERR_R_PASSED_NULL_PARAMETER); | |
349 | return NULL; | |
350 | } | |
351 | CRYPTO_r_lock(CRYPTO_LOCK_ENGINE); | |
352 | if(!engine_internal_check()) | |
353 | ENGINEerr(ENGINE_F_ENGINE_BY_ID, | |
354 | ENGINE_R_INTERNAL_LIST_ERROR); | |
355 | else | |
356 | { | |
357 | iterator = engine_list_head; | |
358 | while(iterator && (strcmp(id, iterator->id) != 0)) | |
359 | iterator = iterator->next; | |
360 | if(iterator) | |
0ce5f3e4 GT |
361 | { |
362 | /* We need to return a structural reference. If this is | |
363 | * a "dynamic" ENGINE type, make a duplicate - otherwise | |
364 | * increment the existing ENGINE's reference count. */ | |
365 | if(iterator->flags & ENGINE_FLAGS_BY_ID_COPY) | |
366 | { | |
367 | cp = ENGINE_new(); | |
368 | if(!cp) | |
369 | iterator = NULL; | |
370 | else | |
371 | { | |
372 | ENGINE_cpy(cp, iterator); | |
373 | iterator = cp; | |
374 | } | |
375 | } | |
376 | else | |
b41f836e | 377 | { |
0ce5f3e4 | 378 | iterator->struct_ref++; |
b41f836e GT |
379 | engine_ref_debug(iterator, 0, 1) |
380 | } | |
0ce5f3e4 | 381 | } |
5270e702 RL |
382 | } |
383 | CRYPTO_r_unlock(CRYPTO_LOCK_ENGINE); | |
384 | if(iterator == NULL) | |
385 | ENGINEerr(ENGINE_F_ENGINE_BY_ID, | |
386 | ENGINE_R_NO_SUCH_ENGINE); | |
387 | return iterator; | |
388 | } | |
389 | ||
5270e702 RL |
390 | ENGINE *ENGINE_new(void) |
391 | { | |
392 | ENGINE *ret; | |
393 | ||
394 | ret = (ENGINE *)OPENSSL_malloc(sizeof(ENGINE)); | |
395 | if(ret == NULL) | |
396 | { | |
397 | ENGINEerr(ENGINE_F_ENGINE_NEW, ERR_R_MALLOC_FAILURE); | |
398 | return NULL; | |
399 | } | |
400 | memset(ret, 0, sizeof(ENGINE)); | |
5270e702 | 401 | ret->struct_ref = 1; |
b41f836e | 402 | engine_ref_debug(ret, 0, 1) |
0ce5f3e4 | 403 | CRYPTO_new_ex_data(engine_ex_data_stack, ret, &ret->ex_data); |
5270e702 RL |
404 | return ret; |
405 | } | |
5270e702 RL |
406 | |
407 | int ENGINE_free(ENGINE *e) | |
408 | { | |
409 | int i; | |
410 | ||
411 | if(e == NULL) | |
412 | { | |
413 | ENGINEerr(ENGINE_F_ENGINE_FREE, | |
414 | ERR_R_PASSED_NULL_PARAMETER); | |
415 | return 0; | |
416 | } | |
417 | i = CRYPTO_add(&e->struct_ref,-1,CRYPTO_LOCK_ENGINE); | |
b41f836e | 418 | engine_ref_debug(e, 0, -1) |
5270e702 RL |
419 | if (i > 0) return 1; |
420 | #ifdef REF_CHECK | |
421 | if (i < 0) | |
422 | { | |
b41f836e | 423 | fprintf(stderr,"ENGINE_free, bad structural reference count\n"); |
5270e702 RL |
424 | abort(); |
425 | } | |
426 | #endif | |
0ce5f3e4 | 427 | CRYPTO_free_ex_data(engine_ex_data_stack, e, &e->ex_data); |
dcd87618 | 428 | OPENSSL_free(e); |
5270e702 RL |
429 | return 1; |
430 | } | |
431 | ||
0ce5f3e4 GT |
432 | int ENGINE_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func, |
433 | CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func) | |
434 | { | |
435 | engine_ex_data_num++; | |
436 | return(CRYPTO_get_ex_new_index(engine_ex_data_num - 1, | |
437 | &engine_ex_data_stack, argl, argp, | |
438 | new_func, dup_func, free_func)); | |
439 | } | |
440 | ||
441 | int ENGINE_set_ex_data(ENGINE *e, int idx, void *arg) | |
442 | { | |
443 | return(CRYPTO_set_ex_data(&e->ex_data, idx, arg)); | |
444 | } | |
445 | ||
446 | void *ENGINE_get_ex_data(const ENGINE *e, int idx) | |
447 | { | |
448 | return(CRYPTO_get_ex_data(&e->ex_data, idx)); | |
449 | } | |
450 | ||
a679116f | 451 | void ENGINE_cleanup(void) |
b41f836e GT |
452 | { |
453 | ENGINE *iterator = engine_list_head; | |
454 | ||
455 | while(iterator != NULL) | |
456 | { | |
457 | ENGINE_remove(iterator); | |
458 | iterator = engine_list_head; | |
459 | } | |
460 | engine_list_flag = 0; | |
461 | /* Also unset any "default" ENGINEs that may have been set up (a default | |
462 | * constitutes a functional reference on an ENGINE and there's one for | |
463 | * each algorithm). */ | |
464 | ENGINE_clear_defaults(); | |
465 | return; | |
466 | } | |
a679116f | 467 | |
5270e702 RL |
468 | int ENGINE_set_id(ENGINE *e, const char *id) |
469 | { | |
d54bf145 | 470 | if(id == NULL) |
5270e702 RL |
471 | { |
472 | ENGINEerr(ENGINE_F_ENGINE_SET_ID, | |
473 | ERR_R_PASSED_NULL_PARAMETER); | |
474 | return 0; | |
475 | } | |
476 | e->id = id; | |
477 | return 1; | |
478 | } | |
479 | ||
480 | int ENGINE_set_name(ENGINE *e, const char *name) | |
481 | { | |
d54bf145 | 482 | if(name == NULL) |
5270e702 RL |
483 | { |
484 | ENGINEerr(ENGINE_F_ENGINE_SET_NAME, | |
485 | ERR_R_PASSED_NULL_PARAMETER); | |
486 | return 0; | |
487 | } | |
488 | e->name = name; | |
489 | return 1; | |
490 | } | |
491 | ||
10e473e9 | 492 | int ENGINE_set_RSA(ENGINE *e, const RSA_METHOD *rsa_meth) |
5270e702 | 493 | { |
9e78e6c3 | 494 | #ifndef OPENSSL_NO_RSA |
5270e702 RL |
495 | e->rsa_meth = rsa_meth; |
496 | return 1; | |
9e78e6c3 | 497 | #else |
b41f836e | 498 | return 0; |
9e78e6c3 | 499 | #endif |
5270e702 RL |
500 | } |
501 | ||
a4aba800 | 502 | int ENGINE_set_DSA(ENGINE *e, const DSA_METHOD *dsa_meth) |
5270e702 | 503 | { |
9e78e6c3 | 504 | #ifndef OPENSSL_NO_DSA |
5270e702 RL |
505 | e->dsa_meth = dsa_meth; |
506 | return 1; | |
9e78e6c3 | 507 | #else |
b41f836e | 508 | return 0; |
9e78e6c3 | 509 | #endif |
5270e702 RL |
510 | } |
511 | ||
f971ccb2 | 512 | int ENGINE_set_DH(ENGINE *e, const DH_METHOD *dh_meth) |
5270e702 | 513 | { |
9e78e6c3 | 514 | #ifndef OPENSSL_NO_DH |
5270e702 RL |
515 | e->dh_meth = dh_meth; |
516 | return 1; | |
9e78e6c3 | 517 | #else |
b41f836e | 518 | return 0; |
9e78e6c3 | 519 | #endif |
5270e702 RL |
520 | } |
521 | ||
d54bf145 | 522 | int ENGINE_set_RAND(ENGINE *e, const RAND_METHOD *rand_meth) |
5270e702 | 523 | { |
5270e702 RL |
524 | e->rand_meth = rand_meth; |
525 | return 1; | |
526 | } | |
527 | ||
528 | int ENGINE_set_BN_mod_exp(ENGINE *e, BN_MOD_EXP bn_mod_exp) | |
529 | { | |
5270e702 RL |
530 | e->bn_mod_exp = bn_mod_exp; |
531 | return 1; | |
532 | } | |
533 | ||
534 | int ENGINE_set_BN_mod_exp_crt(ENGINE *e, BN_MOD_EXP_CRT bn_mod_exp_crt) | |
535 | { | |
5270e702 RL |
536 | e->bn_mod_exp_crt = bn_mod_exp_crt; |
537 | return 1; | |
538 | } | |
539 | ||
540 | int ENGINE_set_init_function(ENGINE *e, ENGINE_GEN_INT_FUNC_PTR init_f) | |
541 | { | |
5270e702 RL |
542 | e->init = init_f; |
543 | return 1; | |
544 | } | |
545 | ||
546 | int ENGINE_set_finish_function(ENGINE *e, ENGINE_GEN_INT_FUNC_PTR finish_f) | |
547 | { | |
5270e702 RL |
548 | e->finish = finish_f; |
549 | return 1; | |
550 | } | |
551 | ||
552 | int ENGINE_set_ctrl_function(ENGINE *e, ENGINE_CTRL_FUNC_PTR ctrl_f) | |
553 | { | |
5270e702 RL |
554 | e->ctrl = ctrl_f; |
555 | return 1; | |
556 | } | |
557 | ||
d54bf145 GT |
558 | int ENGINE_set_load_privkey_function(ENGINE *e, ENGINE_LOAD_KEY_PTR loadpriv_f) |
559 | { | |
560 | e->load_privkey = loadpriv_f; | |
561 | return 1; | |
562 | } | |
563 | ||
564 | int ENGINE_set_load_pubkey_function(ENGINE *e, ENGINE_LOAD_KEY_PTR loadpub_f) | |
565 | { | |
566 | e->load_pubkey = loadpub_f; | |
567 | return 1; | |
568 | } | |
569 | ||
570 | int ENGINE_set_flags(ENGINE *e, int flags) | |
571 | { | |
572 | e->flags = flags; | |
573 | return 1; | |
574 | } | |
575 | ||
40fcda29 GT |
576 | int ENGINE_set_cmd_defns(ENGINE *e, const ENGINE_CMD_DEFN *defns) |
577 | { | |
578 | e->cmd_defns = defns; | |
579 | return 1; | |
580 | } | |
581 | ||
d54bf145 GT |
582 | int ENGINE_cpy(ENGINE *dest, const ENGINE *src) |
583 | { | |
584 | if(ENGINE_set_id(dest, ENGINE_get_id(src)) && | |
585 | ENGINE_set_name(dest, ENGINE_get_name(src)) && | |
9e78e6c3 | 586 | #ifndef OPENSSL_NO_RSA |
d54bf145 | 587 | ENGINE_set_RSA(dest, ENGINE_get_RSA(src)) && |
9e78e6c3 RL |
588 | #endif |
589 | #ifndef OPENSSL_NO_RSA | |
d54bf145 | 590 | ENGINE_set_DSA(dest, ENGINE_get_DSA(src)) && |
9e78e6c3 RL |
591 | #endif |
592 | #ifndef OPENSSL_NO_RSA | |
d54bf145 | 593 | ENGINE_set_DH(dest, ENGINE_get_DH(src)) && |
9e78e6c3 | 594 | #endif |
d54bf145 GT |
595 | ENGINE_set_RAND(dest, ENGINE_get_RAND(src)) && |
596 | ENGINE_set_BN_mod_exp(dest, | |
597 | ENGINE_get_BN_mod_exp(src)) && | |
598 | ENGINE_set_BN_mod_exp_crt(dest, | |
599 | ENGINE_get_BN_mod_exp_crt(src)) && | |
600 | ENGINE_set_init_function(dest, | |
601 | ENGINE_get_init_function(src)) && | |
602 | ENGINE_set_finish_function(dest, | |
603 | ENGINE_get_finish_function(src)) && | |
604 | ENGINE_set_ctrl_function(dest, | |
605 | ENGINE_get_ctrl_function(src)) && | |
606 | ENGINE_set_load_privkey_function(dest, | |
607 | ENGINE_get_load_privkey_function(src)) && | |
608 | ENGINE_set_load_pubkey_function(dest, | |
609 | ENGINE_get_load_pubkey_function(src)) && | |
40fcda29 GT |
610 | ENGINE_set_flags(dest, ENGINE_get_flags(src)) && |
611 | ENGINE_set_cmd_defns(dest, ENGINE_get_cmd_defns(src))) | |
d54bf145 GT |
612 | return 1; |
613 | return 0; | |
614 | } | |
615 | ||
616 | const char *ENGINE_get_id(const ENGINE *e) | |
5270e702 | 617 | { |
5270e702 RL |
618 | return e->id; |
619 | } | |
620 | ||
d54bf145 | 621 | const char *ENGINE_get_name(const ENGINE *e) |
5270e702 | 622 | { |
5270e702 RL |
623 | return e->name; |
624 | } | |
625 | ||
d54bf145 | 626 | const RSA_METHOD *ENGINE_get_RSA(const ENGINE *e) |
5270e702 | 627 | { |
5270e702 RL |
628 | return e->rsa_meth; |
629 | } | |
630 | ||
d54bf145 | 631 | const DSA_METHOD *ENGINE_get_DSA(const ENGINE *e) |
5270e702 | 632 | { |
5270e702 RL |
633 | return e->dsa_meth; |
634 | } | |
635 | ||
d54bf145 | 636 | const DH_METHOD *ENGINE_get_DH(const ENGINE *e) |
5270e702 | 637 | { |
5270e702 RL |
638 | return e->dh_meth; |
639 | } | |
640 | ||
d54bf145 | 641 | const RAND_METHOD *ENGINE_get_RAND(const ENGINE *e) |
5270e702 | 642 | { |
5270e702 RL |
643 | return e->rand_meth; |
644 | } | |
645 | ||
d54bf145 | 646 | BN_MOD_EXP ENGINE_get_BN_mod_exp(const ENGINE *e) |
5270e702 | 647 | { |
5270e702 RL |
648 | return e->bn_mod_exp; |
649 | } | |
650 | ||
d54bf145 | 651 | BN_MOD_EXP_CRT ENGINE_get_BN_mod_exp_crt(const ENGINE *e) |
5270e702 | 652 | { |
5270e702 RL |
653 | return e->bn_mod_exp_crt; |
654 | } | |
655 | ||
d54bf145 | 656 | ENGINE_GEN_INT_FUNC_PTR ENGINE_get_init_function(const ENGINE *e) |
5270e702 | 657 | { |
5270e702 RL |
658 | return e->init; |
659 | } | |
660 | ||
d54bf145 | 661 | ENGINE_GEN_INT_FUNC_PTR ENGINE_get_finish_function(const ENGINE *e) |
5270e702 | 662 | { |
5270e702 RL |
663 | return e->finish; |
664 | } | |
665 | ||
d54bf145 | 666 | ENGINE_CTRL_FUNC_PTR ENGINE_get_ctrl_function(const ENGINE *e) |
5270e702 | 667 | { |
5270e702 RL |
668 | return e->ctrl; |
669 | } | |
670 | ||
d54bf145 GT |
671 | ENGINE_LOAD_KEY_PTR ENGINE_get_load_privkey_function(const ENGINE *e) |
672 | { | |
673 | return e->load_privkey; | |
674 | } | |
675 | ||
676 | ENGINE_LOAD_KEY_PTR ENGINE_get_load_pubkey_function(const ENGINE *e) | |
677 | { | |
678 | return e->load_pubkey; | |
679 | } | |
680 | ||
681 | int ENGINE_get_flags(const ENGINE *e) | |
682 | { | |
683 | return e->flags; | |
684 | } | |
40fcda29 GT |
685 | |
686 | const ENGINE_CMD_DEFN *ENGINE_get_cmd_defns(const ENGINE *e) | |
687 | { | |
688 | return e->cmd_defns; | |
689 | } |