Commit 5d58ea3a authored by Eric Biggers's avatar Eric Biggers Committed by Jason A. Donenfeld

random: remove use_input_pool parameter from crng_reseed()

The primary_crng is always reseeded from the input_pool, while the NUMA
crngs are always reseeded from the primary_crng.  Remove the redundant
'use_input_pool' parameter from crng_reseed() and just directly check
whether the crng is the primary_crng.
Signed-off-by: default avatarEric Biggers <ebiggers@google.com>
Signed-off-by: default avatarJason A. Donenfeld <Jason@zx2c4.com>
parent a49c010e
...@@ -365,7 +365,7 @@ static struct { ...@@ -365,7 +365,7 @@ static struct {
static void extract_entropy(void *buf, size_t nbytes); static void extract_entropy(void *buf, size_t nbytes);
static void crng_reseed(struct crng_state *crng, bool use_input_pool); static void crng_reseed(struct crng_state *crng);
/* /*
* This function adds bytes into the entropy "pool". It does not * This function adds bytes into the entropy "pool". It does not
...@@ -464,7 +464,7 @@ static void credit_entropy_bits(int nbits) ...@@ -464,7 +464,7 @@ static void credit_entropy_bits(int nbits)
trace_credit_entropy_bits(nbits, entropy_count, _RET_IP_); trace_credit_entropy_bits(nbits, entropy_count, _RET_IP_);
if (crng_init < 2 && entropy_count >= POOL_MIN_BITS) if (crng_init < 2 && entropy_count >= POOL_MIN_BITS)
crng_reseed(&primary_crng, true); crng_reseed(&primary_crng);
} }
/********************************************************************* /*********************************************************************
...@@ -701,7 +701,7 @@ static int crng_slow_load(const u8 *cp, size_t len) ...@@ -701,7 +701,7 @@ static int crng_slow_load(const u8 *cp, size_t len)
return 1; return 1;
} }
static void crng_reseed(struct crng_state *crng, bool use_input_pool) static void crng_reseed(struct crng_state *crng)
{ {
unsigned long flags; unsigned long flags;
int i; int i;
...@@ -710,7 +710,7 @@ static void crng_reseed(struct crng_state *crng, bool use_input_pool) ...@@ -710,7 +710,7 @@ static void crng_reseed(struct crng_state *crng, bool use_input_pool)
u32 key[8]; u32 key[8];
} buf; } buf;
if (use_input_pool) { if (crng == &primary_crng) {
int entropy_count; int entropy_count;
do { do {
entropy_count = READ_ONCE(input_pool.entropy_count); entropy_count = READ_ONCE(input_pool.entropy_count);
...@@ -748,7 +748,7 @@ static void _extract_crng(struct crng_state *crng, u8 out[CHACHA_BLOCK_SIZE]) ...@@ -748,7 +748,7 @@ static void _extract_crng(struct crng_state *crng, u8 out[CHACHA_BLOCK_SIZE])
init_time = READ_ONCE(crng->init_time); init_time = READ_ONCE(crng->init_time);
if (time_after(READ_ONCE(crng_global_init_time), init_time) || if (time_after(READ_ONCE(crng_global_init_time), init_time) ||
time_after(jiffies, init_time + CRNG_RESEED_INTERVAL)) time_after(jiffies, init_time + CRNG_RESEED_INTERVAL))
crng_reseed(crng, crng == &primary_crng); crng_reseed(crng);
} }
spin_lock_irqsave(&crng->lock, flags); spin_lock_irqsave(&crng->lock, flags);
chacha20_block(&crng->state[0], out); chacha20_block(&crng->state[0], out);
...@@ -1547,7 +1547,7 @@ static long random_ioctl(struct file *f, unsigned int cmd, unsigned long arg) ...@@ -1547,7 +1547,7 @@ static long random_ioctl(struct file *f, unsigned int cmd, unsigned long arg)
return -EPERM; return -EPERM;
if (crng_init < 2) if (crng_init < 2)
return -ENODATA; return -ENODATA;
crng_reseed(&primary_crng, true); crng_reseed(&primary_crng);
WRITE_ONCE(crng_global_init_time, jiffies - 1); WRITE_ONCE(crng_global_init_time, jiffies - 1);
return 0; return 0;
default: default:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment