Add _init() and _free() for hash modules
diff --git a/library/md4.c b/library/md4.c
index ccde1a1..f6b71d5 100644
--- a/library/md4.c
+++ b/library/md4.c
@@ -79,6 +79,19 @@
}
#endif
+void md4_init( md4_context *ctx )
+{
+ memset( ctx, 0, sizeof( md4_context ) );
+}
+
+void md4_free( md4_context *ctx )
+{
+ if( ctx == NULL )
+ return;
+
+ polarssl_zeroize( ctx, sizeof( md4_context ) );
+}
+
/*
* MD4 context setup
*/
@@ -285,11 +298,11 @@
{
md4_context ctx;
+ md4_init( &ctx );
md4_starts( &ctx );
md4_update( &ctx, input, ilen );
md4_finish( &ctx, output );
-
- polarssl_zeroize( &ctx, sizeof( md4_context ) );
+ md4_free( &ctx );
}
#if defined(POLARSSL_FS_IO)
@@ -306,14 +319,14 @@
if( ( f = fopen( path, "rb" ) ) == NULL )
return( POLARSSL_ERR_MD4_FILE_IO_ERROR );
+ md4_init( &ctx );
md4_starts( &ctx );
while( ( n = fread( buf, 1, sizeof( buf ), f ) ) > 0 )
md4_update( &ctx, buf, n );
md4_finish( &ctx, output );
-
- polarssl_zeroize( &ctx, sizeof( md4_context ) );
+ md4_free( &ctx );
if( ferror( f ) != 0 )
{
@@ -400,11 +413,11 @@
{
md4_context ctx;
+ md4_init( &ctx );
md4_hmac_starts( &ctx, key, keylen );
md4_hmac_update( &ctx, input, ilen );
md4_hmac_finish( &ctx, output );
-
- polarssl_zeroize( &ctx, sizeof( md4_context ) );
+ md4_free( &ctx );
}
#if defined(POLARSSL_SELF_TEST)