Add a static lock called HWCRHK, for the case of having an application
authorRichard Levitte <levitte@openssl.org>
Thu, 12 Dec 2002 17:41:36 +0000 (17:41 +0000)
committerRichard Levitte <levitte@openssl.org>
Thu, 12 Dec 2002 17:41:36 +0000 (17:41 +0000)
that wants to use the hw_ncipher engine without having given any
callbacks for the dynamic type of locks.

CHANGES
crypto/cryptlib.c
crypto/crypto.h
crypto/engine/hw_ncipher.c
crypto/engine/hw_ncipher_err.c
crypto/engine/hw_ncipher_err.h

diff --git a/CHANGES b/CHANGES
index bf5d58006303017520c71a8e5d1ff915186f1190..84683d2b9ea4e75e2d6357e74a41ee04afe77047 100644 (file)
--- 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.
index b7fec9049e05f2a1cbcae62228f4c5f6ff0acc66..2924def2bb0840899d477dff44d12393f36fbc12 100644 (file)
@@ -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
        };
index 7c98d631e5cb1eefc8667a00f0a326e4d4c7c380..273bc5e3f87df60d82e4dc75feed4c109d2ce3e0 100644 (file)
@@ -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
index 58272a18c8085f2dfd449785a61e3fa1244423bd..0d1c6b8df0ef76935e2e49e4ca8dc8841a36c0c7 100644 (file)
@@ -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,
index e184dcaad9b7c98a4bc3075a844e3c421e347c31..5bc94581b741d0afd7a8c4d7e8e3de7704726c5c 100644 (file)
@@ -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"},
index 482086e3b51a95f81db5217d11acc88229b2d55b..d232d023198442c7b7cbea1f8efcd1de70ff2770 100644 (file)
@@ -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