* [RFC PATCH v1 20/50] lib/random32: Move prandom_warmup() inside prandom_seed_early()
@ 2019-03-18 18:56 George Spelvin
0 siblings, 0 replies; only message in thread
From: George Spelvin @ 2019-03-18 18:56 UTC (permalink / raw)
To: linux-kernel, lkml
Cc: Daniel Borkmann, Stephen Hemminger, Hannes Frederic Sowa
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@sdf.org>
Cc: Daniel Borkmann <daniel@iogearbox.net>
Cc: Stephen Hemminger <stephen@networkplumber.org>
Cc: Hannes Frederic Sowa <hannes@stressinduktion.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
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2020-03-28 16:43 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-03-18 18:56 [RFC PATCH v1 20/50] lib/random32: Move prandom_warmup() inside prandom_seed_early() George Spelvin
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®