Add a test case for MBEDTLS_ERR_ENTROPY_NO_SOURCES_DEFINED

This commit is contained in:
Gilles Peskine 2019-10-08 14:51:49 +02:00
parent ed04a676ee
commit 7f246510d0
2 changed files with 21 additions and 2 deletions

View file

@ -7,6 +7,9 @@ entropy_seed_file:"data_files/entropy_seed":0
Entropy write/update seed file: nonexistent
entropy_seed_file:"no_such_dir/file":MBEDTLS_ERR_ENTROPY_FILE_IO_ERROR
Entropy no sources
entropy_no_sources:
Entropy too many sources
entropy_too_many_sources:

View file

@ -45,7 +45,6 @@ static int entropy_dummy_source( void *arg, unsigned char *output,
return( 0 );
}
#if defined(MBEDTLS_ENTROPY_NV_SEED)
/*
* Ability to clear entropy sources to allow testing with just predefined
* entropy sources. This function or tests depending on it might break if there
@ -57,11 +56,12 @@ static int entropy_dummy_source( void *arg, unsigned char *output,
* This might break memory checks in the future if sources need 'free-ing' then
* as well.
*/
void entropy_clear_sources( mbedtls_entropy_context *ctx )
static void entropy_clear_sources( mbedtls_entropy_context *ctx )
{
ctx->source_count = 0;
}
#if defined(MBEDTLS_ENTROPY_NV_SEED)
/*
* NV seed read/write functions that use a buffer instead of a file
*/
@ -148,6 +148,22 @@ exit:
}
/* END_CASE */
/* BEGIN_CASE */
void entropy_no_sources( )
{
mbedtls_entropy_context ctx;
unsigned char buf[MBEDTLS_ENTROPY_BLOCK_SIZE];
mbedtls_entropy_init( &ctx );
entropy_clear_sources( &ctx );
TEST_EQUAL( mbedtls_entropy_func( &ctx, buf, sizeof( buf ) ),
MBEDTLS_ERR_ENTROPY_NO_SOURCES_DEFINED );
exit:
mbedtls_entropy_free( &ctx );
}
/* END_CASE */
/* BEGIN_CASE */
void entropy_too_many_sources( )
{