Zeroize tmp bufs in entropy.c functions

This commit is contained in:
Andres Amaya Garcia 2017-07-12 10:32:27 +01:00
parent f148312db4
commit fa6fa6850e

View File

@ -210,7 +210,7 @@ static int entropy_gather_internal( entropy_context *ctx )
if( ( ret = ctx->source[i].f_source( ctx->source[i].p_source,
buf, ENTROPY_MAX_GATHER, &olen ) ) != 0 )
{
return( ret );
goto cleanup;
}
/*
@ -223,7 +223,10 @@ static int entropy_gather_internal( entropy_context *ctx )
}
}
return( 0 );
cleanup:
polarssl_zeroize( buf, sizeof( buf ) );
return( ret );
}
/*
@ -324,6 +327,8 @@ int entropy_func( void *data, unsigned char *output, size_t len )
ret = 0;
exit:
polarssl_zeroize( buf, sizeof( buf ) );
#if defined(POLARSSL_THREADING_C)
if( polarssl_mutex_unlock( &ctx->mutex ) != 0 )
return( POLARSSL_ERR_THREADING_MUTEX_ERROR );
@ -354,12 +359,15 @@ int entropy_write_seed_file( entropy_context *ctx, const char *path )
ret = 0;
exit:
polarssl_zeroize( buf, sizeof( buf ) );
fclose( f );
return( ret );
}
int entropy_update_seed_file( entropy_context *ctx, const char *path )
{
int ret = 0;
FILE *f;
size_t n;
unsigned char buf[ ENTROPY_MAX_SEED_SIZE ];
@ -375,14 +383,16 @@ int entropy_update_seed_file( entropy_context *ctx, const char *path )
n = ENTROPY_MAX_SEED_SIZE;
if( fread( buf, 1, n, f ) != n )
{
fclose( f );
return( POLARSSL_ERR_ENTROPY_FILE_IO_ERROR );
}
ret = POLARSSL_ERR_ENTROPY_FILE_IO_ERROR;
else
ret = entropy_update_manual( ctx, buf, n );
fclose( f );
entropy_update_manual( ctx, buf, n );
polarssl_zeroize( buf, sizeof( buf ) );
if( ret != 0 )
return( ret );
return( entropy_write_seed_file( ctx, path ) );
}