Commit 404f952a authored by Geoff Thorpe's avatar Geoff Thorpe
Browse files

Some more tweaks to ENGINE code.

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.
parent dcd87618
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -130,11 +130,11 @@ typedef struct engine_st ENGINE;
/* 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 */
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 */
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".
+5 −5
Original line number Diff line number Diff line
@@ -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;
	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;
+5 −5
Original line number Diff line number Diff line
@@ -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. */
		to_return = e->init();
		to_return = e->init(e);
	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 "==" :-) */
		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
@@ -242,7 +242,7 @@ EVP_PKEY *ENGINE_load_private_key(ENGINE *e, const char *key_id,
			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,
@@ -278,7 +278,7 @@ EVP_PKEY *ENGINE_load_public_key(ENGINE *e, const char *key_id,
			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,
@@ -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;
		}
	return e->ctrl(cmd, i, p, f);
	return e->ctrl(e, cmd, i, p, f);
	}

static ENGINE *engine_get_default_type(ENGINE_TYPE t)
+4 −4
Original line number Diff line number Diff line
@@ -72,8 +72,8 @@
#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,
@@ -229,7 +229,7 @@ static const char *ATALLA_F2 = "ASI_RSAPrivateKeyOpFn";
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;
@@ -288,7 +288,7 @@ err:
	return 0;
	}

static int atalla_finish(void)
static int atalla_finish(ENGINE *e)
	{
	if(atalla_dso == NULL)
		{
+4 −4
Original line number Diff line number Diff line
@@ -84,8 +84,8 @@
#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,
@@ -251,7 +251,7 @@ static void release_context(SW_CONTEXT_HANDLE hac)
	}

/* (de)initialisation functions. */
static int cswift_init(void)
static int cswift_init(ENGINE *e)
	{
        SW_CONTEXT_HANDLE hac;
        t_swAcquireAccContext *p1;
@@ -308,7 +308,7 @@ err:
	return 0;
	}

static int cswift_finish(void)
static int cswift_finish(ENGINE *e)
	{
	if(cswift_dso == NULL)
		{
Loading