Skip to contentSkip to conversation

hwrng: add randomness to system from rng sources

PATCH RESEND Superseded Kees Cook 1 participant 1 message Oct 25, 2013 Hardware random number generator core

lore
Share & tools
lore

Kees Cook

author
#0 lore raw

PATCH RESEND 1/1 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.

---
 drivers/char/hw_random/core.c |    7 +++++++
 1 file changed, 7 insertions(+)
drivers/char/hw_random/core.c +7 -0
index a0f7724852eb..6e5bb68a708c 100644
@@ -41,6 +41,7 @@
 #include <linux/miscdevice.h>
 #include <linux/delay.h>
 #include <linux/slab.h>
+#include <linux/random.h>
 #include <asm/uaccess.h>
 
 
@@ -305,6 +306,8 @@ int hwrng_register(struct hwrng *rng)
 	int must_register_misc;
 	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))
@@ -348,6 +351,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:
Signature · 6 lines
1.7.9.5


-- 
Kees Cook
Chrome OS Security