From 2727091fd6ca14b4c05b054ece24d141ff448556 Mon Sep 17 00:00:00 2001 From: Ken Raeburn Date: Wed, 2 Jun 2004 23:41:51 +0000 Subject: [PATCH] * prng.c (init_once): Variable deleted. (krb5_c_random_add_entropy): Do the initialization once, using the yarrow_lock mutex instead of k5_once to protect it. git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@16392 dc483132-0cff-0310-8789-dd5450dbe970 --- src/lib/crypto/ChangeLog | 6 ++++++ src/lib/crypto/prng.c | 16 +++++++--------- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/lib/crypto/ChangeLog b/src/lib/crypto/ChangeLog index 952aaa9a5..b30a22c92 100644 --- a/src/lib/crypto/ChangeLog +++ b/src/lib/crypto/ChangeLog @@ -1,3 +1,9 @@ +2004-06-02 Ken Raeburn + + * prng.c (init_once): Variable deleted. + (krb5_c_random_add_entropy): Do the initialization once, using + the yarrow_lock mutex instead of k5_once to protect it. + 2004-05-24 Ezra Peisach * t_nfold.c (fold_kerberos): Change nbytes argument to unsigned. diff --git a/src/lib/crypto/prng.c b/src/lib/crypto/prng.c index be757d21c..f9ea8696d 100644 --- a/src/lib/crypto/prng.c +++ b/src/lib/crypto/prng.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2001, 2002 by the Massachusetts Institute of Technology. + * Copyright (C) 2001, 2002, 2004 by the Massachusetts Institute of Technology. * All rights reserved. * * @@ -30,7 +30,6 @@ #include "yarrow.h" static Yarrow_CTX y_ctx; -static k5_once_t init_once = K5_ONCE_INIT; static int inited, init_error; static k5_mutex_t yarrow_lock = K5_MUTEX_PARTIAL_INITIALIZER; @@ -95,17 +94,16 @@ krb5_c_random_add_entropy (krb5_context context, unsigned int randsource, yerr = krb5int_crypto_init(); if (yerr) return yerr; - /* Run the Yarrow init code, if not done already. */ - yerr = k5_once(&init_once, do_yarrow_init); - if (yerr) - return yerr; - /* Return an error if the Yarrow initialization failed. */ - if (init_error) - return KRB5_CRYPTO_INTERNAL; /* Now, finally, feed in the data. */ yerr = k5_mutex_lock(&yarrow_lock); if (yerr) return yerr; + if (!inited) + do_yarrow_init(); + if (init_error) { + k5_mutex_unlock(&yarrow_lock); + return KRB5_CRYPTO_INTERNAL; + } yerr = krb5int_yarrow_input (&y_ctx, randsource, data->data, data->length, entropy_estimate (randsource, data->length)); -- 2.26.2