Test mbedtls_mpi_exp_mod both with and without _RR

mbedtls_mpi_exp_mod can be called in three ways regarding the speed-up
parameter _RR: null (unused), zero (will be updated), nonzero (will be
used). Systematically test all three.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
This commit is contained in:
Gilles Peskine 2021-06-09 18:31:35 +02:00
parent 1c6d6be355
commit 4cc8021a00

View file

@ -1212,6 +1212,24 @@ void mbedtls_mpi_exp_mod( int radix_A, char * input_A, int radix_E,
TEST_ASSERT( mbedtls_test_read_mpi( &N, radix_N, input_N ) == 0 );
TEST_ASSERT( mbedtls_test_read_mpi( &X, radix_X, input_X ) == 0 );
res = mbedtls_mpi_exp_mod( &Z, &A, &E, &N, NULL );
TEST_ASSERT( res == div_result );
if( res == 0 )
{
TEST_ASSERT( sign_is_valid( &Z ) );
TEST_ASSERT( mbedtls_mpi_cmp_mpi( &Z, &X ) == 0 );
}
/* Now test again with the speed-up parameter supplied as an output. */
res = mbedtls_mpi_exp_mod( &Z, &A, &E, &N, &RR );
TEST_ASSERT( res == div_result );
if( res == 0 )
{
TEST_ASSERT( sign_is_valid( &Z ) );
TEST_ASSERT( mbedtls_mpi_cmp_mpi( &Z, &X ) == 0 );
}
/* Now test again with the speed-up parameter supplied in calculated form. */
res = mbedtls_mpi_exp_mod( &Z, &A, &E, &N, &RR );
TEST_ASSERT( res == div_result );
if( res == 0 )