From 77b877d5a79277e445a15aed73b5c735fa074c63 Mon Sep 17 00:00:00 2001 From: Gabor Mezei Date: Fri, 16 Dec 2022 15:25:02 +0100 Subject: [PATCH] Generate operands in Mongomery representation for the test function Signed-off-by: Gabor Mezei --- scripts/mbedtls_dev/bignum_mod.py | 8 ++++---- tests/suites/test_suite_bignum_mod.function | 12 ------------ 2 files changed, 4 insertions(+), 16 deletions(-) diff --git a/scripts/mbedtls_dev/bignum_mod.py b/scripts/mbedtls_dev/bignum_mod.py index e0fc15939..1960723f1 100644 --- a/scripts/mbedtls_dev/bignum_mod.py +++ b/scripts/mbedtls_dev/bignum_mod.py @@ -41,14 +41,14 @@ class BignumModMul(bignum_common.ModOperationCommon, arity = 2 def arguments(self) -> List[str]: - return [bignum_common.quote_str(n) for n in [self.arg_a, - self.arg_b, - self.arg_n] + return [self.format_result(self.to_montgomery(self.int_a)), + self.format_result(self.to_montgomery(self.int_b)), + bignum_common.quote_str(self.arg_n) ] + self.result() def result(self) -> List[str]: result = (self.int_a * self.int_b) % self.int_n - return [self.format_result(result)] + return [self.format_result(self.to_montgomery(result))] # END MERGE SLOT 2 diff --git a/tests/suites/test_suite_bignum_mod.function b/tests/suites/test_suite_bignum_mod.function index 7c407a8a6..51a910fd1 100644 --- a/tests/suites/test_suite_bignum_mod.function +++ b/tests/suites/test_suite_bignum_mod.function @@ -149,37 +149,28 @@ void mpi_mod_mul( char * input_A, mbedtls_mpi_mod_residue rX; TEST_EQUAL( mbedtls_mpi_mod_residue_setup( &rX, &m, X, limbs ), 0 ); - /* Convert to Montgomery representation */ - TEST_EQUAL( mbedtls_mpi_mod_raw_to_mont_rep( rA.p, &m ), 0 ); - TEST_EQUAL( mbedtls_mpi_mod_raw_to_mont_rep( rB.p, &m ), 0 ); - TEST_EQUAL( mbedtls_mpi_mod_mul( &rX, &rA, &rB, &m ), 0 ); - TEST_EQUAL( mbedtls_mpi_mod_raw_from_mont_rep( rX.p, &m ), 0 ); ASSERT_COMPARE( rX.p, bytes, R, bytes ); /* alias X to A */ memcpy( rX.p, rA.p, bytes ); TEST_EQUAL( mbedtls_mpi_mod_mul( &rX, &rX, &rB, &m ), 0 ); - TEST_EQUAL( mbedtls_mpi_mod_raw_from_mont_rep( rX.p, &m ), 0 ); ASSERT_COMPARE( rX.p, bytes, R, bytes ); /* alias X to B */ memcpy( rX.p, rB.p, bytes ); TEST_EQUAL( mbedtls_mpi_mod_mul( &rX, &rA, &rX, &m ), 0); - TEST_EQUAL( mbedtls_mpi_mod_raw_from_mont_rep( rX.p, &m ), 0 ); ASSERT_COMPARE( rX.p, bytes, R, bytes ); /* A == B: alias A and B */ if( memcmp( rA.p, rB.p, bytes ) == 0 ) { TEST_EQUAL( mbedtls_mpi_mod_mul( &rX, &rA, &rA, &m ), 0 ); - TEST_EQUAL( mbedtls_mpi_mod_raw_from_mont_rep( rX.p, &m ), 0 ); ASSERT_COMPARE( rX.p, bytes, R, bytes ); /* X, A, B all aliased together */ memcpy( rX.p, rA.p, bytes ); TEST_EQUAL( mbedtls_mpi_mod_mul( &rX, &rX, &rX, &m ), 0 ); - TEST_EQUAL( mbedtls_mpi_mod_raw_from_mont_rep( rX.p, &m ), 0 ); ASSERT_COMPARE( rX.p, bytes, R, bytes ); } @@ -187,19 +178,16 @@ void mpi_mod_mul( char * input_A, else { TEST_EQUAL( mbedtls_mpi_mod_mul( &rX, &rB, &rA, &m ), 0 ); - TEST_EQUAL( mbedtls_mpi_mod_raw_from_mont_rep( rX.p, &m ), 0 ); ASSERT_COMPARE( rX.p, bytes, R, bytes ); /* B * A: alias X to A */ memcpy( rX.p, rA.p, bytes ); TEST_EQUAL( mbedtls_mpi_mod_mul( &rX, &rB, &rX, &m ), 0 ); - TEST_EQUAL( mbedtls_mpi_mod_raw_from_mont_rep( rX.p, &m ), 0 ); ASSERT_COMPARE( rX.p, bytes, R, bytes ); /* B + A: alias X to B */ memcpy( rX.p, rB.p, bytes ); TEST_EQUAL( mbedtls_mpi_mod_mul( &rX, &rX, &rA, &m ), 0 ); - TEST_EQUAL( mbedtls_mpi_mod_raw_from_mont_rep( rX.p, &m ), 0 ); ASSERT_COMPARE( rX.p, bytes, R, bytes ); }