iPXE
|
Entropy source. More...
#include <stdint.h>
#include <assert.h>
#include <string.h>
#include <errno.h>
#include <ipxe/crypto.h>
#include <ipxe/hash_df.h>
#include <ipxe/entropy.h>
Go to the source code of this file.
Macros | |
#define | EPIPE_REPETITION_COUNT_TEST __einfo_error ( EINFO_EPIPE_REPETITION_COUNT_TEST ) |
#define | EINFO_EPIPE_REPETITION_COUNT_TEST __einfo_uniqify ( EINFO_EPIPE, 0x01, "Repetition count test failed" ) |
#define | EPIPE_ADAPTIVE_PROPORTION_TEST __einfo_error ( EINFO_EPIPE_ADAPTIVE_PROPORTION_TEST ) |
#define | EINFO_EPIPE_ADAPTIVE_PROPORTION_TEST __einfo_uniqify ( EINFO_EPIPE, 0x02, "Adaptive proportion test failed" ) |
#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... | |
Functions | |
FILE_LICENCE (GPL2_OR_LATER_OR_UBDL) | |
static | __attribute__ ((always_inline)) |
Calculate cutoff value for the repetition count test. More... | |
static int | repetition_count_test (noise_sample_t sample) |
Perform repetition count test. More... | |
static int | adaptive_proportion_test (noise_sample_t sample) |
Perform adaptive proportion test. More... | |
static int | get_entropy (entropy_sample_t *entropy) |
Get entropy sample. More... | |
static uint32_t | make_next_nonce (void) |
Create next nonce value. More... | |
int | get_entropy_input_tmp (unsigned int num_samples, uint8_t *tmp, size_t tmp_len) |
Obtain entropy input temporary buffer. More... | |
Entropy source.
This algorithm is designed to comply with ANS X9.82 Part 4 (April 2011 Draft) Section 13.3. This standard is unfortunately not freely available.
Definition in file entropy.c.
#define EPIPE_REPETITION_COUNT_TEST __einfo_error ( EINFO_EPIPE_REPETITION_COUNT_TEST ) |
#define EINFO_EPIPE_REPETITION_COUNT_TEST __einfo_uniqify ( EINFO_EPIPE, 0x01, "Repetition count test failed" ) |
#define EPIPE_ADAPTIVE_PROPORTION_TEST __einfo_error ( EINFO_EPIPE_ADAPTIVE_PROPORTION_TEST ) |
#define EINFO_EPIPE_ADAPTIVE_PROPORTION_TEST __einfo_uniqify ( EINFO_EPIPE, 0x02, "Adaptive proportion test failed" ) |
#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 |
FILE_LICENCE | ( | GPL2_OR_LATER_OR_UBDL | ) |
|
inlinestatic |
Calculate cutoff value for the repetition count test.
Calculate number of samples required for startup tests.
Calculate cutoff value for the adaptive proportion test.
Look up value in adaptive proportion test cutoff table.
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.
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.
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.
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 61 of file entropy.c.
References linker_assert, MIN_ENTROPY, and min_entropy_per_sample().
Referenced by get_entropy_input_tmp().
|
static |
Perform repetition count test.
sample | Noise sample |
rc | Return status code |
This is the Repetition Count Test defined in ANS X9.82 Part 2 (October 2011 Draft) Section 8.5.2.1.2.
Definition at line 104 of file entropy.c.
References EPIPE_REPETITION_COUNT_TEST.
Referenced by get_entropy().
|
static |
Perform adaptive proportion test.
sample | Noise sample |
rc | Return status code |
This is the Adaptive Proportion Test for the Most Common Value defined in ANS X9.82 Part 2 (October 2011 Draft) Section 8.5.2.1.3.
Definition at line 264 of file entropy.c.
References ADAPTIVE_PROPORTION_WINDOW_SIZE, and EPIPE_ADAPTIVE_PROPORTION_TEST.
Referenced by get_entropy().
|
static |
Get entropy sample.
entropy | Entropy sample |
rc | Return status code |
This is the GetEntropy function defined in ANS X9.82 Part 2 (October 2011 Draft) Section 6.5.1.
Definition at line 333 of file entropy.c.
References adaptive_proportion_test(), get_noise(), rc, and repetition_count_test().
Referenced by get_entropy_input_tmp().
|
static |
Create next nonce value.
nonce | Nonce |
This is the MakeNextNonce function defined in ANS X9.82 Part 4 (April 2011 Draft) Section 13.3.4.2.
Definition at line 393 of file entropy.c.
References nonce.
Referenced by get_entropy_input_tmp().
Obtain entropy input temporary buffer.
num_samples | Number of entropy samples |
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.
To minimise code size, the number of samples required is calculated at compilation time.
Definition at line 419 of file entropy.c.
References __attribute__(), data, entropy_disable(), entropy_enable(), entropy_hash_df_algorithm, get_entropy(), hash_df(), make_next_nonce(), memset(), nonce, num_samples, rc, tmp, and tmp_len.