浏览代码

[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>
tags/v1.20.1
Michael Brown 8 年前
父节点
当前提交
2c197517f2
共有 1 个文件被更改,包括 2 次插入0 次删除
  1. 2
    0
      src/core/random.c

+ 2
- 0
src/core/random.c 查看文件

@@ -18,6 +18,8 @@ static int32_t rnd_seed = 0;
18 18
  */
19 19
 void srandom ( unsigned int seed ) {
20 20
 	rnd_seed = seed;
21
+	if ( ! rnd_seed )
22
+		rnd_seed = 4; /* Chosen by fair dice roll */
21 23
 }
22 24
 
23 25
 /**

正在加载...
取消
保存