summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/engine/engine.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libcrypto/engine/engine.h')
-rw-r--r--src/lib/libcrypto/engine/engine.h158
1 files changed, 107 insertions, 51 deletions
diff --git a/src/lib/libcrypto/engine/engine.h b/src/lib/libcrypto/engine/engine.h
index 900f75ce8d..3ec59338ff 100644
--- a/src/lib/libcrypto/engine/engine.h
+++ b/src/lib/libcrypto/engine/engine.h
@@ -3,7 +3,7 @@
3 * project 2000. 3 * project 2000.
4 */ 4 */
5/* ==================================================================== 5/* ====================================================================
6 * Copyright (c) 1999-2001 The OpenSSL Project. All rights reserved. 6 * Copyright (c) 1999-2004 The OpenSSL Project. All rights reserved.
7 * 7 *
8 * Redistribution and use in source and binary forms, with or without 8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions 9 * modification, are permitted provided that the following conditions
@@ -55,6 +55,11 @@
55 * Hudson (tjh@cryptsoft.com). 55 * Hudson (tjh@cryptsoft.com).
56 * 56 *
57 */ 57 */
58/* ====================================================================
59 * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.
60 * ECDH support in OpenSSL originally developed by
61 * SUN MICROSYSTEMS, INC., and contributed to the OpenSSL project.
62 */
58 63
59#ifndef HEADER_ENGINE_H 64#ifndef HEADER_ENGINE_H
60#define HEADER_ENGINE_H 65#define HEADER_ENGINE_H
@@ -65,7 +70,7 @@
65#error ENGINE is disabled. 70#error ENGINE is disabled.
66#endif 71#endif
67 72
68#include <openssl/ossl_typ.h> 73#ifndef OPENSSL_NO_DEPRECATED
69#include <openssl/bn.h> 74#include <openssl/bn.h>
70#ifndef OPENSSL_NO_RSA 75#ifndef OPENSSL_NO_RSA
71#include <openssl/rsa.h> 76#include <openssl/rsa.h>
@@ -76,34 +81,36 @@
76#ifndef OPENSSL_NO_DH 81#ifndef OPENSSL_NO_DH
77#include <openssl/dh.h> 82#include <openssl/dh.h>
78#endif 83#endif
84#ifndef OPENSSL_NO_ECDH
85#include <openssl/ecdh.h>
86#endif
87#ifndef OPENSSL_NO_ECDSA
88#include <openssl/ecdsa.h>
89#endif
79#include <openssl/rand.h> 90#include <openssl/rand.h>
91#include <openssl/store.h>
80#include <openssl/ui.h> 92#include <openssl/ui.h>
81#include <openssl/symhacks.h>
82#include <openssl/err.h> 93#include <openssl/err.h>
94#endif
95
96#include <openssl/ossl_typ.h>
97#include <openssl/symhacks.h>
83 98
84#ifdef __cplusplus 99#ifdef __cplusplus
85extern "C" { 100extern "C" {
86#endif 101#endif
87 102
88/* Fixups for missing algorithms */
89#ifdef OPENSSL_NO_RSA
90typedef void RSA_METHOD;
91#endif
92#ifdef OPENSSL_NO_DSA
93typedef void DSA_METHOD;
94#endif
95#ifdef OPENSSL_NO_DH
96typedef void DH_METHOD;
97#endif
98
99/* These flags are used to control combinations of algorithm (methods) 103/* These flags are used to control combinations of algorithm (methods)
100 * by bitwise "OR"ing. */ 104 * by bitwise "OR"ing. */
101#define ENGINE_METHOD_RSA (unsigned int)0x0001 105#define ENGINE_METHOD_RSA (unsigned int)0x0001
102#define ENGINE_METHOD_DSA (unsigned int)0x0002 106#define ENGINE_METHOD_DSA (unsigned int)0x0002
103#define ENGINE_METHOD_DH (unsigned int)0x0004 107#define ENGINE_METHOD_DH (unsigned int)0x0004
104#define ENGINE_METHOD_RAND (unsigned int)0x0008 108#define ENGINE_METHOD_RAND (unsigned int)0x0008
109#define ENGINE_METHOD_ECDH (unsigned int)0x0010
110#define ENGINE_METHOD_ECDSA (unsigned int)0x0020
105#define ENGINE_METHOD_CIPHERS (unsigned int)0x0040 111#define ENGINE_METHOD_CIPHERS (unsigned int)0x0040
106#define ENGINE_METHOD_DIGESTS (unsigned int)0x0080 112#define ENGINE_METHOD_DIGESTS (unsigned int)0x0080
113#define ENGINE_METHOD_STORE (unsigned int)0x0100
107/* Obvious all-or-nothing cases. */ 114/* Obvious all-or-nothing cases. */
108#define ENGINE_METHOD_ALL (unsigned int)0xFFFF 115#define ENGINE_METHOD_ALL (unsigned int)0xFFFF
109#define ENGINE_METHOD_NONE (unsigned int)0x0000 116#define ENGINE_METHOD_NONE (unsigned int)0x0000
@@ -173,9 +180,15 @@ typedef void DH_METHOD;
173 handles/connections etc. */ 180 handles/connections etc. */
174#define ENGINE_CTRL_SET_USER_INTERFACE 4 /* Alternative to callback */ 181#define ENGINE_CTRL_SET_USER_INTERFACE 4 /* Alternative to callback */
175#define ENGINE_CTRL_SET_CALLBACK_DATA 5 /* User-specific data, used 182#define ENGINE_CTRL_SET_CALLBACK_DATA 5 /* User-specific data, used
176 when calling the password 183 when calling the password
177 callback and the user 184 callback and the user
178 interface */ 185 interface */
186#define ENGINE_CTRL_LOAD_CONFIGURATION 6 /* Load a configuration, given
187 a string that represents a
188 file name or so */
189#define ENGINE_CTRL_LOAD_SECTION 7 /* Load data from a given
190 section in the already loaded
191 configuration */
179 192
180/* These control commands allow an application to deal with an arbitrary engine 193/* These control commands allow an application to deal with an arbitrary engine
181 * in a dynamic way. Warn: Negative return values indicate errors FOR THESE 194 * in a dynamic way. Warn: Negative return values indicate errors FOR THESE
@@ -222,7 +235,7 @@ typedef void DH_METHOD;
222 235
223/* ENGINE implementations should start the numbering of their own control 236/* ENGINE implementations should start the numbering of their own control
224 * commands from this value. (ie. ENGINE_CMD_BASE, ENGINE_CMD_BASE + 1, etc). */ 237 * commands from this value. (ie. ENGINE_CMD_BASE, ENGINE_CMD_BASE + 1, etc). */
225#define ENGINE_CMD_BASE 200 238#define ENGINE_CMD_BASE 200
226 239
227/* NB: These 2 nCipher "chil" control commands are deprecated, and their 240/* NB: These 2 nCipher "chil" control commands are deprecated, and their
228 * functionality is now available through ENGINE-specific control commands 241 * functionality is now available through ENGINE-specific control commands
@@ -257,11 +270,11 @@ typedef struct ENGINE_CMD_DEFN_st
257 } ENGINE_CMD_DEFN; 270 } ENGINE_CMD_DEFN;
258 271
259/* Generic function pointer */ 272/* Generic function pointer */
260typedef int (*ENGINE_GEN_FUNC_PTR)(); 273typedef int (*ENGINE_GEN_FUNC_PTR)(void);
261/* Generic function pointer taking no arguments */ 274/* Generic function pointer taking no arguments */
262typedef int (*ENGINE_GEN_INT_FUNC_PTR)(ENGINE *); 275typedef int (*ENGINE_GEN_INT_FUNC_PTR)(ENGINE *);
263/* Specific control function pointer */ 276/* Specific control function pointer */
264typedef int (*ENGINE_CTRL_FUNC_PTR)(ENGINE *, int, long, void *, void (*f)()); 277typedef int (*ENGINE_CTRL_FUNC_PTR)(ENGINE *, int, long, void *, void (*f)(void));
265/* Generic load_key function pointer */ 278/* Generic load_key function pointer */
266typedef EVP_PKEY * (*ENGINE_LOAD_KEY_PTR)(ENGINE *, const char *, 279typedef EVP_PKEY * (*ENGINE_LOAD_KEY_PTR)(ENGINE *, const char *,
267 UI_METHOD *ui_method, void *callback_data); 280 UI_METHOD *ui_method, void *callback_data);
@@ -305,15 +318,21 @@ ENGINE *ENGINE_by_id(const char *id);
305/* Add all the built-in engines. */ 318/* Add all the built-in engines. */
306void ENGINE_load_openssl(void); 319void ENGINE_load_openssl(void);
307void ENGINE_load_dynamic(void); 320void ENGINE_load_dynamic(void);
308void ENGINE_load_cswift(void); 321#ifndef OPENSSL_NO_STATIC_ENGINE
309void ENGINE_load_chil(void); 322void ENGINE_load_4758cca(void);
323void ENGINE_load_aep(void);
310void ENGINE_load_atalla(void); 324void ENGINE_load_atalla(void);
325void ENGINE_load_chil(void);
326void ENGINE_load_cswift(void);
327#ifndef OPENSSL_NO_GMP
328void ENGINE_load_gmp(void);
329#endif
311void ENGINE_load_nuron(void); 330void ENGINE_load_nuron(void);
312void ENGINE_load_ubsec(void);
313void ENGINE_load_aep(void);
314void ENGINE_load_sureware(void); 331void ENGINE_load_sureware(void);
315void ENGINE_load_4758cca(void); 332void ENGINE_load_ubsec(void);
333#endif
316void ENGINE_load_cryptodev(void); 334void ENGINE_load_cryptodev(void);
335void ENGINE_load_padlock(void);
317void ENGINE_load_builtin_engines(void); 336void ENGINE_load_builtin_engines(void);
318 337
319/* Get and set global flags (ENGINE_TABLE_FLAG_***) for the implementation 338/* Get and set global flags (ENGINE_TABLE_FLAG_***) for the implementation
@@ -337,6 +356,14 @@ int ENGINE_register_DSA(ENGINE *e);
337void ENGINE_unregister_DSA(ENGINE *e); 356void ENGINE_unregister_DSA(ENGINE *e);
338void ENGINE_register_all_DSA(void); 357void ENGINE_register_all_DSA(void);
339 358
359int ENGINE_register_ECDH(ENGINE *e);
360void ENGINE_unregister_ECDH(ENGINE *e);
361void ENGINE_register_all_ECDH(void);
362
363int ENGINE_register_ECDSA(ENGINE *e);
364void ENGINE_unregister_ECDSA(ENGINE *e);
365void ENGINE_register_all_ECDSA(void);
366
340int ENGINE_register_DH(ENGINE *e); 367int ENGINE_register_DH(ENGINE *e);
341void ENGINE_unregister_DH(ENGINE *e); 368void ENGINE_unregister_DH(ENGINE *e);
342void ENGINE_register_all_DH(void); 369void ENGINE_register_all_DH(void);
@@ -345,6 +372,10 @@ int ENGINE_register_RAND(ENGINE *e);
345void ENGINE_unregister_RAND(ENGINE *e); 372void ENGINE_unregister_RAND(ENGINE *e);
346void ENGINE_register_all_RAND(void); 373void ENGINE_register_all_RAND(void);
347 374
375int ENGINE_register_STORE(ENGINE *e);
376void ENGINE_unregister_STORE(ENGINE *e);
377void ENGINE_register_all_STORE(void);
378
348int ENGINE_register_ciphers(ENGINE *e); 379int ENGINE_register_ciphers(ENGINE *e);
349void ENGINE_unregister_ciphers(ENGINE *e); 380void ENGINE_unregister_ciphers(ENGINE *e);
350void ENGINE_register_all_ciphers(void); 381void ENGINE_register_all_ciphers(void);
@@ -367,7 +398,7 @@ int ENGINE_register_all_complete(void);
367 * reference to an engine, but many control commands may require the engine be 398 * reference to an engine, but many control commands may require the engine be
368 * functional. The caller should be aware of trying commands that require an 399 * functional. The caller should be aware of trying commands that require an
369 * operational ENGINE, and only use functional references in such situations. */ 400 * operational ENGINE, and only use functional references in such situations. */
370int ENGINE_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)()); 401int ENGINE_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)(void));
371 402
372/* This function tests if an ENGINE-specific command is usable as a "setting". 403/* This function tests if an ENGINE-specific command is usable as a "setting".
373 * Eg. in an application's config file that gets processed through 404 * Eg. in an application's config file that gets processed through
@@ -380,7 +411,7 @@ int ENGINE_cmd_is_executable(ENGINE *e, int cmd);
380 * See the comment on ENGINE_ctrl_cmd_string() for an explanation on how to 411 * See the comment on ENGINE_ctrl_cmd_string() for an explanation on how to
381 * use the cmd_name and cmd_optional. */ 412 * use the cmd_name and cmd_optional. */
382int ENGINE_ctrl_cmd(ENGINE *e, const char *cmd_name, 413int ENGINE_ctrl_cmd(ENGINE *e, const char *cmd_name,
383 long i, void *p, void (*f)(), int cmd_optional); 414 long i, void *p, void (*f)(void), int cmd_optional);
384 415
385/* This function passes a command-name and argument to an ENGINE. The cmd_name 416/* This function passes a command-name and argument to an ENGINE. The cmd_name
386 * is converted to a command number and the control command is called using 417 * is converted to a command number and the control command is called using
@@ -417,8 +448,11 @@ int ENGINE_set_id(ENGINE *e, const char *id);
417int ENGINE_set_name(ENGINE *e, const char *name); 448int ENGINE_set_name(ENGINE *e, const char *name);
418int ENGINE_set_RSA(ENGINE *e, const RSA_METHOD *rsa_meth); 449int ENGINE_set_RSA(ENGINE *e, const RSA_METHOD *rsa_meth);
419int ENGINE_set_DSA(ENGINE *e, const DSA_METHOD *dsa_meth); 450int ENGINE_set_DSA(ENGINE *e, const DSA_METHOD *dsa_meth);
451int ENGINE_set_ECDH(ENGINE *e, const ECDH_METHOD *ecdh_meth);
452int ENGINE_set_ECDSA(ENGINE *e, const ECDSA_METHOD *ecdsa_meth);
420int ENGINE_set_DH(ENGINE *e, const DH_METHOD *dh_meth); 453int ENGINE_set_DH(ENGINE *e, const DH_METHOD *dh_meth);
421int ENGINE_set_RAND(ENGINE *e, const RAND_METHOD *rand_meth); 454int ENGINE_set_RAND(ENGINE *e, const RAND_METHOD *rand_meth);
455int ENGINE_set_STORE(ENGINE *e, const STORE_METHOD *store_meth);
422int ENGINE_set_destroy_function(ENGINE *e, ENGINE_GEN_INT_FUNC_PTR destroy_f); 456int ENGINE_set_destroy_function(ENGINE *e, ENGINE_GEN_INT_FUNC_PTR destroy_f);
423int ENGINE_set_init_function(ENGINE *e, ENGINE_GEN_INT_FUNC_PTR init_f); 457int ENGINE_set_init_function(ENGINE *e, ENGINE_GEN_INT_FUNC_PTR init_f);
424int ENGINE_set_finish_function(ENGINE *e, ENGINE_GEN_INT_FUNC_PTR finish_f); 458int ENGINE_set_finish_function(ENGINE *e, ENGINE_GEN_INT_FUNC_PTR finish_f);
@@ -429,11 +463,11 @@ int ENGINE_set_ciphers(ENGINE *e, ENGINE_CIPHERS_PTR f);
429int ENGINE_set_digests(ENGINE *e, ENGINE_DIGESTS_PTR f); 463int ENGINE_set_digests(ENGINE *e, ENGINE_DIGESTS_PTR f);
430int ENGINE_set_flags(ENGINE *e, int flags); 464int ENGINE_set_flags(ENGINE *e, int flags);
431int ENGINE_set_cmd_defns(ENGINE *e, const ENGINE_CMD_DEFN *defns); 465int ENGINE_set_cmd_defns(ENGINE *e, const ENGINE_CMD_DEFN *defns);
432/* These functions (and the "get" function lower down) allow control over any 466/* These functions allow control over any per-structure ENGINE data. */
433 * per-structure ENGINE data. */
434int ENGINE_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func, 467int ENGINE_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func,
435 CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func); 468 CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func);
436int ENGINE_set_ex_data(ENGINE *e, int idx, void *arg); 469int ENGINE_set_ex_data(ENGINE *e, int idx, void *arg);
470void *ENGINE_get_ex_data(const ENGINE *e, int idx);
437 471
438/* This function cleans up anything that needs it. Eg. the ENGINE_add() function 472/* This function cleans up anything that needs it. Eg. the ENGINE_add() function
439 * automatically ensures the list cleanup function is registered to be called 473 * automatically ensures the list cleanup function is registered to be called
@@ -449,8 +483,11 @@ const char *ENGINE_get_id(const ENGINE *e);
449const char *ENGINE_get_name(const ENGINE *e); 483const char *ENGINE_get_name(const ENGINE *e);
450const RSA_METHOD *ENGINE_get_RSA(const ENGINE *e); 484const RSA_METHOD *ENGINE_get_RSA(const ENGINE *e);
451const DSA_METHOD *ENGINE_get_DSA(const ENGINE *e); 485const DSA_METHOD *ENGINE_get_DSA(const ENGINE *e);
486const ECDH_METHOD *ENGINE_get_ECDH(const ENGINE *e);
487const ECDSA_METHOD *ENGINE_get_ECDSA(const ENGINE *e);
452const DH_METHOD *ENGINE_get_DH(const ENGINE *e); 488const DH_METHOD *ENGINE_get_DH(const ENGINE *e);
453const RAND_METHOD *ENGINE_get_RAND(const ENGINE *e); 489const RAND_METHOD *ENGINE_get_RAND(const ENGINE *e);
490const STORE_METHOD *ENGINE_get_STORE(const ENGINE *e);
454ENGINE_GEN_INT_FUNC_PTR ENGINE_get_destroy_function(const ENGINE *e); 491ENGINE_GEN_INT_FUNC_PTR ENGINE_get_destroy_function(const ENGINE *e);
455ENGINE_GEN_INT_FUNC_PTR ENGINE_get_init_function(const ENGINE *e); 492ENGINE_GEN_INT_FUNC_PTR ENGINE_get_init_function(const ENGINE *e);
456ENGINE_GEN_INT_FUNC_PTR ENGINE_get_finish_function(const ENGINE *e); 493ENGINE_GEN_INT_FUNC_PTR ENGINE_get_finish_function(const ENGINE *e);
@@ -463,7 +500,6 @@ const EVP_CIPHER *ENGINE_get_cipher(ENGINE *e, int nid);
463const EVP_MD *ENGINE_get_digest(ENGINE *e, int nid); 500const EVP_MD *ENGINE_get_digest(ENGINE *e, int nid);
464const ENGINE_CMD_DEFN *ENGINE_get_cmd_defns(const ENGINE *e); 501const ENGINE_CMD_DEFN *ENGINE_get_cmd_defns(const ENGINE *e);
465int ENGINE_get_flags(const ENGINE *e); 502int ENGINE_get_flags(const ENGINE *e);
466void *ENGINE_get_ex_data(const ENGINE *e, int idx);
467 503
468/* FUNCTIONAL functions. These functions deal with ENGINE structures 504/* FUNCTIONAL functions. These functions deal with ENGINE structures
469 * that have (or will) be initialised for use. Broadly speaking, the 505 * that have (or will) be initialised for use. Broadly speaking, the
@@ -501,6 +537,8 @@ EVP_PKEY *ENGINE_load_public_key(ENGINE *e, const char *key_id,
501ENGINE *ENGINE_get_default_RSA(void); 537ENGINE *ENGINE_get_default_RSA(void);
502/* Same for the other "methods" */ 538/* Same for the other "methods" */
503ENGINE *ENGINE_get_default_DSA(void); 539ENGINE *ENGINE_get_default_DSA(void);
540ENGINE *ENGINE_get_default_ECDH(void);
541ENGINE *ENGINE_get_default_ECDSA(void);
504ENGINE *ENGINE_get_default_DH(void); 542ENGINE *ENGINE_get_default_DH(void);
505ENGINE *ENGINE_get_default_RAND(void); 543ENGINE *ENGINE_get_default_RAND(void);
506/* These functions can be used to get a functional reference to perform 544/* These functions can be used to get a functional reference to perform
@@ -516,6 +554,8 @@ int ENGINE_set_default_RSA(ENGINE *e);
516int ENGINE_set_default_string(ENGINE *e, const char *def_list); 554int ENGINE_set_default_string(ENGINE *e, const char *def_list);
517/* Same for the other "methods" */ 555/* Same for the other "methods" */
518int ENGINE_set_default_DSA(ENGINE *e); 556int ENGINE_set_default_DSA(ENGINE *e);
557int ENGINE_set_default_ECDH(ENGINE *e);
558int ENGINE_set_default_ECDSA(ENGINE *e);
519int ENGINE_set_default_DH(ENGINE *e); 559int ENGINE_set_default_DH(ENGINE *e);
520int ENGINE_set_default_RAND(ENGINE *e); 560int ENGINE_set_default_RAND(ENGINE *e);
521int ENGINE_set_default_ciphers(ENGINE *e); 561int ENGINE_set_default_ciphers(ENGINE *e);
@@ -538,17 +578,20 @@ void ENGINE_add_conf_module(void);
538/**************************/ 578/**************************/
539 579
540/* Binary/behaviour compatibility levels */ 580/* Binary/behaviour compatibility levels */
541#define OSSL_DYNAMIC_VERSION (unsigned long)0x00010200 581#define OSSL_DYNAMIC_VERSION (unsigned long)0x00020000
542/* Binary versions older than this are too old for us (whether we're a loader or 582/* Binary versions older than this are too old for us (whether we're a loader or
543 * a loadee) */ 583 * a loadee) */
544#define OSSL_DYNAMIC_OLDEST (unsigned long)0x00010200 584#define OSSL_DYNAMIC_OLDEST (unsigned long)0x00020000
545 585
546/* When compiling an ENGINE entirely as an external shared library, loadable by 586/* When compiling an ENGINE entirely as an external shared library, loadable by
547 * the "dynamic" ENGINE, these types are needed. The 'dynamic_fns' structure 587 * the "dynamic" ENGINE, these types are needed. The 'dynamic_fns' structure
548 * type provides the calling application's (or library's) error functionality 588 * type provides the calling application's (or library's) error functionality
549 * and memory management function pointers to the loaded library. These should 589 * and memory management function pointers to the loaded library. These should
550 * be used/set in the loaded library code so that the loading application's 590 * be used/set in the loaded library code so that the loading application's
551 * 'state' will be used/changed in all operations. */ 591 * 'state' will be used/changed in all operations. The 'static_state' pointer
592 * allows the loaded library to know if it shares the same static data as the
593 * calling application (or library), and thus whether these callbacks need to be
594 * set or not. */
552typedef void *(*dyn_MEM_malloc_cb)(size_t); 595typedef void *(*dyn_MEM_malloc_cb)(size_t);
553typedef void *(*dyn_MEM_realloc_cb)(void *, size_t); 596typedef void *(*dyn_MEM_realloc_cb)(void *, size_t);
554typedef void (*dyn_MEM_free_cb)(void *); 597typedef void (*dyn_MEM_free_cb)(void *);
@@ -576,6 +619,7 @@ typedef struct st_dynamic_LOCK_fns {
576 } dynamic_LOCK_fns; 619 } dynamic_LOCK_fns;
577/* The top-level structure */ 620/* The top-level structure */
578typedef struct st_dynamic_fns { 621typedef struct st_dynamic_fns {
622 void *static_state;
579 const ERR_FNS *err_fns; 623 const ERR_FNS *err_fns;
580 const CRYPTO_EX_DATA_IMPL *ex_data_fns; 624 const CRYPTO_EX_DATA_IMPL *ex_data_fns;
581 dynamic_MEM_fns mem_fns; 625 dynamic_MEM_fns mem_fns;
@@ -593,7 +637,7 @@ typedef struct st_dynamic_fns {
593 * can be fully instantiated with IMPLEMENT_DYNAMIC_CHECK_FN(). */ 637 * can be fully instantiated with IMPLEMENT_DYNAMIC_CHECK_FN(). */
594typedef unsigned long (*dynamic_v_check_fn)(unsigned long ossl_version); 638typedef unsigned long (*dynamic_v_check_fn)(unsigned long ossl_version);
595#define IMPLEMENT_DYNAMIC_CHECK_FN() \ 639#define IMPLEMENT_DYNAMIC_CHECK_FN() \
596 unsigned long v_check(unsigned long v) { \ 640 OPENSSL_EXPORT unsigned long v_check(unsigned long v) { \
597 if(v >= OSSL_DYNAMIC_OLDEST) return OSSL_DYNAMIC_VERSION; \ 641 if(v >= OSSL_DYNAMIC_OLDEST) return OSSL_DYNAMIC_VERSION; \
598 return 0; } 642 return 0; }
599 643
@@ -615,24 +659,35 @@ typedef unsigned long (*dynamic_v_check_fn)(unsigned long ossl_version);
615typedef int (*dynamic_bind_engine)(ENGINE *e, const char *id, 659typedef int (*dynamic_bind_engine)(ENGINE *e, const char *id,
616 const dynamic_fns *fns); 660 const dynamic_fns *fns);
617#define IMPLEMENT_DYNAMIC_BIND_FN(fn) \ 661#define IMPLEMENT_DYNAMIC_BIND_FN(fn) \
662 OPENSSL_EXPORT \
618 int bind_engine(ENGINE *e, const char *id, const dynamic_fns *fns) { \ 663 int bind_engine(ENGINE *e, const char *id, const dynamic_fns *fns) { \
619 if (ERR_get_implementation() != fns->err_fns) \ 664 if(ENGINE_get_static_state() == fns->static_state) goto skip_cbs; \
620 { \ 665 if(!CRYPTO_set_mem_functions(fns->mem_fns.malloc_cb, \
621 if(!CRYPTO_set_mem_functions(fns->mem_fns.malloc_cb, \ 666 fns->mem_fns.realloc_cb, fns->mem_fns.free_cb)) \
622 fns->mem_fns.realloc_cb, fns->mem_fns.free_cb)) \ 667 return 0; \
623 return 0; \ 668 CRYPTO_set_locking_callback(fns->lock_fns.lock_locking_cb); \
624 CRYPTO_set_locking_callback(fns->lock_fns.lock_locking_cb); \ 669 CRYPTO_set_add_lock_callback(fns->lock_fns.lock_add_lock_cb); \
625 CRYPTO_set_add_lock_callback(fns->lock_fns.lock_add_lock_cb); \ 670 CRYPTO_set_dynlock_create_callback(fns->lock_fns.dynlock_create_cb); \
626 CRYPTO_set_dynlock_create_callback(fns->lock_fns.dynlock_create_cb); \ 671 CRYPTO_set_dynlock_lock_callback(fns->lock_fns.dynlock_lock_cb); \
627 CRYPTO_set_dynlock_lock_callback(fns->lock_fns.dynlock_lock_cb); \ 672 CRYPTO_set_dynlock_destroy_callback(fns->lock_fns.dynlock_destroy_cb); \
628 CRYPTO_set_dynlock_destroy_callback(fns->lock_fns.dynlock_destroy_cb); \ 673 if(!CRYPTO_set_ex_data_implementation(fns->ex_data_fns)) \
629 if(!CRYPTO_set_ex_data_implementation(fns->ex_data_fns)) \ 674 return 0; \
630 return 0; \ 675 if(!ERR_set_implementation(fns->err_fns)) return 0; \
631 if(!ERR_set_implementation(fns->err_fns)) return 0; \ 676 skip_cbs: \
632 } \
633 if(!fn(e,id)) return 0; \ 677 if(!fn(e,id)) return 0; \
634 return 1; } 678 return 1; }
635 679
680/* If the loading application (or library) and the loaded ENGINE library share
681 * the same static data (eg. they're both dynamically linked to the same
682 * libcrypto.so) we need a way to avoid trying to set system callbacks - this
683 * would fail, and for the same reason that it's unnecessary to try. If the
684 * loaded ENGINE has (or gets from through the loader) its own copy of the
685 * libcrypto static data, we will need to set the callbacks. The easiest way to
686 * detect this is to have a function that returns a pointer to some static data
687 * and let the loading application and loaded ENGINE compare their respective
688 * values. */
689void *ENGINE_get_static_state(void);
690
636#if defined(__OpenBSD__) || defined(__FreeBSD__) 691#if defined(__OpenBSD__) || defined(__FreeBSD__)
637void ENGINE_setup_bsd_cryptodev(void); 692void ENGINE_setup_bsd_cryptodev(void);
638#endif 693#endif
@@ -649,6 +704,7 @@ void ERR_load_ENGINE_strings(void);
649#define ENGINE_F_DYNAMIC_CTRL 180 704#define ENGINE_F_DYNAMIC_CTRL 180
650#define ENGINE_F_DYNAMIC_GET_DATA_CTX 181 705#define ENGINE_F_DYNAMIC_GET_DATA_CTX 181
651#define ENGINE_F_DYNAMIC_LOAD 182 706#define ENGINE_F_DYNAMIC_LOAD 182
707#define ENGINE_F_DYNAMIC_SET_DATA_CTX 183
652#define ENGINE_F_ENGINE_ADD 105 708#define ENGINE_F_ENGINE_ADD 105
653#define ENGINE_F_ENGINE_BY_ID 106 709#define ENGINE_F_ENGINE_BY_ID 106
654#define ENGINE_F_ENGINE_CMD_IS_EXECUTABLE 170 710#define ENGINE_F_ENGINE_CMD_IS_EXECUTABLE 170
@@ -656,7 +712,7 @@ void ERR_load_ENGINE_strings(void);
656#define ENGINE_F_ENGINE_CTRL_CMD 178 712#define ENGINE_F_ENGINE_CTRL_CMD 178
657#define ENGINE_F_ENGINE_CTRL_CMD_STRING 171 713#define ENGINE_F_ENGINE_CTRL_CMD_STRING 171
658#define ENGINE_F_ENGINE_FINISH 107 714#define ENGINE_F_ENGINE_FINISH 107
659#define ENGINE_F_ENGINE_FREE 108 715#define ENGINE_F_ENGINE_FREE_UTIL 108
660#define ENGINE_F_ENGINE_GET_CIPHER 185 716#define ENGINE_F_ENGINE_GET_CIPHER 185
661#define ENGINE_F_ENGINE_GET_DEFAULT_TYPE 177 717#define ENGINE_F_ENGINE_GET_DEFAULT_TYPE 177
662#define ENGINE_F_ENGINE_GET_DIGEST 186 718#define ENGINE_F_ENGINE_GET_DIGEST 186
@@ -667,7 +723,6 @@ void ERR_load_ENGINE_strings(void);
667#define ENGINE_F_ENGINE_LIST_REMOVE 121 723#define ENGINE_F_ENGINE_LIST_REMOVE 121
668#define ENGINE_F_ENGINE_LOAD_PRIVATE_KEY 150 724#define ENGINE_F_ENGINE_LOAD_PRIVATE_KEY 150
669#define ENGINE_F_ENGINE_LOAD_PUBLIC_KEY 151 725#define ENGINE_F_ENGINE_LOAD_PUBLIC_KEY 151
670#define ENGINE_F_ENGINE_MODULE_INIT 187
671#define ENGINE_F_ENGINE_NEW 122 726#define ENGINE_F_ENGINE_NEW 122
672#define ENGINE_F_ENGINE_REMOVE 123 727#define ENGINE_F_ENGINE_REMOVE 123
673#define ENGINE_F_ENGINE_SET_DEFAULT_STRING 189 728#define ENGINE_F_ENGINE_SET_DEFAULT_STRING 189
@@ -676,11 +731,12 @@ void ERR_load_ENGINE_strings(void);
676#define ENGINE_F_ENGINE_SET_NAME 130 731#define ENGINE_F_ENGINE_SET_NAME 130
677#define ENGINE_F_ENGINE_TABLE_REGISTER 184 732#define ENGINE_F_ENGINE_TABLE_REGISTER 184
678#define ENGINE_F_ENGINE_UNLOAD_KEY 152 733#define ENGINE_F_ENGINE_UNLOAD_KEY 152
734#define ENGINE_F_ENGINE_UNLOCKED_FINISH 191
679#define ENGINE_F_ENGINE_UP_REF 190 735#define ENGINE_F_ENGINE_UP_REF 190
680#define ENGINE_F_INT_CTRL_HELPER 172 736#define ENGINE_F_INT_CTRL_HELPER 172
681#define ENGINE_F_INT_ENGINE_CONFIGURE 188 737#define ENGINE_F_INT_ENGINE_CONFIGURE 188
738#define ENGINE_F_INT_ENGINE_MODULE_INIT 187
682#define ENGINE_F_LOG_MESSAGE 141 739#define ENGINE_F_LOG_MESSAGE 141
683#define ENGINE_F_SET_DATA_CTX 183
684 740
685/* Reason codes. */ 741/* Reason codes. */
686#define ENGINE_R_ALREADY_LOADED 100 742#define ENGINE_R_ALREADY_LOADED 100