Improved on the fix of #309 and extended the test to cover subroutines.

This commit is contained in:
Janos Follath 2015-10-25 12:29:13 +01:00 committed by Manuel Pégourié-Gonnard
parent 87f1494809
commit ff5317e99b
2 changed files with 23 additions and 7 deletions

View file

@ -893,12 +893,19 @@ int mpi_add_abs( mpi *X, const mpi *A, const mpi *B )
if( X == B )
{
const mpi *T;
if( B == A )
return mpi_shift_l( X, 1 );
{
// Making a temporary copy instead of shifting by one to deny
// the possibility of corresponding side-channel attacks.
mpi TB;
T = A; A = X; B = T;
mpi_init( &TB );
MBEDTLS_MPI_CHK( mpi_copy( &TB, B ) );
return mpi_add_abs( X, A, &TB );
}
B = A; A = X;
}
if( X != A )

View file

@ -443,15 +443,24 @@ exit:
void mpi_add_mpi_inplace( int radix_X, char *input_X, int radix_A, char *input_A )
{
mpi X, A;
mpi_init( &X ); mbedtls_mpi_init( &A );
mpi_init( &X ); mpi_init( &A );
TEST_ASSERT( mpi_read_string( &A, radix_A, input_A ) == 0 );
TEST_ASSERT( mpi_read_string( &X, radix_X, input_X ) == 0 );
TEST_ASSERT( mpi_sub_abs( &X, &X, &X ) == 0 );
TEST_ASSERT( mpi_cmp_int( &X, 0 ) == 0 );
TEST_ASSERT( mpi_read_string( &X, radix_X, input_X ) == 0 );
TEST_ASSERT( mpi_add_abs( &X, &X, &X ) == 0 );
TEST_ASSERT( mpi_cmp_mpi( &X, &A ) == 0 );
TEST_ASSERT( mpi_read_string( &X, radix_X, input_X ) == 0 );
TEST_ASSERT( mpi_read_string( &A, radix_A, input_A ) == 0 );
TEST_ASSERT( mpi_add_mpi( &X, &X, &X ) == 0 );
TEST_ASSERT( mpi_cmp_mpi( &X, &A ) == 0 );
exit:
mpi_free( &X ); mbedtls_mpi_free( &A );
mpi_free( &X ); mpi_free( &A );
}
/* END_CASE */