Skip to content

Commit af704c8

Browse files
committed
random: skip fast_init if hwrng provides large chunk of entropy
At boot time, EFI calls add_bootloader_randomness(), which in turn calls add_hwgenerator_randomness(). Currently add_hwgenerator_randomness() feeds the first 64 bytes of randomness to the "fast init" non-crypto-grade phase. But if add_hwgenerator_randomness() gets called with more than POOL_MIN_BITS of entropy, there's no point in passing it off to the "fast init" stage, since that's enough entropy to bootstrap the real RNG. The "fast init" stage is just there to provide _something_ in the case where we don't have enough entropy to properly bootstrap the RNG. But if we do have enough entropy to bootstrap the RNG, the current logic doesn't serve a purpose. So, in the case where we're passed greater than or equal to POOL_MIN_BITS of entropy, this commit makes us skip the "fast init" phase. Cc: Dominik Brodowski <linux@dominikbrodowski.net> Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
1 parent 34af78c commit af704c8

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

drivers/char/random.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1128,7 +1128,7 @@ void rand_initialize_disk(struct gendisk *disk)
11281128
void add_hwgenerator_randomness(const void *buffer, size_t count,
11291129
size_t entropy)
11301130
{
1131-
if (unlikely(crng_init == 0)) {
1131+
if (unlikely(crng_init == 0 && entropy < POOL_MIN_BITS)) {
11321132
size_t ret = crng_pre_init_inject(buffer, count, true);
11331133
mix_pool_bytes(buffer, ret);
11341134
count -= ret;

0 commit comments

Comments
 (0)