From: George Spelvin <lkml@sdf.org>
To: linux-kernel@vger.kernel.org, lkml@sdf.org
Cc: Daniel Borkmann <daniel@iogearbox.net>,
Stephen Hemminger <stephen@networkplumber.org>,
Hannes Frederic Sowa <hannes@stressinduktion.org>
Subject: [RFC PATCH v1 20/50] lib/random32: Move prandom_warmup() inside prandom_seed_early()
Date: Mon, 18 Mar 2019 14:56:15 -0400 [thread overview]
Message-ID: <202003281643.02SGhES8009024@sdf.org> (raw)
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
reply other threads:[~2020-03-28 16:43 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=202003281643.02SGhES8009024@sdf.org \
--to=lkml@sdf.org \
--cc=daniel@iogearbox.net \
--cc=hannes@stressinduktion.org \
--cc=linux-kernel@vger.kernel.org \
--cc=stephen@networkplumber.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
all inboxes | Powered by JetHome®