diff options
author | Andrei Homescu <ahomescu@google.com> | 2022-06-03 00:04:21 +0000 |
---|---|---|
committer | Andrei Homescu <ahomescu@google.com> | 2022-08-16 22:06:13 +0000 |
commit | 601b7210df13e4edb0fa952d342a76e9b9d0ab62 (patch) | |
tree | d5ee4ba691a33e54fc109f66f9bfe541782013d3 /platform | |
parent | ec9f9b45c46935a4eacfba70496e876b11e54c5a (diff) | |
download | common-601b7210df13e4edb0fa952d342a76e9b9d0ab62.tar.gz |
[platform] Emit error message when using default RNG
The default kernel RNG is very bad cryptographically, so this
emits an error message every time someone calls the default
platform_random_get_bytes().
Bug: 235303382
Change-Id: I9efab7f76e6ed0a0912209143b10d6c61af19b80
Diffstat (limited to 'platform')
-rw-r--r-- | platform/random.c | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/platform/random.c b/platform/random.c index d0210faf..066d41e6 100644 --- a/platform/random.c +++ b/platform/random.c @@ -22,6 +22,7 @@ */ #include <assert.h> +#include <debug.h> #include <platform/random.h> #include <rand.h> @@ -31,6 +32,14 @@ */ __WEAK void platform_random_get_bytes(uint8_t *buf, size_t len) { + /* Print a warning about using this, but only once per boot */ + static bool printed_warning = false; + if (unlikely(!printed_warning)) { + dprintf(CRITICAL, + "FAKE RNG implementation MUST be replaced with the REAL one\n"); + printed_warning = true; + } + DEBUG_ASSERT(buf); while (len) { /* lk's rand() returns 32 pseudo random bits */ |