mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH] lib: random: add CONFIG_INSECURE logging of seeds
Date: Wed, 28 May 2025 17:37:09 +0200	[thread overview]
Message-ID: <20250528153709.636444-1-a.fatoum@pengutronix.de> (raw)

clocksource_srand() can be called after events that take a varying
amount of time to extract some entropy. To get an idea about how much
entropy we are getting out, add a CONFIG_INSECURE-guarded debug print
that prints the seeds out as-is.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 lib/random.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/lib/random.c b/lib/random.c
index 889d314e0fad..632f361c4627 100644
--- a/lib/random.c
+++ b/lib/random.c
@@ -11,6 +11,8 @@
  *     CONFIG_ALLOW_PRNG_FALLBACK set, which will emit a warning at runtime.
  */
 
+#define pr_fmt(fmt) "random: " fmt
+
 #include <common.h>
 #include <stdlib.h>
 #include <linux/hw_random.h>
@@ -75,6 +77,12 @@ void randbuf_r(u64 *x, void *buf, size_t len)
  */
 void srand_xor(u64 entropy)
 {
+	/* The PRNG shouldn't be used for crypto anyway, but still let's not
+	 * divulge the whole state in secure configurations.
+	 */
+	if (IS_ENABLED(CONFIG_INSECURE))
+		pr_debug("PRNG seeded with %llu\n", entropy);
+
 	prng_state ^= entropy;
 	/* Ensure prng_state is never zero */
 	prng_state += !prng_state;
-- 
2.39.5




                 reply	other threads:[~2025-05-28 16:28 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250528153709.636444-1-a.fatoum@pengutronix.de \
    --to=a.fatoum@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox