Zeroize tmp bufs in hmac_drbg.c functions

This commit is contained in:
Andres Amaya Garcia 2017-07-12 10:36:30 +01:00
parent fa6fa6850e
commit beb42837ac

View file

@ -342,11 +342,14 @@ int hmac_drbg_write_seed_file( hmac_drbg_context *ctx, const char *path )
exit: exit:
fclose( f ); fclose( f );
polarssl_zeroize( buf, sizeof( buf ) );
return( ret ); return( ret );
} }
int hmac_drbg_update_seed_file( hmac_drbg_context *ctx, const char *path ) int hmac_drbg_update_seed_file( hmac_drbg_context *ctx, const char *path )
{ {
int ret = 0;
FILE *f; FILE *f;
size_t n; size_t n;
unsigned char buf[ POLARSSL_HMAC_DRBG_MAX_INPUT ]; unsigned char buf[ POLARSSL_HMAC_DRBG_MAX_INPUT ];
@ -365,15 +368,17 @@ int hmac_drbg_update_seed_file( hmac_drbg_context *ctx, const char *path )
} }
if( fread( buf, 1, n, f ) != n ) if( fread( buf, 1, n, f ) != n )
{ ret = POLARSSL_ERR_HMAC_DRBG_FILE_IO_ERROR;
fclose( f ); else
return( POLARSSL_ERR_HMAC_DRBG_FILE_IO_ERROR );
}
fclose( f );
hmac_drbg_update( ctx, buf, n ); hmac_drbg_update( ctx, buf, n );
fclose( f );
polarssl_zeroize( buf, sizeof( buf ) );
if( ret != 0 )
return( ret );
return( hmac_drbg_write_seed_file( ctx, path ) ); return( hmac_drbg_write_seed_file( ctx, path ) );
} }
#endif /* POLARSSL_FS_IO */ #endif /* POLARSSL_FS_IO */