diff options
author | Michael Brown | 2016-06-09 09:39:25 +0200 |
---|---|---|
committer | Michael Brown | 2016-06-09 09:44:32 +0200 |
commit | 2c197517f2a82970ab6866e197f06a3099418324 (patch) | |
tree | e0ac644e77307e80f549a926b503e302b42b4e5d /src/core | |
parent | [build] Remove nested "my" declaration (diff) | |
download | ipxe-2c197517f2a82970ab6866e197f06a3099418324.tar.gz ipxe-2c197517f2a82970ab6866e197f06a3099418324.tar.xz ipxe-2c197517f2a82970ab6866e197f06a3099418324.zip |
[libc] Always use a non-zero seed for the (non-crypto) RNG
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>
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/random.c | 2 |
1 files changed, 2 insertions, 0 deletions
diff --git a/src/core/random.c b/src/core/random.c index a74175a7..975a03cf 100644 --- a/src/core/random.c +++ b/src/core/random.c @@ -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 */ } /** |