Some more tweaks to ENGINE code.
authorGeoff Thorpe <geoff@openssl.org>
Wed, 18 Apr 2001 03:57:05 +0000 (03:57 +0000)
committerGeoff Thorpe <geoff@openssl.org>
Wed, 18 Apr 2001 03:57:05 +0000 (03:57 +0000)
ENGINE handler functions should take the ENGINE structure as a parameter -
this is because ENGINE structures can be copied, and like other
structure/method setups in OpenSSL, it should be possible for init(),
finish(), ctrl(), etc to adjust state inside the ENGINE structures rather
than globally. This commit includes the dependant changes in the ENGINE
implementations.

crypto/engine/engine.h
crypto/engine/engine_int.h
crypto/engine/engine_lib.c
crypto/engine/hw_atalla.c
crypto/engine/hw_cswift.c
crypto/engine/hw_ncipher.c
crypto/engine/hw_nuron.c
crypto/engine/hw_ubsec.c

index 2674bb1aa25070dac8d83a5f2d17182e3f610700..7931df0e6fc28429cf9f379dd606bb8ed08e99c4 100644 (file)
@@ -130,11 +130,11 @@ typedef struct engine_st ENGINE;
 /* Generic function pointer */
 typedef int (*ENGINE_GEN_FUNC_PTR)();
 /* Generic function pointer taking no arguments */
 /* Generic function pointer */
 typedef int (*ENGINE_GEN_FUNC_PTR)();
 /* Generic function pointer taking no arguments */
-typedef int (*ENGINE_GEN_INT_FUNC_PTR)(void);
+typedef int (*ENGINE_GEN_INT_FUNC_PTR)(ENGINE *);
 /* Specific control function pointer */
 /* Specific control function pointer */
-typedef int (*ENGINE_CTRL_FUNC_PTR)(int cmd, long i, void *p, void (*f)());
+typedef int (*ENGINE_CTRL_FUNC_PTR)(ENGINE *, int, long, void *, void (*f)());
 /* Generic load_key function pointer */
 /* Generic load_key function pointer */
-typedef EVP_PKEY * (*ENGINE_LOAD_KEY_PTR)(const char *key_id, const char *passphrase);
+typedef EVP_PKEY * (*ENGINE_LOAD_KEY_PTR)(ENGINE *, const char *, const char *);
 
 /* STRUCTURE functions ... all of these functions deal with pointers to
  * ENGINE structures where the pointers have a "structural reference".
 
 /* STRUCTURE functions ... all of these functions deal with pointers to
  * ENGINE structures where the pointers have a "structural reference".
index 6e9c4ac61f3fc4efcc118d710bd5ff5d85c1d28e..dc5349cb3cbbe1f4a7c0130b9895bbdf6f39ea55 100644 (file)
@@ -88,11 +88,11 @@ struct engine_st
        const RAND_METHOD *rand_meth;
        BN_MOD_EXP bn_mod_exp;
        BN_MOD_EXP_CRT bn_mod_exp_crt;
        const RAND_METHOD *rand_meth;
        BN_MOD_EXP bn_mod_exp;
        BN_MOD_EXP_CRT bn_mod_exp_crt;
-       int (*init)(void);
-       int (*finish)(void);
-       int (*ctrl)(int cmd, long i, void *p, void (*f)());
-       EVP_PKEY *(*load_privkey)(const char *key_id, const char *passphrase);
-       EVP_PKEY *(*load_pubkey)(const char *key_id, const char *passphrase);
+       ENGINE_GEN_INT_FUNC_PTR init;
+       ENGINE_GEN_INT_FUNC_PTR finish;
+       ENGINE_CTRL_FUNC_PTR ctrl;
+       ENGINE_LOAD_KEY_PTR load_privkey;
+       ENGINE_LOAD_KEY_PTR load_pubkey;
        int flags;
        /* reference count on the structure itself */
        int struct_ref;
        int flags;
        /* reference count on the structure itself */
        int struct_ref;
index cefaec36f2aaf283bfcceee79c265cd9f46cbc50..3b8fe6936a0db12162548b29bdeab7076b74f58a 100644 (file)
@@ -153,7 +153,7 @@ int ENGINE_init(ENGINE *e)
        if((e->funct_ref == 0) && e->init)
                /* This is the first functional reference and the engine
                 * requires initialisation so we do it now. */
        if((e->funct_ref == 0) && e->init)
                /* This is the first functional reference and the engine
                 * requires initialisation so we do it now. */
-               to_return = e->init();
+               to_return = e->init(e);
        if(to_return)
                {
                /* OK, we return a functional reference which is also a
        if(to_return)
                {
                /* OK, we return a functional reference which is also a
@@ -200,7 +200,7 @@ int ENGINE_finish(ENGINE *e)
                {
                CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE);
                /* CODE ALERT: This *IS* supposed to be "=" and NOT "==" :-) */
                {
                CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE);
                /* CODE ALERT: This *IS* supposed to be "=" and NOT "==" :-) */
-               if((to_return = e->finish()))
+               if((to_return = e->finish(e)))
                        {
                        CRYPTO_w_lock(CRYPTO_LOCK_ENGINE);
                        /* Cleanup the functional reference which is also a
                        {
                        CRYPTO_w_lock(CRYPTO_LOCK_ENGINE);
                        /* Cleanup the functional reference which is also a
@@ -242,7 +242,7 @@ EVP_PKEY *ENGINE_load_private_key(ENGINE *e, const char *key_id,
                        ENGINE_R_NO_LOAD_FUNCTION);
                return 0;
                }
                        ENGINE_R_NO_LOAD_FUNCTION);
                return 0;
                }
-       pkey = e->load_privkey(key_id, passphrase);
+       pkey = e->load_privkey(e, key_id, passphrase);
        if (!pkey)
                {
                ENGINEerr(ENGINE_F_ENGINE_LOAD_PRIVATE_KEY,
        if (!pkey)
                {
                ENGINEerr(ENGINE_F_ENGINE_LOAD_PRIVATE_KEY,
@@ -278,7 +278,7 @@ EVP_PKEY *ENGINE_load_public_key(ENGINE *e, const char *key_id,
                        ENGINE_R_NO_LOAD_FUNCTION);
                return 0;
                }
                        ENGINE_R_NO_LOAD_FUNCTION);
                return 0;
                }
-       pkey = e->load_pubkey(key_id, passphrase);
+       pkey = e->load_pubkey(e, key_id, passphrase);
        if (!pkey)
                {
                ENGINEerr(ENGINE_F_ENGINE_LOAD_PUBLIC_KEY,
        if (!pkey)
                {
                ENGINEerr(ENGINE_F_ENGINE_LOAD_PUBLIC_KEY,
@@ -310,7 +310,7 @@ int ENGINE_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)())
                ENGINEerr(ENGINE_F_ENGINE_CTRL,ENGINE_R_NO_CONTROL_FUNCTION);
                return 0;
                }
                ENGINEerr(ENGINE_F_ENGINE_CTRL,ENGINE_R_NO_CONTROL_FUNCTION);
                return 0;
                }
-       return e->ctrl(cmd, i, p, f);
+       return e->ctrl(e, cmd, i, p, f);
        }
 
 static ENGINE *engine_get_default_type(ENGINE_TYPE t)
        }
 
 static ENGINE *engine_get_default_type(ENGINE_TYPE t)
index 37066eb8083074590f63265681a6afeeb08c87c2..acb432109f44dc34f088699c274c0065de5b7ca5 100644 (file)
@@ -72,8 +72,8 @@
 #include "vendor_defns/atalla.h"
 #endif
 
 #include "vendor_defns/atalla.h"
 #endif
 
-static int atalla_init(void);
-static int atalla_finish(void);
+static int atalla_init(ENGINE *e);
+static int atalla_finish(ENGINE *e);
 
 /* BIGNUM stuff */
 static int atalla_mod_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
 
 /* BIGNUM stuff */
 static int atalla_mod_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
@@ -229,7 +229,7 @@ static const char *ATALLA_F2 = "ASI_RSAPrivateKeyOpFn";
 static const char *ATALLA_F3 = "ASI_GetPerformanceStatistics";
 
 /* (de)initialisation functions. */
 static const char *ATALLA_F3 = "ASI_GetPerformanceStatistics";
 
 /* (de)initialisation functions. */
-static int atalla_init(void)
+static int atalla_init(ENGINE *e)
        {
        tfnASI_GetHardwareConfig *p1;
        tfnASI_RSAPrivateKeyOpFn *p2;
        {
        tfnASI_GetHardwareConfig *p1;
        tfnASI_RSAPrivateKeyOpFn *p2;
@@ -288,7 +288,7 @@ err:
        return 0;
        }
 
        return 0;
        }
 
-static int atalla_finish(void)
+static int atalla_finish(ENGINE *e)
        {
        if(atalla_dso == NULL)
                {
        {
        if(atalla_dso == NULL)
                {
index 2ee9040ca06372cb5e6397901e833b384f9c2bdf..4066d1d164011e9fb75526dd577cf34194e45b5f 100644 (file)
@@ -84,8 +84,8 @@
 #include "vendor_defns/cswift.h"
 #endif
 
 #include "vendor_defns/cswift.h"
 #endif
 
-static int cswift_init(void);
-static int cswift_finish(void);
+static int cswift_init(ENGINE *);
+static int cswift_finish(ENGINE *);
 
 /* BIGNUM stuff */
 static int cswift_mod_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
 
 /* BIGNUM stuff */
 static int cswift_mod_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
@@ -251,7 +251,7 @@ static void release_context(SW_CONTEXT_HANDLE hac)
        }
 
 /* (de)initialisation functions. */
        }
 
 /* (de)initialisation functions. */
-static int cswift_init(void)
+static int cswift_init(ENGINE *e)
        {
         SW_CONTEXT_HANDLE hac;
         t_swAcquireAccContext *p1;
        {
         SW_CONTEXT_HANDLE hac;
         t_swAcquireAccContext *p1;
@@ -308,7 +308,7 @@ err:
        return 0;
        }
 
        return 0;
        }
 
-static int cswift_finish(void)
+static int cswift_finish(ENGINE *e)
        {
        if(cswift_dso == NULL)
                {
        {
        if(cswift_dso == NULL)
                {
index 98fd5227bc6c247994c03fda6382567bdc1cff7a..5c5595b8c96fcde323aeb134301cc0107aab59a2 100644 (file)
@@ -82,9 +82,9 @@
 #include "vendor_defns/hwcryptohook.h"
 #endif
 
 #include "vendor_defns/hwcryptohook.h"
 #endif
 
-static int hwcrhk_init(void);
-static int hwcrhk_finish(void);
-static int hwcrhk_ctrl(int cmd, long i, void *p, void (*f)()); 
+static int hwcrhk_init(ENGINE *e);
+static int hwcrhk_finish(ENGINE *e);
+static int hwcrhk_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)()); 
 
 /* Functions to handle mutexes */
 static int hwcrhk_mutex_init(HWCryptoHook_Mutex*, HWCryptoHook_CallerContext*);
 
 /* Functions to handle mutexes */
 static int hwcrhk_mutex_init(HWCryptoHook_Mutex*, HWCryptoHook_CallerContext*);
@@ -113,9 +113,9 @@ static int hwcrhk_rand_bytes(unsigned char *buf, int num);
 static int hwcrhk_rand_status(void);
 
 /* KM stuff */
 static int hwcrhk_rand_status(void);
 
 /* KM stuff */
-static EVP_PKEY *hwcrhk_load_privkey(const char *key_id,
+static EVP_PKEY *hwcrhk_load_privkey(ENGINE *eng, const char *key_id,
        const char *passphrase);
        const char *passphrase);
-static EVP_PKEY *hwcrhk_load_pubkey(const char *key_id,
+static EVP_PKEY *hwcrhk_load_pubkey(ENGINE *eng, const char *key_id,
        const char *passphrase);
 static void hwcrhk_ex_free(void *obj, void *item, CRYPTO_EX_DATA *ad,
        int ind,long argl, void *argp);
        const char *passphrase);
 static void hwcrhk_ex_free(void *obj, void *item, CRYPTO_EX_DATA *ad,
        int ind,long argl, void *argp);
@@ -376,7 +376,7 @@ static void release_context(HWCryptoHook_ContextHandle hac)
        }
 
 /* (de)initialisation functions. */
        }
 
 /* (de)initialisation functions. */
-static int hwcrhk_init(void)
+static int hwcrhk_init(ENGINE *e)
        {
        HWCryptoHook_Init_t *p1;
        HWCryptoHook_Finish_t *p2;
        {
        HWCryptoHook_Init_t *p1;
        HWCryptoHook_Finish_t *p2;
@@ -475,7 +475,7 @@ err:
        return 0;
        }
 
        return 0;
        }
 
-static int hwcrhk_finish(void)
+static int hwcrhk_finish(ENGINE *e)
        {
        int to_return = 1;
        if(hwcrhk_dso == NULL)
        {
        int to_return = 1;
        if(hwcrhk_dso == NULL)
@@ -507,7 +507,7 @@ static int hwcrhk_finish(void)
        return to_return;
        }
 
        return to_return;
        }
 
-static int hwcrhk_ctrl(int cmd, long i, void *p, void (*f)())
+static int hwcrhk_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)())
        {
        int to_return = 1;
 
        {
        int to_return = 1;
 
@@ -569,7 +569,7 @@ static int hwcrhk_ctrl(int cmd, long i, void *p, void (*f)())
        return to_return;
        }
 
        return to_return;
        }
 
-static EVP_PKEY *hwcrhk_load_privkey(const char *key_id,
+static EVP_PKEY *hwcrhk_load_privkey(ENGINE *eng, const char *key_id,
        const char *passphrase)
        {
        RSA *rtmp = NULL;
        const char *passphrase)
        {
        RSA *rtmp = NULL;
@@ -649,9 +649,10 @@ static EVP_PKEY *hwcrhk_load_privkey(const char *key_id,
        return NULL;
        }
 
        return NULL;
        }
 
-static EVP_PKEY *hwcrhk_load_pubkey(const char *key_id, const char *passphrase)
+static EVP_PKEY *hwcrhk_load_pubkey(ENGINE *eng, const char *key_id,
+       const char *passphrase)
        {
        {
-       EVP_PKEY *res = hwcrhk_load_privkey(key_id, passphrase);
+       EVP_PKEY *res = hwcrhk_load_privkey(eng, key_id, passphrase);
 
        if (res)
                switch(res->type)
 
        if (res)
                switch(res->type)
index 5199a81305afef45b869ee72172ea5c2b769f180..ad858450ebaf419f062345efd6aa308bd68028fe 100644 (file)
@@ -72,7 +72,7 @@ static tfnModExp *pfnModExp = NULL;
 
 static DSO *pvDSOHandle = NULL;
 
 
 static DSO *pvDSOHandle = NULL;
 
-static int nuron_init(void)
+static int nuron_init(ENGINE *e)
        {
        if(pvDSOHandle != NULL)
                {
        {
        if(pvDSOHandle != NULL)
                {
@@ -98,7 +98,7 @@ static int nuron_init(void)
        return 1;
        }
 
        return 1;
        }
 
-static int nuron_finish(void)
+static int nuron_finish(ENGINE *e)
        {
        if(pvDSOHandle == NULL)
                {
        {
        if(pvDSOHandle == NULL)
                {
index e8766e7506ed3d37fa4a4e3495f30be8a03efcd7..143efbdeea4e588d9414a964af3089d3e4cd1866 100644 (file)
@@ -74,8 +74,8 @@
 #include "vendor_defns/hw_ubsec.h"
 #endif
 
 #include "vendor_defns/hw_ubsec.h"
 #endif
 
-static int ubsec_init(void);
-static int ubsec_finish(void);
+static int ubsec_init(ENGINE *e);
+static int ubsec_finish(ENGINE *e);
 static int ubsec_mod_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
                const BIGNUM *m, BN_CTX *ctx);
 static int ubsec_mod_exp_crt(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
 static int ubsec_mod_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
                const BIGNUM *m, BN_CTX *ctx);
 static int ubsec_mod_exp_crt(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
@@ -251,7 +251,7 @@ static const char *UBSEC_F11 = "math_accelerate_ioctl";
 static const char *UBSEC_F12 = "rng_ioctl";
 
 /* (de)initialisation functions. */
 static const char *UBSEC_F12 = "rng_ioctl";
 
 /* (de)initialisation functions. */
-static int ubsec_init()
+static int ubsec_init(ENGINE *e)
        {
        t_UBSEC_ubsec_bytes_to_bits *p1;
        t_UBSEC_ubsec_bits_to_bytes *p2;
        {
        t_UBSEC_ubsec_bytes_to_bits *p1;
        t_UBSEC_ubsec_bits_to_bytes *p2;
@@ -347,7 +347,7 @@ err:
        return 0;
        }
 
        return 0;
        }
 
-static int ubsec_finish()
+static int ubsec_finish(ENGINE *e)
        {
        if(ubsec_dso == NULL)
                {
        {
        if(ubsec_dso == NULL)
                {