linux/include/linux/hw_random.h
<<
>>
Prefs
   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_
  14
  15#include <linux/completion.h>
  16#include <linux/types.h>
  17#include <linux/list.h>
  18#include <linux/kref.h>
  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
  27 *                      there is always data available.  *OBSOLETE*
  28 * @data_read:          Read data from the RNG device.
  29 *                      Returns the number of lower random bytes in "data".
  30 *                      Must not be NULL.    *OBSOLETE*
  31 * @read:               New API. drivers can fill up to max bytes of data
  32 *                      into the buffer. The buffer is aligned for any type.
  33 * @priv:               Private data, for use by the RNG driver.
  34 * @quality:            Estimation of true entropy in RNG's bitstream
  35 *                      (per mill).
  36 */
  37struct hwrng {
  38        const char *name;
  39        int (*init)(struct hwrng *rng);
  40        void (*cleanup)(struct hwrng *rng);
  41        int (*data_present)(struct hwrng *rng, int wait);
  42        int (*data_read)(struct hwrng *rng, u32 *data);
  43        int (*read)(struct hwrng *rng, void *data, size_t max, bool wait);
  44        unsigned long priv;
  45        unsigned short quality;
  46
  47        /* internal. */
  48        struct list_head list;
  49        struct kref ref;
  50        struct completion cleanup_done;
  51};
  52
  53struct device;
  54
  55/** Register a new Hardware Random Number Generator driver. */
  56extern int hwrng_register(struct hwrng *rng);
  57extern int devm_hwrng_register(struct device *dev, struct hwrng *rng);
  58/** Unregister a Hardware Random Number Generator driver. */
  59extern void hwrng_unregister(struct hwrng *rng);
  60extern void devm_hwrng_unregister(struct device *dve, struct hwrng *rng);
  61/** Feed random bits into the pool. */
  62extern void add_hwgenerator_randomness(const char *buffer, size_t count, size_t entropy);
  63
  64#endif /* LINUX_HWRANDOM_H_ */
  65