Skip to content

Commit

Permalink
[libc] Always use a non-zero seed for the (non-crypto) RNG
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
mcb30 committed Jun 9, 2016
1 parent f6e8b80 commit 2c19751
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/core/random.c
Expand Up @@ -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 */
}

/**
Expand Down

0 comments on commit 2c19751

Please sign in to comment.