mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2025-08-08 17:42:09 +03:00
Don't bother to test b + a after testing a + b if a == b
Signed-off-by: Tom Cosgrove <tom.cosgrove@arm.com>
This commit is contained in:
@@ -1784,7 +1784,8 @@ void mpi_core_add_if( char * input_A, char * input_B,
|
|||||||
memcpy( b, B.p, B.n * sizeof(mbedtls_mpi_uint) );
|
memcpy( b, B.p, B.n * sizeof(mbedtls_mpi_uint) );
|
||||||
memcpy( sum, X->p, X->n * sizeof(mbedtls_mpi_uint) );
|
memcpy( sum, X->p, X->n * sizeof(mbedtls_mpi_uint) );
|
||||||
|
|
||||||
/* The test cases have a <= b to avoid repetition, so we test a + b then b + a */
|
/* The test cases have a <= b to avoid repetition, so we test a + b then,
|
||||||
|
* if a != b, b + a. If a == b, we can test when a and b are aliased */
|
||||||
|
|
||||||
/* a + b */
|
/* a + b */
|
||||||
|
|
||||||
@@ -1797,21 +1798,10 @@ void mpi_core_add_if( char * input_A, char * input_B,
|
|||||||
TEST_EQUAL( carry, mbedtls_mpi_core_add_if( d, b, limbs, 1 ) );
|
TEST_EQUAL( carry, mbedtls_mpi_core_add_if( d, b, limbs, 1 ) );
|
||||||
ASSERT_COMPARE( d, bytes, sum, bytes );
|
ASSERT_COMPARE( d, bytes, sum, bytes );
|
||||||
|
|
||||||
/* b + a */
|
|
||||||
|
|
||||||
/* cond = 0 => d unchanged, no carry */
|
|
||||||
memcpy( d, b, bytes );
|
|
||||||
TEST_EQUAL( 0, mbedtls_mpi_core_add_if( d, a, limbs, 0 ) );
|
|
||||||
ASSERT_COMPARE( d, bytes, b, bytes );
|
|
||||||
|
|
||||||
/* cond = 1 => correct result and carry */
|
|
||||||
TEST_EQUAL( carry, mbedtls_mpi_core_add_if( d, a, limbs, 1 ) );
|
|
||||||
ASSERT_COMPARE( d, bytes, sum, bytes );
|
|
||||||
|
|
||||||
/* If a == b we can test where a and b are aliased */
|
|
||||||
|
|
||||||
if ( A.n == B.n && memcmp( A.p, B.p, bytes ) == 0 )
|
if ( A.n == B.n && memcmp( A.p, B.p, bytes ) == 0 )
|
||||||
{
|
{
|
||||||
|
/* a == b, so test where a and b are aliased */
|
||||||
|
|
||||||
/* cond = 0 => d unchanged, no carry */
|
/* cond = 0 => d unchanged, no carry */
|
||||||
TEST_EQUAL( 0, mbedtls_mpi_core_add_if( b, b, limbs, 0 ) );
|
TEST_EQUAL( 0, mbedtls_mpi_core_add_if( b, b, limbs, 0 ) );
|
||||||
ASSERT_COMPARE( b, bytes, B.p, bytes );
|
ASSERT_COMPARE( b, bytes, B.p, bytes );
|
||||||
@@ -1820,6 +1810,19 @@ void mpi_core_add_if( char * input_A, char * input_B,
|
|||||||
TEST_EQUAL( carry, mbedtls_mpi_core_add_if( b, b, limbs, 1 ) );
|
TEST_EQUAL( carry, mbedtls_mpi_core_add_if( b, b, limbs, 1 ) );
|
||||||
ASSERT_COMPARE( b, bytes, sum, bytes );
|
ASSERT_COMPARE( b, bytes, sum, bytes );
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* a != b, so test b + a */
|
||||||
|
|
||||||
|
/* cond = 0 => d unchanged, no carry */
|
||||||
|
memcpy( d, b, bytes );
|
||||||
|
TEST_EQUAL( 0, mbedtls_mpi_core_add_if( d, a, limbs, 0 ) );
|
||||||
|
ASSERT_COMPARE( d, bytes, b, bytes );
|
||||||
|
|
||||||
|
/* cond = 1 => correct result and carry */
|
||||||
|
TEST_EQUAL( carry, mbedtls_mpi_core_add_if( d, a, limbs, 1 ) );
|
||||||
|
ASSERT_COMPARE( d, bytes, sum, bytes );
|
||||||
|
}
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
mbedtls_free( a );
|
mbedtls_free( a );
|
||||||
|
Reference in New Issue
Block a user