Skip to content

Commit a4bfa9b

Browse files
committed
random: remove incomplete last_data logic
There were a few things added under the "if (fips_enabled)" banner, which never really got completed, and the FIPS people anyway are choosing a different direction. Rather than keep around this halfbaked code, get rid of it so that we can focus on a single design of the RNG rather than two designs. Reviewed-by: Dominik Brodowski <[email protected]> Signed-off-by: Jason A. Donenfeld <[email protected]>
1 parent d38bb08 commit a4bfa9b

File tree

1 file changed

+4
-35
lines changed

1 file changed

+4
-35
lines changed

drivers/char/random.c

Lines changed: 4 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,6 @@
337337
#include <linux/spinlock.h>
338338
#include <linux/kthread.h>
339339
#include <linux/percpu.h>
340-
#include <linux/fips.h>
341340
#include <linux/ptrace.h>
342341
#include <linux/workqueue.h>
343342
#include <linux/irq.h>
@@ -517,14 +516,12 @@ struct entropy_store {
517516
u16 add_ptr;
518517
u16 input_rotate;
519518
int entropy_count;
520-
unsigned int last_data_init:1;
521-
u8 last_data[EXTRACT_SIZE];
522519
};
523520

524521
static ssize_t extract_entropy(struct entropy_store *r, void *buf,
525522
size_t nbytes, int min, int rsvd);
526523
static ssize_t _extract_entropy(struct entropy_store *r, void *buf,
527-
size_t nbytes, int fips);
524+
size_t nbytes);
528525

529526
static void crng_reseed(struct crng_state *crng, struct entropy_store *r);
530527
static u32 input_pool_data[INPUT_POOL_WORDS] __latent_entropy;
@@ -821,7 +818,7 @@ static void crng_initialize_secondary(struct crng_state *crng)
821818

822819
static void __init crng_initialize_primary(struct crng_state *crng)
823820
{
824-
_extract_entropy(&input_pool, &crng->state[4], sizeof(u32) * 12, 0);
821+
_extract_entropy(&input_pool, &crng->state[4], sizeof(u32) * 12);
825822
if (crng_init_try_arch_early(crng) && trust_cpu && crng_init < 2) {
826823
invalidate_batched_entropy();
827824
numa_crng_init();
@@ -1426,22 +1423,13 @@ static void extract_buf(struct entropy_store *r, u8 *out)
14261423
}
14271424

14281425
static ssize_t _extract_entropy(struct entropy_store *r, void *buf,
1429-
size_t nbytes, int fips)
1426+
size_t nbytes)
14301427
{
14311428
ssize_t ret = 0, i;
14321429
u8 tmp[EXTRACT_SIZE];
1433-
unsigned long flags;
14341430

14351431
while (nbytes) {
14361432
extract_buf(r, tmp);
1437-
1438-
if (fips) {
1439-
spin_lock_irqsave(&r->lock, flags);
1440-
if (!memcmp(tmp, r->last_data, EXTRACT_SIZE))
1441-
panic("Hardware RNG duplicated output!\n");
1442-
memcpy(r->last_data, tmp, EXTRACT_SIZE);
1443-
spin_unlock_irqrestore(&r->lock, flags);
1444-
}
14451433
i = min_t(int, nbytes, EXTRACT_SIZE);
14461434
memcpy(buf, tmp, i);
14471435
nbytes -= i;
@@ -1467,28 +1455,9 @@ static ssize_t _extract_entropy(struct entropy_store *r, void *buf,
14671455
static ssize_t extract_entropy(struct entropy_store *r, void *buf,
14681456
size_t nbytes, int min, int reserved)
14691457
{
1470-
u8 tmp[EXTRACT_SIZE];
1471-
unsigned long flags;
1472-
1473-
/* if last_data isn't primed, we need EXTRACT_SIZE extra bytes */
1474-
if (fips_enabled) {
1475-
spin_lock_irqsave(&r->lock, flags);
1476-
if (!r->last_data_init) {
1477-
r->last_data_init = 1;
1478-
spin_unlock_irqrestore(&r->lock, flags);
1479-
trace_extract_entropy(r->name, EXTRACT_SIZE,
1480-
ENTROPY_BITS(r), _RET_IP_);
1481-
extract_buf(r, tmp);
1482-
spin_lock_irqsave(&r->lock, flags);
1483-
memcpy(r->last_data, tmp, EXTRACT_SIZE);
1484-
}
1485-
spin_unlock_irqrestore(&r->lock, flags);
1486-
}
1487-
14881458
trace_extract_entropy(r->name, nbytes, ENTROPY_BITS(r), _RET_IP_);
14891459
nbytes = account(r, nbytes, min, reserved);
1490-
1491-
return _extract_entropy(r, buf, nbytes, fips_enabled);
1460+
return _extract_entropy(r, buf, nbytes);
14921461
}
14931462

14941463
#define warn_unseeded_randomness(previous) \

0 commit comments

Comments
 (0)