Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756634Ab3ILJj4 (ORCPT ); Thu, 12 Sep 2013 05:39:56 -0400 Received: from verein.lst.de ([213.95.11.211]:55326 "EHLO newverein.lst.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751380Ab3ILJjz (ORCPT ); Thu, 12 Sep 2013 05:39:55 -0400 Date: Thu, 12 Sep 2013 11:38:56 +0200 (CEST) From: Torsten Duwe Reply-To: Torsten Duwe To: tytso@mit.edu, ingo.tuchscherer@de.ibm.com cc: linux-kernel@vger.kernel.org, Hans-Georg Markgraf , Gerald Schaefer , Martin Schwidefsky , Heiko Carstens , Joe Perches Subject: [Resend PATCH 1/2] add direct interface for true hardware RNGs Message-ID: User-Agent: Alpine 2.00 (LNX 1167 2008-08-23) Organization: LST e.V. MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2172 Lines: 62 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 --- 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 #include #include +#include #include #include #include @@ -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 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/