|
iPXE
|
Entropy source. More...
#include <stdint.h>#include <string.h>#include <assert.h>#include <ipxe/hash_df.h>#include <ipxe/sha256.h>#include <ipxe/tables.h>#include <config/entropy.h>Go to the source code of this file.
Data Structures | |
| struct | entropy_repetition_count_test |
| Repetition count test state. More... | |
| struct | entropy_adaptive_proportion_test |
| Adaptive proportion test state. More... | |
| struct | entropy_startup_test |
| Startup test state. More... | |
| struct | entropy_source |
| An entropy source. More... | |
Macros | |
| #define | MIN_ENTROPY_SCALE ( 1 << 16 ) |
| Fixed-point scale for min-entropy amounts. | |
| #define | MIN_ENTROPY(bits) |
| Construct a min-entropy fixed-point value. | |
| #define | ENTROPY_SOURCES __table ( struct entropy_source, "entropy_sources" ) |
| Entropy source table. | |
| #define | __entropy_source(order) |
| Declare an entropy source. | |
| #define | ENTROPY_PREFERRED 01 |
| Preferred entropy source. | |
| #define | ENTROPY_NORMAL 02 |
| Normal entropy source. | |
| #define | ENTROPY_FALLBACK 03 |
| Fallback entropy source. | |
| #define | entropy_hash_df_algorithm sha256_algorithm |
| Use SHA-256 as the underlying hash algorithm for Hash_df. | |
| #define | ENTROPY_HASH_DF_OUTLEN_BYTES SHA256_DIGEST_SIZE |
| Underlying hash algorithm output length (in bytes) | |
| #define | ADAPTIVE_PROPORTION_WINDOW_SIZE 64 |
| Window size for the adaptive proportion test. | |
| #define | APC_N_H(n, h) |
| Combine adaptive proportion test window size and min-entropy. | |
| #define | APC_TABLE_ROW(h, c16, c64, c256, c4096, c65536) |
| Define a row of the adaptive proportion cutoff table. | |
| #define | APC_NA 0 |
| Value used to represent "N/A" in adaptive proportion cutoff table. | |
Typedefs | |
| typedef uint8_t | noise_sample_t |
| A noise sample. | |
| typedef uint8_t | entropy_sample_t |
| An entropy sample. | |
| typedef unsigned int | min_entropy_t |
| An amount of min-entropy. | |
Functions | |
| FILE_LICENCE (GPL2_OR_LATER_OR_UBDL) | |
| FILE_SECBOOT (PERMITTED) | |
| int | get_entropy_input_tmp (min_entropy_t min_entropy, uint8_t *tmp, size_t tmp_len) |
| Obtain entropy input temporary buffer. | |
| static int | get_noise (struct entropy_source *source, noise_sample_t *noise) |
| Get noise sample. | |
| static int | get_entropy_input (unsigned int min_entropy_bits, void *data, size_t min_len, size_t max_len) |
| Obtain entropy input. | |
| static unsigned int | entropy_repetition_count_cutoff (min_entropy_t min_entropy_per_sample) |
| Calculate cutoff value for the repetition count test. | |
| static unsigned int | entropy_adaptive_proportion_cutoff_lookup (unsigned int n, unsigned int h) |
| Look up value in adaptive proportion test cutoff table. | |
| static unsigned int | entropy_adaptive_proportion_cutoff (min_entropy_t min_entropy_per_sample) |
| Calculate cutoff value for the adaptive proportion test. | |
| static unsigned int | entropy_startup_test_count (unsigned int repetition_count_cutoff, unsigned int adaptive_proportion_cutoff) |
| Calculate number of samples required for startup tests. | |
| static void | entropy_init (struct entropy_source *source, min_entropy_t min_entropy_per_sample) |
| Initialise entropy source. | |
| int | entropy_enable (struct entropy_source *source) |
| Enable entropy gathering. | |
| void | entropy_disable (struct entropy_source *source) |
| Disable entropy gathering. | |
Entropy source.
Definition in file entropy.h.
| #define MIN_ENTROPY_SCALE ( 1 << 16 ) |
Fixed-point scale for min-entropy amounts.
Definition at line 35 of file entropy.h.
Referenced by entropy_adaptive_proportion_cutoff(), and get_entropy_input_tmp().
| #define MIN_ENTROPY | ( | bits | ) |
Construct a min-entropy fixed-point value.
| bits | min-entropy in bits |
| min_entropy | min-entropy as a fixed-point value |
Definition at line 43 of file entropy.h.
Referenced by efi_entropy_enable(), efirng_enable(), entropy_init(), entropy_repetition_count_cutoff(), get_entropy_input(), get_entropy_input_tmp(), rdrand_entropy_enable(), and rtc_entropy_enable().
| #define ENTROPY_SOURCES __table ( struct entropy_source, "entropy_sources" ) |
Entropy source table.
Definition at line 170 of file entropy.h.
Referenced by entropy_enable_working(), and entropy_sample_test_exec().
| #define __entropy_source | ( | order | ) |
Declare an entropy source.
Definition at line 173 of file entropy.h.
Referenced by __entropy_source(), __entropy_source(), and __entropy_source().
| #define entropy_hash_df_algorithm sha256_algorithm |
Use SHA-256 as the underlying hash algorithm for Hash_df.
Hash_df using SHA-256 is an Approved algorithm in ANS X9.82.
Definition at line 193 of file entropy.h.
Referenced by get_entropy_input(), and get_entropy_input_tmp().
| #define ENTROPY_HASH_DF_OUTLEN_BYTES SHA256_DIGEST_SIZE |
Underlying hash algorithm output length (in bytes)
Definition at line 196 of file entropy.h.
Referenced by get_entropy_input().
| #define ADAPTIVE_PROPORTION_WINDOW_SIZE 64 |
Window size for the adaptive proportion test.
ANS X9.82 Part 2 (October 2011 Draft) Section 8.5.2.1.3.1.1 allows five possible window sizes: 16, 64, 256, 4096 and 65536.
We expect to generate relatively few (<256) entropy samples during a typical iPXE run; the use of a large window size would mean that the test would never complete a single cycle. We use a window size of 64, which is the smallest window size that permits values of H_min down to one bit per sample.
Definition at line 354 of file entropy.h.
Referenced by adaptive_proportion_test(), adaptive_proportion_test_init(), and entropy_adaptive_proportion_cutoff().
| #define APC_N_H | ( | n, | |
| h ) |
Combine adaptive proportion test window size and min-entropy.
| n | N (window size) |
| h | H (min-entropy) |
| n_h | (N,H) combined value |
Definition at line 363 of file entropy.h.
Referenced by entropy_adaptive_proportion_cutoff_lookup().
| #define APC_TABLE_ROW | ( | h, | |
| c16, | |||
| c64, | |||
| c256, | |||
| c4096, | |||
| c65536 ) |
Define a row of the adaptive proportion cutoff table.
| h | H (min-entropy) |
| c16 | Cutoff for N=16 |
| c64 | Cutoff for N=64 |
| c256 | Cutoff for N=256 |
| c4096 | Cutoff for N=4096 |
| c65536 | Cutoff for N=65536 |
Definition at line 375 of file entropy.h.
Referenced by entropy_adaptive_proportion_cutoff_lookup().
| #define APC_NA 0 |
Value used to represent "N/A" in adaptive proportion cutoff table.
Definition at line 383 of file entropy.h.
Referenced by entropy_adaptive_proportion_cutoff(), and entropy_adaptive_proportion_cutoff_lookup().
| typedef uint8_t noise_sample_t |
| typedef uint8_t entropy_sample_t |
| typedef unsigned int min_entropy_t |
| FILE_LICENCE | ( | GPL2_OR_LATER_OR_UBDL | ) |
| FILE_SECBOOT | ( | PERMITTED | ) |
|
extern |
Obtain entropy input temporary buffer.
| min_entropy | Min-entropy required |
| tmp | Temporary buffer |
| tmp_len | Length of temporary buffer |
| rc | Return status code |
This is (part of) the implementation of the Get_entropy_input function (using an entropy source as the source of entropy input and condensing each entropy source output after each GetEntropy call) as defined in ANS X9.82 Part 4 (April 2011 Draft) Section 13.3.4.2.
Definition at line 426 of file entropy.c.
References __attribute__, assert, entropy_startup_test::count, data, DBGC, entropy_disable(), entropy_enable_working(), entropy_hash_df_algorithm, get_entropy(), hash_df(), make_next_nonce(), memset(), MIN_ENTROPY, entropy_source::min_entropy_per_sample, MIN_ENTROPY_SCALE, entropy_source::name, nonce, entropy_source::rc, rc, entropy_source::startup_test, entropy_startup_test::tested, and tmp.
Referenced by get_entropy_input().
|
inlinestatic |
Get noise sample.
| source | Entropy source |
| noise | Noise sample |
| rc | Return status code |
This is the GetNoise function defined in ANS X9.82 Part 2 (October 2011 Draft) Section 6.5.2.
Definition at line 209 of file entropy.h.
References entropy_source::get_noise.
Referenced by entropy_sample(), and get_entropy().
|
inlinestatic |
Obtain entropy input.
| min_entropy_bits | Minimum amount of entropy, in bits |
| data | Data buffer |
| min_len | Minimum length of entropy input, in bytes |
| max_len | Maximum length of entropy input, in bytes |
| len | Length of entropy input, in bytes, or negative error |
This is the implementation of the Get_entropy_input function (using an entropy source as the source of entropy input and condensing each entropy source output after each GetEntropy call) as defined in ANS X9.82 Part 4 (April 2011 Draft) Section 13.3.4.2.
This function is inlined since the entropy amount and length inputs are always compile-time constants.
Definition at line 232 of file entropy.h.
References build_assert, data, entropy_hash_df_algorithm, ENTROPY_HASH_DF_OUTLEN_BYTES, get_entropy_input_tmp(), hash_df(), memset(), MIN_ENTROPY, rc, and tmp.
Referenced by drbg_instantiate(), and drbg_reseed().
|
inlinestatic |
Calculate cutoff value for the repetition count test.
| min_entropy_per_sample | Min-entropy per sample |
| cutoff | Cutoff value |
This is the cutoff value for the Repetition Count Test defined in ANS X9.82 Part 2 (October 2011 Draft) Section 8.5.2.1.2.
Definition at line 310 of file entropy.h.
References build_assert, and MIN_ENTROPY.
Referenced by entropy_init().
|
inlinestatic |
Look up value in adaptive proportion test cutoff table.
| n | N (window size) |
| h | H (min-entropy) |
| cutoff | Cutoff |
This is the table of cutoff values defined in ANS X9.82 Part 2 (October 2011 Draft) Section 8.5.2.1.3.1.2.
Definition at line 396 of file entropy.h.
References APC_N_H, APC_NA, APC_TABLE_ROW, and h.
Referenced by entropy_adaptive_proportion_cutoff().
|
inlinestatic |
Calculate cutoff value for the adaptive proportion test.
| min_entropy_per_sample | Min-entropy per sample |
| cutoff | Cutoff value |
This is the cutoff value for the Adaptive Proportion Test defined in ANS X9.82 Part 2 (October 2011 Draft) Section 8.5.2.1.3.1.2.
Definition at line 433 of file entropy.h.
References ADAPTIVE_PROPORTION_WINDOW_SIZE, APC_NA, build_assert, entropy_adaptive_proportion_cutoff_lookup(), h, and MIN_ENTROPY_SCALE.
Referenced by entropy_init().
|
inlinestatic |
Calculate number of samples required for startup tests.
| repetition_count_cutoff | Repetition count test cutoff value |
| adaptive_proportion_cutoff | Adaptive proportion test cutoff value |
| num_samples | Number of samples required |
ANS X9.82 Part 2 (October 2011 Draft) Section 8.5.2.1.5 requires that at least one full cycle of the continuous tests must be performed at start-up.
Definition at line 464 of file entropy.h.
References build_assert.
Referenced by entropy_init().
|
inlinestatic |
Initialise entropy source.
| source | Entropy source |
| min_entropy_per_sample | Min-entropy per sample |
The cutoff value calculations for the repetition count test and the adaptive proportion test are provided as static inline functions since the results will always be compile-time constants.
Definition at line 490 of file entropy.h.
References entropy_source::adaptive_proportion_test, build_assert, entropy_startup_test::count, entropy_adaptive_proportion_test::cutoff, entropy_repetition_count_test::cutoff, entropy_adaptive_proportion_cutoff(), entropy_repetition_count_cutoff(), entropy_startup_test_count(), MIN_ENTROPY, entropy_source::min_entropy_per_sample, entropy_source::repetition_count_test, and entropy_source::startup_test.
Referenced by efi_entropy_enable(), efirng_enable(), rdrand_entropy_enable(), and rtc_entropy_enable().
|
extern |
Enable entropy gathering.
| source | Entropy source |
| rc | Return status code |
Definition at line 303 of file entropy.c.
References adaptive_proportion_test_init(), assert, DBGC, entropy_source::enable, entropy_source::min_entropy_per_sample, entropy_source::name, entropy_source::rc, rc, repetition_count_test_init(), entropy_source::startup_test, startup_test_init(), strerror(), and entropy_startup_test::tested.
Referenced by entropy_enable_and_test(), entropy_sample(), and REQUIRING_SYMBOL().
|
extern |
Disable entropy gathering.
| source | Entropy source |
Definition at line 386 of file entropy.c.
References DBGC, entropy_source::disable, and entropy_source::name.
Referenced by entropy_enable_and_test(), entropy_sample(), and get_entropy_input_tmp().