From 4cc8021a007f493962aa0bbd3102ea3ed373d881 Mon Sep 17 00:00:00 2001 From: Gilles Peskine Date: Wed, 9 Jun 2021 18:31:35 +0200 Subject: [PATCH] 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 --- tests/suites/test_suite_mpi.function | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/tests/suites/test_suite_mpi.function b/tests/suites/test_suite_mpi.function index b13428f91..a622a4e43 100644 --- a/tests/suites/test_suite_mpi.function +++ b/tests/suites/test_suite_mpi.function @@ -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 )