Add double check to entropy-loop
To prevent glitching and going through without strong source
diff --git a/library/entropy.c b/library/entropy.c
index 75421cf..fdb2e15 100644
--- a/library/entropy.c
+++ b/library/entropy.c
@@ -258,7 +258,8 @@
*/
static int entropy_gather_internal( mbedtls_entropy_context *ctx )
{
- int ret, i, have_one_strong = 0;
+ int ret, i;
+ volatile int have_one_strong_fi = 0;
unsigned char buf[MBEDTLS_ENTROPY_MAX_GATHER];
size_t olen;
@@ -271,7 +272,7 @@
for( i = 0; i < ctx->source_count; i++ )
{
if( ctx->source[i].strong == MBEDTLS_ENTROPY_SOURCE_STRONG )
- have_one_strong = 1;
+ have_one_strong_fi = 1;
olen = 0;
if( ( ret = ctx->source[i].f_source( ctx->source[i].p_source,
@@ -292,8 +293,14 @@
}
}
- if( have_one_strong == 0 )
- ret = MBEDTLS_ERR_ENTROPY_NO_STRONG_SOURCE;
+ if( have_one_strong_fi == 0 )
+ {
+ mbedtls_platform_enforce_volatile_reads();
+ if( have_one_strong_fi == 0)
+ {
+ ret = MBEDTLS_ERR_ENTROPY_NO_STRONG_SOURCE;
+ }
+ }
cleanup:
mbedtls_platform_zeroize( buf, sizeof( buf ) );