public inbox for linux-crypto@vger.kernel.org
 help / color / mirror / Atom feed
From: "Jason A. Donenfeld" <Jason@zx2c4.com>
To: linux-kernel@vger.kernel.org, linux-crypto@vger.kernel.org
Cc: "Jason A. Donenfeld" <Jason@zx2c4.com>,
	Theodore Ts'o <tytso@mit.edu>,
	Dominik Brodowski <linux@dominikbrodowski.net>
Subject: [PATCH v1 4/7] random: ensure early RDSEED goes through mixer on init
Date: Tue,  8 Feb 2022 16:53:32 +0100	[thread overview]
Message-ID: <20220208155335.378318-5-Jason@zx2c4.com> (raw)
In-Reply-To: <20220208155335.378318-1-Jason@zx2c4.com>

Continuing the reasoning of "random: use RDSEED instead of RDRAND in
entropy extraction" from this series, at init time we also don't want to
be xoring RDSEED directly into the crng. Instead it's safer to put it
into our entropy collector and then re-extract it, so that it goes
through a hash function with preimage resistance.

Cc: Theodore Ts'o <tytso@mit.edu>
Cc: Dominik Brodowski <linux@dominikbrodowski.net>
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
---
 drivers/char/random.c | 14 ++++----------
 1 file changed, 4 insertions(+), 10 deletions(-)

diff --git a/drivers/char/random.c b/drivers/char/random.c
index db0e0e77613e..2bd19dce822d 100644
--- a/drivers/char/random.c
+++ b/drivers/char/random.c
@@ -1218,24 +1218,18 @@ int __init rand_initialize(void)
 	bool arch_init = true;
 	unsigned long rv;
 
+	mix_pool_bytes(utsname(), sizeof(*(utsname())));
 	mix_pool_bytes(&now, sizeof(now));
 	for (i = BLAKE2S_BLOCK_SIZE; i > 0; i -= sizeof(rv)) {
-		if (!arch_get_random_seed_long(&rv) &&
-		    !arch_get_random_long(&rv))
-			rv = random_get_entropy();
-		mix_pool_bytes(&rv, sizeof(rv));
-	}
-	mix_pool_bytes(utsname(), sizeof(*(utsname())));
-
-	extract_entropy(&primary_crng.state[4], sizeof(u32) * 12);
-	for (i = 4; i < 16; i++) {
 		if (!arch_get_random_seed_long_early(&rv) &&
 		    !arch_get_random_long_early(&rv)) {
 			rv = random_get_entropy();
 			arch_init = false;
 		}
-		primary_crng.state[i] ^= rv;
+		mix_pool_bytes(&rv, sizeof(rv));
 	}
+
+	extract_entropy(&primary_crng.state[4], sizeof(u32) * 12);
 	if (arch_init && trust_cpu && crng_init < 2) {
 		invalidate_batched_entropy();
 		crng_init = 2;
-- 
2.35.0


  parent reply	other threads:[~2022-02-08 15:54 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-08 15:53 [PATCH v1 0/7] random: cleanups around per-cpu crng & rdrand Jason A. Donenfeld
2022-02-08 15:53 ` [PATCH v1 1/7] random: use RDSEED instead of RDRAND in entropy extraction Jason A. Donenfeld
2022-02-08 23:07   ` Eric Biggers
2022-02-08 15:53 ` [PATCH v1 2/7] random: get rid of secondary crngs Jason A. Donenfeld
2022-02-08 15:53 ` [PATCH v1 3/7] random: inline leaves of rand_initialize() Jason A. Donenfeld
2022-02-08 23:08   ` Eric Biggers
2022-02-08 15:53 ` Jason A. Donenfeld [this message]
2022-02-08 23:10   ` [PATCH v1 4/7] random: ensure early RDSEED goes through mixer on init Eric Biggers
2022-02-08 15:53 ` [PATCH v1 5/7] random: do not xor RDRAND when writing into /dev/random Jason A. Donenfeld
2022-02-08 23:11   ` Eric Biggers
2022-02-08 15:53 ` [PATCH v1 6/7] random: use simpler fast key erasure flow on per-cpu keys Jason A. Donenfeld
2022-02-08 23:39   ` Eric Biggers
2022-02-09  0:21     ` Jason A. Donenfeld
2022-02-08 15:53 ` [PATCH v1 7/7] random: remove outdated INT_MAX >> 6 check in urandom_read() Jason A. Donenfeld

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=20220208155335.378318-5-Jason@zx2c4.com \
    --to=jason@zx2c4.com \
    --cc=linux-crypto@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@dominikbrodowski.net \
    --cc=tytso@mit.edu \
    /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