Index: engines/e_chil.c
===================================================================
RCS file: /home/openssl/cvs/openssl/engines/e_chil.c,v
retrieving revision 1.5
diff -u -r1.5 e_chil.c
--- engines/e_chil.c	18 Mar 2006 14:22:20 -0000	1.5
+++ engines/e_chil.c	22 Aug 2008 05:56:18 -0000
@@ -59,6 +59,7 @@
 
 #include <stdio.h>
 #include <string.h>
+#include <pthread.h>
 #include <openssl/crypto.h>
 #include <openssl/pem.h>
 #include <openssl/dso.h>
@@ -103,6 +104,9 @@
 static int hwcrhk_mutex_lock(HWCryptoHook_Mutex*);
 static void hwcrhk_mutex_unlock(HWCryptoHook_Mutex*);
 static void hwcrhk_mutex_destroy(HWCryptoHook_Mutex*);
+static struct CRYPTO_dynlock_value *hwcrhk_dyn_create_function(const char *file, int line);
+static void hwcrhk_dyn_lock_function(int mode, struct CRYPTO_dynlock_value *l, const char *file, int line);
+static void hwcrhk_dyn_destroy_function(struct CRYPTO_dynlock_value *l, const char *file, int line);
 
 /* BIGNUM stuff */
 static int hwcrhk_mod_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
@@ -247,6 +251,11 @@
 	int lockid;
 	};
 
+struct CRYPTO_dynlock_value 
+{
+    pthread_mutex_t mutex;
+};
+
 /* hwcryptohook.h has some typedefs that turn
    struct HWCryptoHook_PassphraseContextValue
    into HWCryptoHook_PassphraseContext */
@@ -590,9 +599,12 @@
 			}
 		else if (CRYPTO_get_locking_callback() != NULL)
 			{
-			HWCRHKerr(HWCRHK_F_HWCRHK_INIT,HWCRHK_R_LOCKING_MISSING);
-			ERR_add_error_data(1,"You HAVE to add dynamic locking callbacks via CRYPTO_set_dynlock_{create,lock,destroy}_callback()");
-			goto err;
+			    /* Upcalls haven't been set by the
+			     * application, use our own as
+			     * fallback. */
+/* 			    CRYPTO_set_dynlock_create_callback(hwcrhk_dyn_create_function); */
+/* 			    CRYPTO_set_dynlock_lock_callback(hwcrhk_dyn_lock_function); */
+/* 			    CRYPTO_set_dynlock_destroy_callback(hwcrhk_dyn_destroy_function); */
 			}
 		}
 
@@ -1199,6 +1211,33 @@
 	CRYPTO_destroy_dynlockid(mt->lockid);
 	}
 
+static struct CRYPTO_dynlock_value *hwcrhk_dyn_create_function(const char *file, int line)
+{
+    struct CRYPTO_dynlock_value *value;
+    
+    value = (struct CRYPTO_dynlock_value *) OPENSSL_malloc(sizeof(struct CRYPTO_dynlock_value));
+    
+    if (!value) 
+	return NULL;
+    pthread_mutex_init(&(value->mutex), NULL);
+    return value;
+}
+
+static void hwcrhk_dyn_lock_function(int mode, struct CRYPTO_dynlock_value *l, const char *file, int line) 
+{
+    if (mode & CRYPTO_LOCK) 
+	pthread_mutex_lock(&(l->mutex));
+    else
+	pthread_mutex_unlock(&(l->mutex));
+}
+
+static void hwcrhk_dyn_destroy_function(struct CRYPTO_dynlock_value *l, 
+					const char *file, int line)
+{
+    pthread_mutex_destroy(&(l->mutex));
+    OPENSSL_free(l);
+}
+
 static int hwcrhk_get_pass(const char *prompt_info,
 	int *len_io, char *buf,
 	HWCryptoHook_PassphraseContext *ppctx,
