diff options
author | Torsten Duwe <duwe@lst.de> | 2014-06-14 23:38:36 -0400 |
---|---|---|
committer | Theodore Ts'o <tytso@mit.edu> | 2014-07-15 04:49:40 -0400 |
commit | c84dbf61a7b322188d2a7fddc0cc6317ac6713e2 (patch) | |
tree | 9c89724ab1fbfc2a21b2cd681d706791a0105694 | |
parent | 43759d4f429c8d55fd56f863542e20f4e6e8f589 (diff) | |
download | op-kernel-dev-c84dbf61a7b322188d2a7fddc0cc6317ac6713e2.zip op-kernel-dev-c84dbf61a7b322188d2a7fddc0cc6317ac6713e2.tar.gz |
random: add_hwgenerator_randomness() for feeding entropy from devices
This patch adds an interface to the random pool for feeding entropy
in-kernel.
Signed-off-by: Torsten Duwe <duwe@suse.de>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Acked-by: H. Peter Anvin <hpa@zytor.com>
-rw-r--r-- | drivers/char/random.c | 21 | ||||
-rw-r--r-- | include/linux/hw_random.h | 2 |
2 files changed, 23 insertions, 0 deletions
diff --git a/drivers/char/random.c b/drivers/char/random.c index d3bb792..914b157 100644 --- a/drivers/char/random.c +++ b/drivers/char/random.c @@ -250,6 +250,7 @@ #include <linux/interrupt.h> #include <linux/mm.h> #include <linux/spinlock.h> +#include <linux/kthread.h> #include <linux/percpu.h> #include <linux/cryptohash.h> #include <linux/fips.h> @@ -1750,3 +1751,23 @@ randomize_range(unsigned long start, unsigned long end, unsigned long len) return 0; return PAGE_ALIGN(get_random_int() % range + start); } + +/* Interface for in-kernel drivers of true hardware RNGs. + * Those devices may produce endless random bits and will be throttled + * when our pool is full. + */ +void add_hwgenerator_randomness(const char *buffer, size_t count, + size_t entropy) +{ + struct entropy_store *poolp = &input_pool; + + /* Suspend writing if we're above the trickle threshold. + * We'll be woken up again once below random_write_wakeup_thresh, + * or when the calling thread is about to terminate. + */ + wait_event_interruptible(random_write_wait, kthread_should_stop() || + ENTROPY_BITS(&input_pool) <= random_write_wakeup_bits); + mix_pool_bytes(poolp, buffer, count); + credit_entropy_bits(poolp, entropy); +} +EXPORT_SYMBOL_GPL(add_hwgenerator_randomness); diff --git a/include/linux/hw_random.h b/include/linux/hw_random.h index b4b0eef..3f075ff 100644 --- a/include/linux/hw_random.h +++ b/include/linux/hw_random.h @@ -47,5 +47,7 @@ struct hwrng { extern int hwrng_register(struct hwrng *rng); /** Unregister a Hardware Random Number Generator driver. */ extern void hwrng_unregister(struct hwrng *rng); +/** Feed random bits into the pool. */ +extern void add_hwgenerator_randomness(const char *buffer, size_t count, size_t entropy); #endif /* LINUX_HWRANDOM_H_ */ |