Michael Buesch | 844dd05 | 2006-06-26 00:24:59 -0700 | [diff] [blame] | 1 | /* |
| 2 | Hardware Random Number Generator |
| 3 | |
| 4 | Please read Documentation/hw_random.txt for details on use. |
| 5 | |
| 6 | ---------------------------------------------------------- |
| 7 | This software may be used and distributed according to the terms |
| 8 | of the GNU General Public License, incorporated herein by reference. |
| 9 | |
| 10 | */ |
| 11 | |
| 12 | #ifndef LINUX_HWRANDOM_H_ |
| 13 | #define LINUX_HWRANDOM_H_ |
Michael Buesch | 844dd05 | 2006-06-26 00:24:59 -0700 | [diff] [blame] | 14 | |
Herbert Xu | 77584ee | 2014-12-23 16:40:17 +1100 | [diff] [blame^] | 15 | #include <linux/completion.h> |
Michael Buesch | 844dd05 | 2006-06-26 00:24:59 -0700 | [diff] [blame] | 16 | #include <linux/types.h> |
| 17 | #include <linux/list.h> |
Rusty Russell | 3a2c0ba | 2014-12-08 16:50:37 +0800 | [diff] [blame] | 18 | #include <linux/kref.h> |
Michael Buesch | 844dd05 | 2006-06-26 00:24:59 -0700 | [diff] [blame] | 19 | |
| 20 | /** |
| 21 | * struct hwrng - Hardware Random Number Generator driver |
| 22 | * @name: Unique RNG name. |
| 23 | * @init: Initialization callback (can be NULL). |
| 24 | * @cleanup: Cleanup callback (can be NULL). |
| 25 | * @data_present: Callback to determine if data is available |
| 26 | * on the RNG. If NULL, it is assumed that |
Ian Molton | 9996508 | 2009-12-01 14:47:32 +0800 | [diff] [blame] | 27 | * there is always data available. *OBSOLETE* |
Michael Buesch | 844dd05 | 2006-06-26 00:24:59 -0700 | [diff] [blame] | 28 | * @data_read: Read data from the RNG device. |
| 29 | * Returns the number of lower random bytes in "data". |
Sasha Levin | 988acec | 2011-05-25 15:12:20 +0300 | [diff] [blame] | 30 | * Must not be NULL. *OBSOLETE* |
Ian Molton | 9996508 | 2009-12-01 14:47:32 +0800 | [diff] [blame] | 31 | * @read: New API. drivers can fill up to max bytes of data |
| 32 | * into the buffer. The buffer is aligned for any type. |
Michael Buesch | 844dd05 | 2006-06-26 00:24:59 -0700 | [diff] [blame] | 33 | * @priv: Private data, for use by the RNG driver. |
Torsten Duwe | 0f734e6 | 2014-06-14 23:48:41 -0400 | [diff] [blame] | 34 | * @quality: Estimation of true entropy in RNG's bitstream |
| 35 | * (per mill). |
Michael Buesch | 844dd05 | 2006-06-26 00:24:59 -0700 | [diff] [blame] | 36 | */ |
| 37 | struct hwrng { |
| 38 | const char *name; |
| 39 | int (*init)(struct hwrng *rng); |
| 40 | void (*cleanup)(struct hwrng *rng); |
Patrick McHardy | 984e976 | 2007-11-21 12:24:45 +0800 | [diff] [blame] | 41 | int (*data_present)(struct hwrng *rng, int wait); |
Michael Buesch | 844dd05 | 2006-06-26 00:24:59 -0700 | [diff] [blame] | 42 | int (*data_read)(struct hwrng *rng, u32 *data); |
Ian Molton | 9996508 | 2009-12-01 14:47:32 +0800 | [diff] [blame] | 43 | int (*read)(struct hwrng *rng, void *data, size_t max, bool wait); |
Michael Buesch | 844dd05 | 2006-06-26 00:24:59 -0700 | [diff] [blame] | 44 | unsigned long priv; |
Torsten Duwe | 0f734e6 | 2014-06-14 23:48:41 -0400 | [diff] [blame] | 45 | unsigned short quality; |
Michael Buesch | 844dd05 | 2006-06-26 00:24:59 -0700 | [diff] [blame] | 46 | |
| 47 | /* internal. */ |
| 48 | struct list_head list; |
Rusty Russell | 3a2c0ba | 2014-12-08 16:50:37 +0800 | [diff] [blame] | 49 | struct kref ref; |
Herbert Xu | 77584ee | 2014-12-23 16:40:17 +1100 | [diff] [blame^] | 50 | struct completion cleanup_done; |
Michael Buesch | 844dd05 | 2006-06-26 00:24:59 -0700 | [diff] [blame] | 51 | }; |
| 52 | |
| 53 | /** Register a new Hardware Random Number Generator driver. */ |
| 54 | extern int hwrng_register(struct hwrng *rng); |
| 55 | /** Unregister a Hardware Random Number Generator driver. */ |
Rafael J. Wysocki | b844eba | 2008-03-23 20:28:24 +0100 | [diff] [blame] | 56 | extern void hwrng_unregister(struct hwrng *rng); |
Torsten Duwe | c84dbf6 | 2014-06-14 23:38:36 -0400 | [diff] [blame] | 57 | /** Feed random bits into the pool. */ |
| 58 | extern void add_hwgenerator_randomness(const char *buffer, size_t count, size_t entropy); |
Michael Buesch | 844dd05 | 2006-06-26 00:24:59 -0700 | [diff] [blame] | 59 | |
Michael Buesch | 844dd05 | 2006-06-26 00:24:59 -0700 | [diff] [blame] | 60 | #endif /* LINUX_HWRANDOM_H_ */ |