mirror of
https://github.com/yuzu-emu/mbedtls.git
synced 2025-07-03 05:38:27 +00:00
Zeroize tmp bufs in entropy.c functions
This commit is contained in:
parent
f148312db4
commit
fa6fa6850e
|
@ -210,7 +210,7 @@ static int entropy_gather_internal( entropy_context *ctx )
|
||||||
if( ( ret = ctx->source[i].f_source( ctx->source[i].p_source,
|
if( ( ret = ctx->source[i].f_source( ctx->source[i].p_source,
|
||||||
buf, ENTROPY_MAX_GATHER, &olen ) ) != 0 )
|
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;
|
ret = 0;
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
|
polarssl_zeroize( buf, sizeof( buf ) );
|
||||||
|
|
||||||
#if defined(POLARSSL_THREADING_C)
|
#if defined(POLARSSL_THREADING_C)
|
||||||
if( polarssl_mutex_unlock( &ctx->mutex ) != 0 )
|
if( polarssl_mutex_unlock( &ctx->mutex ) != 0 )
|
||||||
return( POLARSSL_ERR_THREADING_MUTEX_ERROR );
|
return( POLARSSL_ERR_THREADING_MUTEX_ERROR );
|
||||||
|
@ -354,12 +359,15 @@ int entropy_write_seed_file( entropy_context *ctx, const char *path )
|
||||||
ret = 0;
|
ret = 0;
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
|
polarssl_zeroize( buf, sizeof( buf ) );
|
||||||
|
|
||||||
fclose( f );
|
fclose( f );
|
||||||
return( ret );
|
return( ret );
|
||||||
}
|
}
|
||||||
|
|
||||||
int entropy_update_seed_file( entropy_context *ctx, const char *path )
|
int entropy_update_seed_file( entropy_context *ctx, const char *path )
|
||||||
{
|
{
|
||||||
|
int ret = 0;
|
||||||
FILE *f;
|
FILE *f;
|
||||||
size_t n;
|
size_t n;
|
||||||
unsigned char buf[ ENTROPY_MAX_SEED_SIZE ];
|
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;
|
n = ENTROPY_MAX_SEED_SIZE;
|
||||||
|
|
||||||
if( fread( buf, 1, n, f ) != n )
|
if( fread( buf, 1, n, f ) != n )
|
||||||
{
|
ret = POLARSSL_ERR_ENTROPY_FILE_IO_ERROR;
|
||||||
fclose( f );
|
else
|
||||||
return( POLARSSL_ERR_ENTROPY_FILE_IO_ERROR );
|
ret = entropy_update_manual( ctx, buf, n );
|
||||||
}
|
|
||||||
|
|
||||||
fclose( f );
|
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 ) );
|
return( entropy_write_seed_file( ctx, path ) );
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue