From 7d71cf318a2a6fedde7aaf9303b1cdec0cf51660 Mon Sep 17 00:00:00 2001 From: Michael Brown Date: Mon, 20 Feb 2023 13:55:40 +0000 Subject: [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 --- src/tests/entropy_sample.c | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) (limited to 'src/tests') diff --git a/src/tests/entropy_sample.c b/src/tests/entropy_sample.c index b45648c11..3c2386eab 100644 --- a/src/tests/entropy_sample.c +++ b/src/tests/entropy_sample.c @@ -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", -- cgit v1.2.3-55-g7522