mirror of
https://github.com/ipxe/ipxe
synced 2026-01-31 11:39:46 +03:00
[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:
@@ -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",
|
||||
|
||||
Reference in New Issue
Block a user