lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [day] [month] [year] [list]
Message-Id: <202003281643.02SGhES8009024@sdf.org>
Date:   Mon, 18 Mar 2019 14:56:15 -0400
From:   George Spelvin <lkml@....org>
To:     linux-kernel@...r.kernel.org, lkml@....org
Cc:     Daniel Borkmann <daniel@...earbox.net>,
        Stephen Hemminger <stephen@...workplumber.org>,
        Hannes Frederic Sowa <hannes@...essinduktion.org>
Subject: [RFC PATCH v1 20/50] lib/random32: Move prandom_warmup() inside
 prandom_seed_early()

They're always called as a pair, so shrink the code.

Also, unrolling prandom_warmup() is just a waste of code space.
Write it as a loop.

Signed-off-by: George Spelvin <lkml@....org>
Cc: Daniel Borkmann <daniel@...earbox.net>
Cc: Stephen Hemminger <stephen@...workplumber.org>
Cc: Hannes Frederic Sowa <hannes@...essinduktion.org>
---
 lib/random32.c | 17 ++++-------------
 1 file changed, 4 insertions(+), 13 deletions(-)

diff --git a/lib/random32.c b/lib/random32.c
index fc369f4e550c2..340696decc3bb 100644
--- a/lib/random32.c
+++ b/lib/random32.c
@@ -138,17 +138,10 @@ EXPORT_SYMBOL(prandom_bytes);
 
 static void prandom_warmup(struct rnd_state *state)
 {
+	int i;
 	/* Calling RNG ten times to satisfy recurrence condition */
-	prandom_u32_state(state);
-	prandom_u32_state(state);
-	prandom_u32_state(state);
-	prandom_u32_state(state);
-	prandom_u32_state(state);
-	prandom_u32_state(state);
-	prandom_u32_state(state);
-	prandom_u32_state(state);
-	prandom_u32_state(state);
-	prandom_u32_state(state);
+	for (i = 0; i < 10; i++)
+		prandom_u32_state(state);
 }
 
 static u32 __extract_hwseed(void)
@@ -170,6 +163,7 @@ static void prandom_seed_early(struct rnd_state *state, u32 seed,
 	state->s2 = __seed(HWSEED() ^ LCG(state->s1),   8U);
 	state->s3 = __seed(HWSEED() ^ LCG(state->s2),  16U);
 	state->s4 = __seed(HWSEED() ^ LCG(state->s3), 128U);
+	prandom_warmup(state);
 }
 
 /**
@@ -209,7 +203,6 @@ static int __init prandom_init(void)
 		u32 weak_seed = (i + jiffies) ^ random_get_entropy();
 
 		prandom_seed_early(state, weak_seed, true);
-		prandom_warmup(state);
 	}
 
 	return 0;
@@ -433,7 +426,6 @@ static void __init prandom_state_selftest(void)
 		struct rnd_state state;
 
 		prandom_seed_early(&state, test1[i].seed, false);
-		prandom_warmup(&state);
 
 		if (test1[i].result != prandom_u32_state(&state))
 			error = true;
@@ -448,7 +440,6 @@ static void __init prandom_state_selftest(void)
 		struct rnd_state state;
 
 		prandom_seed_early(&state, test2[i].seed, false);
-		prandom_warmup(&state);
 
 		for (j = 0; j < test2[i].iteration - 1; j++)
 			prandom_u32_state(&state);
-- 
2.26.0

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ