From: "Jason A. Donenfeld" <Jason@zx2c4.com>
To: linux-kernel@vger.kernel.org
Cc: "Jason A. Donenfeld" <Jason@zx2c4.com>
Subject: [PATCH 3/4] random: access input_pool_data directly rather than through pointer
Date: Sun, 16 Jan 2022 17:35:46 +0100 [thread overview]
Message-ID: <20220116163547.154991-3-Jason@zx2c4.com> (raw)
In-Reply-To: <20220116163547.154991-1-Jason@zx2c4.com>
This gets rid of another abstraction we no longer need. It would be nice
if we could instead make pool an array rather than a pointer, but the
latent entropy plugin won't be able to do its magic in that case. So
instead we put all accesses to the input pool's actual data through the
input_pool_data array directly.
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
---
drivers/char/random.c | 21 ++++++++-------------
1 file changed, 8 insertions(+), 13 deletions(-)
diff --git a/drivers/char/random.c b/drivers/char/random.c
index 7343bff086c5..274056155e50 100644
--- a/drivers/char/random.c
+++ b/drivers/char/random.c
@@ -496,17 +496,12 @@ MODULE_PARM_DESC(ratelimit_disable, "Disable random ratelimit suppression");
static u32 input_pool_data[POOL_WORDS] __latent_entropy;
static struct {
- /* read-only data: */
- u32 *pool;
-
- /* read-write data: */
spinlock_t lock;
u16 add_ptr;
u16 input_rotate;
int entropy_count;
} input_pool = {
.lock = __SPIN_LOCK_UNLOCKED(input_pool.lock),
- .pool = input_pool_data
};
static ssize_t extract_entropy(void *buf, size_t nbytes, int min);
@@ -544,15 +539,15 @@ static void _mix_pool_bytes(const void *in, int nbytes)
i = (i - 1) & POOL_WORDMASK;
/* XOR in the various taps */
- w ^= input_pool.pool[i];
- w ^= input_pool.pool[(i + POOL_TAP1) & POOL_WORDMASK];
- w ^= input_pool.pool[(i + POOL_TAP2) & POOL_WORDMASK];
- w ^= input_pool.pool[(i + POOL_TAP3) & POOL_WORDMASK];
- w ^= input_pool.pool[(i + POOL_TAP4) & POOL_WORDMASK];
- w ^= input_pool.pool[(i + POOL_TAP5) & POOL_WORDMASK];
+ w ^= input_pool_data[i];
+ w ^= input_pool_data[(i + POOL_TAP1) & POOL_WORDMASK];
+ w ^= input_pool_data[(i + POOL_TAP2) & POOL_WORDMASK];
+ w ^= input_pool_data[(i + POOL_TAP3) & POOL_WORDMASK];
+ w ^= input_pool_data[(i + POOL_TAP4) & POOL_WORDMASK];
+ w ^= input_pool_data[(i + POOL_TAP5) & POOL_WORDMASK];
/* Mix the result back in with a twist */
- input_pool.pool[i] = (w >> 3) ^ twist_table[w & 7];
+ input_pool_data[i] = (w >> 3) ^ twist_table[w & 7];
/*
* Normally, we add 7 bits of rotation to the pool.
@@ -1369,7 +1364,7 @@ static void extract_buf(u8 *out)
/* Generate a hash across the pool */
spin_lock_irqsave(&input_pool.lock, flags);
- blake2s_update(&state, (const u8 *)input_pool.pool, POOL_BYTES);
+ blake2s_update(&state, (const u8 *)input_pool_data, POOL_BYTES);
blake2s_final(&state, hash); /* final zeros out state */
/*
--
2.34.1
next prev parent reply other threads:[~2022-01-16 16:36 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-01-13 15:44 [PATCH 0/7] first in overall series of rng code house cleaning Jason A. Donenfeld
2022-01-13 15:44 ` [PATCH 1/7] random: cleanup poolinfo abstraction Jason A. Donenfeld
2022-01-16 13:24 ` Dominik Brodowski
2022-01-13 15:44 ` [PATCH 2/7] random: cleanup integer types Jason A. Donenfeld
2022-01-16 13:24 ` Dominik Brodowski
2022-01-13 15:44 ` [PATCH 3/7] random: remove incomplete last_data logic Jason A. Donenfeld
2022-01-16 13:24 ` Dominik Brodowski
2022-01-13 15:44 ` [PATCH 4/7] random: remove unused reserved argument Jason A. Donenfeld
2022-01-16 13:24 ` Dominik Brodowski
2022-01-16 16:22 ` Jason A. Donenfeld
2022-01-17 17:28 ` Dominik Brodowski
2022-01-17 17:52 ` [PATCH] random: simplify arithmetic function flow in account() Jason A. Donenfeld
2022-01-17 17:55 ` Jason A. Donenfeld
2022-01-13 15:44 ` [PATCH 5/7] random: rather than entropy_store abstraction, use global Jason A. Donenfeld
2022-01-16 13:24 ` Dominik Brodowski
2022-01-13 15:44 ` [PATCH 6/7] random: remove unused OUTPUT_POOL constants Jason A. Donenfeld
2022-01-16 13:25 ` Dominik Brodowski
2022-01-13 15:44 ` [PATCH 7/7] random: de-duplicate INPUT_POOL constants Jason A. Donenfeld
2022-01-16 13:25 ` Dominik Brodowski
2022-01-14 15:33 ` [PATCH] random: cleanup fractional entropy shift constants Jason A. Donenfeld
2022-01-14 15:39 ` David Laight
2022-01-14 15:46 ` Jason A. Donenfeld
2022-01-16 16:35 ` [PATCH 1/4] random: prepend remaining pool constants with POOL_ Jason A. Donenfeld
2022-01-16 16:35 ` [PATCH 2/4] random: cleanup fractional entropy shift constants Jason A. Donenfeld
2022-01-17 17:31 ` Dominik Brodowski
2022-01-16 16:35 ` Jason A. Donenfeld [this message]
2022-01-17 17:32 ` [PATCH 3/4] random: access input_pool_data directly rather than through pointer Dominik Brodowski
2022-01-16 16:35 ` [PATCH 4/4] random: selectively clang-format where it makes sense Jason A. Donenfeld
2022-01-17 17:34 ` Dominik Brodowski
2022-01-17 17:29 ` [PATCH 1/4] random: prepend remaining pool constants with POOL_ Dominik Brodowski
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=20220116163547.154991-3-Jason@zx2c4.com \
--to=jason@zx2c4.com \
--cc=linux-kernel@vger.kernel.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.