From 960292337c461f99070c677bfaeab3016222b4b2 Mon Sep 17 00:00:00 2001 From: Paul Bakker Date: Wed, 1 Jun 2016 15:25:50 +0100 Subject: [PATCH] Initial entropy run should be context specific Otherwise test influence each other. Is a change to the context but only if the NV seed feature is enabled --- include/mbedtls/entropy.h | 3 +++ library/entropy.c | 8 ++------ 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/include/mbedtls/entropy.h b/include/mbedtls/entropy.h index c9bd9613d..fed0494ed 100644 --- a/include/mbedtls/entropy.h +++ b/include/mbedtls/entropy.h @@ -134,6 +134,9 @@ typedef struct #if defined(MBEDTLS_THREADING_C) mbedtls_threading_mutex_t mutex; /*!< mutex */ #endif +#if defined(MBEDTLS_ENTROPY_NV_SEED) + int initial_entropy_run; +#endif } mbedtls_entropy_context; diff --git a/library/entropy.c b/library/entropy.c index 1982b1096..dc2a00c85 100644 --- a/library/entropy.c +++ b/library/entropy.c @@ -54,10 +54,6 @@ static void mbedtls_zeroize( void *v, size_t n ) { volatile unsigned char *p = v; while( n-- ) *p++ = 0; } -#if defined(MBEDTLS_ENTROPY_NV_SEED) -static int initial_entropy_run = 0; -#endif - #define ENTROPY_MAX_LOOP 256 /**< Maximum amount to loop before error */ void mbedtls_entropy_init( mbedtls_entropy_context *ctx ) @@ -285,9 +281,9 @@ int mbedtls_entropy_func( void *data, unsigned char *output, size_t len ) /* Update the NV entropy seed before generating any entropy for outside * use. */ - if( initial_entropy_run == 0 ) + if( ctx->initial_entropy_run == 0 ) { - initial_entropy_run = 1; + ctx->initial_entropy_run = 1; if( ( ret = mbedtls_entropy_update_nv_seed( ctx ) ) != 0 ) return( ret ); }