From 799eaeefdb585478c192cf13974e762ed6269b80 Mon Sep 17 00:00:00 2001 From: Janos Follath Date: Fri, 25 Nov 2022 15:57:04 +0000 Subject: [PATCH] Bignum Mod: move init before any goto Test macros have goto instructions to the end where everything is freed. We need to call init before that happens to make calling free functions safe. Signed-off-by: Janos Follath --- tests/suites/test_suite_bignum_mod.function | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/tests/suites/test_suite_bignum_mod.function b/tests/suites/test_suite_bignum_mod.function index bb87ba9d9..b716ab5ca 100644 --- a/tests/suites/test_suite_bignum_mod.function +++ b/tests/suites/test_suite_bignum_mod.function @@ -130,15 +130,15 @@ void mpi_mod_io_neg( ) const size_t buff_bytes = 1024; + mbedtls_mpi_mod_modulus_init( &m ); + mbedtls_mpi_mod_modulus_init( &m2 ); + /* Allocate the memory for intermediate data structures */ TEST_EQUAL( 0, mbedtls_test_read_mpi_core( &N, &n_limbs, hex_modulus_single ) ); TEST_EQUAL( 0, mbedtls_test_read_mpi_core( &R, &r_limbs, hex_residue_single ) ); TEST_EQUAL( 0, mbedtls_test_read_mpi_core( &N2, &n2_limbs, hex_modulus_multi ) ); TEST_EQUAL( 0, mbedtls_test_read_mpi_core( &R2, &r2_limbs, hex_residue_multi ) ); - mbedtls_mpi_mod_modulus_init( &m ); - mbedtls_mpi_mod_modulus_init( &m2 ); - /* Allocate more than required space on buffer so we can test for input_r > mpi */ ASSERT_ALLOC( r_buff, buff_bytes ); memset( r_buff, 0x1, 1 ); @@ -218,6 +218,8 @@ void mpi_mod_io( char * input_N, data_t * input_A, int endian ) mbedtls_mpi_mod_residue r; size_t n_limbs, n_bytes, a_bytes; + mbedtls_mpi_mod_modulus_init( &m ); + /* Read inputs */ TEST_EQUAL( 0, mbedtls_test_read_mpi_core( &N, &n_limbs, input_N ) ); n_bytes = n_limbs * sizeof( mbedtls_mpi_uint ); @@ -231,7 +233,6 @@ void mpi_mod_io( char * input_N, data_t * input_A, int endian ) TEST_LE_U(a_bytes, n_bytes ); /* Init Structures */ - mbedtls_mpi_mod_modulus_init( &m ); TEST_EQUAL( 0, mbedtls_mpi_mod_modulus_setup( &m, N, n_limbs, MBEDTLS_MPI_MOD_REP_MONTGOMERY ) );