You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

rtc_entropy.h 1.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #ifndef _IPXE_RTC_ENTROPY_H
  2. #define _IPXE_RTC_ENTROPY_H
  3. /** @file
  4. *
  5. * RTC-based entropy source
  6. *
  7. */
  8. FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
  9. #include <stdint.h>
  10. #ifdef ENTROPY_RTC
  11. #define ENTROPY_PREFIX_rtc
  12. #else
  13. #define ENTROPY_PREFIX_rtc __rtc_
  14. #endif
  15. /**
  16. * min-entropy per sample
  17. *
  18. * @ret min_entropy min-entropy of each sample
  19. */
  20. static inline __always_inline double
  21. ENTROPY_INLINE ( rtc, min_entropy_per_sample ) ( void ) {
  22. /* The min-entropy has been measured on several platforms
  23. * using the entropy_sample test code. Modelling the samples
  24. * as independent, and using a confidence level of 99.99%, the
  25. * measurements were as follows:
  26. *
  27. * qemu-kvm : 7.38 bits
  28. * VMware : 7.46 bits
  29. * Physical hardware : 2.67 bits
  30. *
  31. * We choose the lowest of these (2.67 bits) and apply a 50%
  32. * safety margin to allow for some potential non-independence
  33. * of samples.
  34. */
  35. return 1.3;
  36. }
  37. extern uint8_t rtc_sample ( void );
  38. /**
  39. * Get noise sample
  40. *
  41. * @ret noise Noise sample
  42. * @ret rc Return status code
  43. */
  44. static inline __always_inline int
  45. ENTROPY_INLINE ( rtc, get_noise ) ( noise_sample_t *noise ) {
  46. /* Get sample */
  47. *noise = rtc_sample();
  48. /* Always successful */
  49. return 0;
  50. }
  51. #endif /* _IPXE_RTC_ENTROPY_H */