Introduce polarssl_zeroize() instead of memset() for zeroization
diff --git a/library/md4.c b/library/md4.c
index 980f5e4..597e5f4 100644
--- a/library/md4.c
+++ b/library/md4.c
@@ -39,6 +39,11 @@
#include <stdio.h>
#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)
/*
@@ -274,7 +279,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)
@@ -298,7 +303,7 @@
md4_finish( &ctx, output );
- memset( &ctx, 0, sizeof( md4_context ) );
+ polarssl_zeroize( &ctx, sizeof( md4_context ) );
if( ferror( f ) != 0 )
{
@@ -338,7 +343,7 @@
md4_starts( ctx );
md4_update( ctx, ctx->ipad, 64 );
- memset( sum, 0, sizeof( sum ) );
+ polarssl_zeroize( sum, sizeof( sum ) );
}
/*
@@ -362,7 +367,7 @@
md4_update( ctx, tmpbuf, 16 );
md4_finish( ctx, output );
- memset( tmpbuf, 0, sizeof( tmpbuf ) );
+ polarssl_zeroize( tmpbuf, sizeof( tmpbuf ) );
}
/*
@@ -387,7 +392,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)