iPXE
null_entropy.h
Go to the documentation of this file.
1 #ifndef _IPXE_NULL_ENTROPY_H
2 #define _IPXE_NULL_ENTROPY_H
3 
4 /** @file
5  *
6  * Nonexistent entropy source
7  *
8  * This source provides no entropy and must NOT be used in a
9  * security-sensitive environment.
10  */
11 
12 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
13 
14 #include <stdint.h>
15 
16 #ifdef ENTROPY_NULL
17 #define ENTROPY_PREFIX_null
18 #else
19 #define ENTROPY_PREFIX_null __null_
20 #endif
21 
22 static inline __always_inline int
23 ENTROPY_INLINE ( null, entropy_enable ) ( void ) {
24  /* Do nothing */
25  return 0;
26 }
27 
28 static inline __always_inline void
29 ENTROPY_INLINE ( null, entropy_disable ) ( void ) {
30  /* Do nothing */
31 }
32 
33 static inline __always_inline min_entropy_t
35  /* Actual amount of min-entropy is zero. To avoid
36  * division-by-zero errors and to allow compilation of
37  * entropy-consuming code, pretend to have 1 bit of entropy in
38  * each sample.
39  */
40  return MIN_ENTROPY ( 1.0 );
41 }
42 
43 static inline __always_inline int
44 ENTROPY_INLINE ( null, get_noise ) ( noise_sample_t *noise ) {
45 
46  /* All sample values are constant */
47  *noise = 0x01;
48 
49  return 0;
50 }
51 
52 #endif /* _IPXE_NULL_ENTROPY_H */
void entropy_disable(void)
Disable entropy gathering.
static __always_inline int ENTROPY_INLINE(null, entropy_enable)(void)
Definition: null_entropy.h:23
min_entropy_t min_entropy_per_sample(void)
min-entropy per sample
int get_noise(noise_sample_t *noise)
Get noise sample.
FILE_LICENCE(GPL2_OR_LATER_OR_UBDL)
int entropy_enable(void)
Enable entropy gathering.
#define __always_inline
Declare a function to be always inline.
Definition: compiler.h:611
#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
uint8_t noise_sample_t
A noise sample.
Definition: entropy.h:50