Adapt programs / test suites
diff --git a/library/entropy.c b/library/entropy.c
index 04de07f..7f95317 100644
--- a/library/entropy.c
+++ b/library/entropy.c
@@ -83,6 +83,9 @@
void entropy_free( entropy_context *ctx )
{
+#if defined(POLARSSL_HAVEGE_C)
+ havege_free( &ctx->havege_data );
+#endif
polarssl_zeroize( ctx, sizeof( entropy_context ) );
#if defined(POLARSSL_THREADING_C)
polarssl_mutex_free( &ctx->mutex );
diff --git a/library/havege.c b/library/havege.c
index de024de..3acd5bc 100644
--- a/library/havege.c
+++ b/library/havege.c
@@ -43,6 +43,11 @@
#include <string.h>
+/* Implementation that should never be optimized out by the compiler */
+static void polarssl_zeroize( void *v, size_t n ) {
+ volatile unsigned char *p = v; while( n-- ) *p++ = 0;
+}
+
/* ------------------------------------------------------------------------
* On average, one iteration accesses two 8-word blocks in the havege WALK
* table, and generates 16 words in the RES array.
@@ -200,6 +205,14 @@
havege_fill( hs );
}
+void havege_free( havege_state *hs )
+{
+ if( hs == NULL )
+ return;
+
+ polarssl_zeroize( hs, sizeof( havege_state ) );
+}
+
/*
* HAVEGE rand function
*/