From: Wouter Wijngaards Date: Tue, 3 Jul 2012 09:32:16 +0000 (+0000) Subject: - FIPS_mode openssl does not use arc4random but RAND_pseudo_bytes. X-Git-Tag: release-1.4.18rc1~14 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=64b28585e02a2659ebbe231fca43d9634dc5dee5;p=thirdparty%2Funbound.git - FIPS_mode openssl does not use arc4random but RAND_pseudo_bytes. git-svn-id: file:///svn/unbound/trunk@2709 be551aaa-1e26-0410-a405-d3ace91eadb9 --- diff --git a/doc/Changelog b/doc/Changelog index b62afeb72..543a113d9 100644 --- a/doc/Changelog +++ b/doc/Changelog @@ -1,3 +1,6 @@ +3 July 2012: Wouter + - FIPS_mode openssl does not use arc4random but RAND_pseudo_bytes. + 2 July 2012: Wouter - updated iana ports list. diff --git a/util/random.c b/util/random.c index 2fbabbfd1..5b61aef7f 100644 --- a/util/random.c +++ b/util/random.c @@ -147,6 +147,16 @@ ub_arc4random_stir(struct ub_randstate* s, struct ub_randstate* from) return; } } +#ifdef HAVE_FIPS_MODE + if(FIPS_mode()) { + /* RC4 is not allowed, get some trustworthy randomness */ + /* double certainty here, this routine should not be + * called in FIPS_mode */ + memset(rand_buf, 0, sizeof(rand_buf)); + s->rc4_ready = REKEY_BYTES; + return; + } +#endif /* FIPS_MODE */ RC4_set_key(&s->rc4, SEED_SIZE, (unsigned char*)rand_buf); /* @@ -171,6 +181,9 @@ ub_initstate(unsigned int seed, struct ub_randstate* from) return NULL; } ub_systemseed(seed); +#ifdef HAVE_FIPS_MODE + if(!FIPS_mode()) +#endif ub_arc4random_stir(s, from); return s; } @@ -179,6 +192,20 @@ long int ub_random(struct ub_randstate* s) { unsigned int r = 0; +#ifdef HAVE_FIPS_MODE + if(FIPS_mode()) { + /* RC4 is not allowed, get some trustworthy randomness */ + /* we use pseudo bytes: it tries to return secure randomness + * but returns 'something' if that fails. We need something + * else if it fails, because we cannot block here */ + if(RAND_pseudo_bytes((unsigned char*)&r, (int)sizeof(r)) + == -1) { + log_err("FIPSmode, no arc4random but RAND failed " + "(error %ld)", ERR_get_error()); + } + return (long int)((r) % (((unsigned)MAX_VALUE + 1))); + } +#endif /* FIPS_MODE */ if (s->rc4_ready <= 0) { ub_arc4random_stir(s, NULL); }