Skip to content

Commit 6c0eace

Browse files
committed
random: access input_pool_data directly rather than through pointer
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. Reviewed-by: Dominik Brodowski <linux@dominikbrodowski.net> Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
1 parent 18263c4 commit 6c0eace

File tree

1 file changed

+8
-13
lines changed

1 file changed

+8
-13
lines changed

drivers/char/random.c

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -496,17 +496,12 @@ MODULE_PARM_DESC(ratelimit_disable, "Disable random ratelimit suppression");
496496
static u32 input_pool_data[POOL_WORDS] __latent_entropy;
497497

498498
static struct {
499-
/* read-only data: */
500-
u32 *pool;
501-
502-
/* read-write data: */
503499
spinlock_t lock;
504500
u16 add_ptr;
505501
u16 input_rotate;
506502
int entropy_count;
507503
} input_pool = {
508504
.lock = __SPIN_LOCK_UNLOCKED(input_pool.lock),
509-
.pool = input_pool_data
510505
};
511506

512507
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)
544539
i = (i - 1) & POOL_WORDMASK;
545540

546541
/* XOR in the various taps */
547-
w ^= input_pool.pool[i];
548-
w ^= input_pool.pool[(i + POOL_TAP1) & POOL_WORDMASK];
549-
w ^= input_pool.pool[(i + POOL_TAP2) & POOL_WORDMASK];
550-
w ^= input_pool.pool[(i + POOL_TAP3) & POOL_WORDMASK];
551-
w ^= input_pool.pool[(i + POOL_TAP4) & POOL_WORDMASK];
552-
w ^= input_pool.pool[(i + POOL_TAP5) & POOL_WORDMASK];
542+
w ^= input_pool_data[i];
543+
w ^= input_pool_data[(i + POOL_TAP1) & POOL_WORDMASK];
544+
w ^= input_pool_data[(i + POOL_TAP2) & POOL_WORDMASK];
545+
w ^= input_pool_data[(i + POOL_TAP3) & POOL_WORDMASK];
546+
w ^= input_pool_data[(i + POOL_TAP4) & POOL_WORDMASK];
547+
w ^= input_pool_data[(i + POOL_TAP5) & POOL_WORDMASK];
553548

554549
/* Mix the result back in with a twist */
555-
input_pool.pool[i] = (w >> 3) ^ twist_table[w & 7];
550+
input_pool_data[i] = (w >> 3) ^ twist_table[w & 7];
556551

557552
/*
558553
* Normally, we add 7 bits of rotation to the pool.
@@ -1369,7 +1364,7 @@ static void extract_buf(u8 *out)
13691364

13701365
/* Generate a hash across the pool */
13711366
spin_lock_irqsave(&input_pool.lock, flags);
1372-
blake2s_update(&state, (const u8 *)input_pool.pool, POOL_BYTES);
1367+
blake2s_update(&state, (const u8 *)input_pool_data, POOL_BYTES);
13731368
blake2s_final(&state, hash); /* final zeros out state */
13741369

13751370
/*

0 commit comments

Comments
 (0)