[rng] Allow for entropy sources that fail during startup tests

Provide per-source state variables for the repetition count test and
adaptive proportion test, to allow for the situation in which an
entropy source can be enabled but then fails during the startup tests,
thereby requiring an alternative entropy source to be used.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
This commit is contained in:
Michael Brown
2023-02-20 13:55:40 +00:00
parent 6625e49cea
commit 7d71cf318a
3 changed files with 349 additions and 159 deletions

View File

@@ -42,8 +42,9 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
/**
* Generate entropy samples for external testing
*
* @v source Entropy source
*/
static void entropy_sample_test_exec ( void ) {
static void entropy_sample ( struct entropy_source *source ) {
static noise_sample_t samples[SAMPLE_BLOCKSIZE];
unsigned int i;
unsigned int j;
@@ -53,22 +54,35 @@ static void entropy_sample_test_exec ( void ) {
for ( i = 0 ; i < ( SAMPLE_COUNT / SAMPLE_BLOCKSIZE ) ; i++ ) {
/* Collect one block of samples */
rc = entropy_enable();
rc = entropy_enable ( source );
ok ( rc == 0 );
for ( j = 0 ; j < SAMPLE_BLOCKSIZE ; j++ ) {
rc = get_noise ( &samples[j] );
rc = get_noise ( source, &samples[j] );
ok ( rc == 0 );
}
entropy_disable();
entropy_disable ( source );
/* Print out sample values */
for ( j = 0 ; j < SAMPLE_BLOCKSIZE ; j++ ) {
printf ( "SAMPLE %d %d\n", ( i * SAMPLE_BLOCKSIZE + j ),
samples[j] );
printf ( "SAMPLE %s %d %d\n", source->name,
( i * SAMPLE_BLOCKSIZE + j ), samples[j] );
}
}
}
/**
* Generate entropy samples for external testing
*
*/
static void entropy_sample_test_exec ( void ) {
struct entropy_source *source;
/* Test each entropy source */
for_each_table_entry ( source, ENTROPY_SOURCES ) {
entropy_sample ( source );
}
}
/** Entropy sampling self-test */
struct self_test entropy_sample_test __self_test = {
.name = "entropy_sample",