mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 1/2] add direct interface for true hardware RNGs
@ 2013-09-02 16:42 Torsten Duwe
  0 siblings, 0 replies; only message in thread
From: Torsten Duwe @ 2013-09-02 16:42 UTC (permalink / raw)
  To: tytso; +Cc: linux-kernel


This patch adds an interface to the random pool for feeding entropy in-kernel.
It might be dangerous when some driver writers think they have "good"
randomness when really they haven't.

Signed-off-by: Torsten Duwe <duwe@lst.de>

---
 include/linux/hw_random.h |    2 ++
 drivers/char/random.c     |   20 ++++++++++++++++++++
 2 files changed, 22 insertions(+)
--- 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);
 
 #endif /* LINUX_HWRANDOM_H_ */
--- 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>
@@ -796,6 +797,25 @@ add_disk_randomness(
 }
 #endif
 
+/* 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)
+{
+	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() ||
+				 input_pool.entropy_count <= trickle_thresh);
+	mix_pool_bytes(poolp, buffer, count, NULL);
+	credit_entropy_bits(poolp, count*8);
+}
+EXPORT_SYMBOL_GPL(add_hwgenerator_randomness);
+
 /*********************************************************************
  *
  * Entropy extraction routines

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2013-09-02 16:49 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-09-02 16:42 [PATCH 1/2] add direct interface for true hardware RNGs Torsten Duwe

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®