mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2025-03-29 13:20:21 +00:00
test_suite_ecp: Introduced ecp_mod_p_generic_raw
This patch replaces similiarly structured test functions for: * MBEDTLS_ECP_DP_SECP192R1 * MBEDTLS_ECP_DP_SECP224R1 * MBEDTLS_ECP_DP_SECP256R1 * MBEDTLS_ECP_DP_SECP384R1 * MBEDTLS_ECP_DP_BP512R1R1 with a more generic version, which adjusts the parameters, based on the `curve_id` field, provided by the testing data. The python test framework has been updated to provide that extra field. Signed-off-by: Minos Galanakis <minos.galanakis@arm.com>
This commit is contained in:
parent
3615be65f8
commit
1358648f77
@ -30,7 +30,7 @@ class EcpP192R1Raw(bignum_common.ModOperationCommon,
|
|||||||
EcpTarget):
|
EcpTarget):
|
||||||
"""Test cases for ECP P192 fast reduction."""
|
"""Test cases for ECP P192 fast reduction."""
|
||||||
symbol = "-"
|
symbol = "-"
|
||||||
test_function = "ecp_mod_p192_raw"
|
test_function = "ecp_mod_p_generic_raw"
|
||||||
test_name = "ecp_mod_p192_raw"
|
test_name = "ecp_mod_p192_raw"
|
||||||
input_style = "fixed"
|
input_style = "fixed"
|
||||||
arity = 1
|
arity = 1
|
||||||
@ -96,12 +96,16 @@ class EcpP192R1Raw(bignum_common.ModOperationCommon,
|
|||||||
def is_valid(self) -> bool:
|
def is_valid(self) -> bool:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
def arguments(self):
|
||||||
|
args = super().arguments()
|
||||||
|
return ["MBEDTLS_ECP_DP_SECP192R1"] + args
|
||||||
|
|
||||||
|
|
||||||
class EcpP224R1Raw(bignum_common.ModOperationCommon,
|
class EcpP224R1Raw(bignum_common.ModOperationCommon,
|
||||||
EcpTarget):
|
EcpTarget):
|
||||||
"""Test cases for ECP P224 fast reduction."""
|
"""Test cases for ECP P224 fast reduction."""
|
||||||
symbol = "-"
|
symbol = "-"
|
||||||
test_function = "ecp_mod_p224_raw"
|
test_function = "ecp_mod_p_generic_raw"
|
||||||
test_name = "ecp_mod_p224_raw"
|
test_name = "ecp_mod_p224_raw"
|
||||||
input_style = "arch_split"
|
input_style = "arch_split"
|
||||||
arity = 1
|
arity = 1
|
||||||
@ -168,12 +172,16 @@ class EcpP224R1Raw(bignum_common.ModOperationCommon,
|
|||||||
def is_valid(self) -> bool:
|
def is_valid(self) -> bool:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
def arguments(self):
|
||||||
|
args = super().arguments()
|
||||||
|
return ["MBEDTLS_ECP_DP_SECP224R1"] + args
|
||||||
|
|
||||||
|
|
||||||
class EcpP256R1Raw(bignum_common.ModOperationCommon,
|
class EcpP256R1Raw(bignum_common.ModOperationCommon,
|
||||||
EcpTarget):
|
EcpTarget):
|
||||||
"""Test cases for ECP P256 fast reduction."""
|
"""Test cases for ECP P256 fast reduction."""
|
||||||
symbol = "-"
|
symbol = "-"
|
||||||
test_function = "ecp_mod_p256_raw"
|
test_function = "ecp_mod_p_generic_raw"
|
||||||
test_name = "ecp_mod_p256_raw"
|
test_name = "ecp_mod_p256_raw"
|
||||||
input_style = "fixed"
|
input_style = "fixed"
|
||||||
arity = 1
|
arity = 1
|
||||||
@ -247,11 +255,15 @@ class EcpP256R1Raw(bignum_common.ModOperationCommon,
|
|||||||
def is_valid(self) -> bool:
|
def is_valid(self) -> bool:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
def arguments(self):
|
||||||
|
args = super().arguments()
|
||||||
|
return ["MBEDTLS_ECP_DP_SECP256R1"] + args
|
||||||
|
|
||||||
|
|
||||||
class EcpP384R1Raw(bignum_common.ModOperationCommon,
|
class EcpP384R1Raw(bignum_common.ModOperationCommon,
|
||||||
EcpTarget):
|
EcpTarget):
|
||||||
"""Test cases for ECP P384 fast reduction."""
|
"""Test cases for ECP P384 fast reduction."""
|
||||||
test_function = "ecp_mod_p384_raw"
|
test_function = "ecp_mod_p_generic_raw"
|
||||||
test_name = "ecp_mod_p384_raw"
|
test_name = "ecp_mod_p384_raw"
|
||||||
input_style = "fixed"
|
input_style = "fixed"
|
||||||
arity = 1
|
arity = 1
|
||||||
@ -364,10 +376,15 @@ class EcpP384R1Raw(bignum_common.ModOperationCommon,
|
|||||||
def is_valid(self) -> bool:
|
def is_valid(self) -> bool:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
def arguments(self):
|
||||||
|
args = super().arguments()
|
||||||
|
return ["MBEDTLS_ECP_DP_SECP384R1"] + args
|
||||||
|
|
||||||
|
|
||||||
class EcpP521R1Raw(bignum_common.ModOperationCommon,
|
class EcpP521R1Raw(bignum_common.ModOperationCommon,
|
||||||
EcpTarget):
|
EcpTarget):
|
||||||
"""Test cases for ECP P521 fast reduction."""
|
"""Test cases for ECP P521 fast reduction."""
|
||||||
test_function = "ecp_mod_p521_raw"
|
test_function = "ecp_mod_p_generic_raw"
|
||||||
test_name = "ecp_mod_p521_raw"
|
test_name = "ecp_mod_p521_raw"
|
||||||
input_style = "arch_split"
|
input_style = "arch_split"
|
||||||
arity = 1
|
arity = 1
|
||||||
@ -462,3 +479,7 @@ class EcpP521R1Raw(bignum_common.ModOperationCommon,
|
|||||||
@property
|
@property
|
||||||
def is_valid(self) -> bool:
|
def is_valid(self) -> bool:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
def arguments(self):
|
||||||
|
args = super().arguments()
|
||||||
|
return ["MBEDTLS_ECP_DP_SECP521R1"] + args
|
||||||
|
@ -1266,10 +1266,11 @@ exit:
|
|||||||
}
|
}
|
||||||
/* END_CASE */
|
/* END_CASE */
|
||||||
|
|
||||||
/* BEGIN_CASE depends_on:MBEDTLS_TEST_HOOKS:MBEDTLS_ECP_DP_SECP192R1_ENABLED */
|
/* BEGIN_CASE depends_on:MBEDTLS_TEST_HOOKS */
|
||||||
void ecp_mod_p192_raw(char *input_N,
|
void ecp_mod_p_generic_raw(int curve_id,
|
||||||
char *input_X,
|
char *input_N,
|
||||||
char *result)
|
char *input_X,
|
||||||
|
char *result)
|
||||||
{
|
{
|
||||||
mbedtls_mpi_uint *X = NULL;
|
mbedtls_mpi_uint *X = NULL;
|
||||||
mbedtls_mpi_uint *N = NULL;
|
mbedtls_mpi_uint *N = NULL;
|
||||||
@ -1278,48 +1279,10 @@ void ecp_mod_p192_raw(char *input_N,
|
|||||||
size_t limbs_N;
|
size_t limbs_N;
|
||||||
size_t limbs_res;
|
size_t limbs_res;
|
||||||
|
|
||||||
mbedtls_mpi_mod_modulus m;
|
size_t bytes;
|
||||||
mbedtls_mpi_mod_modulus_init(&m);
|
size_t limbs;
|
||||||
|
size_t curve_bits;
|
||||||
TEST_EQUAL(mbedtls_test_read_mpi_core(&X, &limbs_X, input_X), 0);
|
int (*curve_func)(mbedtls_mpi_uint *X, size_t X_limbs);
|
||||||
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);
|
|
||||||
|
|
||||||
size_t limbs = limbs_N;
|
|
||||||
size_t bytes = limbs * sizeof(mbedtls_mpi_uint);
|
|
||||||
|
|
||||||
TEST_EQUAL(limbs_X, 2 * limbs);
|
|
||||||
TEST_EQUAL(limbs_res, limbs);
|
|
||||||
|
|
||||||
TEST_EQUAL(mbedtls_mpi_mod_modulus_setup(
|
|
||||||
&m, N, limbs,
|
|
||||||
MBEDTLS_MPI_MOD_REP_MONTGOMERY), 0);
|
|
||||||
|
|
||||||
TEST_EQUAL(mbedtls_ecp_mod_p192_raw(X, limbs_X), 0);
|
|
||||||
TEST_LE_U(mbedtls_mpi_core_bitlen(X, limbs_X), 192);
|
|
||||||
mbedtls_mpi_mod_raw_fix_quasi_reduction(X, &m);
|
|
||||||
ASSERT_COMPARE(X, bytes, res, bytes);
|
|
||||||
|
|
||||||
exit:
|
|
||||||
mbedtls_free(X);
|
|
||||||
mbedtls_free(res);
|
|
||||||
|
|
||||||
mbedtls_mpi_mod_modulus_free(&m);
|
|
||||||
mbedtls_free(N);
|
|
||||||
}
|
|
||||||
/* END_CASE */
|
|
||||||
|
|
||||||
/* BEGIN_CASE depends_on:MBEDTLS_TEST_HOOKS:MBEDTLS_ECP_DP_SECP224R1_ENABLED */
|
|
||||||
void ecp_mod_p224_raw(char *input_N,
|
|
||||||
char *input_X,
|
|
||||||
char *result)
|
|
||||||
{
|
|
||||||
mbedtls_mpi_uint *X = NULL;
|
|
||||||
mbedtls_mpi_uint *N = NULL;
|
|
||||||
mbedtls_mpi_uint *res = NULL;
|
|
||||||
size_t limbs_X;
|
|
||||||
size_t limbs_N;
|
|
||||||
size_t limbs_res;
|
|
||||||
|
|
||||||
mbedtls_mpi_mod_modulus m;
|
mbedtls_mpi_mod_modulus m;
|
||||||
mbedtls_mpi_mod_modulus_init(&m);
|
mbedtls_mpi_mod_modulus_init(&m);
|
||||||
@ -1327,148 +1290,59 @@ void ecp_mod_p224_raw(char *input_N,
|
|||||||
TEST_EQUAL(mbedtls_test_read_mpi_core(&X, &limbs_X, input_X), 0);
|
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);
|
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_core(&res, &limbs_res, result), 0);
|
||||||
|
bytes = limbs_N * sizeof(mbedtls_mpi_uint);
|
||||||
|
|
||||||
size_t limbs = limbs_N;
|
switch (curve_id) {
|
||||||
size_t bytes = limbs * sizeof(mbedtls_mpi_uint);
|
#if defined(MBEDTLS_ECP_DP_SECP192R1_ENABLED)
|
||||||
|
case MBEDTLS_ECP_DP_SECP192R1:
|
||||||
|
limbs = 2 * limbs_N;
|
||||||
|
curve_bits = 192;
|
||||||
|
curve_func = &mbedtls_ecp_mod_p192_raw;
|
||||||
|
break;
|
||||||
|
#endif
|
||||||
|
#if defined(MBEDTLS_ECP_DP_SECP224R1_ENABLED)
|
||||||
|
case MBEDTLS_ECP_DP_SECP224R1:
|
||||||
|
limbs = 448 / biL;
|
||||||
|
curve_bits = 224;
|
||||||
|
curve_func = &mbedtls_ecp_mod_p224_raw;
|
||||||
|
break;
|
||||||
|
#endif
|
||||||
|
#if defined(MBEDTLS_ECP_DP_SECP256R1_ENABLED)
|
||||||
|
case MBEDTLS_ECP_DP_SECP256R1:
|
||||||
|
limbs = 2 * limbs_N;
|
||||||
|
curve_bits = 256;
|
||||||
|
curve_func = &mbedtls_ecp_mod_p256_raw;
|
||||||
|
break;
|
||||||
|
#endif
|
||||||
|
#if defined(MBEDTLS_ECP_DP_SECP384R1_ENABLED)
|
||||||
|
case MBEDTLS_ECP_DP_SECP384R1:
|
||||||
|
limbs = 2 * limbs_N;
|
||||||
|
curve_bits = 384;
|
||||||
|
curve_func = &mbedtls_ecp_mod_p384_raw;
|
||||||
|
break;
|
||||||
|
#endif
|
||||||
|
#if defined(MBEDTLS_ECP_DP_SECP521R1_ENABLED)
|
||||||
|
case MBEDTLS_ECP_DP_SECP521R1:
|
||||||
|
limbs = 2 * limbs_N;
|
||||||
|
curve_bits = 522;
|
||||||
|
curve_func = &mbedtls_ecp_mod_p521_raw;
|
||||||
|
break;
|
||||||
|
#endif
|
||||||
|
default:
|
||||||
|
mbedtls_test_fail("Unsupported curve_id", __LINE__, __FILE__);
|
||||||
|
goto exit;
|
||||||
|
}
|
||||||
|
|
||||||
TEST_EQUAL(limbs_X, 448 / biL);
|
TEST_EQUAL(limbs_X, limbs);
|
||||||
TEST_EQUAL(limbs_res, limbs);
|
TEST_EQUAL(limbs_res, limbs_N);
|
||||||
|
|
||||||
TEST_EQUAL(mbedtls_mpi_mod_modulus_setup(
|
TEST_EQUAL(mbedtls_mpi_mod_modulus_setup(
|
||||||
&m, N, limbs,
|
&m, N, limbs_N,
|
||||||
MBEDTLS_MPI_MOD_REP_MONTGOMERY), 0);
|
MBEDTLS_MPI_MOD_REP_MONTGOMERY), 0);
|
||||||
|
|
||||||
TEST_EQUAL(mbedtls_ecp_mod_p224_raw(X, limbs_X), 0);
|
TEST_EQUAL((*curve_func)(X, limbs_X), 0);
|
||||||
TEST_LE_U(mbedtls_mpi_core_bitlen(X, limbs_X), 224);
|
|
||||||
mbedtls_mpi_mod_raw_fix_quasi_reduction(X, &m);
|
|
||||||
ASSERT_COMPARE(X, bytes, res, bytes);
|
|
||||||
|
|
||||||
exit:
|
TEST_LE_U(mbedtls_mpi_core_bitlen(X, limbs_X), curve_bits);
|
||||||
mbedtls_free(X);
|
|
||||||
mbedtls_free(res);
|
|
||||||
|
|
||||||
mbedtls_mpi_mod_modulus_free(&m);
|
|
||||||
mbedtls_free(N);
|
|
||||||
}
|
|
||||||
/* END_CASE */
|
|
||||||
|
|
||||||
/* BEGIN_CASE depends_on:MBEDTLS_TEST_HOOKS:MBEDTLS_ECP_DP_SECP256R1_ENABLED */
|
|
||||||
void ecp_mod_p256_raw(char *input_N,
|
|
||||||
char *input_X,
|
|
||||||
char *result)
|
|
||||||
{
|
|
||||||
mbedtls_mpi_uint *X = NULL;
|
|
||||||
mbedtls_mpi_uint *N = NULL;
|
|
||||||
mbedtls_mpi_uint *res = NULL;
|
|
||||||
size_t limbs_X;
|
|
||||||
size_t limbs_N;
|
|
||||||
size_t limbs_res;
|
|
||||||
|
|
||||||
mbedtls_mpi_mod_modulus m;
|
|
||||||
mbedtls_mpi_mod_modulus_init(&m);
|
|
||||||
|
|
||||||
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);
|
|
||||||
TEST_EQUAL(mbedtls_test_read_mpi_core(&res, &limbs_res, result), 0);
|
|
||||||
|
|
||||||
size_t limbs = limbs_N;
|
|
||||||
size_t bytes = limbs * sizeof(mbedtls_mpi_uint);
|
|
||||||
|
|
||||||
TEST_EQUAL(limbs_X, 2 * limbs);
|
|
||||||
TEST_EQUAL(limbs_res, limbs);
|
|
||||||
|
|
||||||
TEST_EQUAL(mbedtls_mpi_mod_modulus_setup(
|
|
||||||
&m, N, limbs,
|
|
||||||
MBEDTLS_MPI_MOD_REP_MONTGOMERY), 0);
|
|
||||||
|
|
||||||
TEST_EQUAL(mbedtls_ecp_mod_p256_raw(X, limbs_X), 0);
|
|
||||||
TEST_LE_U(mbedtls_mpi_core_bitlen(X, limbs_X), 256);
|
|
||||||
mbedtls_mpi_mod_raw_fix_quasi_reduction(X, &m);
|
|
||||||
ASSERT_COMPARE(X, bytes, res, bytes);
|
|
||||||
|
|
||||||
exit:
|
|
||||||
mbedtls_free(X);
|
|
||||||
mbedtls_free(res);
|
|
||||||
|
|
||||||
mbedtls_mpi_mod_modulus_free(&m);
|
|
||||||
mbedtls_free(N);
|
|
||||||
}
|
|
||||||
/* END_CASE */
|
|
||||||
|
|
||||||
/* BEGIN_CASE depends_on:MBEDTLS_TEST_HOOKS:MBEDTLS_ECP_DP_SECP384R1_ENABLED */
|
|
||||||
void ecp_mod_p384_raw(char *input_N,
|
|
||||||
char *input_X,
|
|
||||||
char *result)
|
|
||||||
{
|
|
||||||
mbedtls_mpi_uint *X = NULL;
|
|
||||||
mbedtls_mpi_uint *N = NULL;
|
|
||||||
mbedtls_mpi_uint *res = NULL;
|
|
||||||
size_t limbs_X;
|
|
||||||
size_t limbs_N;
|
|
||||||
size_t limbs_res;
|
|
||||||
|
|
||||||
mbedtls_mpi_mod_modulus m;
|
|
||||||
mbedtls_mpi_mod_modulus_init(&m);
|
|
||||||
|
|
||||||
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);
|
|
||||||
TEST_EQUAL(mbedtls_test_read_mpi_core(&res, &limbs_res, result), 0);
|
|
||||||
|
|
||||||
size_t limbs = limbs_N;
|
|
||||||
size_t bytes = limbs * sizeof(mbedtls_mpi_uint);
|
|
||||||
|
|
||||||
TEST_EQUAL(limbs_X, 2 * limbs);
|
|
||||||
TEST_EQUAL(limbs_res, limbs);
|
|
||||||
|
|
||||||
TEST_EQUAL(mbedtls_mpi_mod_modulus_setup(
|
|
||||||
&m, N, limbs,
|
|
||||||
MBEDTLS_MPI_MOD_REP_MONTGOMERY), 0);
|
|
||||||
|
|
||||||
TEST_EQUAL(mbedtls_ecp_mod_p384_raw(X, limbs_X), 0);
|
|
||||||
TEST_LE_U(mbedtls_mpi_core_bitlen(X, limbs_X), 384);
|
|
||||||
mbedtls_mpi_mod_raw_fix_quasi_reduction(X, &m);
|
|
||||||
ASSERT_COMPARE(X, bytes, res, bytes);
|
|
||||||
|
|
||||||
exit:
|
|
||||||
mbedtls_free(X);
|
|
||||||
mbedtls_free(res);
|
|
||||||
|
|
||||||
mbedtls_mpi_mod_modulus_free(&m);
|
|
||||||
mbedtls_free(N);
|
|
||||||
}
|
|
||||||
/* END_CASE */
|
|
||||||
|
|
||||||
/* BEGIN_CASE depends_on:MBEDTLS_TEST_HOOKS:MBEDTLS_ECP_DP_SECP521R1_ENABLED */
|
|
||||||
void ecp_mod_p521_raw(char *input_N,
|
|
||||||
char *input_X,
|
|
||||||
char *result)
|
|
||||||
{
|
|
||||||
mbedtls_mpi_uint *X = NULL;
|
|
||||||
mbedtls_mpi_uint *N = NULL;
|
|
||||||
mbedtls_mpi_uint *res = NULL;
|
|
||||||
size_t limbs_X;
|
|
||||||
size_t limbs_N;
|
|
||||||
size_t limbs_res;
|
|
||||||
|
|
||||||
mbedtls_mpi_mod_modulus m;
|
|
||||||
mbedtls_mpi_mod_modulus_init(&m);
|
|
||||||
|
|
||||||
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);
|
|
||||||
TEST_EQUAL(mbedtls_test_read_mpi_core(&res, &limbs_res, result), 0);
|
|
||||||
|
|
||||||
size_t limbs = limbs_N;
|
|
||||||
size_t bytes = limbs * sizeof(mbedtls_mpi_uint);
|
|
||||||
|
|
||||||
TEST_EQUAL(limbs_X, 2 * limbs);
|
|
||||||
TEST_EQUAL(limbs_res, limbs);
|
|
||||||
|
|
||||||
TEST_EQUAL(mbedtls_mpi_mod_modulus_setup(
|
|
||||||
&m, N, limbs,
|
|
||||||
MBEDTLS_MPI_MOD_REP_MONTGOMERY), 0);
|
|
||||||
|
|
||||||
TEST_EQUAL(mbedtls_ecp_mod_p521_raw(X, limbs_X), 0);
|
|
||||||
TEST_LE_U(mbedtls_mpi_core_bitlen(X, limbs_X), 522);
|
|
||||||
mbedtls_mpi_mod_raw_fix_quasi_reduction(X, &m);
|
mbedtls_mpi_mod_raw_fix_quasi_reduction(X, &m);
|
||||||
ASSERT_COMPARE(X, bytes, res, bytes);
|
ASSERT_COMPARE(X, bytes, res, bytes);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user