Add a static lock called HWCRHK, for the case of having an application
that wants to use the hw_ncipher engine without having given any callbacks for the dynamic type of locks.
This commit is contained in:
parent
712419b73a
commit
5c72869563
6 changed files with 58 additions and 6 deletions
14
CHANGES
14
CHANGES
|
@ -4,6 +4,20 @@
|
|||
|
||||
Changes between 0.9.6h and 0.9.7 [XX xxx 2002]
|
||||
|
||||
*) The hw_ncipher.c engine requires dynamic locks. Unfortunately, it
|
||||
seems that in spite of existing for more than a year, no application
|
||||
author has done anything to provide the necessary callbacks, which
|
||||
means that this particular engine will not work properly anywhere.
|
||||
This is a very unfortunate situation which forces us, in the name
|
||||
of usability, to give the hw_ncipher.c a static lock, which is part
|
||||
of libcrypto.
|
||||
NOTE: This is for the 0.9.7 series ONLY. This hack will never
|
||||
appear in 0.9.8 or later. We EXPECT application authors to have
|
||||
dealt properly with this when 0.9.8 is released (unless we actually
|
||||
make such changes in the libcrypto locking code that changes will
|
||||
have to be made anyway).
|
||||
[Richard Levitte]
|
||||
|
||||
*) In asn1_d2i_read_bio() repeatedly call BIO_read() until all content
|
||||
octets have been read, EOF or an error occurs. Without this change
|
||||
some truncated ASN1 structures will not produce an error.
|
||||
|
|
|
@ -104,7 +104,8 @@ static const char* lock_names[CRYPTO_NUM_LOCKS] =
|
|||
"dynlock",
|
||||
"engine",
|
||||
"ui",
|
||||
#if CRYPTO_NUM_LOCKS != 32
|
||||
"hwcrhk", /* This is a HACK which will disappear in 0.9.8 */
|
||||
#if CRYPTO_NUM_LOCKS != 33
|
||||
# error "Inconsistency between crypto.h and cryptlib.c"
|
||||
#endif
|
||||
};
|
||||
|
|
|
@ -127,7 +127,8 @@ extern "C" {
|
|||
#define CRYPTO_LOCK_DYNLOCK 29
|
||||
#define CRYPTO_LOCK_ENGINE 30
|
||||
#define CRYPTO_LOCK_UI 31
|
||||
#define CRYPTO_NUM_LOCKS 32
|
||||
#define CRYPTO_LOCK_HWCRHK 32 /* This is a HACK which will disappear in 0.9.8 */
|
||||
#define CRYPTO_NUM_LOCKS 33
|
||||
|
||||
#define CRYPTO_LOCK 1
|
||||
#define CRYPTO_UNLOCK 2
|
||||
|
|
|
@ -91,11 +91,19 @@ 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 */
|
||||
/* Functions to handle mutexes if have dynamic locks */
|
||||
static int hwcrhk_mutex_init(HWCryptoHook_Mutex*, HWCryptoHook_CallerContext*);
|
||||
static int hwcrhk_mutex_lock(HWCryptoHook_Mutex*);
|
||||
static void hwcrhk_mutex_unlock(HWCryptoHook_Mutex*);
|
||||
static void hwcrhk_mutex_destroy(HWCryptoHook_Mutex*);
|
||||
#if 1 /* This is a HACK which will disappear in 0.9.8 */
|
||||
/* Functions to handle mutexes if only have static locks */
|
||||
static int hwcrhk_static_mutex_init(HWCryptoHook_Mutex *m,
|
||||
HWCryptoHook_CallerContext *c);
|
||||
static int hwcrhk_static_mutex_lock(HWCryptoHook_Mutex *m);
|
||||
static void hwcrhk_static_mutex_unlock(HWCryptoHook_Mutex *m);
|
||||
static void hwcrhk_static_mutex_destroy(HWCryptoHook_Mutex *m);
|
||||
#endif
|
||||
|
||||
/* BIGNUM stuff */
|
||||
static int hwcrhk_mod_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
|
||||
|
@ -573,9 +581,17 @@ static int hwcrhk_init(ENGINE *e)
|
|||
}
|
||||
else if (CRYPTO_get_locking_callback() != NULL)
|
||||
{
|
||||
HWCRHKerr(HWCRHK_F_HWCRHK_INIT,HWCRHK_R_LOCKING_MISSING);
|
||||
HWCRHKerr(HWCRHK_F_HWCRHK_INIT,HWCRHK_R_DYNAMIC_LOCKING_MISSING);
|
||||
ERR_add_error_data(1,"You HAVE to add dynamic locking callbacks via CRYPTO_set_dynlock_{create,lock,destroy}_callback()");
|
||||
#if 1 /* This is a HACK which will disappear in 0.9.8 */
|
||||
hwcrhk_globals.maxmutexes = 1; /* Only have one lock */
|
||||
hwcrhk_globals.mutex_init = hwcrhk_static_mutex_init;
|
||||
hwcrhk_globals.mutex_acquire = hwcrhk_static_mutex_lock;
|
||||
hwcrhk_globals.mutex_release = hwcrhk_static_mutex_unlock;
|
||||
hwcrhk_globals.mutex_destroy = hwcrhk_static_mutex_destroy;
|
||||
#else
|
||||
goto err;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1181,6 +1197,26 @@ static void hwcrhk_mutex_destroy(HWCryptoHook_Mutex *mt)
|
|||
CRYPTO_destroy_dynlockid(mt->lockid);
|
||||
}
|
||||
|
||||
/* Mutex upcalls to use if the application does not support dynamic locks */
|
||||
|
||||
static int hwcrhk_static_mutex_init(HWCryptoHook_Mutex *m,
|
||||
HWCryptoHook_CallerContext *c)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
static int hwcrhk_static_mutex_lock(HWCryptoHook_Mutex *m)
|
||||
{
|
||||
CRYPTO_w_lock(CRYPTO_LOCK_HWCRHK);
|
||||
return 0;
|
||||
}
|
||||
static void hwcrhk_static_mutex_unlock(HWCryptoHook_Mutex *m)
|
||||
{
|
||||
CRYPTO_w_unlock(CRYPTO_LOCK_HWCRHK);
|
||||
}
|
||||
static void hwcrhk_static_mutex_destroy(HWCryptoHook_Mutex *m)
|
||||
{
|
||||
}
|
||||
|
||||
static int hwcrhk_get_pass(const char *prompt_info,
|
||||
int *len_io, char *buf,
|
||||
HWCryptoHook_PassphraseContext *ppctx,
|
||||
|
|
|
@ -86,7 +86,7 @@ static ERR_STRING_DATA HWCRHK_str_reasons[]=
|
|||
{HWCRHK_R_CHIL_ERROR ,"chil error"},
|
||||
{HWCRHK_R_CTRL_COMMAND_NOT_IMPLEMENTED ,"ctrl command not implemented"},
|
||||
{HWCRHK_R_DSO_FAILURE ,"dso failure"},
|
||||
{HWCRHK_R_LOCKING_MISSING ,"locking missing"},
|
||||
{HWCRHK_R_DYNAMIC_LOCKING_MISSING ,"dynamic locking missing"},
|
||||
{HWCRHK_R_MISSING_KEY_COMPONENTS ,"missing key components"},
|
||||
{HWCRHK_R_NOT_INITIALISED ,"not initialised"},
|
||||
{HWCRHK_R_NOT_LOADED ,"not loaded"},
|
||||
|
|
|
@ -84,7 +84,7 @@ static void ERR_HWCRHK_error(int function, int reason, char *file, int line);
|
|||
#define HWCRHK_R_CHIL_ERROR 102
|
||||
#define HWCRHK_R_CTRL_COMMAND_NOT_IMPLEMENTED 103
|
||||
#define HWCRHK_R_DSO_FAILURE 104
|
||||
#define HWCRHK_R_LOCKING_MISSING 114
|
||||
#define HWCRHK_R_DYNAMIC_LOCKING_MISSING 114
|
||||
#define HWCRHK_R_MISSING_KEY_COMPONENTS 105
|
||||
#define HWCRHK_R_NOT_INITIALISED 106
|
||||
#define HWCRHK_R_NOT_LOADED 107
|
||||
|
|
Loading…
Reference in a new issue