ENGINE uses a very opaque design, so we can predeclare the structure type
[openssl.git] / crypto / engine / engine.h
index 4c03be3ac25a82f4c3fc7deece73cde50584f5a7..99b378c9d465da9f9420d020d8532ca43ce5c600 100644 (file)
@@ -259,13 +259,6 @@ typedef int (*BN_MOD_EXP_CRT)(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
                const BIGNUM *q, const BIGNUM *dmp1, const BIGNUM *dmq1,
                const BIGNUM *iqmp, BN_CTX *ctx);
 
-/* The list of "engine" types is a static array of (const ENGINE*)
- * pointers (not dynamic because static is fine for now and we otherwise
- * have to hook an appropriate load/unload function in to initialise and
- * cleanup). */
-struct engine_st;
-typedef struct engine_st ENGINE;
-
 /* Generic function pointer */
 typedef int (*ENGINE_GEN_FUNC_PTR)();
 /* Generic function pointer taking no arguments */
@@ -371,6 +364,7 @@ int ENGINE_set_DH(ENGINE *e, const DH_METHOD *dh_meth);
 int ENGINE_set_RAND(ENGINE *e, const RAND_METHOD *rand_meth);
 int ENGINE_set_BN_mod_exp(ENGINE *e, BN_MOD_EXP bn_mod_exp);
 int ENGINE_set_BN_mod_exp_crt(ENGINE *e, BN_MOD_EXP_CRT bn_mod_exp_crt);
+int ENGINE_set_destroy_function(ENGINE *e, ENGINE_GEN_INT_FUNC_PTR destroy_f);
 int ENGINE_set_init_function(ENGINE *e, ENGINE_GEN_INT_FUNC_PTR init_f);
 int ENGINE_set_finish_function(ENGINE *e, ENGINE_GEN_INT_FUNC_PTR finish_f);
 int ENGINE_set_ctrl_function(ENGINE *e, ENGINE_CTRL_FUNC_PTR ctrl_f);
@@ -409,6 +403,7 @@ int ENGINE_cipher_num(const ENGINE *e);
 const EVP_CIPHER *ENGINE_get_cipher(const ENGINE *e, int n);
 BN_MOD_EXP ENGINE_get_BN_mod_exp(const ENGINE *e);
 BN_MOD_EXP_CRT ENGINE_get_BN_mod_exp_crt(const ENGINE *e);
+ENGINE_GEN_INT_FUNC_PTR ENGINE_get_destroy_function(const ENGINE *e);
 ENGINE_GEN_INT_FUNC_PTR ENGINE_get_init_function(const ENGINE *e);
 ENGINE_GEN_INT_FUNC_PTR ENGINE_get_finish_function(const ENGINE *e);
 ENGINE_CTRL_FUNC_PTR ENGINE_get_ctrl_function(const ENGINE *e);
@@ -504,18 +499,37 @@ const EVP_CIPHER *ENGINE_get_cipher_by_name(ENGINE *e,const char *name);
  * and memory management function pointers to the loaded library. These should
  * be used/set in the loaded library code so that the loading application's
  * 'state' will be used/changed in all operations. */
-typedef void *(*dynamic_MEM_malloc_cb)(size_t);
-typedef void *(*dynamic_MEM_realloc_cb)(void *, size_t);
-typedef void (*dynamic_MEM_free_cb)(void *);
+typedef void *(*dyn_MEM_malloc_cb)(size_t);
+typedef void *(*dyn_MEM_realloc_cb)(void *, size_t);
+typedef void (*dyn_MEM_free_cb)(void *);
 typedef struct st_dynamic_MEM_fns {
-       dynamic_MEM_malloc_cb                   malloc_cb;
-       dynamic_MEM_realloc_cb                  realloc_cb;
-       dynamic_MEM_free_cb                     free_cb;
+       dyn_MEM_malloc_cb                       malloc_cb;
+       dyn_MEM_realloc_cb                      realloc_cb;
+       dyn_MEM_free_cb                         free_cb;
        } dynamic_MEM_fns;
+/* FIXME: Perhaps the memory and locking code (crypto.h) should declare and use
+ * these types so we (and any other dependant code) can simplify a bit?? */
+typedef void (*dyn_lock_locking_cb)(int,int,const char *,int);
+typedef int (*dyn_lock_add_lock_cb)(int*,int,int,const char *,int);
+typedef struct CRYPTO_dynlock_value *(*dyn_dynlock_create_cb)(
+                                               const char *,int);
+typedef void (*dyn_dynlock_lock_cb)(int,struct CRYPTO_dynlock_value *,
+                                               const char *,int);
+typedef void (*dyn_dynlock_destroy_cb)(struct CRYPTO_dynlock_value *,
+                                               const char *,int);
+typedef struct st_dynamic_LOCK_fns {
+       dyn_lock_locking_cb                     lock_locking_cb;
+       dyn_lock_add_lock_cb                    lock_add_lock_cb;
+       dyn_dynlock_create_cb                   dynlock_create_cb;
+       dyn_dynlock_lock_cb                     dynlock_lock_cb;
+       dyn_dynlock_destroy_cb                  dynlock_destroy_cb;
+       } dynamic_LOCK_fns;
+/* The top-level structure */
 typedef struct st_dynamic_fns {
        const ERR_FNS                           *err_fns;
        const CRYPTO_EX_DATA_IMPL               *ex_data_fns;
        dynamic_MEM_fns                         mem_fns;
+       dynamic_LOCK_fns                        lock_fns;
        } dynamic_fns;
 
 /* The version checking function should be of this prototype. NB: The
@@ -555,15 +569,17 @@ typedef int (*dynamic_bind_engine)(ENGINE *e, const char *id,
                if(!CRYPTO_set_mem_functions(fns->mem_fns.malloc_cb, \
                        fns->mem_fns.realloc_cb, fns->mem_fns.free_cb)) \
                        return 0; \
+               CRYPTO_set_locking_callback(fns->lock_fns.lock_locking_cb); \
+               CRYPTO_set_add_lock_callback(fns->lock_fns.lock_add_lock_cb); \
+               CRYPTO_set_dynlock_create_callback(fns->lock_fns.dynlock_create_cb); \
+               CRYPTO_set_dynlock_lock_callback(fns->lock_fns.dynlock_lock_cb); \
+               CRYPTO_set_dynlock_destroy_callback(fns->lock_fns.dynlock_destroy_cb); \
                if(!CRYPTO_set_ex_data_implementation(fns->ex_data_fns)) \
                        return 0; \
                if(!ERR_set_implementation(fns->err_fns)) return 0; \
                if(!fn(e,id)) return 0; \
                return 1; }
 
-/* Obligatory error function. */
-void ERR_load_ENGINE_strings(void);
-
 /* BEGIN ERROR CODES */
 /* The following lines are auto generated by the script mkerr.pl. Any changes
  * made after this point may be overwritten when the script is next run.
@@ -573,19 +589,6 @@ void ERR_load_ENGINE_strings(void);
 /* Error codes for the ENGINE functions. */
 
 /* Function codes. */
-#define ENGINE_F_ATALLA_CTRL                            173
-#define ENGINE_F_ATALLA_FINISH                          159
-#define ENGINE_F_ATALLA_INIT                            160
-#define ENGINE_F_ATALLA_MOD_EXP                                 161
-#define ENGINE_F_ATALLA_RSA_MOD_EXP                     162
-#define ENGINE_F_CSWIFT_CTRL                            174
-#define ENGINE_F_CSWIFT_DSA_SIGN                        133
-#define ENGINE_F_CSWIFT_DSA_VERIFY                      134
-#define ENGINE_F_CSWIFT_FINISH                          100
-#define ENGINE_F_CSWIFT_INIT                            101
-#define ENGINE_F_CSWIFT_MOD_EXP                                 102
-#define ENGINE_F_CSWIFT_MOD_EXP_CRT                     103
-#define ENGINE_F_CSWIFT_RSA_MOD_EXP                     104
 #define ENGINE_F_DYNAMIC_CTRL                           180
 #define ENGINE_F_DYNAMIC_GET_DATA_CTX                   181
 #define ENGINE_F_DYNAMIC_LOAD                           182
@@ -611,32 +614,9 @@ void ERR_load_ENGINE_strings(void);
 #define ENGINE_F_ENGINE_SET_ID                          129
 #define ENGINE_F_ENGINE_SET_NAME                        130
 #define ENGINE_F_ENGINE_UNLOAD_KEY                      152
-#define ENGINE_F_HWCRHK_CTRL                            143
-#define ENGINE_F_HWCRHK_FINISH                          135
-#define ENGINE_F_HWCRHK_GET_PASS                        155
-#define ENGINE_F_HWCRHK_INIT                            136
-#define ENGINE_F_HWCRHK_INSERT_CARD                     179
-#define ENGINE_F_HWCRHK_LOAD_PRIVKEY                    153
-#define ENGINE_F_HWCRHK_LOAD_PUBKEY                     154
-#define ENGINE_F_HWCRHK_MOD_EXP                                 137
-#define ENGINE_F_HWCRHK_MOD_EXP_CRT                     138
-#define ENGINE_F_HWCRHK_RAND_BYTES                      139
-#define ENGINE_F_HWCRHK_RSA_MOD_EXP                     140
 #define ENGINE_F_INT_CTRL_HELPER                        172
 #define ENGINE_F_LOG_MESSAGE                            141
-#define ENGINE_F_NURON_CTRL                             175
-#define ENGINE_F_NURON_FINISH                           157
-#define ENGINE_F_NURON_INIT                             156
-#define ENGINE_F_NURON_MOD_EXP                          158
 #define ENGINE_F_SET_DATA_CTX                           183
-#define ENGINE_F_UBSEC_CTRL                             176
-#define ENGINE_F_UBSEC_DSA_SIGN                                 163
-#define ENGINE_F_UBSEC_DSA_VERIFY                       164
-#define ENGINE_F_UBSEC_FINISH                           165
-#define ENGINE_F_UBSEC_INIT                             166
-#define ENGINE_F_UBSEC_MOD_EXP                          167
-#define ENGINE_F_UBSEC_RSA_MOD_EXP                      168
-#define ENGINE_F_UBSEC_RSA_MOD_EXP_CRT                  169
 
 /* Reason codes. */
 #define ENGINE_R_ALREADY_LOADED                                 100