From bffd73791fe8ddbff42c8a636ecead7ffbfc2f0b Mon Sep 17 00:00:00 2001 From: Wouter Wijngaards Date: Wed, 9 Jan 2008 10:48:10 +0000 Subject: [PATCH] rng fixup. git-svn-id: file:///svn/unbound/branches/beta-0.7@826 be551aaa-1e26-0410-a405-d3ace91eadb9 --- doc/Changelog | 4 ++++ util/random.c | 12 ++++++++---- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/doc/Changelog b/doc/Changelog index 01afb9454..0908ee39f 100644 --- a/doc/Changelog +++ b/doc/Changelog @@ -1,3 +1,7 @@ +9 January 2008: Wouter + - fixup openssl RAND problem, when the system is not configured to + give entropy, and the rng needs to be seeded. (for 0.7.2) + 3 December 2007: Wouter - Fixup building in a subdirectory. (for 0.7.2) diff --git a/util/random.c b/util/random.c index 19a72834b..3f3611d9c 100644 --- a/util/random.c +++ b/util/random.c @@ -92,7 +92,7 @@ ub_arc4random_stir(struct ub_hiddenstate* s) } int -ub_initstate(unsigned int ATTR_UNUSED(seed), struct ub_randstate* state, +ub_initstate(unsigned int seed, struct ub_randstate* state, unsigned long ATTR_UNUSED(n)) { state->s = calloc(1, sizeof(*state->s)); @@ -103,9 +103,13 @@ ub_initstate(unsigned int ATTR_UNUSED(seed), struct ub_randstate* state, /* RAND_ is threadsafe, by the way */ if(!RAND_status()) { - log_err("Random generator has no entropy (error %ld)", - ERR_get_error()); - return 0; + /* try to seed it */ + RAND_seed(&seed, (int)sizeof(seed)); + if(!RAND_status()) { + log_err("Random generator has no entropy (error %ld)", + ERR_get_error()); + return 0; + } } ub_arc4random_stir(state->s); return 1; -- 2.47.2