From 8b3ba5532cc8f3529c1780b94eab9a5f592387b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Love=20H=C3=B6rnquist=20=C3=85strand?= Date: Fri, 16 May 2003 20:44:55 +0000 Subject: [PATCH] protect the random initiator with a mutex git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@12305 ec53bebd-3082-4978-b11e-865c3cabbd6b --- lib/krb5/crypto.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lib/krb5/crypto.c b/lib/krb5/crypto.c index 60c8c7e15..97fd5a570 100644 --- a/lib/krb5/crypto.c +++ b/lib/krb5/crypto.c @@ -152,6 +152,9 @@ static void free_key_data(krb5_context context, struct key_data *key); * * ************************************************************/ +static HEIMDAL_MUTEX crypto_mutex = HEIMDAL_MUTEX_INITIALIZER; + + static void krb5_DES_random_key(krb5_context context, krb5_keyblock *key) @@ -3194,12 +3197,14 @@ krb5_generate_random_block(void *buf, size_t len) { static int rng_initialized = 0; + HEIMDAL_MUTEX_lock(&crypto_mutex); if (!rng_initialized) { if (seed_something()) krb5_abortx(NULL, "Fatal: could not seed the random number generator"); rng_initialized = 1; } + HEIMDAL_MUTEX_unlock(&crypto_mutex); RAND_bytes(buf, len); } @@ -3214,12 +3219,15 @@ krb5_generate_random_block(void *buf, size_t len) int i; static int initialized = 0; + HEIMDAL_MUTEX_lock(&crypto_mutex); if(!initialized) { des_new_random_key(&key); des_set_key(&key, schedule); memset(&key, 0, sizeof(key)); des_new_random_key(&counter); + initialized = 1; } + HEIMDAL_MUTEX_unlock(&crypto_mutex); while(len > 0) { des_ecb_encrypt(&counter, &out, schedule, DES_ENCRYPT); for(i = 7; i >=0; i--)