aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/char
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/char')
-rw-r--r--drivers/char/random.c21
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 */
1759void 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}
1773EXPORT_SYMBOL_GPL(add_hwgenerator_randomness);