Modify zeroize internal buffers in md modules
Modify all the following functions to zeroize an internal buffer before
exiting the function. The buffer could potentially contain confidential
data read from a file.
* md2_file()
* md4_file()
* md5_file()
* ripemd160_file()
* sha1_file()
* sha256_file()
* sha512_file()
diff --git a/library/md4.c b/library/md4.c
index 8754d2f..9c4a9b8 100644
--- a/library/md4.c
+++ b/library/md4.c
@@ -313,6 +313,7 @@
*/
int md4_file( const char *path, unsigned char output[16] )
{
+ int ret = 0;
FILE *f;
size_t n;
md4_context ctx;
@@ -327,17 +328,16 @@
while( ( n = fread( buf, 1, sizeof( buf ), f ) ) > 0 )
md4_update( &ctx, buf, n );
- md4_finish( &ctx, output );
- md4_free( &ctx );
-
if( ferror( f ) != 0 )
- {
- fclose( f );
- return( POLARSSL_ERR_MD4_FILE_IO_ERROR );
- }
+ ret = POLARSSL_ERR_MD4_FILE_IO_ERROR;
+ else
+ md4_finish( &ctx, output );
+ md4_free( &ctx );
+ polarssl_zeroize( buf, sizeof( buf ) );
fclose( f );
- return( 0 );
+
+ return( ret );
}
#endif /* POLARSSL_FS_IO */