Commit d9e79726 authored by Kees Cook's avatar Kees Cook Committed by Herbert Xu

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: default avatarKees Cook <keescook@chromium.org>
Reviewed-by: default avatarJason Cooper <jason@lakedaemon.net>
Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
parent 04d088cc
...@@ -41,6 +41,7 @@ ...@@ -41,6 +41,7 @@
#include <linux/miscdevice.h> #include <linux/miscdevice.h>
#include <linux/delay.h> #include <linux/delay.h>
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/random.h>
#include <asm/uaccess.h> #include <asm/uaccess.h>
...@@ -304,6 +305,8 @@ int hwrng_register(struct hwrng *rng) ...@@ -304,6 +305,8 @@ int hwrng_register(struct hwrng *rng)
{ {
int err = -EINVAL; int err = -EINVAL;
struct hwrng *old_rng, *tmp; struct hwrng *old_rng, *tmp;
unsigned char bytes[16];
int bytes_read;
if (rng->name == NULL || if (rng->name == NULL ||
(rng->data_read == NULL && rng->read == NULL)) (rng->data_read == NULL && rng->read == NULL))
...@@ -344,6 +347,10 @@ int hwrng_register(struct hwrng *rng) ...@@ -344,6 +347,10 @@ int hwrng_register(struct hwrng *rng)
} }
INIT_LIST_HEAD(&rng->list); INIT_LIST_HEAD(&rng->list);
list_add_tail(&rng->list, &rng_list); list_add_tail(&rng->list, &rng_list);
bytes_read = rng_get_data(rng, bytes, sizeof(bytes), 1);
if (bytes_read > 0)
add_device_randomness(bytes, bytes_read);
out_unlock: out_unlock:
mutex_unlock(&rng_mutex); mutex_unlock(&rng_mutex);
out: out:
......
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