iPXE
rtc_entropy.h
Go to the documentation of this file.
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_OR_UBDL );
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 min_entropy_t
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 MIN_ENTROPY ( 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
54 
55  /* Get sample */
56  *noise = rtc_sample();
57 
58  /* Always successful */
59  return 0;
60 }
61 
62 #endif /* _IPXE_RTC_ENTROPY_H */
min_entropy_t min_entropy_per_sample(void)
min-entropy per sample
int get_noise(noise_sample_t *noise)
Get noise sample.
#define __always_inline
Declare a function to be always inline.
Definition: compiler.h:611
unsigned char uint8_t
Definition: stdint.h:10
FILE_LICENCE(GPL2_OR_LATER_OR_UBDL)
uint8_t rtc_sample(void)
Measure a single RTC tick.
Definition: rtc_entropy.c:214
#define MIN_ENTROPY(bits)
Construct a min-entropy fixed-point value.
Definition: entropy.h:71
unsigned int min_entropy_t
An amount of min-entropy.
Definition: entropy.h:60
static __always_inline min_entropy_t ENTROPY_INLINE(rtc, min_entropy_per_sample)(void)
min-entropy per sample
Definition: rtc_entropy.h:26
uint8_t noise_sample_t
A noise sample.
Definition: entropy.h:50