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