summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2022-06-13 10:07:49 +0200
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2022-06-14 18:36:27 +0200
commit51e5572724826d433d74c40702fa762342a3406c (patch)
tree1ce65257da0ddcf5f2259ff5eaf2ef332d21aa55
parente59a120f2d435ee2cfa47035be903cc2d8cc6731 (diff)
downloadlinux-51e5572724826d433d74c40702fa762342a3406c.tar.gz
linux-51e5572724826d433d74c40702fa762342a3406c.tar.bz2
linux-51e5572724826d433d74c40702fa762342a3406c.zip
random: account for arch randomness in bits
commit 77fc95f8c0dc9e1f8e620ec14d2fb65028fb7adc upstream. Rather than accounting in bytes and multiplying (shifting), we can just account in bits and avoid the shift. The main motivation for this is there are other patches in flux that expand this code a bit, and avoiding the duplication of "* 8" everywhere makes things a bit clearer. Cc: stable@vger.kernel.org Fixes: 12e45a2a6308 ("random: credit architectural init the exact amount") Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r--drivers/char/random.c8
1 files changed, 4 insertions, 4 deletions
diff --git a/drivers/char/random.c b/drivers/char/random.c
index c9b7e0c28043..7f6585c49380 100644
--- a/drivers/char/random.c
+++ b/drivers/char/random.c
@@ -813,7 +813,7 @@ early_param("random.trust_bootloader", parse_trust_bootloader);
int __init random_init(const char *command_line)
{
ktime_t now = ktime_get_real();
- unsigned int i, arch_bytes;
+ unsigned int i, arch_bits;
unsigned long entropy;
#if defined(LATENT_ENTROPY_PLUGIN)
@@ -821,12 +821,12 @@ int __init random_init(const char *command_line)
_mix_pool_bytes(compiletime_seed, sizeof(compiletime_seed));
#endif
- for (i = 0, arch_bytes = BLAKE2S_BLOCK_SIZE;
+ for (i = 0, arch_bits = BLAKE2S_BLOCK_SIZE * 8;
i < BLAKE2S_BLOCK_SIZE; i += sizeof(entropy)) {
if (!arch_get_random_seed_long_early(&entropy) &&
!arch_get_random_long_early(&entropy)) {
entropy = random_get_entropy();
- arch_bytes -= sizeof(entropy);
+ arch_bits -= sizeof(entropy) * 8;
}
_mix_pool_bytes(&entropy, sizeof(entropy));
}
@@ -838,7 +838,7 @@ int __init random_init(const char *command_line)
if (crng_ready())
crng_reseed();
else if (trust_cpu)
- _credit_init_bits(arch_bytes * 8);
+ _credit_init_bits(arch_bits);
return 0;
}