mirror of
https://github.com/yuzu-emu/mbedtls.git
synced 2025-01-09 04:55:38 +00:00
Zeroize tmp bufs in entropy.c functions
This commit is contained in:
parent
2390c2ad9e
commit
81284add2e
|
@ -222,7 +222,7 @@ static int entropy_gather_internal( mbedtls_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, MBEDTLS_ENTROPY_MAX_GATHER, &olen ) ) != 0 )
|
buf, MBEDTLS_ENTROPY_MAX_GATHER, &olen ) ) != 0 )
|
||||||
{
|
{
|
||||||
return( ret );
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -236,9 +236,12 @@ static int entropy_gather_internal( mbedtls_entropy_context *ctx )
|
||||||
}
|
}
|
||||||
|
|
||||||
if( have_one_strong == 0 )
|
if( have_one_strong == 0 )
|
||||||
return( MBEDTLS_ERR_ENTROPY_NO_STRONG_SOURCE );
|
ret = MBEDTLS_ERR_ENTROPY_NO_STRONG_SOURCE;
|
||||||
|
|
||||||
return( 0 );
|
cleanup:
|
||||||
|
mbedtls_zeroize( buf, sizeof( buf ) );
|
||||||
|
|
||||||
|
return( ret );
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -338,6 +341,8 @@ int mbedtls_entropy_func( void *data, unsigned char *output, size_t len )
|
||||||
ret = 0;
|
ret = 0;
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
|
mbedtls_zeroize( buf, sizeof( buf ) );
|
||||||
|
|
||||||
#if defined(MBEDTLS_THREADING_C)
|
#if defined(MBEDTLS_THREADING_C)
|
||||||
if( mbedtls_mutex_unlock( &ctx->mutex ) != 0 )
|
if( mbedtls_mutex_unlock( &ctx->mutex ) != 0 )
|
||||||
return( MBEDTLS_ERR_THREADING_MUTEX_ERROR );
|
return( MBEDTLS_ERR_THREADING_MUTEX_ERROR );
|
||||||
|
@ -368,12 +373,15 @@ int mbedtls_entropy_write_seed_file( mbedtls_entropy_context *ctx, const char *p
|
||||||
ret = 0;
|
ret = 0;
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
|
mbedtls_zeroize( buf, sizeof( buf ) );
|
||||||
|
|
||||||
fclose( f );
|
fclose( f );
|
||||||
return( ret );
|
return( ret );
|
||||||
}
|
}
|
||||||
|
|
||||||
int mbedtls_entropy_update_seed_file( mbedtls_entropy_context *ctx, const char *path )
|
int mbedtls_entropy_update_seed_file( mbedtls_entropy_context *ctx, const char *path )
|
||||||
{
|
{
|
||||||
|
int ret = 0;
|
||||||
FILE *f;
|
FILE *f;
|
||||||
size_t n;
|
size_t n;
|
||||||
unsigned char buf[ MBEDTLS_ENTROPY_MAX_SEED_SIZE ];
|
unsigned char buf[ MBEDTLS_ENTROPY_MAX_SEED_SIZE ];
|
||||||
|
@ -389,14 +397,16 @@ int mbedtls_entropy_update_seed_file( mbedtls_entropy_context *ctx, const char *
|
||||||
n = MBEDTLS_ENTROPY_MAX_SEED_SIZE;
|
n = MBEDTLS_ENTROPY_MAX_SEED_SIZE;
|
||||||
|
|
||||||
if( fread( buf, 1, n, f ) != n )
|
if( fread( buf, 1, n, f ) != n )
|
||||||
{
|
ret = MBEDTLS_ERR_ENTROPY_FILE_IO_ERROR;
|
||||||
fclose( f );
|
else
|
||||||
return( MBEDTLS_ERR_ENTROPY_FILE_IO_ERROR );
|
ret = mbedtls_entropy_update_manual( ctx, buf, n );
|
||||||
}
|
|
||||||
|
|
||||||
fclose( f );
|
fclose( f );
|
||||||
|
|
||||||
mbedtls_entropy_update_manual( ctx, buf, n );
|
mbedtls_zeroize( buf, sizeof( buf ) );
|
||||||
|
|
||||||
|
if( ret != 0 )
|
||||||
|
return( ret );
|
||||||
|
|
||||||
return( mbedtls_entropy_write_seed_file( ctx, path ) );
|
return( mbedtls_entropy_write_seed_file( ctx, path ) );
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue