mirror of
https://github.com/yuzu-emu/mbedtls.git
synced 2025-03-21 18:57:32 +00:00
Zeroize tmp bufs in ctr_drbg.c functions
This commit is contained in:
parent
ff13995812
commit
dd471788d8
|
@ -402,12 +402,11 @@ int ctr_drbg_write_seed_file( ctr_drbg_context *ctx, const char *path )
|
||||||
goto exit;
|
goto exit;
|
||||||
|
|
||||||
if( fwrite( buf, 1, CTR_DRBG_MAX_INPUT, f ) != CTR_DRBG_MAX_INPUT )
|
if( fwrite( buf, 1, CTR_DRBG_MAX_INPUT, f ) != CTR_DRBG_MAX_INPUT )
|
||||||
{
|
|
||||||
ret = POLARSSL_ERR_CTR_DRBG_FILE_IO_ERROR;
|
ret = POLARSSL_ERR_CTR_DRBG_FILE_IO_ERROR;
|
||||||
goto exit;
|
else
|
||||||
}
|
ret = 0;
|
||||||
|
|
||||||
ret = 0;
|
polarssl_zeroize( buf, sizeof( buf ) );
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
fclose( f );
|
fclose( f );
|
||||||
|
@ -416,6 +415,7 @@ exit:
|
||||||
|
|
||||||
int ctr_drbg_update_seed_file( ctr_drbg_context *ctx, const char *path )
|
int ctr_drbg_update_seed_file( ctr_drbg_context *ctx, const char *path )
|
||||||
{
|
{
|
||||||
|
int ret = 0;
|
||||||
FILE *f;
|
FILE *f;
|
||||||
size_t n;
|
size_t n;
|
||||||
unsigned char buf[ CTR_DRBG_MAX_INPUT ];
|
unsigned char buf[ CTR_DRBG_MAX_INPUT ];
|
||||||
|
@ -428,20 +428,18 @@ int ctr_drbg_update_seed_file( ctr_drbg_context *ctx, const char *path )
|
||||||
fseek( f, 0, SEEK_SET );
|
fseek( f, 0, SEEK_SET );
|
||||||
|
|
||||||
if( n > CTR_DRBG_MAX_INPUT )
|
if( n > CTR_DRBG_MAX_INPUT )
|
||||||
{
|
ret = POLARSSL_ERR_CTR_DRBG_INPUT_TOO_BIG;
|
||||||
fclose( f );
|
else if( fread( buf, 1, n, f ) != n )
|
||||||
return( POLARSSL_ERR_CTR_DRBG_INPUT_TOO_BIG );
|
ret = POLARSSL_ERR_CTR_DRBG_FILE_IO_ERROR;
|
||||||
}
|
else
|
||||||
|
ctr_drbg_update( ctx, buf, n );
|
||||||
if( fread( buf, 1, n, f ) != n )
|
|
||||||
{
|
|
||||||
fclose( f );
|
|
||||||
return( POLARSSL_ERR_CTR_DRBG_FILE_IO_ERROR );
|
|
||||||
}
|
|
||||||
|
|
||||||
fclose( f );
|
fclose( f );
|
||||||
|
|
||||||
ctr_drbg_update( ctx, buf, n );
|
polarssl_zeroize( buf, sizeof( buf ) );
|
||||||
|
|
||||||
|
if( ret != 0 )
|
||||||
|
return( ret );
|
||||||
|
|
||||||
return( ctr_drbg_write_seed_file( ctx, path ) );
|
return( ctr_drbg_write_seed_file( ctx, path ) );
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue