summaryrefslogtreecommitdiffstats
path: root/qemu/roms/ipxe/src/include/ipxe/null_entropy.h
blob: 646d1a17e0f1d97992d8ce34e9e0366879be6075 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#ifndef _IPXE_NULL_ENTROPY_H
#define _IPXE_NULL_ENTROPY_H

/** @file
 *
 * Nonexistent entropy source
 *
 * This source provides no entropy and must NOT be used in a
 * security-sensitive environment.
 */

FILE_LICENCE ( GPL2_OR_LATER );

#include <stdint.h>

#ifdef ENTROPY_NULL
#define ENTROPY_PREFIX_null
#else
#define ENTROPY_PREFIX_null __null_
#endif

static inline __always_inline int
ENTROPY_INLINE ( null, entropy_enable ) ( void ) {
	/* Do nothing */
	return 0;
}

static inline __always_inline void
ENTROPY_INLINE ( null, entropy_disable ) ( void ) {
	/* Do nothing */
}

static inline __always_inline double
ENTROPY_INLINE ( null, min_entropy_per_sample ) ( void ) {
	/* Actual amount of min-entropy is zero.  To avoid
	 * division-by-zero errors and to allow compilation of
	 * entropy-consuming code, pretend to have 1 bit of entropy in
	 * each sample.
	 */
	return 1.0;
}

static inline __always_inline int
ENTROPY_INLINE ( null, get_noise ) ( noise_sample_t *noise ) {

	/* All sample values are constant */
	*noise = 0x01;

	return 0;
}

#endif /* _IPXE_NULL_ENTROPY_H */