From 0b3b5733fcd27261de5cab1e35212e08339ca65e Mon Sep 17 00:00:00 2001 From: Gilles Peskine Date: Tue, 20 Nov 2018 23:09:54 +0100 Subject: [PATCH] Support NV seed enabled at compile time but not at runtime When testing with custom entropy sources, if MBEDTLS_ENTROPY_NV_SEED is enabled at compile time but the NV seed source is not used at runtime, mbedtls_entropy_func makes a second pass anyway. Cope with this in the test code by telling the entropy module not to make this second pass. --- tests/suites/test_suite_psa_crypto_init.function | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/tests/suites/test_suite_psa_crypto_init.function b/tests/suites/test_suite_psa_crypto_init.function index 5aa571d49..13dfd3366 100644 --- a/tests/suites/test_suite_psa_crypto_init.function +++ b/tests/suites/test_suite_psa_crypto_init.function @@ -95,10 +95,17 @@ static void custom_entropy_init( mbedtls_entropy_context *ctx ) #endif #if defined(MBEDTLS_ENTROPY_NV_SEED) if( custom_entropy_sources_mask & ENTROPY_SOURCE_NV_SEED ) + { mbedtls_entropy_add_source( ctx, mbedtls_nv_seed_poll, NULL, MBEDTLS_ENTROPY_BLOCK_SIZE, MBEDTLS_ENTROPY_SOURCE_STRONG ); - ctx->initial_entropy_run = 0; + ctx->initial_entropy_run = 0; + } + else + { + /* Skip the NV seed even though it's compiled in. */ + ctx->initial_entropy_run = 1; + } #endif if( custom_entropy_sources_mask & ENTROPY_SOURCE_FAKE )