Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

hwrng: add randomness to system from rng sources

When bringing a new RNG source online, it seems like it would make sense
to use some of its bytes to make the system entropy pool more random,
as done with all sorts of other devices that contain per-device or
per-boot differences.

Signed-off-by: Kees Cook <keescook@chromium.org>
Reviewed-by: Jason Cooper <jason@lakedaemon.net>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

authored by

Kees Cook and committed by
Herbert Xu
d9e79726 04d088cc

+7
+7
drivers/char/hw_random/core.c
··· 41 41 #include <linux/miscdevice.h> 42 42 #include <linux/delay.h> 43 43 #include <linux/slab.h> 44 + #include <linux/random.h> 44 45 #include <asm/uaccess.h> 45 46 46 47 ··· 305 304 { 306 305 int err = -EINVAL; 307 306 struct hwrng *old_rng, *tmp; 307 + unsigned char bytes[16]; 308 + int bytes_read; 308 309 309 310 if (rng->name == NULL || 310 311 (rng->data_read == NULL && rng->read == NULL)) ··· 347 344 } 348 345 INIT_LIST_HEAD(&rng->list); 349 346 list_add_tail(&rng->list, &rng_list); 347 + 348 + bytes_read = rng_get_data(rng, bytes, sizeof(bytes), 1); 349 + if (bytes_read > 0) 350 + add_device_randomness(bytes, bytes_read); 350 351 out_unlock: 351 352 mutex_unlock(&rng_mutex); 352 353 out: