diff --git a/library/bignum_core.c b/library/bignum_core.c index 9adc4effb0..7074a0962b 100644 --- a/library/bignum_core.c +++ b/library/bignum_core.c @@ -178,15 +178,14 @@ void mbedtls_mpi_core_cond_assign( mbedtls_mpi_uint *X, } void mbedtls_mpi_core_cond_swap( mbedtls_mpi_uint *X, - size_t X_limbs, mbedtls_mpi_uint *Y, - size_t Y_limbs, + size_t limbs, unsigned char swap ) { /* all-bits 1 if swap is 1, all-bits 0 if swap is 0 */ mbedtls_mpi_uint limb_mask = mbedtls_ct_mpi_uint_mask( swap ); - for( size_t i = 0; i < X_limbs; i++ ) + for( size_t i = 0; i < limbs; i++ ) { mbedtls_mpi_uint tmp = X[i]; X[i] = ( X[i] & ~limb_mask ) | ( Y[i] & limb_mask ); diff --git a/library/bignum_core.h b/library/bignum_core.h index a538ece0f5..779fb08d9c 100644 --- a/library/bignum_core.h +++ b/library/bignum_core.h @@ -123,9 +123,8 @@ void mbedtls_mpi_core_cond_assign( mbedtls_mpi_uint *X, * values different to either of the original ones. */ void mbedtls_mpi_core_cond_swap( mbedtls_mpi_uint *X, - size_t X_limbs, mbedtls_mpi_uint *Y, - size_t Y_limbs, + size_t limbs, unsigned char swap ); /** Import X from unsigned binary data, little-endian. diff --git a/library/bignum_mod_raw.c b/library/bignum_mod_raw.c index 60ff9bbed8..bb4a37a1ab 100644 --- a/library/bignum_mod_raw.c +++ b/library/bignum_mod_raw.c @@ -55,8 +55,7 @@ void mbedtls_mpi_mod_raw_cond_swap( mbedtls_mpi_uint *X, const mbedtls_mpi_mod_modulus *m, unsigned char swap ) { - mbedtls_mpi_core_cond_swap( X, m->limbs, - Y, m->limbs, swap ); + mbedtls_mpi_core_cond_swap( X, Y, m->limbs, swap ); } int mbedtls_mpi_mod_raw_read( mbedtls_mpi_uint *X, diff --git a/library/constant_time.c b/library/constant_time.c index 09a86cdf26..7bf67f4328 100644 --- a/library/constant_time.c +++ b/library/constant_time.c @@ -716,7 +716,7 @@ int mbedtls_mpi_safe_cond_swap( mbedtls_mpi *X, X->s = mbedtls_ct_cond_select_sign( swap, Y->s, X->s ); Y->s = mbedtls_ct_cond_select_sign( swap, s, Y->s ); - mbedtls_mpi_core_cond_swap( X->p, X->n, Y->p, Y->n, swap ); + mbedtls_mpi_core_cond_swap( X->p, Y->p, X->n, swap ); cleanup: return( ret ); diff --git a/tests/suites/test_suite_mpi.function b/tests/suites/test_suite_mpi.function index d6769de5b4..4f5b69d285 100644 --- a/tests/suites/test_suite_mpi.function +++ b/tests/suites/test_suite_mpi.function @@ -866,7 +866,7 @@ void mpi_core_cond_swap( data_t * input_X, TEST_CF_SECRET( X, len_X * sizeof( mbedtls_mpi_uint ) ); TEST_CF_SECRET( Y, len_Y * sizeof( mbedtls_mpi_uint ) ); - mbedtls_mpi_core_cond_swap( X, len_X, Y, len_Y, cond ); + mbedtls_mpi_core_cond_swap( X, Y, len_X, cond ); TEST_CF_PUBLIC( X, len_X * sizeof( mbedtls_mpi_uint ) ); TEST_CF_PUBLIC( Y, len_Y * sizeof( mbedtls_mpi_uint ) );