mirror of
https://github.com/yuzu-emu/mbedtls.git
synced 2024-12-23 09:35:39 +00:00
Improved on the fix of #309 and extended the test to cover subroutines.
This commit is contained in:
parent
87f1494809
commit
ff5317e99b
|
@ -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 )
|
||||
{
|
||||
// Making a temporary copy instead of shifting by one to deny
|
||||
// the possibility of corresponding side-channel attacks.
|
||||
mpi TB;
|
||||
|
||||
if( B == A)
|
||||
return mpi_shift_l( X, 1 );
|
||||
mpi_init( &TB );
|
||||
MBEDTLS_MPI_CHK( mpi_copy( &TB, B ) );
|
||||
|
||||
T = A; A = X; B = T;
|
||||
return mpi_add_abs( X, A, &TB );
|
||||
}
|
||||
|
||||
B = A; A = X;
|
||||
}
|
||||
|
||||
if( X != A )
|
||||
|
|
|
@ -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 */
|
||||
|
||||
|
|
Loading…
Reference in a new issue