From 254f94bb43d916e21ea08011f436cd3b1a9c9016 Mon Sep 17 00:00:00 2001 From: Xiaokang Qian Date: Mon, 29 May 2023 07:46:40 +0000 Subject: [PATCH] Add test code for big endian write/read Signed-off-by: Xiaokang Qian --- tests/suites/test_suite_ecp.function | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/tests/suites/test_suite_ecp.function b/tests/suites/test_suite_ecp.function index d1d7644b7..e5ec3737a 100644 --- a/tests/suites/test_suite_ecp.function +++ b/tests/suites/test_suite_ecp.function @@ -1591,6 +1591,9 @@ void ecp_mod_read_write(char *input_A, int id, int ctype) bytes = limbs * ciL; ASSERT_ALLOC(bufx, limbs); + /* Write source mod residue to a buffer, then read it back to + * the destination mod residue, compare the two mod residues. + * Firstly test little endian write and read */ TEST_EQUAL(0, mbedtls_mpi_mod_write(&rA, &m, (unsigned char *) bufx, bytes, MBEDTLS_MPI_MOD_EXT_REP_LE)); @@ -1602,6 +1605,20 @@ void ecp_mod_read_write(char *input_A, int id, int ctype) TEST_EQUAL(limbs, rX.limbs); ASSERT_COMPARE(rA.p, bytes, rX.p, bytes); + memset(bufx, 0x00, bytes); + memset(rX_raw, 0x00, bytes); + /* Then test big endian write and read */ + TEST_EQUAL(0, mbedtls_mpi_mod_write(&rA, &m, (unsigned char *) bufx, + bytes, + MBEDTLS_MPI_MOD_EXT_REP_BE)); + + TEST_EQUAL(0, mbedtls_mpi_mod_read(&rX, &m, (unsigned char *) bufx, + bytes, + MBEDTLS_MPI_MOD_EXT_REP_BE)); + + TEST_EQUAL(limbs, rX.limbs); + ASSERT_COMPARE(rA.p, bytes, rX.p, bytes); + exit: mbedtls_mpi_mod_modulus_free(&m); mbedtls_mpi_mod_residue_release(&rA);