Introduce polarssl_zeroize() instead of memset() for zeroization
diff --git a/library/md4.c b/library/md4.c
index 97cb5f0..ccde1a1 100644
--- a/library/md4.c
+++ b/library/md4.c
@@ -49,6 +49,11 @@
#define polarssl_printf printf
#endif
+/* 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;
+}
+
#if !defined(POLARSSL_MD4_ALT)
/*
@@ -284,7 +289,7 @@
md4_update( &ctx, input, ilen );
md4_finish( &ctx, output );
- memset( &ctx, 0, sizeof( md4_context ) );
+ polarssl_zeroize( &ctx, sizeof( md4_context ) );
}
#if defined(POLARSSL_FS_IO)
@@ -308,7 +313,7 @@
md4_finish( &ctx, output );
- memset( &ctx, 0, sizeof( md4_context ) );
+ polarssl_zeroize( &ctx, sizeof( md4_context ) );
if( ferror( f ) != 0 )
{
@@ -349,7 +354,7 @@
md4_starts( ctx );
md4_update( ctx, ctx->ipad, 64 );
- memset( sum, 0, sizeof( sum ) );
+ polarssl_zeroize( sum, sizeof( sum ) );
}
/*
@@ -374,7 +379,7 @@
md4_update( ctx, tmpbuf, 16 );
md4_finish( ctx, output );
- memset( tmpbuf, 0, sizeof( tmpbuf ) );
+ polarssl_zeroize( tmpbuf, sizeof( tmpbuf ) );
}
/*
@@ -399,7 +404,7 @@
md4_hmac_update( &ctx, input, ilen );
md4_hmac_finish( &ctx, output );
- memset( &ctx, 0, sizeof( md4_context ) );
+ polarssl_zeroize( &ctx, sizeof( md4_context ) );
}
#if defined(POLARSSL_SELF_TEST)