|
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. More... | |
| #define | MIN_ENTROPY(bits) ( ( min_entropy_t ) ( (bits) * MIN_ENTROPY_SCALE ) ) |
| Construct a min-entropy fixed-point value. More... | |
| #define | ENTROPY_SOURCES __table ( struct entropy_source, "entropy_sources" ) |
| Entropy source table. More... | |
| #define | __entropy_source(order) __table_entry ( ENTROPY_SOURCES, order ) |
| Declare an entropy source. More... | |
| #define | ENTROPY_PREFERRED 01 |
| Preferred entropy source. More... | |
| #define | ENTROPY_NORMAL 02 |
| Normal entropy source. More... | |
| #define | ENTROPY_FALLBACK 03 |
| Fallback entropy source. More... | |
| #define | entropy_hash_df_algorithm sha256_algorithm |
| Use SHA-256 as the underlying hash algorithm for Hash_df. More... | |
| #define | ENTROPY_HASH_DF_OUTLEN_BYTES SHA256_DIGEST_SIZE |
| Underlying hash algorithm output length (in bytes) More... | |
| #define | ADAPTIVE_PROPORTION_WINDOW_SIZE 64 |
| Window size for the adaptive proportion test. More... | |
| #define | APC_N_H(n, h) ( ( (n) << 8 ) | (h) ) |
| Combine adaptive proportion test window size and min-entropy. More... | |
| #define | APC_TABLE_ROW(h, c16, c64, c256, c4096, c65536) |
| Define a row of the adaptive proportion cutoff table. More... | |
| #define | APC_NA 0 |
| Value used to represent "N/A" in adaptive proportion cutoff table. More... | |
Typedefs | |
| typedef uint8_t | noise_sample_t |
| A noise sample. More... | |
| typedef uint8_t | entropy_sample_t |
| An entropy sample. More... | |
| typedef unsigned int | min_entropy_t |
| An amount of min-entropy. More... | |
Functions | |
| FILE_LICENCE (GPL2_OR_LATER_OR_UBDL) | |
| int | get_entropy_input_tmp (min_entropy_t min_entropy, uint8_t *tmp, size_t tmp_len) |
| Obtain entropy input temporary buffer. More... | |
| static int | get_noise (struct entropy_source *source, noise_sample_t *noise) |
| Get noise sample. More... | |
| static int | get_entropy_input (unsigned int min_entropy_bits, void *data, size_t min_len, size_t max_len) |
| Obtain entropy input. More... | |
| static unsigned int | entropy_repetition_count_cutoff (min_entropy_t min_entropy_per_sample) |
| Calculate cutoff value for the repetition count test. More... | |
| static unsigned int | entropy_adaptive_proportion_cutoff_lookup (unsigned int n, unsigned int h) |
| Look up value in adaptive proportion test cutoff table. More... | |
| static unsigned int | entropy_adaptive_proportion_cutoff (min_entropy_t min_entropy_per_sample) |
| Calculate cutoff value for the adaptive proportion test. More... | |
| 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. More... | |
| static void | entropy_init (struct entropy_source *source, min_entropy_t min_entropy_per_sample) |
| Initialise entropy source. More... | |
| int | entropy_enable (struct entropy_source *source) |
| Enable entropy gathering. More... | |
| void | entropy_disable (struct entropy_source *source) |
| Disable entropy gathering. More... | |
Entropy source.
Definition in file entropy.h.
| #define MIN_ENTROPY_SCALE ( 1 << 16 ) |
| #define MIN_ENTROPY | ( | bits | ) | ( ( min_entropy_t ) ( (bits) * MIN_ENTROPY_SCALE ) ) |
| #define ENTROPY_SOURCES __table ( struct entropy_source, "entropy_sources" ) |
| #define __entropy_source | ( | order | ) | __table_entry ( ENTROPY_SOURCES, order ) |
| #define entropy_hash_df_algorithm sha256_algorithm |
| #define ENTROPY_HASH_DF_OUTLEN_BYTES SHA256_DIGEST_SIZE |
| #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.
| #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 |
| #define APC_NA 0 |
| 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 | ) |
| int get_entropy_input_tmp | ( | min_entropy_t | min_entropy, |
| uint8_t * | tmp, | ||
| size_t | tmp_len | ||
| ) |
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 425 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 208 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 231 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 309 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 395 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 432 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 463 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 489 of file entropy.h.
References entropy_source::adaptive_proportion_test, build_assert, entropy_startup_test::count, entropy_repetition_count_test::cutoff, entropy_adaptive_proportion_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().
| int entropy_enable | ( | struct entropy_source * | source | ) |
Enable entropy gathering.
| source | Entropy source |
| rc | Return status code |
Definition at line 302 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(), and entropy_sample().
| void entropy_disable | ( | struct entropy_source * | source | ) |
Disable entropy gathering.
| source | Entropy source |
Definition at line 385 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().
1.8.15