]> git.ipfire.org Git - thirdparty/ipxe.git/commitdiff
[libc] Always use a non-zero seed for the (non-crypto) RNG
authorMichael Brown <mcb30@ipxe.org>
Thu, 9 Jun 2016 07:39:25 +0000 (08:39 +0100)
committerMichael Brown <mcb30@ipxe.org>
Thu, 9 Jun 2016 07:44:32 +0000 (08:44 +0100)
The non-cryptographic RNG implemented by random() has the property
that a seed value of zero will result in a generated sequence of
all-zero values.  This situation can arise if currticks() returns zero
at start of day.

Work around this problem by falling back to a fixed non-zero seed if
necessary.

This has no effect on the separate DRBG used by cryptographic code.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
src/core/random.c

index a74175a7969ec299625b6203754dc6c92474454f..975a03cf588ecd8161e4fa0f253763a20d96fca4 100644 (file)
@@ -18,6 +18,8 @@ static int32_t rnd_seed = 0;
  */
 void srandom ( unsigned int seed ) {
        rnd_seed = seed;
+       if ( ! rnd_seed )
+               rnd_seed = 4; /* Chosen by fair dice roll */
 }
 
 /**