iPXE
rtc_entropy.h
Go to the documentation of this file.
00001 #ifndef _IPXE_RTC_ENTROPY_H
00002 #define _IPXE_RTC_ENTROPY_H
00003 
00004 /** @file
00005  *
00006  * RTC-based entropy source
00007  *
00008  */
00009 
00010 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
00011 
00012 #include <stdint.h>
00013 
00014 #ifdef ENTROPY_RTC
00015 #define ENTROPY_PREFIX_rtc
00016 #else
00017 #define ENTROPY_PREFIX_rtc __rtc_
00018 #endif
00019 
00020 /**
00021  * min-entropy per sample
00022  *
00023  * @ret min_entropy     min-entropy of each sample
00024  */
00025 static inline __always_inline min_entropy_t
00026 ENTROPY_INLINE ( rtc, min_entropy_per_sample ) ( void ) {
00027 
00028         /* The min-entropy has been measured on several platforms
00029          * using the entropy_sample test code.  Modelling the samples
00030          * as independent, and using a confidence level of 99.99%, the
00031          * measurements were as follows:
00032          *
00033          *    qemu-kvm          : 7.38 bits
00034          *    VMware            : 7.46 bits
00035          *    Physical hardware : 2.67 bits
00036          *
00037          * We choose the lowest of these (2.67 bits) and apply a 50%
00038          * safety margin to allow for some potential non-independence
00039          * of samples.
00040          */
00041         return MIN_ENTROPY ( 1.3 );
00042 }
00043 
00044 extern uint8_t rtc_sample ( void );
00045 
00046 /**
00047  * Get noise sample
00048  *
00049  * @ret noise           Noise sample
00050  * @ret rc              Return status code
00051  */
00052 static inline __always_inline int
00053 ENTROPY_INLINE ( rtc, get_noise ) ( noise_sample_t *noise ) {
00054 
00055         /* Get sample */
00056         *noise = rtc_sample();
00057 
00058         /* Always successful */
00059         return 0;
00060 }
00061 
00062 #endif /* _IPXE_RTC_ENTROPY_H */