blob: 914bb08cd7381939697467306bb72ac33b11ac1e [file] [log] [blame]
Michael Buesch844dd052006-06-26 00:24:59 -07001/*
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 Buesch844dd052006-06-26 00:24:59 -070014
15#include <linux/types.h>
16#include <linux/list.h>
17
18/**
19 * struct hwrng - Hardware Random Number Generator driver
20 * @name: Unique RNG name.
21 * @init: Initialization callback (can be NULL).
22 * @cleanup: Cleanup callback (can be NULL).
23 * @data_present: Callback to determine if data is available
24 * on the RNG. If NULL, it is assumed that
Ian Molton99965082009-12-01 14:47:32 +080025 * there is always data available. *OBSOLETE*
Michael Buesch844dd052006-06-26 00:24:59 -070026 * @data_read: Read data from the RNG device.
27 * Returns the number of lower random bytes in "data".
Sasha Levin988acec2011-05-25 15:12:20 +030028 * Must not be NULL. *OBSOLETE*
Ian Molton99965082009-12-01 14:47:32 +080029 * @read: New API. drivers can fill up to max bytes of data
30 * into the buffer. The buffer is aligned for any type.
Michael Buesch844dd052006-06-26 00:24:59 -070031 * @priv: Private data, for use by the RNG driver.
Torsten Duwe0f734e62014-06-14 23:48:41 -040032 * @quality: Estimation of true entropy in RNG's bitstream
33 * (per mill).
Michael Buesch844dd052006-06-26 00:24:59 -070034 */
35struct hwrng {
36 const char *name;
37 int (*init)(struct hwrng *rng);
38 void (*cleanup)(struct hwrng *rng);
Patrick McHardy984e9762007-11-21 12:24:45 +080039 int (*data_present)(struct hwrng *rng, int wait);
Michael Buesch844dd052006-06-26 00:24:59 -070040 int (*data_read)(struct hwrng *rng, u32 *data);
Ian Molton99965082009-12-01 14:47:32 +080041 int (*read)(struct hwrng *rng, void *data, size_t max, bool wait);
Michael Buesch844dd052006-06-26 00:24:59 -070042 unsigned long priv;
Torsten Duwe0f734e62014-06-14 23:48:41 -040043 unsigned short quality;
Michael Buesch844dd052006-06-26 00:24:59 -070044
45 /* internal. */
46 struct list_head list;
47};
48
49/** Register a new Hardware Random Number Generator driver. */
50extern int hwrng_register(struct hwrng *rng);
51/** Unregister a Hardware Random Number Generator driver. */
Rafael J. Wysockib844eba2008-03-23 20:28:24 +010052extern void hwrng_unregister(struct hwrng *rng);
Torsten Duwec84dbf62014-06-14 23:38:36 -040053/** Feed random bits into the pool. */
54extern void add_hwgenerator_randomness(const char *buffer, size_t count, size_t entropy);
Michael Buesch844dd052006-06-26 00:24:59 -070055
Michael Buesch844dd052006-06-26 00:24:59 -070056#endif /* LINUX_HWRANDOM_H_ */