Werner Lewis | 0c6ea12 | 2022-09-30 13:02:16 +0100 | [diff] [blame] | 1 | /* BEGIN_HEADER */ |
| 2 | #include "mbedtls/bignum.h" |
| 3 | #include "mbedtls/entropy.h" |
| 4 | #include "bignum_mod.h" |
| 5 | #include "constant_time_internal.h" |
| 6 | #include "test/constant_flow.h" |
Werner Lewis | 0c6ea12 | 2022-09-30 13:02:16 +0100 | [diff] [blame] | 7 | /* END_HEADER */ |
| 8 | |
| 9 | /* BEGIN_DEPENDENCIES |
| 10 | * depends_on:MBEDTLS_BIGNUM_C |
| 11 | * END_DEPENDENCIES |
| 12 | */ |
| 13 | |
| 14 | /* BEGIN_CASE */ |
| 15 | void mpi_mod_setup( int ext_rep, int int_rep, int iret ) |
| 16 | { |
| 17 | #define MLIMBS 8 |
| 18 | mbedtls_mpi_uint mp[MLIMBS]; |
| 19 | mbedtls_mpi_mod_modulus m; |
| 20 | int ret; |
| 21 | |
| 22 | memset( mp, 0xFF, sizeof(mp) ); |
| 23 | |
| 24 | mbedtls_mpi_mod_modulus_init( &m ); |
| 25 | ret = mbedtls_mpi_mod_modulus_setup( &m, mp, MLIMBS, ext_rep, int_rep ); |
| 26 | TEST_EQUAL( ret, iret ); |
| 27 | |
| 28 | /* Address sanitiser should catch if we try to free mp */ |
| 29 | mbedtls_mpi_mod_modulus_free( &m ); |
| 30 | |
| 31 | /* Make sure that the modulus doesn't have reference to mp anymore */ |
| 32 | TEST_ASSERT( m.p != mp ); |
| 33 | |
| 34 | exit: |
| 35 | /* It should be safe to call an mbedtls free several times */ |
| 36 | mbedtls_mpi_mod_modulus_free( &m ); |
| 37 | |
| 38 | #undef MLIMBS |
| 39 | } |
| 40 | /* END_CASE */ |