44 #define EPIPE_REPETITION_COUNT_TEST \ 45 __einfo_error ( EINFO_EPIPE_REPETITION_COUNT_TEST ) 46 #define EINFO_EPIPE_REPETITION_COUNT_TEST \ 47 __einfo_uniqify ( EINFO_EPIPE, 0x01, "Repetition count test failed" ) 48 #define EPIPE_ADAPTIVE_PROPORTION_TEST \ 49 __einfo_error ( EINFO_EPIPE_ADAPTIVE_PROPORTION_TEST ) 50 #define EINFO_EPIPE_ADAPTIVE_PROPORTION_TEST \ 51 __einfo_uniqify ( EINFO_EPIPE, 0x02, "Adaptive proportion test failed" ) 93 if ( ( sample ==
test->most_recent_sample ) &&
94 (
test->repetition_count > 0 ) ) {
97 test->repetition_count++;
102 if (
test->repetition_count >=
test->cutoff ) {
103 DBGC ( source,
"ENTROPY %s excessively repeated " 104 "value %d (%d/%d)\n", source->
name, sample,
105 test->repetition_count,
test->cutoff );
114 test->most_recent_sample = sample;
117 test->repetition_count = 1;
177 test->current_counted_sample = sample;
180 test->sample_count = 0;
183 test->repetition_count = 0;
190 test->sample_count++;
193 if ( sample ==
test->current_counted_sample ) {
196 test->repetition_count++;
202 if (
test->repetition_count >
test->cutoff ) {
203 DBGC ( source,
"ENTROPY %s excessively " 204 "repeated value %d (%d/%d)\n",
205 source->
name, sample,
206 test->repetition_count,
test->cutoff );
231 if ( (
rc = source->
rc ) != 0 )
243 goto err_repetition_count_test;
245 goto err_adaptive_proportion_test;
252 err_adaptive_proportion_test:
253 err_repetition_count_test:
287 DBGC ( source,
"ENTROPY %s failed: %s\n",
306 if ( (
rc = source->
rc ) != 0 )
310 if ( (
rc = source->
enable() ) != 0 ) {
311 DBGC ( source,
"ENTROPY %s could not enable: %s\n",
327 DBGC ( source,
"ENTROPY %s enabled\n", source->
name );
348 DBGC ( source,
"ENTROPY %s passed %d startup tests\n",
375 DBGC ( *source,
"ENTROPY has no working sources: %s\n",
391 DBGC ( source,
"ENTROPY %s disabled\n", source->
name );
434 unsigned int num_samples;
440 goto err_enable_working;
453 for ( num_samples = 0 ; entropy_total < min_entropy ; num_samples++ ) {
459 goto err_get_entropy;
468 df_buf,
sizeof ( df_buf ) );
469 for ( i = 0 ; i < tmp_len ; i++ )
479 DBGC ( source,
"ENTROPY %s gathered %d bits in %d samples\n",
int rc
Failure status (if any)
struct arbelprm_rc_send_wqe rc
unsigned int tested
Number of startup tests performed.
#define MIN_ENTROPY_SCALE
Fixed-point scale for min-entropy amounts.
void(* disable)(void)
Disable entropy gathering.
static int repetition_count_test(struct entropy_source *source, noise_sample_t sample)
Perform repetition count test.
int(* enable)(void)
Enable entropy gathering.
#define ENOENT
No such file or directory.
min_entropy_t min_entropy_per_sample
min-entropy per sample
static void adaptive_proportion_test_init(struct entropy_source *source)
Initialise adaptive proportion test.
Hash-based derivation function (Hash_df)
#define EPIPE_ADAPTIVE_PROPORTION_TEST
#define ENTROPY_SOURCES
Entropy source table.
int get_entropy_input_tmp(min_entropy_t min_entropy, uint8_t *tmp, size_t tmp_len)
Obtain entropy input temporary buffer.
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 EPIPE_REPETITION_COUNT_TEST
Repetition count test state.
struct entropy_repetition_count_test repetition_count_test
Repetition count test state.
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
struct entropy_startup_test startup_test
Startup test state.
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.
char * strerror(int errno)
Retrieve string representation of error number.
REQUIRING_SYMBOL(entropy_enable)
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.
#define for_each_table_entry(pointer, table)
Iterate through all entries within a linker table.
REQUIRE_OBJECT(config_entropy)
static int get_noise(struct entropy_source *source, noise_sample_t *noise)
Get noise sample.
static int entropy_enable_working(struct entropy_source **source)
Enable first working entropy source.
static int get_entropy(struct entropy_source *source, entropy_sample_t *entropy)
Get entropy sample.
int entropy_enable(struct entropy_source *source)
Enable entropy gathering.
#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.
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.
void entropy_disable(struct entropy_source *source)
Disable entropy gathering.
FILE_LICENCE(GPL2_OR_LATER_OR_UBDL)
static int entropy_enable_and_test(struct entropy_source *source)
Enable and test entropy source.
Adaptive proportion test state.
void * memset(void *dest, int character, size_t len) __nonnull