diff options
| -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 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); | ||
diff --git a/include/linux/hw_random.h b/include/linux/hw_random.h index b4b0eef5fddf..3f075ff00411 100644 --- a/include/linux/hw_random.h +++ b/include/linux/hw_random.h | |||
| @@ -47,5 +47,7 @@ struct hwrng { | |||
| 47 | extern int hwrng_register(struct hwrng *rng); | 47 | extern int hwrng_register(struct hwrng *rng); |
| 48 | /** Unregister a Hardware Random Number Generator driver. */ | 48 | /** Unregister a Hardware Random Number Generator driver. */ |
| 49 | extern void hwrng_unregister(struct hwrng *rng); | 49 | extern void hwrng_unregister(struct hwrng *rng); |
| 50 | /** Feed random bits into the pool. */ | ||
| 51 | extern void add_hwgenerator_randomness(const char *buffer, size_t count, size_t entropy); | ||
| 50 | 52 | ||
| 51 | #endif /* LINUX_HWRANDOM_H_ */ | 53 | #endif /* LINUX_HWRANDOM_H_ */ |
