mirror of
https://github.com/yuzu-emu/mbedtls.git
synced 2024-12-01 23:24:24 +01:00
Fix CTR_DRBG benchmark
You can't reuse a CTR_DRBG context without free()ing it and re-init()ing. This generally happened to work, but was never guaranteed. It could have failed with alternative implementations of the AES module because mbedtls_ctr_drbg_seed() calls mbedtls_aes_init() on a context which is already initialized if mbedtls_ctr_drbg_seed() hasn't been called before, plausibly causing a memory leak. Calling free() and seed() with no intervening init fails when MBEDTLS_THREADING_C is enabled and all-bits-zero is not a valid mutex representation. So add the missing free() and init().
This commit is contained in:
parent
d69ae8c21d
commit
216040d46f
@ -686,12 +686,13 @@ int main( int argc, char *argv[] )
|
|||||||
mbedtls_ctr_drbg_context ctr_drbg;
|
mbedtls_ctr_drbg_context ctr_drbg;
|
||||||
|
|
||||||
mbedtls_ctr_drbg_init( &ctr_drbg );
|
mbedtls_ctr_drbg_init( &ctr_drbg );
|
||||||
|
|
||||||
if( mbedtls_ctr_drbg_seed( &ctr_drbg, myrand, NULL, NULL, 0 ) != 0 )
|
if( mbedtls_ctr_drbg_seed( &ctr_drbg, myrand, NULL, NULL, 0 ) != 0 )
|
||||||
mbedtls_exit(1);
|
mbedtls_exit(1);
|
||||||
TIME_AND_TSC( "CTR_DRBG (NOPR)",
|
TIME_AND_TSC( "CTR_DRBG (NOPR)",
|
||||||
mbedtls_ctr_drbg_random( &ctr_drbg, buf, BUFSIZE ) );
|
mbedtls_ctr_drbg_random( &ctr_drbg, buf, BUFSIZE ) );
|
||||||
|
mbedtls_ctr_drbg_free( &ctr_drbg );
|
||||||
|
|
||||||
|
mbedtls_ctr_drbg_init( &ctr_drbg );
|
||||||
if( mbedtls_ctr_drbg_seed( &ctr_drbg, myrand, NULL, NULL, 0 ) != 0 )
|
if( mbedtls_ctr_drbg_seed( &ctr_drbg, myrand, NULL, NULL, 0 ) != 0 )
|
||||||
mbedtls_exit(1);
|
mbedtls_exit(1);
|
||||||
mbedtls_ctr_drbg_set_prediction_resistance( &ctr_drbg, MBEDTLS_CTR_DRBG_PR_ON );
|
mbedtls_ctr_drbg_set_prediction_resistance( &ctr_drbg, MBEDTLS_CTR_DRBG_PR_ON );
|
||||||
|
Loading…
Reference in New Issue
Block a user