hw_random.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /*
  2. Hardware Random Number Generator
  3. Please read Documentation/admin-guide/hw_random.rst for details on use.
  4. ----------------------------------------------------------
  5. This software may be used and distributed according to the terms
  6. of the GNU General Public License, incorporated herein by reference.
  7. */
  8. #ifndef LINUX_HWRANDOM_H_
  9. #define LINUX_HWRANDOM_H_
  10. #include <linux/completion.h>
  11. #include <linux/types.h>
  12. #include <linux/list.h>
  13. #include <linux/kref.h>
  14. /**
  15. * struct hwrng - Hardware Random Number Generator driver
  16. * @name: Unique RNG name.
  17. * @init: Initialization callback (can be NULL).
  18. * @cleanup: Cleanup callback (can be NULL).
  19. * @data_present: Callback to determine if data is available
  20. * on the RNG. If NULL, it is assumed that
  21. * there is always data available. *OBSOLETE*
  22. * @data_read: Read data from the RNG device.
  23. * Returns the number of lower random bytes in "data".
  24. * Must not be NULL. *OBSOLETE*
  25. * @read: New API. drivers can fill up to max bytes of data
  26. * into the buffer. The buffer is aligned for any type
  27. * and max is a multiple of 4 and >= 32 bytes.
  28. * @priv: Private data, for use by the RNG driver.
  29. * @quality: Estimation of true entropy in RNG's bitstream
  30. * (in bits of entropy per 1024 bits of input;
  31. * valid values: 1 to 1024, or 0 for unknown).
  32. */
  33. struct hwrng {
  34. const char *name;
  35. int (*init)(struct hwrng *rng);
  36. void (*cleanup)(struct hwrng *rng);
  37. int (*data_present)(struct hwrng *rng, int wait);
  38. int (*data_read)(struct hwrng *rng, u32 *data);
  39. int (*read)(struct hwrng *rng, void *data, size_t max, bool wait);
  40. unsigned long priv;
  41. unsigned short quality;
  42. /* internal. */
  43. struct list_head list;
  44. struct kref ref;
  45. struct completion cleanup_done;
  46. };
  47. struct device;
  48. /** Register a new Hardware Random Number Generator driver. */
  49. extern int hwrng_register(struct hwrng *rng);
  50. extern int devm_hwrng_register(struct device *dev, struct hwrng *rng);
  51. /** Unregister a Hardware Random Number Generator driver. */
  52. extern void hwrng_unregister(struct hwrng *rng);
  53. extern void devm_hwrng_unregister(struct device *dve, struct hwrng *rng);
  54. /** Feed random bits into the pool. */
  55. extern void add_hwgenerator_randomness(const char *buffer, size_t count, size_t entropy);
  56. #endif /* LINUX_HWRANDOM_H_ */