mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2026-09-08 11:19:56 +00:00
ecp: test mod_pXXX_raw() also without WITH_MPI_UINT
The functions being tested are now used regardless of whether MBEDTLS_ECP_WITH_MPI_UINT is defined, so they should also be tested regardless of that option. Signed-off-by: Manuel Pégourié-Gonnard <[email protected]>
This commit is contained in:
@@ -1551,7 +1551,7 @@ exit:
|
||||
}
|
||||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE depends_on:MBEDTLS_TEST_HOOKS:MBEDTLS_ECP_WITH_MPI_UINT */
|
||||
/* BEGIN_CASE depends_on:MBEDTLS_TEST_HOOKS */
|
||||
void ecp_mod_p_generic_raw(int curve_id,
|
||||
char *input_N,
|
||||
char *input_X,
|
||||
@@ -1569,8 +1569,10 @@ void ecp_mod_p_generic_raw(int curve_id,
|
||||
size_t curve_bits;
|
||||
int (*curve_func)(mbedtls_mpi_uint *X, size_t X_limbs);
|
||||
|
||||
#if defined(MBEDTLS_ECP_WITH_MPI_UINT)
|
||||
mbedtls_mpi_mod_modulus m;
|
||||
mbedtls_mpi_mod_modulus_init(&m);
|
||||
#endif
|
||||
|
||||
TEST_EQUAL(mbedtls_test_read_mpi_core(&X, &limbs_X, input_X), 0);
|
||||
TEST_EQUAL(mbedtls_test_read_mpi_core(&N, &limbs_N, input_N), 0);
|
||||
@@ -1656,12 +1658,19 @@ void ecp_mod_p_generic_raw(int curve_id,
|
||||
TEST_EQUAL(limbs_X, limbs);
|
||||
TEST_EQUAL(limbs_res, limbs_N);
|
||||
|
||||
TEST_EQUAL(mbedtls_mpi_mod_modulus_setup(
|
||||
&m, N, limbs_N), 0);
|
||||
|
||||
TEST_EQUAL((*curve_func)(X, limbs_X), 0);
|
||||
|
||||
#if defined(MBEDTLS_ECP_WITH_MPI_UINT)
|
||||
/* This is what we'll do in the future, based on bignum_mod_raw */
|
||||
TEST_EQUAL(mbedtls_mpi_mod_modulus_setup(&m, N, limbs_N), 0);
|
||||
mbedtls_mpi_mod_raw_fix_quasi_reduction(X, &m);
|
||||
#else
|
||||
/* This is what we're doing now, based on bignum_core,
|
||||
* see ecp_modp() in ecp.c */
|
||||
mbedtls_mpi_uint c = mbedtls_mpi_core_sub(X, X, N, limbs_N);
|
||||
(void) mbedtls_mpi_core_add_if(X, N, limbs_N, (unsigned) c);
|
||||
#endif
|
||||
TEST_LE_U(mbedtls_mpi_core_bitlen(X, limbs_X), curve_bits);
|
||||
TEST_MEMORY_COMPARE(X, bytes, res, bytes);
|
||||
|
||||
@@ -1669,7 +1678,9 @@ exit:
|
||||
mbedtls_free(X);
|
||||
mbedtls_free(res);
|
||||
|
||||
#if defined(MBEDTLS_ECP_WITH_MPI_UINT)
|
||||
mbedtls_mpi_mod_modulus_free(&m);
|
||||
#endif
|
||||
mbedtls_free(N);
|
||||
}
|
||||
/* END_CASE */
|
||||
|
||||
Reference in New Issue
Block a user