Skip to content

Commit

Permalink
hwrng: add randomness to system from rng sources
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
kees authored and herbertx committed Mar 10, 2014
1 parent 04d088c commit d9e7972
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions drivers/char/hw_random/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
#include <linux/miscdevice.h>
#include <linux/delay.h>
#include <linux/slab.h>
#include <linux/random.h>
#include <asm/uaccess.h>


Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit d9e7972

Please sign in to comment.