test_suite_ecp: Refactored ecp_mod_p256k1 to alignt with ecp_mod_p192k1

Signed-off-by: Minos Galanakis <minos.galanakis@arm.com>
This commit is contained in:
Minos Galanakis 2023-04-18 11:58:51 +01:00
parent 9c2c81f996
commit 4dfed0a186

View file

@ -1439,41 +1439,36 @@ void ecp_mod_p256k1(char *input_N,
char *result)
{
mbedtls_mpi X;
mbedtls_mpi_uint *N = NULL;
mbedtls_mpi_uint *res = NULL;
size_t limbs_N;
size_t limbs_res;
mbedtls_mpi N;
mbedtls_mpi res;
mbedtls_mpi_mod_modulus m;
mbedtls_mpi_init(&X);
mbedtls_mpi_mod_modulus_init(&m);
mbedtls_mpi_init(&N);
mbedtls_mpi_init(&res);
TEST_EQUAL(mbedtls_test_read_mpi(&X, input_X), 0);
TEST_EQUAL(mbedtls_test_read_mpi_core(&N, &limbs_N, input_N), 0);
TEST_EQUAL(mbedtls_test_read_mpi_core(&res, &limbs_res, result), 0);
TEST_EQUAL(mbedtls_test_read_mpi(&X, input_X), 0);
TEST_EQUAL(mbedtls_test_read_mpi(&N, input_N), 0);
TEST_EQUAL(mbedtls_test_read_mpi(&res, result), 0);
size_t limbs = limbs_N;
TEST_ASSERT(mbedtls_mpi_core_uint_le_mpi(0, X.p, X.n));
TEST_ASSERT(mbedtls_mpi_core_uint_le_mpi(0, N.p, N.n));
TEST_ASSERT(mbedtls_mpi_core_uint_le_mpi(0, res.p, res.n));
size_t limbs = N.n;
size_t bytes = limbs * sizeof(mbedtls_mpi_uint);
TEST_EQUAL(X.s, 1);
TEST_LE_U(X.n, 2 * limbs_N);
TEST_EQUAL(limbs_res, limbs);
TEST_EQUAL(mbedtls_mpi_mod_modulus_setup(
&m, N, limbs,
MBEDTLS_MPI_MOD_REP_MONTGOMERY), 0);
TEST_LE_U(X.n, 2 * limbs);
TEST_EQUAL(res.n, limbs);
TEST_EQUAL(mbedtls_ecp_mod_p256k1(&X), 0);
TEST_EQUAL(mbedtls_mpi_mod_mpi(&X, &X, &N), 0);
TEST_LE_U(mbedtls_mpi_core_bitlen(X.p, X.n), 256);
mbedtls_mpi_mod_raw_fix_quasi_reduction(X.p, &m);
ASSERT_COMPARE(X.p, bytes, res, bytes);
ASSERT_COMPARE(X.p, bytes, res.p, bytes);
exit:
mbedtls_mpi_free(&X);
mbedtls_free(res);
mbedtls_mpi_mod_modulus_free(&m);
mbedtls_free(N);
mbedtls_mpi_free(&N);
mbedtls_mpi_free(&res);
}
/* END_CASE */