1 #ifndef _IPXE_ENTROPY_H 2 #define _IPXE_ENTROPY_H 34 #define MIN_ENTROPY_SCALE ( 1 << 16 ) 42 #define MIN_ENTROPY( bits ) \ 43 ( ( min_entropy_t ) ( (bits) * MIN_ENTROPY_SCALE ) ) 169 #define ENTROPY_SOURCES __table ( struct entropy_source, "entropy_sources" ) 172 #define __entropy_source( order ) __table_entry ( ENTROPY_SOURCES, order ) 179 #define ENTROPY_PREFERRED 01 180 #define ENTROPY_NORMAL 02 181 #define ENTROPY_FALLBACK 03 192 #define entropy_hash_df_algorithm sha256_algorithm 195 #define ENTROPY_HASH_DF_OUTLEN_BYTES SHA256_DIGEST_SIZE 233 size_t tmp_len = ( ( ( min_entropy_bits * 2 ) + 7 ) / 8 );
243 min_entropy_bits = ( ( min_entropy_bits + 7 ) & ~7 );
256 n = ( 2 * min_entropy_bits );
274 tmp, tmp_len ) ) != 0 ) {
282 if ( tmp_len < min_len ) {
285 memset ( (
data + tmp_len ), 0, ( min_len - tmp_len ) );
287 }
else if ( tmp_len > max_len ) {
310 double max_repetitions;
321 min_entropy_per_sample ) );
326 cutoff = max_repetitions;
327 if ( cutoff < max_repetitions )
353 #define ADAPTIVE_PROPORTION_WINDOW_SIZE 64 362 #define APC_N_H( n, h ) ( ( (n) << 8 ) | (h) ) 374 #define APC_TABLE_ROW( h, c16, c64, c256, c4096, c65536) \ 375 case APC_N_H ( 16, h ) : return c16; \ 376 case APC_N_H ( 64, h ) : return c64; \ 377 case APC_N_H ( 256, h ) : return c256; \ 378 case APC_N_H ( 4096, h ) : return c4096; \ 379 case APC_N_H ( 65536, h ) : return c65536; 464 unsigned int adaptive_proportion_cutoff ) {
465 unsigned int num_samples;
470 num_samples = repetition_count_cutoff;
471 if ( num_samples < adaptive_proportion_cutoff )
472 num_samples = adaptive_proportion_cutoff;
491 unsigned int repetition_count_cutoff;
492 unsigned int adaptive_proportion_cutoff;
493 unsigned int startup_test_count;
501 repetition_count_cutoff =
503 adaptive_proportion_cutoff =
507 adaptive_proportion_cutoff );
int rc
Failure status (if any)
struct arbelprm_rc_send_wqe rc
unsigned int tested
Number of startup tests performed.
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_adaptive_proportion_cutoff(min_entropy_t min_entropy_per_sample)
Calculate cutoff value for the adaptive proportion test.
#define MIN_ENTROPY_SCALE
Fixed-point scale for min-entropy amounts.
void(* disable)(void)
Disable entropy gathering.
int(* enable)(void)
Enable entropy gathering.
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.
min_entropy_t min_entropy_per_sample
min-entropy per sample
Hash-based derivation function (Hash_df)
void entropy_disable(struct entropy_source *source)
Disable entropy gathering.
Repetition count test state.
struct entropy_repetition_count_test repetition_count_test
Repetition count test state.
Entropy API configuration.
struct entropy_startup_test startup_test
Startup test state.
static unsigned int entropy_repetition_count_cutoff(min_entropy_t min_entropy_per_sample)
Calculate cutoff value for the repetition count test.
#define build_assert(condition)
Assert a condition at build time (after dead code elimination)
int get_entropy_input_tmp(min_entropy_t min_entropy, uint8_t *tmp, size_t tmp_len)
Obtain entropy input temporary buffer.
#define APC_N_H(n, h)
Combine adaptive proportion test window size and min-entropy.
noise_sample_t most_recent_sample
A = the most recently seen sample value.
int(* get_noise)(noise_sample_t *noise)
Get noise sample.
static unsigned int entropy_adaptive_proportion_cutoff_lookup(unsigned int n, unsigned int h)
Look up value in adaptive proportion test cutoff table.
unsigned int repetition_count
B = the number of times that value A has been seen in a row.
#define ENTROPY_HASH_DF_OUTLEN_BYTES
Underlying hash algorithm output length (in bytes)
unsigned int sample_count
S = the number of samples examined in this run of the test so far.
int entropy_enable(struct entropy_source *source)
Enable entropy gathering.
unsigned int repetition_count
B = the current number of times that S (sic) has been seen in the W (sic) samples examined so far.
void hash_df(struct digest_algorithm *hash, const void *input, size_t input_len, void *output, size_t output_len)
Distribute entropy throughout a buffer.
static int get_noise(struct entropy_source *source, noise_sample_t *noise)
Get noise sample.
noise_sample_t current_counted_sample
A = the sample value currently being counted.
#define ADAPTIVE_PROPORTION_WINDOW_SIZE
Window size for the adaptive proportion test.
#define MIN_ENTROPY(bits)
Construct a min-entropy fixed-point value.
unsigned int min_entropy_t
An amount of min-entropy.
uint8_t entropy_sample_t
An entropy sample.
struct entropy_adaptive_proportion_test adaptive_proportion_test
Adaptive proportion test state.
unsigned int count
Number of startup tests required for one full cycle.
FILE_LICENCE(GPL2_OR_LATER_OR_UBDL)
#define APC_TABLE_ROW(h, c16, c64, c256, c4096, c65536)
Define a row of the adaptive proportion cutoff table.
uint8_t data[48]
Additional event data.
uint8_t noise_sample_t
A noise sample.
#define entropy_hash_df_algorithm
Use SHA-256 as the underlying hash algorithm for Hash_df.
unsigned int cutoff
C = the cutoff value above which the repetition test should fail.
#define APC_NA
Value used to represent "N/A" in adaptive proportion cutoff table.
static void entropy_init(struct entropy_source *source, min_entropy_t min_entropy_per_sample)
Initialise entropy source.
unsigned int cutoff
C = the cutoff value above which the repetition test should fail.
Adaptive proportion test state.
void * memset(void *dest, int character, size_t len) __nonnull