From 5c72869563a01a0aeeac5f02002ad0e3142a2918 Mon Sep 17 00:00:00 2001 From: Richard Levitte Date: Thu, 12 Dec 2002 17:41:36 +0000 Subject: [PATCH] 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. --- CHANGES | 14 ++++++++++++ crypto/cryptlib.c | 3 ++- crypto/crypto.h | 3 ++- crypto/engine/hw_ncipher.c | 40 ++++++++++++++++++++++++++++++++-- crypto/engine/hw_ncipher_err.c | 2 +- crypto/engine/hw_ncipher_err.h | 2 +- 6 files changed, 58 insertions(+), 6 deletions(-) diff --git a/CHANGES b/CHANGES index bf5d580063..84683d2b9e 100644 --- a/CHANGES +++ b/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. diff --git a/crypto/cryptlib.c b/crypto/cryptlib.c index b7fec9049e..2924def2bb 100644 --- a/crypto/cryptlib.c +++ b/crypto/cryptlib.c @@ -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 }; diff --git a/crypto/crypto.h b/crypto/crypto.h index 7c98d631e5..273bc5e3f8 100644 --- a/crypto/crypto.h +++ b/crypto/crypto.h @@ -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 diff --git a/crypto/engine/hw_ncipher.c b/crypto/engine/hw_ncipher.c index 58272a18c8..0d1c6b8df0 100644 --- a/crypto/engine/hw_ncipher.c +++ b/crypto/engine/hw_ncipher.c @@ -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, diff --git a/crypto/engine/hw_ncipher_err.c b/crypto/engine/hw_ncipher_err.c index e184dcaad9..5bc94581b7 100644 --- a/crypto/engine/hw_ncipher_err.c +++ b/crypto/engine/hw_ncipher_err.c @@ -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"}, diff --git a/crypto/engine/hw_ncipher_err.h b/crypto/engine/hw_ncipher_err.h index 482086e3b5..d232d02319 100644 --- a/crypto/engine/hw_ncipher_err.h +++ b/crypto/engine/hw_ncipher_err.h @@ -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 -- 2.25.1