diff options
author | Andrei Homescu <ahomescu@google.com> | 2022-01-26 04:00:02 +0000 |
---|---|---|
committer | Andrei Homescu <ahomescu@google.com> | 2022-01-26 04:22:16 +0000 |
commit | 21c96c68c48d5d3c1dbc5d0dfe21b562659e513a (patch) | |
tree | f27a21cb6ad022848898efd6a3d4c1804f48ddb6 /lib | |
parent | 88e9aa5eb551f11330be5e4054e2b40f6457fb79 (diff) | |
download | common-21c96c68c48d5d3c1dbc5d0dfe21b562659e513a.tar.gz |
[lib][libc] Use a build-time random value as the seed
Set the seed for the kernel's rand() implementation
to a random value computed at build-time, so we get some
minimal randomness from that RNG.
Bug: 80147716
Change-Id: If5f7915a892b825cb7eba46554f2cb29b8ad2eda
Diffstat (limited to 'lib')
-rw-r--r-- | lib/libc/rand.c | 2 | ||||
-rw-r--r-- | lib/libc/rules.mk | 9 |
2 files changed, 10 insertions, 1 deletions
diff --git a/lib/libc/rand.c b/lib/libc/rand.c index 5bc5d36c..74ab2c97 100644 --- a/lib/libc/rand.c +++ b/lib/libc/rand.c @@ -23,7 +23,7 @@ #include <rand.h> #include <sys/types.h> -static unsigned int randseed = 12345; +static unsigned int randseed = KERNEL_LIBC_RANDSEED; void srand(unsigned int seed) { diff --git a/lib/libc/rules.mk b/lib/libc/rules.mk index 41655714..ab2baad9 100644 --- a/lib/libc/rules.mk +++ b/lib/libc/rules.mk @@ -9,6 +9,15 @@ ifndef WITH_CUSTOM_MALLOC MODULE_DEPS += lib/heap endif +# Generate a random 32-bit seed for the RNG +KERNEL_LIBC_RANDSEED_HEX := $(shell xxd -l4 -g0 -p /dev/urandom) +KERNEL_LIBC_RANDSEED := 0x$(KERNEL_LIBC_RANDSEED_HEX)U + +MODULE_DEFINES += \ + KERNEL_LIBC_RANDSEED=$(KERNEL_LIBC_RANDSEED) \ + +$(info KERNEL_LIBC_RANDSEED = $(KERNEL_LIBC_RANDSEED)) + MODULE_SRCS += \ $(LOCAL_DIR)/atoi.c \ $(LOCAL_DIR)/bsearch.c \ |