Add first cut symmetric crypto support.
[openssl.git] / crypto / engine / engine_list.c
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
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
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 static int ENGINE_free_nolock(ENGINE *e);
89
90 /* These static functions starting with a lower case "engine_" always
91  * take place when CRYPTO_LOCK_ENGINE has been locked up. */
92 static int engine_list_add(ENGINE *e)
93         {
94         int conflict = 0;
95         ENGINE *iterator = NULL;
96
97         if(e == NULL)
98                 {
99                 ENGINEerr(ENGINE_F_ENGINE_LIST_ADD,
100                         ERR_R_PASSED_NULL_PARAMETER);
101                 return 0;
102                 }
103         iterator = engine_list_head;
104         while(iterator && !conflict)
105                 {
106                 conflict = (strcmp(iterator->id, e->id) == 0);
107                 iterator = iterator->next;
108                 }
109         if(conflict)
110                 {
111                 ENGINEerr(ENGINE_F_ENGINE_LIST_ADD,
112                         ENGINE_R_CONFLICTING_ENGINE_ID);
113                 return 0;
114                 }
115         if(engine_list_head == NULL)
116                 {
117                 /* We are adding to an empty list. */
118                 if(engine_list_tail)
119                         {
120                         ENGINEerr(ENGINE_F_ENGINE_LIST_ADD,
121                                 ENGINE_R_INTERNAL_LIST_ERROR);
122                         return 0;
123                         }
124                 engine_list_head = e;
125                 e->prev = NULL;
126                 }
127         else
128                 {
129                 /* We are adding to the tail of an existing list. */
130                 if((engine_list_tail == NULL) ||
131                                 (engine_list_tail->next != NULL))
132                         {
133                         ENGINEerr(ENGINE_F_ENGINE_LIST_ADD,
134                                 ENGINE_R_INTERNAL_LIST_ERROR);
135                         return 0;
136                         }
137                 engine_list_tail->next = e;
138                 e->prev = engine_list_tail;
139                 }
140         /* Having the engine in the list assumes a structural
141          * reference. */
142         e->struct_ref++;
143         engine_ref_debug(e, 0, 1)
144         /* However it came to be, e is the last item in the list. */
145         engine_list_tail = e;
146         e->next = NULL;
147         return 1;
148         }
149
150 static int engine_list_remove(ENGINE *e)
151         {
152         ENGINE *iterator;
153
154         if(e == NULL)
155                 {
156                 ENGINEerr(ENGINE_F_ENGINE_LIST_REMOVE,
157                         ERR_R_PASSED_NULL_PARAMETER);
158                 return 0;
159                 }
160         /* We need to check that e is in our linked list! */
161         iterator = engine_list_head;
162         while(iterator && (iterator != e))
163                 iterator = iterator->next;
164         if(iterator == NULL)
165                 {
166                 ENGINEerr(ENGINE_F_ENGINE_LIST_REMOVE,
167                         ENGINE_R_ENGINE_IS_NOT_IN_LIST);
168                 return 0;
169                 }
170         /* un-link e from the chain. */
171         if(e->next)
172                 e->next->prev = e->prev;
173         if(e->prev)
174                 e->prev->next = e->next;
175         /* Correct our head/tail if necessary. */
176         if(engine_list_head == e)
177                 engine_list_head = e->next;
178         if(engine_list_tail == e)
179                 engine_list_tail = e->prev;
180         ENGINE_free_nolock(e);
181         return 1;
182         }
183
184 /* This check always takes place with CRYPTO_LOCK_ENGINE locked up
185  * so we're synchronised, but we can't call anything that tries to
186  * lock it again! :-) NB: For convenience (and code-clarity) we
187  * don't output errors for failures of the engine_list_add function
188  * as it will generate errors itself. */
189 static int engine_internal_check(void)
190         {
191         int toret = 1;
192         ENGINE *def_engine;
193         if(engine_list_flag)
194                 return 1;
195         /* This is our first time up, we need to populate the list
196          * with our statically compiled-in engines. */
197         def_engine = ENGINE_openssl();
198         if(!engine_list_add(def_engine))
199                 toret = 0;
200         else
201                 engine_list_flag = 1;
202         ENGINE_free_nolock(def_engine);
203         return 1;
204         }
205
206 /* Get the first/last "ENGINE" type available. */
207 ENGINE *ENGINE_get_first(void)
208         {
209         ENGINE *ret = NULL;
210
211         CRYPTO_r_lock(CRYPTO_LOCK_ENGINE);
212         if(engine_internal_check())
213                 {
214                 ret = engine_list_head;
215                 if(ret)
216                         {
217                         ret->struct_ref++;
218                         engine_ref_debug(ret, 0, 1)
219                         }
220                 }
221         CRYPTO_r_unlock(CRYPTO_LOCK_ENGINE);
222         return ret;
223         }
224 ENGINE *ENGINE_get_last(void)
225         {
226         ENGINE *ret = NULL;
227
228         CRYPTO_r_lock(CRYPTO_LOCK_ENGINE);
229         if(engine_internal_check())
230                 {
231                 ret = engine_list_tail;
232                 if(ret)
233                         {
234                         ret->struct_ref++;
235                         engine_ref_debug(ret, 0, 1)
236                         }
237                 }
238         CRYPTO_r_unlock(CRYPTO_LOCK_ENGINE);
239         return ret;
240         }
241
242 /* Iterate to the next/previous "ENGINE" type (NULL = end of the list). */
243 ENGINE *ENGINE_get_next(ENGINE *e)
244         {
245         ENGINE *ret = NULL;
246         if(e == NULL)
247                 {
248                 ENGINEerr(ENGINE_F_ENGINE_GET_NEXT,
249                         ERR_R_PASSED_NULL_PARAMETER);
250                 return 0;
251                 }
252         CRYPTO_r_lock(CRYPTO_LOCK_ENGINE);
253         ret = e->next;
254         if(ret)
255                 {
256                 /* Return a valid structural refernce to the next ENGINE */
257                 ret->struct_ref++;
258                 engine_ref_debug(ret, 0, 1)
259                 }
260         CRYPTO_r_unlock(CRYPTO_LOCK_ENGINE);
261         /* Release the structural reference to the previous ENGINE */
262         ENGINE_free(e);
263         return ret;
264         }
265 ENGINE *ENGINE_get_prev(ENGINE *e)
266         {
267         ENGINE *ret = NULL;
268         if(e == NULL)
269                 {
270                 ENGINEerr(ENGINE_F_ENGINE_GET_PREV,
271                         ERR_R_PASSED_NULL_PARAMETER);
272                 return 0;
273                 }
274         CRYPTO_r_lock(CRYPTO_LOCK_ENGINE);
275         ret = e->prev;
276         if(ret)
277                 {
278                 /* Return a valid structural reference to the next ENGINE */
279                 ret->struct_ref++;
280                 engine_ref_debug(ret, 0, 1)
281                 }
282         CRYPTO_r_unlock(CRYPTO_LOCK_ENGINE);
283         /* Release the structural reference to the previous ENGINE */
284         ENGINE_free(e);
285         return ret;
286         }
287
288 /* Add another "ENGINE" type into the list. */
289 int ENGINE_add(ENGINE *e)
290         {
291         int to_return = 1;
292         if(e == NULL)
293                 {
294                 ENGINEerr(ENGINE_F_ENGINE_ADD,
295                         ERR_R_PASSED_NULL_PARAMETER);
296                 return 0;
297                 }
298         if((e->id == NULL) || (e->name == NULL))
299                 {
300                 ENGINEerr(ENGINE_F_ENGINE_ADD,
301                         ENGINE_R_ID_OR_NAME_MISSING);
302                 }
303         CRYPTO_w_lock(CRYPTO_LOCK_ENGINE);
304         if(!engine_internal_check() || !engine_list_add(e))
305                 {
306                 ENGINEerr(ENGINE_F_ENGINE_ADD,
307                         ENGINE_R_INTERNAL_LIST_ERROR);
308                 to_return = 0;
309                 }
310         CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE);
311         return to_return;
312         }
313
314 /* Remove an existing "ENGINE" type from the array. */
315 int ENGINE_remove(ENGINE *e)
316         {
317         int to_return = 1;
318         if(e == NULL)
319                 {
320                 ENGINEerr(ENGINE_F_ENGINE_REMOVE,
321                         ERR_R_PASSED_NULL_PARAMETER);
322                 return 0;
323                 }
324         CRYPTO_w_lock(CRYPTO_LOCK_ENGINE);
325         if(!engine_internal_check() || !engine_list_remove(e))
326                 {
327                 ENGINEerr(ENGINE_F_ENGINE_REMOVE,
328                         ENGINE_R_INTERNAL_LIST_ERROR);
329                 to_return = 0;
330                 }
331         CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE);
332         return to_return;
333         }
334
335 ENGINE *ENGINE_by_id(const char *id)
336         {
337         ENGINE *iterator = NULL, *cp = NULL;
338         if(id == NULL)
339                 {
340                 ENGINEerr(ENGINE_F_ENGINE_BY_ID,
341                         ERR_R_PASSED_NULL_PARAMETER);
342                 return NULL;
343                 }
344         CRYPTO_r_lock(CRYPTO_LOCK_ENGINE);
345         if(!engine_internal_check())
346                 ENGINEerr(ENGINE_F_ENGINE_BY_ID,
347                         ENGINE_R_INTERNAL_LIST_ERROR);
348         else
349                 {
350                 iterator = engine_list_head;
351                 while(iterator && (strcmp(id, iterator->id) != 0))
352                         iterator = iterator->next;
353                 if(iterator)
354                         {
355                         /* We need to return a structural reference. If this is
356                          * a "dynamic" ENGINE type, make a duplicate - otherwise
357                          * increment the existing ENGINE's reference count. */
358                         if(iterator->flags & ENGINE_FLAGS_BY_ID_COPY)
359                                 {
360                                 cp = ENGINE_new();
361                                 if(!cp)
362                                         iterator = NULL;
363                                 else
364                                         {
365                                         ENGINE_cpy(cp, iterator);
366                                         iterator = cp;
367                                         }
368                                 }
369                         else
370                                 {
371                                 iterator->struct_ref++;
372                                 engine_ref_debug(iterator, 0, 1)
373                                 }
374                         }
375                 }
376         CRYPTO_r_unlock(CRYPTO_LOCK_ENGINE);
377         if(iterator == NULL)
378                 ENGINEerr(ENGINE_F_ENGINE_BY_ID,
379                         ENGINE_R_NO_SUCH_ENGINE);
380         return iterator;
381         }
382
383 ENGINE *ENGINE_new(void)
384         {
385         ENGINE *ret;
386
387         ret = (ENGINE *)OPENSSL_malloc(sizeof(ENGINE));
388         if(ret == NULL)
389                 {
390                 ENGINEerr(ENGINE_F_ENGINE_NEW, ERR_R_MALLOC_FAILURE);
391                 return NULL;
392                 }
393         memset(ret, 0, sizeof(ENGINE));
394         ret->struct_ref = 1;
395         engine_ref_debug(ret, 0, 1)
396         CRYPTO_new_ex_data(engine_ex_data_stack, ret, &ret->ex_data);
397         return ret;
398         }
399
400 int ENGINE_free(ENGINE *e)
401         {
402         int i;
403
404         if(e == NULL)
405                 {
406                 ENGINEerr(ENGINE_F_ENGINE_FREE,
407                         ERR_R_PASSED_NULL_PARAMETER);
408                 return 0;
409                 }
410         i = CRYPTO_add(&e->struct_ref,-1,CRYPTO_LOCK_ENGINE);
411         engine_ref_debug(e, 0, -1)
412         if (i > 0) return 1;
413 #ifdef REF_CHECK
414         if (i < 0)
415                 {
416                 fprintf(stderr,"ENGINE_free, bad structural reference count\n");
417                 abort();
418                 }
419 #endif
420         sk_ENGINE_EVP_CIPHER_pop_free(e->ciphers,ENGINE_free_engine_cipher);
421         CRYPTO_free_ex_data(engine_ex_data_stack, e, &e->ex_data);
422         OPENSSL_free(e);
423         return 1;
424         }
425
426 static int ENGINE_free_nolock(ENGINE *e)
427         {
428         int i;
429
430         if(e == NULL)
431                 {
432                 ENGINEerr(ENGINE_F_ENGINE_FREE,
433                         ERR_R_PASSED_NULL_PARAMETER);
434                 return 0;
435                 }
436         
437         i=--e->struct_ref;
438         engine_ref_debug(e, 0, -1)
439         if (i > 0) return 1;
440 #ifdef REF_CHECK
441         if (i < 0)
442                 {
443                 fprintf(stderr,"ENGINE_free, bad structural reference count\n");
444                 abort();
445                 }
446 #endif
447         CRYPTO_free_ex_data(engine_ex_data_stack, e, &e->ex_data);
448         OPENSSL_free(e);
449         return 1;
450         }
451
452 int ENGINE_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func,
453                 CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func)
454         {
455         if(CRYPTO_get_ex_new_index(engine_ex_data_num, &engine_ex_data_stack,
456                         argl, argp, new_func, dup_func, free_func) < 0)
457                 return -1;
458         return (engine_ex_data_num++);
459         }
460
461 int ENGINE_set_ex_data(ENGINE *e, int idx, void *arg)
462         {
463         return(CRYPTO_set_ex_data(&e->ex_data, idx, arg));
464         }
465
466 void *ENGINE_get_ex_data(const ENGINE *e, int idx)
467         {
468         return(CRYPTO_get_ex_data(&e->ex_data, idx));
469         }
470
471 void ENGINE_cleanup(void)
472         {
473         ENGINE *iterator = engine_list_head;
474
475         while(iterator != NULL)
476                 {
477                 ENGINE_remove(iterator);
478                 iterator = engine_list_head;
479                 }
480         engine_list_flag = 0;
481         /* Also unset any "default" ENGINEs that may have been set up (a default
482          * constitutes a functional reference on an ENGINE and there's one for
483          * each algorithm). */
484         ENGINE_clear_defaults();
485         return;
486         }
487
488 int ENGINE_set_id(ENGINE *e, const char *id)
489         {
490         if(id == NULL)
491                 {
492                 ENGINEerr(ENGINE_F_ENGINE_SET_ID,
493                         ERR_R_PASSED_NULL_PARAMETER);
494                 return 0;
495                 }
496         e->id = id;
497         return 1;
498         }
499
500 int ENGINE_set_name(ENGINE *e, const char *name)
501         {
502         if(name == NULL)
503                 {
504                 ENGINEerr(ENGINE_F_ENGINE_SET_NAME,
505                         ERR_R_PASSED_NULL_PARAMETER);
506                 return 0;
507                 }
508         e->name = name;
509         return 1;
510         }
511
512 int ENGINE_set_RSA(ENGINE *e, const RSA_METHOD *rsa_meth)
513         {
514 #ifndef OPENSSL_NO_RSA
515         e->rsa_meth = rsa_meth;
516         return 1;
517 #else
518         return 0;
519 #endif
520         }
521
522 int ENGINE_set_DSA(ENGINE *e, const DSA_METHOD *dsa_meth)
523         {
524 #ifndef OPENSSL_NO_DSA
525         e->dsa_meth = dsa_meth;
526         return 1;
527 #else
528         return 0;
529 #endif
530         }
531
532 int ENGINE_set_DH(ENGINE *e, const DH_METHOD *dh_meth)
533         {
534 #ifndef OPENSSL_NO_DH
535         e->dh_meth = dh_meth;
536         return 1;
537 #else
538         return 0;
539 #endif
540         }
541
542 int ENGINE_set_RAND(ENGINE *e, const RAND_METHOD *rand_meth)
543         {
544         e->rand_meth = rand_meth;
545         return 1;
546         }
547
548 int ENGINE_set_BN_mod_exp(ENGINE *e, BN_MOD_EXP bn_mod_exp)
549         {
550         e->bn_mod_exp = bn_mod_exp;
551         return 1;
552         }
553
554 int ENGINE_set_BN_mod_exp_crt(ENGINE *e, BN_MOD_EXP_CRT bn_mod_exp_crt)
555         {
556         e->bn_mod_exp_crt = bn_mod_exp_crt;
557         return 1;
558         }
559
560 int ENGINE_set_init_function(ENGINE *e, ENGINE_GEN_INT_FUNC_PTR init_f)
561         {
562         e->init = init_f;
563         return 1;
564         }
565
566 int ENGINE_set_finish_function(ENGINE *e, ENGINE_GEN_INT_FUNC_PTR finish_f)
567         {
568         e->finish = finish_f;
569         return 1;
570         }
571
572 int ENGINE_set_ctrl_function(ENGINE *e, ENGINE_CTRL_FUNC_PTR ctrl_f)
573         {
574         e->ctrl = ctrl_f;
575         return 1;
576         }
577
578 int ENGINE_set_load_privkey_function(ENGINE *e, ENGINE_LOAD_KEY_PTR loadpriv_f)
579         {
580         e->load_privkey = loadpriv_f;
581         return 1;
582         }
583
584 int ENGINE_set_load_pubkey_function(ENGINE *e, ENGINE_LOAD_KEY_PTR loadpub_f)
585         {
586         e->load_pubkey = loadpub_f;
587         return 1;
588         }
589
590 int ENGINE_set_flags(ENGINE *e, int flags)
591         {
592         e->flags = flags;
593         return 1;
594         }
595
596 int ENGINE_set_cmd_defns(ENGINE *e, const ENGINE_CMD_DEFN *defns)
597         {
598         e->cmd_defns = defns;
599         return 1;
600         }
601
602 int ENGINE_cpy(ENGINE *dest, const ENGINE *src)
603         {
604         if(ENGINE_set_id(dest, ENGINE_get_id(src)) &&
605                         ENGINE_set_name(dest, ENGINE_get_name(src)) &&
606 #ifndef OPENSSL_NO_RSA
607                         ENGINE_set_RSA(dest, ENGINE_get_RSA(src)) &&
608 #endif
609 #ifndef OPENSSL_NO_RSA
610                         ENGINE_set_DSA(dest, ENGINE_get_DSA(src)) &&
611 #endif
612 #ifndef OPENSSL_NO_RSA
613                         ENGINE_set_DH(dest, ENGINE_get_DH(src)) &&
614 #endif
615                         ENGINE_set_RAND(dest, ENGINE_get_RAND(src)) &&
616                         ENGINE_set_BN_mod_exp(dest,
617                                         ENGINE_get_BN_mod_exp(src)) &&
618                         ENGINE_set_BN_mod_exp_crt(dest,
619                                         ENGINE_get_BN_mod_exp_crt(src)) &&
620                         ENGINE_set_init_function(dest,
621                                         ENGINE_get_init_function(src)) &&
622                         ENGINE_set_finish_function(dest,
623                                         ENGINE_get_finish_function(src)) &&
624                         ENGINE_set_ctrl_function(dest,
625                                         ENGINE_get_ctrl_function(src)) &&
626                         ENGINE_set_load_privkey_function(dest,
627                                         ENGINE_get_load_privkey_function(src)) &&
628                         ENGINE_set_load_pubkey_function(dest,
629                                         ENGINE_get_load_pubkey_function(src)) &&
630                         ENGINE_set_flags(dest, ENGINE_get_flags(src)) &&
631                         ENGINE_set_cmd_defns(dest, ENGINE_get_cmd_defns(src)))
632                 return 1;
633         return 0;
634         }
635
636 const char *ENGINE_get_id(const ENGINE *e)
637         {
638         return e->id;
639         }
640
641 const char *ENGINE_get_name(const ENGINE *e)
642         {
643         return e->name;
644         }
645
646 const RSA_METHOD *ENGINE_get_RSA(const ENGINE *e)
647         {
648         return e->rsa_meth;
649         }
650
651 const DSA_METHOD *ENGINE_get_DSA(const ENGINE *e)
652         {
653         return e->dsa_meth;
654         }
655
656 const DH_METHOD *ENGINE_get_DH(const ENGINE *e)
657         {
658         return e->dh_meth;
659         }
660
661 const RAND_METHOD *ENGINE_get_RAND(const ENGINE *e)
662         {
663         return e->rand_meth;
664         }
665
666 BN_MOD_EXP ENGINE_get_BN_mod_exp(const ENGINE *e)
667         {
668         return e->bn_mod_exp;
669         }
670
671 BN_MOD_EXP_CRT ENGINE_get_BN_mod_exp_crt(const ENGINE *e)
672         {
673         return e->bn_mod_exp_crt;
674         }
675
676 ENGINE_GEN_INT_FUNC_PTR ENGINE_get_init_function(const ENGINE *e)
677         {
678         return e->init;
679         }
680
681 ENGINE_GEN_INT_FUNC_PTR ENGINE_get_finish_function(const ENGINE *e)
682         {
683         return e->finish;
684         }
685
686 ENGINE_CTRL_FUNC_PTR ENGINE_get_ctrl_function(const ENGINE *e)
687         {
688         return e->ctrl;
689         }
690
691 ENGINE_LOAD_KEY_PTR ENGINE_get_load_privkey_function(const ENGINE *e)
692         {
693         return e->load_privkey;
694         }
695
696 ENGINE_LOAD_KEY_PTR ENGINE_get_load_pubkey_function(const ENGINE *e)
697         {
698         return e->load_pubkey;
699         }
700
701 int ENGINE_get_flags(const ENGINE *e)
702         {
703         return e->flags;
704         }
705
706 const ENGINE_CMD_DEFN *ENGINE_get_cmd_defns(const ENGINE *e)
707         {
708         return e->cmd_defns;
709         }