lib/random32: Move prandom_warmup() inside prandom_seed_early()
Subsystems (2)
RFC PATCH 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 <[email protected]>
Cc Daniel Borkmann <[email protected]>
Cc Stephen Hemminger <[email protected]>
Cc Hannes Frederic Sowa <[email protected]>
--- lib/random32.c | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-)
lib/random32.c +4 -13
@@ -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);
Signature · 1 line
2.26.0