blob: bee0827766a397d6d5ff3a2f8cdf42b97925f3c8 [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
Herbert Xu77584ee2014-12-23 16:40:17 +110015#include <linux/completion.h>
Michael Buesch844dd052006-06-26 00:24:59 -070016#include <linux/types.h>
17#include <linux/list.h>
Rusty Russell3a2c0ba2014-12-08 16:50:37 +080018#include <linux/kref.h>
Michael Buesch844dd052006-06-26 00:24:59 -070019
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 Molton99965082009-12-01 14:47:32 +080027 * there is always data available. *OBSOLETE*
Michael Buesch844dd052006-06-26 00:24:59 -070028 * @data_read: Read data from the RNG device.
29 * Returns the number of lower random bytes in "data".
Sasha Levin988acec2011-05-25 15:12:20 +030030 * Must not be NULL. *OBSOLETE*
Ian Molton99965082009-12-01 14:47:32 +080031 * @read: New API. drivers can fill up to max bytes of data
Daniel Thompsoned0bd722016-08-18 13:37:21 +010032 * into the buffer. The buffer is aligned for any type
PrasannaKumar Muralidharaned424bb2016-11-18 23:00:10 +053033 * and max is a multiple of 4 and >= 32 bytes.
Michael Buesch844dd052006-06-26 00:24:59 -070034 * @priv: Private data, for use by the RNG driver.
Torsten Duwe0f734e62014-06-14 23:48:41 -040035 * @quality: Estimation of true entropy in RNG's bitstream
36 * (per mill).
Michael Buesch844dd052006-06-26 00:24:59 -070037 */
38struct hwrng {
39 const char *name;
40 int (*init)(struct hwrng *rng);
41 void (*cleanup)(struct hwrng *rng);
Patrick McHardy984e9762007-11-21 12:24:45 +080042 int (*data_present)(struct hwrng *rng, int wait);
Michael Buesch844dd052006-06-26 00:24:59 -070043 int (*data_read)(struct hwrng *rng, u32 *data);
Ian Molton99965082009-12-01 14:47:32 +080044 int (*read)(struct hwrng *rng, void *data, size_t max, bool wait);
Michael Buesch844dd052006-06-26 00:24:59 -070045 unsigned long priv;
Torsten Duwe0f734e62014-06-14 23:48:41 -040046 unsigned short quality;
Michael Buesch844dd052006-06-26 00:24:59 -070047
48 /* internal. */
49 struct list_head list;
Rusty Russell3a2c0ba2014-12-08 16:50:37 +080050 struct kref ref;
Herbert Xu77584ee2014-12-23 16:40:17 +110051 struct completion cleanup_done;
Michael Buesch844dd052006-06-26 00:24:59 -070052};
53
Dmitry Torokhov4d9b5192015-03-12 14:00:02 -070054struct device;
55
Michael Buesch844dd052006-06-26 00:24:59 -070056/** Register a new Hardware Random Number Generator driver. */
57extern int hwrng_register(struct hwrng *rng);
Dmitry Torokhov4d9b5192015-03-12 14:00:02 -070058extern int devm_hwrng_register(struct device *dev, struct hwrng *rng);
Michael Buesch844dd052006-06-26 00:24:59 -070059/** Unregister a Hardware Random Number Generator driver. */
Rafael J. Wysockib844eba2008-03-23 20:28:24 +010060extern void hwrng_unregister(struct hwrng *rng);
Dmitry Torokhov4d9b5192015-03-12 14:00:02 -070061extern void devm_hwrng_unregister(struct device *dve, struct hwrng *rng);
Torsten Duwec84dbf62014-06-14 23:38:36 -040062/** Feed random bits into the pool. */
63extern void add_hwgenerator_randomness(const char *buffer, size_t count, size_t entropy);
Michael Buesch844dd052006-06-26 00:24:59 -070064
Michael Buesch844dd052006-06-26 00:24:59 -070065#endif /* LINUX_HWRANDOM_H_ */