Skip to content

Commit d9e7972

Browse files
keesherbertx
authored andcommitted
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 <[email protected]> Reviewed-by: Jason Cooper <[email protected]> Signed-off-by: Herbert Xu <[email protected]>
1 parent 04d088c commit d9e7972

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

drivers/char/hw_random/core.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
#include <linux/miscdevice.h>
4242
#include <linux/delay.h>
4343
#include <linux/slab.h>
44+
#include <linux/random.h>
4445
#include <asm/uaccess.h>
4546

4647

@@ -304,6 +305,8 @@ int hwrng_register(struct hwrng *rng)
304305
{
305306
int err = -EINVAL;
306307
struct hwrng *old_rng, *tmp;
308+
unsigned char bytes[16];
309+
int bytes_read;
307310

308311
if (rng->name == NULL ||
309312
(rng->data_read == NULL && rng->read == NULL))
@@ -344,6 +347,10 @@ int hwrng_register(struct hwrng *rng)
344347
}
345348
INIT_LIST_HEAD(&rng->list);
346349
list_add_tail(&rng->list, &rng_list);
350+
351+
bytes_read = rng_get_data(rng, bytes, sizeof(bytes), 1);
352+
if (bytes_read > 0)
353+
add_device_randomness(bytes, bytes_read);
347354
out_unlock:
348355
mutex_unlock(&rng_mutex);
349356
out:

0 commit comments

Comments
 (0)