Zeroize tmp bufs in entropy.c functions
diff --git a/library/entropy.c b/library/entropy.c
index 540a27c..caff22f 100644
--- a/library/entropy.c
+++ b/library/entropy.c
@@ -210,7 +210,7 @@
if( ( ret = ctx->source[i].f_source( ctx->source[i].p_source,
buf, ENTROPY_MAX_GATHER, &olen ) ) != 0 )
{
- return( ret );
+ goto cleanup;
}
/*
@@ -223,7 +223,10 @@
}
}
- return( 0 );
+cleanup:
+ polarssl_zeroize( buf, sizeof( buf ) );
+
+ return( ret );
}
/*
@@ -324,6 +327,8 @@
ret = 0;
exit:
+ polarssl_zeroize( buf, sizeof( buf ) );
+
#if defined(POLARSSL_THREADING_C)
if( polarssl_mutex_unlock( &ctx->mutex ) != 0 )
return( POLARSSL_ERR_THREADING_MUTEX_ERROR );
@@ -354,12 +359,15 @@
ret = 0;
exit:
+ polarssl_zeroize( buf, sizeof( buf ) );
+
fclose( f );
return( ret );
}
int entropy_update_seed_file( entropy_context *ctx, const char *path )
{
+ int ret = 0;
FILE *f;
size_t n;
unsigned char buf[ ENTROPY_MAX_SEED_SIZE ];
@@ -375,14 +383,16 @@
n = ENTROPY_MAX_SEED_SIZE;
if( fread( buf, 1, n, f ) != n )
- {
- fclose( f );
- return( POLARSSL_ERR_ENTROPY_FILE_IO_ERROR );
- }
+ ret = POLARSSL_ERR_ENTROPY_FILE_IO_ERROR;
+ else
+ ret = entropy_update_manual( ctx, buf, n );
fclose( f );
- entropy_update_manual( ctx, buf, n );
+ polarssl_zeroize( buf, sizeof( buf ) );
+
+ if( ret != 0 )
+ return( ret );
return( entropy_write_seed_file( ctx, path ) );
}