summaryrefslogtreecommitdiff
path: root/drivers/char
diff options
context:
space:
mode:
authorKees Cook <keescook@chromium.org>2014-03-03 23:51:48 (GMT)
committerHerbert Xu <herbert@gondor.apana.org.au>2014-03-10 12:17:06 (GMT)
commitd9e79726193346569af7953369a638ee2275ade5 (patch)
tree8818f3e2b0c63d1e9eca6336e9448d29523c0d6c /drivers/char
parent04d088cc0b19a4cb14680b92205fd4600470c46f (diff)
downloadlinux-d9e79726193346569af7953369a638ee2275ade5.tar.xz
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>
Diffstat (limited to 'drivers/char')
-rw-r--r--drivers/char/hw_random/core.c7
1 files changed, 7 insertions, 0 deletions
diff --git a/drivers/char/hw_random/core.c b/drivers/char/hw_random/core.c
index cf49f1c..7ac96fb 100644
--- a/drivers/char/hw_random/core.c
+++ b/drivers/char/hw_random/core.c
@@ -41,6 +41,7 @@
#include <linux/miscdevice.h>
#include <linux/delay.h>
#include <linux/slab.h>
+#include <linux/random.h>
#include <asm/uaccess.h>
@@ -304,6 +305,8 @@ int hwrng_register(struct hwrng *rng)
{
int err = -EINVAL;
struct hwrng *old_rng, *tmp;
+ unsigned char bytes[16];
+ int bytes_read;
if (rng->name == NULL ||
(rng->data_read == NULL && rng->read == NULL))
@@ -344,6 +347,10 @@ int hwrng_register(struct hwrng *rng)
}
INIT_LIST_HEAD(&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:
mutex_unlock(&rng_mutex);
out: