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 /drivers/char | |
parent | 43759d4f429c8d55fd56f863542e20f4e6e8f589 (diff) |
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>
Diffstat (limited to 'drivers/char')
-rw-r--r-- | drivers/char/random.c | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/drivers/char/random.c b/drivers/char/random.c index d3bb7927fb49..914b1575df8f 100644 --- a/drivers/char/random.c +++ b/drivers/char/random.c | |||
@@ -250,6 +250,7 @@ | |||
250 | #include <linux/interrupt.h> | 250 | #include <linux/interrupt.h> |
251 | #include <linux/mm.h> | 251 | #include <linux/mm.h> |
252 | #include <linux/spinlock.h> | 252 | #include <linux/spinlock.h> |
253 | #include <linux/kthread.h> | ||
253 | #include <linux/percpu.h> | 254 | #include <linux/percpu.h> |
254 | #include <linux/cryptohash.h> | 255 | #include <linux/cryptohash.h> |
255 | #include <linux/fips.h> | 256 | #include <linux/fips.h> |
@@ -1750,3 +1751,23 @@ randomize_range(unsigned long start, unsigned long end, unsigned long len) | |||
1750 | return 0; | 1751 | return 0; |
1751 | return PAGE_ALIGN(get_random_int() % range + start); | 1752 | return PAGE_ALIGN(get_random_int() % range + start); |
1752 | } | 1753 | } |
1754 | |||
1755 | /* Interface for in-kernel drivers of true hardware RNGs. | ||
1756 | * Those devices may produce endless random bits and will be throttled | ||
1757 | * when our pool is full. | ||
1758 | */ | ||
1759 | void add_hwgenerator_randomness(const char *buffer, size_t count, | ||
1760 | size_t entropy) | ||
1761 | { | ||
1762 | struct entropy_store *poolp = &input_pool; | ||
1763 | |||
1764 | /* Suspend writing if we're above the trickle threshold. | ||
1765 | * We'll be woken up again once below random_write_wakeup_thresh, | ||
1766 | * or when the calling thread is about to terminate. | ||
1767 | */ | ||
1768 | wait_event_interruptible(random_write_wait, kthread_should_stop() || | ||
1769 | ENTROPY_BITS(&input_pool) <= random_write_wakeup_bits); | ||
1770 | mix_pool_bytes(poolp, buffer, count); | ||
1771 | credit_entropy_bits(poolp, entropy); | ||
1772 | } | ||
1773 | EXPORT_SYMBOL_GPL(add_hwgenerator_randomness); | ||