Generate operands in Mongomery representation for the test function
Signed-off-by: Gabor Mezei <gabor.mezei@arm.com>
This commit is contained in:
parent
95b754dfac
commit
b31b2e62ec
2 changed files with 4 additions and 16 deletions
|
@ -60,14 +60,14 @@ class BignumModRawMul(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
|
||||
|
||||
|
|
|
@ -386,37 +386,28 @@ void mpi_mod_raw_mul( char * input_A,
|
|||
const size_t limbs_T = limbs * 2 + 1;
|
||||
ASSERT_ALLOC( T, limbs_T );
|
||||
|
||||
/* Convert to Montgomery representation */
|
||||
TEST_EQUAL( mbedtls_mpi_mod_raw_to_mont_rep( A, &m ), 0 );
|
||||
TEST_EQUAL( mbedtls_mpi_mod_raw_to_mont_rep( B, &m ), 0 );
|
||||
|
||||
mbedtls_mpi_mod_raw_mul( X, A, B, &m, T );
|
||||
TEST_EQUAL( mbedtls_mpi_mod_raw_from_mont_rep( X, &m ), 0 );
|
||||
ASSERT_COMPARE( X, bytes, R, bytes );
|
||||
|
||||
/* alias X to A */
|
||||
memcpy( X, A, bytes );
|
||||
mbedtls_mpi_mod_raw_mul( X, X, B, &m, T );
|
||||
TEST_EQUAL( mbedtls_mpi_mod_raw_from_mont_rep( X, &m ), 0 );
|
||||
ASSERT_COMPARE( X, bytes, R, bytes );
|
||||
|
||||
/* alias X to B */
|
||||
memcpy( X, B, bytes );
|
||||
mbedtls_mpi_mod_raw_mul( X, A, X, &m, T );
|
||||
TEST_EQUAL( mbedtls_mpi_mod_raw_from_mont_rep( X, &m ), 0 );
|
||||
ASSERT_COMPARE( X, bytes, R, bytes );
|
||||
|
||||
/* A == B: alias A and B */
|
||||
if( memcmp( A, B, bytes ) == 0 )
|
||||
{
|
||||
mbedtls_mpi_mod_raw_mul( X, A, A, &m, T );
|
||||
TEST_EQUAL( mbedtls_mpi_mod_raw_from_mont_rep( X, &m ), 0 );
|
||||
ASSERT_COMPARE( X, bytes, R, bytes );
|
||||
|
||||
/* X, A, B all aliased together */
|
||||
memcpy( X, A, bytes );
|
||||
mbedtls_mpi_mod_raw_mul( X, X, X, &m, T );
|
||||
TEST_EQUAL( mbedtls_mpi_mod_raw_from_mont_rep( X, &m ), 0 );
|
||||
ASSERT_COMPARE( X, bytes, R, bytes );
|
||||
}
|
||||
|
||||
|
@ -424,19 +415,16 @@ void mpi_mod_raw_mul( char * input_A,
|
|||
else
|
||||
{
|
||||
mbedtls_mpi_mod_raw_mul( X, B, A, &m, T );
|
||||
TEST_EQUAL( mbedtls_mpi_mod_raw_from_mont_rep( X, &m ), 0 );
|
||||
ASSERT_COMPARE( X, bytes, R, bytes );
|
||||
|
||||
/* B * A: alias X to A */
|
||||
memcpy( X, A, bytes );
|
||||
mbedtls_mpi_mod_raw_mul( X, B, X, &m, T );
|
||||
TEST_EQUAL( mbedtls_mpi_mod_raw_from_mont_rep( X, &m ), 0 );
|
||||
ASSERT_COMPARE( X, bytes, R, bytes );
|
||||
|
||||
/* B + A: alias X to B */
|
||||
memcpy( X, B, bytes );
|
||||
mbedtls_mpi_mod_raw_mul( X, X, A, &m, T );
|
||||
TEST_EQUAL( mbedtls_mpi_mod_raw_from_mont_rep( X, &m ), 0 );
|
||||
ASSERT_COMPARE( X, bytes, R, bytes );
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue