45#define EPIPE_REPETITION_COUNT_TEST \
46 __einfo_error ( EINFO_EPIPE_REPETITION_COUNT_TEST )
47#define EINFO_EPIPE_REPETITION_COUNT_TEST \
48 __einfo_uniqify ( EINFO_EPIPE, 0x01, "Repetition count test failed" )
49#define EPIPE_ADAPTIVE_PROPORTION_TEST \
50 __einfo_error ( EINFO_EPIPE_ADAPTIVE_PROPORTION_TEST )
51#define EINFO_EPIPE_ADAPTIVE_PROPORTION_TEST \
52 __einfo_uniqify ( EINFO_EPIPE, 0x02, "Adaptive proportion test failed" )
94 if ( ( sample ==
test->most_recent_sample ) &&
95 (
test->repetition_count > 0 ) ) {
98 test->repetition_count++;
103 if (
test->repetition_count >=
test->cutoff ) {
104 DBGC ( source,
"ENTROPY %s excessively repeated "
105 "value %d (%d/%d)\n", source->
name, sample,
106 test->repetition_count,
test->cutoff );
115 test->most_recent_sample = sample;
118 test->repetition_count = 1;
178 test->current_counted_sample = sample;
181 test->sample_count = 0;
184 test->repetition_count = 0;
191 test->sample_count++;
194 if ( sample ==
test->current_counted_sample ) {
197 test->repetition_count++;
203 if (
test->repetition_count >
test->cutoff ) {
204 DBGC ( source,
"ENTROPY %s excessively "
205 "repeated value %d (%d/%d)\n",
206 source->
name, sample,
207 test->repetition_count,
test->cutoff );
232 if ( (
rc = source->
rc ) != 0 )
244 goto err_repetition_count_test;
246 goto err_adaptive_proportion_test;
253 err_adaptive_proportion_test:
254 err_repetition_count_test:
288 DBGC ( source,
"ENTROPY %s failed: %s\n",
307 if ( (
rc = source->
rc ) != 0 )
311 if ( (
rc = source->
enable() ) != 0 ) {
312 DBGC ( source,
"ENTROPY %s could not enable: %s\n",
328 DBGC ( source,
"ENTROPY %s enabled\n", source->
name );
349 DBGC ( source,
"ENTROPY %s passed %d startup tests\n",
376 DBGC ( *source,
"ENTROPY has no working sources: %s\n",
392 DBGC ( source,
"ENTROPY %s disabled\n", source->
name );
435 unsigned int num_samples;
441 goto err_enable_working;
454 for ( num_samples = 0 ; entropy_total < min_entropy ; num_samples++ ) {
460 goto err_get_entropy;
469 df_buf,
sizeof ( df_buf ) );
470 for ( i = 0 ; i < tmp_len ; i++ )
480 DBGC ( source,
"ENTROPY %s gathered %d bits in %d samples\n",
struct arbelprm_rc_send_wqe rc
#define assert(condition)
Assert a condition at run-time.
uint8_t data[48]
Additional event data.
void entropy_disable(struct entropy_source *source)
Disable entropy gathering.
static int entropy_enable_and_test(struct entropy_source *source)
Enable and test entropy source.
static int entropy_enable_working(struct entropy_source **source)
Enable first working entropy source.
#define EPIPE_ADAPTIVE_PROPORTION_TEST
int get_entropy_input_tmp(min_entropy_t min_entropy, uint8_t *tmp, size_t tmp_len)
Obtain entropy input temporary buffer.
static void startup_test_init(struct entropy_source *source)
Initialise startup test.
static void repetition_count_test_init(struct entropy_source *source)
Initialise repetition count test.
int entropy_enable(struct entropy_source *source)
Enable entropy gathering.
static int repetition_count_test(struct entropy_source *source, noise_sample_t sample)
Perform repetition count test.
static void adaptive_proportion_test_init(struct entropy_source *source)
Initialise adaptive proportion test.
#define EPIPE_REPETITION_COUNT_TEST
static int get_entropy(struct entropy_source *source, entropy_sample_t *entropy)
Get entropy sample.
static int startup_test(struct entropy_source *source)
Perform startup test.
static int adaptive_proportion_test(struct entropy_source *source, noise_sample_t sample)
Perform adaptive proportion test.
static uint32_t make_next_nonce(void)
Create next nonce value.
#define FILE_LICENCE(_licence)
Declare a particular licence as applying to a file.
#define REQUIRE_OBJECT(object)
Require an object.
#define ENOENT
No such file or directory.
#define FILE_SECBOOT(_status)
Declare a file's UEFI Secure Boot permission status.
#define REQUIRING_SYMBOL(symbol)
Specify the file's requiring symbol.
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.
Hash-based derivation function (Hash_df)
#define MIN_ENTROPY(bits)
Construct a min-entropy fixed-point value.
uint8_t entropy_sample_t
An entropy sample.
#define MIN_ENTROPY_SCALE
Fixed-point scale for min-entropy amounts.
#define entropy_hash_df_algorithm
Use SHA-256 as the underlying hash algorithm for Hash_df.
#define ENTROPY_SOURCES
Entropy source table.
uint8_t noise_sample_t
A noise sample.
unsigned int min_entropy_t
An amount of min-entropy.
static int get_noise(struct entropy_source *source, noise_sample_t *noise)
Get noise sample.
#define ADAPTIVE_PROPORTION_WINDOW_SIZE
Window size for the adaptive proportion test.
void * memset(void *dest, int character, size_t len) __nonnull
char * strerror(int errno)
Retrieve string representation of error number.
Adaptive proportion test state.
Repetition count test state.
struct entropy_repetition_count_test repetition_count_test
Repetition count test state.
min_entropy_t min_entropy_per_sample
min-entropy per sample
int rc
Failure status (if any)
struct entropy_startup_test startup_test
Startup test state.
void(* disable)(void)
Disable entropy gathering.
struct entropy_adaptive_proportion_test adaptive_proportion_test
Adaptive proportion test state.
int(* enable)(void)
Enable entropy gathering.
unsigned int count
Number of startup tests required for one full cycle.
unsigned int tested
Number of startup tests performed.
#define for_each_table_entry(pointer, table)
Iterate through all entries within a linker table.