summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Brown2023-10-06 13:43:02 +0200
committerMichael Brown2023-10-06 13:50:43 +0200
commitff0f860483e344f1af633f94696ff7bc1854611f (patch)
tree65448287a264184b9f8c911cc1cbc992f24d7976
parent[eapol] Send EAPoL-Start packets to trigger EAP authentication (diff)
downloadipxe-ff0f860483e344f1af633f94696ff7bc1854611f.tar.gz
ipxe-ff0f860483e344f1af633f94696ff7bc1854611f.tar.xz
ipxe-ff0f860483e344f1af633f94696ff7bc1854611f.zip
[libc] Use wall clock time as seed for the (non-cryptographic) RNG
We currently use the number of timer ticks since power-on as a seed for the non-cryptographic RNG implemented by random(). Since iPXE is often executed directly after power-on, and since the timer tick resolution is generally low, this can often result in identical seed values being used on each cold boot attempt. As of commit 41f786c ("[settings] Add "unixtime" builtin setting to expose the current time"), the current wall-clock time is always available within the default build of iPXE. Use this time instead, to introduce variability between cold boot attempts on the same host. (Note that variability between different hosts is obtained by using the MAC address as an additional seed value.) This has no effect on the separate DRBG used by cryptographic code. Suggested-by: Heiko <heik0@xs4all.nl> Signed-off-by: Michael Brown <mcb30@ipxe.org>
-rw-r--r--src/core/random.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/src/core/random.c b/src/core/random.c
index 975a03cf..e3251964 100644
--- a/src/core/random.c
+++ b/src/core/random.c
@@ -6,8 +6,9 @@
FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
+#include <stddef.h>
#include <stdlib.h>
-#include <ipxe/timer.h>
+#include <time.h>
static int32_t rnd_seed = 0;
@@ -30,8 +31,9 @@ void srandom ( unsigned int seed ) {
long int random ( void ) {
int32_t q;
- if ( ! rnd_seed ) /* Initialize linear congruential generator */
- srandom ( currticks() );
+ /* Initialize linear congruential generator */
+ if ( ! rnd_seed )
+ srandom ( time ( NULL ) );
/* simplified version of the LCG given in Bruce Schneier's
"Applied Cryptography" */