Bignum: Add tests for modulus setup and free
Signed-off-by: Janos Follath <janos.follath@arm.com>
This commit is contained in:
parent
dae1147596
commit
1694969a0a
2 changed files with 56 additions and 0 deletions
|
@ -325,6 +325,33 @@ mbedtls_mpi_mod_raw_io:"":1:1:MBEDTLS_MPI_MOD_EXT_REP_INVALID:MBEDTLS_ERR_MPI_BA
|
|||
Test mbedtls_mpi_mod_raw_io #20 (writing with invalid endianness)
|
||||
mbedtls_mpi_mod_raw_io:"":1:1:MBEDTLS_MPI_MOD_EXT_REP_INVALID:0:MBEDTLS_ERR_MPI_BAD_INPUT_DATA
|
||||
|
||||
Test mbedtls_mpi_mod_raw_io #1 (Both representations invalid)
|
||||
mbedtls_mpi_mod_setup:MBEDTLS_MPI_MOD_EXT_REP_INVALID:MBEDTLS_MPI_MOD_REP_INVALID:MBEDTLS_ERR_MPI_BAD_INPUT_DATA
|
||||
|
||||
Test mbedtls_mpi_mod_raw_io #2 (Internal representation invalid)
|
||||
mbedtls_mpi_mod_setup:MBEDTLS_MPI_MOD_EXT_REP_LE:MBEDTLS_MPI_MOD_REP_INVALID:MBEDTLS_ERR_MPI_BAD_INPUT_DATA
|
||||
|
||||
Test mbedtls_mpi_mod_raw_io #3 (Internal representation invalid)
|
||||
mbedtls_mpi_mod_setup:MBEDTLS_MPI_MOD_EXT_REP_BE:MBEDTLS_MPI_MOD_REP_INVALID:MBEDTLS_ERR_MPI_BAD_INPUT_DATA
|
||||
|
||||
Test mbedtls_mpi_mod_raw_io #4 (External representation invalid)
|
||||
mbedtls_mpi_mod_setup:MBEDTLS_MPI_MOD_EXT_REP_INVALID:MBEDTLS_MPI_MOD_REP_MONTGOMERY:MBEDTLS_ERR_MPI_BAD_INPUT_DATA
|
||||
|
||||
Test mbedtls_mpi_mod_raw_io #5 (External representation invalid)
|
||||
mbedtls_mpi_mod_setup:MBEDTLS_MPI_MOD_EXT_REP_INVALID:MBEDTLS_MPI_MOD_REP_OPT_RED:MBEDTLS_ERR_MPI_BAD_INPUT_DATA
|
||||
|
||||
Test mbedtls_mpi_mod_raw_io #6 (Both representations valid)
|
||||
mbedtls_mpi_mod_setup:MBEDTLS_MPI_MOD_EXT_REP_BE:MBEDTLS_MPI_MOD_REP_OPT_RED:0
|
||||
|
||||
Test mbedtls_mpi_mod_raw_io #7 (Both representations valid)
|
||||
mbedtls_mpi_mod_setup:MBEDTLS_MPI_MOD_EXT_REP_BE:MBEDTLS_MPI_MOD_REP_MONTGOMERY:0
|
||||
|
||||
Test mbedtls_mpi_mod_raw_io #8 (Both representations valid)
|
||||
mbedtls_mpi_mod_setup:MBEDTLS_MPI_MOD_EXT_REP_LE:MBEDTLS_MPI_MOD_REP_OPT_RED:0
|
||||
|
||||
Test mbedtls_mpi_mod_raw_io #9 (Both representations valid)
|
||||
mbedtls_mpi_mod_setup:MBEDTLS_MPI_MOD_EXT_REP_LE:MBEDTLS_MPI_MOD_REP_MONTGOMERY:0
|
||||
|
||||
Base test mbedtls_mpi_read_binary #1
|
||||
mbedtls_mpi_read_binary:"0941379d00fed1491fe15df284dfde4a142f68aa8d412023195cee66883e6290ffe703f4ea5963bf212713cee46b107c09182b5edcd955adac418bf4918e2889af48e1099d513830cec85c26ac1e158b52620e33ba8692f893efbb2f958b4424":"0941379D00FED1491FE15DF284DFDE4A142F68AA8D412023195CEE66883E6290FFE703F4EA5963BF212713CEE46B107C09182B5EDCD955ADAC418BF4918E2889AF48E1099D513830CEC85C26AC1E158B52620E33BA8692F893EFBB2F958B4424"
|
||||
|
||||
|
|
|
@ -362,6 +362,35 @@ exit:
|
|||
}
|
||||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void mbedtls_mpi_mod_setup( int ext_rep, int int_rep, int iret )
|
||||
{
|
||||
#define MLIMBS 8
|
||||
mbedtls_mpi_uint mp[MLIMBS];
|
||||
mbedtls_mpi_mod_modulus m;
|
||||
int ret;
|
||||
|
||||
memset( mp, 0xFF, sizeof(mp) );
|
||||
|
||||
mbedtls_mpi_mod_modulus_init( &m );
|
||||
ret = mbedtls_mpi_mod_modulus_setup( &m, mp, MLIMBS, ext_rep, int_rep );
|
||||
TEST_ASSERT( ret == iret );
|
||||
|
||||
/* Address sanitiser should catch if we try to free mp */
|
||||
mbedtls_mpi_mod_modulus_free( &m );
|
||||
|
||||
/* Make sure that the modulus doesn't have reference to mp anymore */
|
||||
TEST_ASSERT( m.p != mp );
|
||||
|
||||
exit:
|
||||
/* It should be safe to call an mbedtls free several times */
|
||||
mbedtls_mpi_mod_modulus_free( &m );
|
||||
|
||||
#undef MLIMBS
|
||||
}
|
||||
/* END_CASE */
|
||||
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void mbedtls_mpi_mod_raw_io( data_t *input, int nb_int, int nx_64_int,
|
||||
int iendian, int iret, int oret )
|
||||
|
|
Loading…
Reference in a new issue