ecp_curves: Minor refactoring.
This patch introduces the following changes:
* Documentation for `mbedtls_ecp_modulus_setup()`
moved to `ecp_invasive.h`.
* Added invalid modulus selector `MBEDTLS_ECP_MOD_NONE`.
* Adjusted negative tests to use invalid selectors.
* Reworded documentation.
Signed-off-by: Minos Galanakis <minos.galanakis@arm.com>
diff --git a/include/mbedtls/ecp.h b/include/mbedtls/ecp.h
index 20b663e..83d5b6a 100644
--- a/include/mbedtls/ecp.h
+++ b/include/mbedtls/ecp.h
@@ -142,10 +142,11 @@
} mbedtls_ecp_curve_type;
/*
- * Curve moduli types
+ * Curve modulus types
*/
typedef enum {
- MBEDTLS_ECP_MOD_COORDINATE = 0,
+ MBEDTLS_ECP_MOD_NONE = 0,
+ MBEDTLS_ECP_MOD_COORDINATE,
MBEDTLS_ECP_MOD_SCALAR
} mbedtls_ecp_modulus_type;
diff --git a/library/ecp_curves.c b/library/ecp_curves.c
index d4d8c08..b352e76 100644
--- a/library/ecp_curves.c
+++ b/library/ecp_curves.c
@@ -5535,22 +5535,6 @@
#endif /* MBEDTLS_ECP_DP_SECP256K1_ENABLED */
#if defined(MBEDTLS_TEST_HOOKS)
-
-/** Initialise a modulus with hard-coded const curve data.
- *
- * \param[out] N The address of the modulus structure to populate.
- * Must be initialized.
- * \param[in] id The mbedtls_ecp_group_id for which to initialise the modulus.
- * \param[in] ctype The mbedtls_ecp_curve_type identifier for a coordinate modulus (P)
- * or a scalar modulus (N).
- *
- * \return \c 0 if successful.
- * \return #MBEDTLS_ERR_ECP_BAD_INPUT_DATA if the given MPIs do not
- * have the correct number of limbs.
- *
- * \note The caller is responsible for the \p N moduli lifecycle.
- *
- */
MBEDTLS_STATIC_TESTABLE
int mbedtls_ecp_modulus_setup(mbedtls_mpi_mod_modulus *N,
const mbedtls_ecp_group_id id,
@@ -5728,7 +5712,7 @@
if (mbedtls_mpi_mod_modulus_setup(N, p, p_limbs,
MBEDTLS_MPI_MOD_REP_MONTGOMERY)) {
- return MBEDTLS_ERR_ECP_BAD_INPUT_DATA;
+ return MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
}
return 0;
}
diff --git a/library/ecp_invasive.h b/library/ecp_invasive.h
index 10aa34b..aba7cca 100644
--- a/library/ecp_invasive.h
+++ b/library/ecp_invasive.h
@@ -118,6 +118,23 @@
#endif /* MBEDTLS_ECP_DP_SECP521R1_ENABLED */
+/** Initialise a modulus with hard-coded const curve data.
+ *
+ * \note The caller is responsible for the \p N modulus' memory.
+ * mbedtls_mpi_mod_modulus_free(&N) should be invoked at the
+ * end of its lifecycle.
+ *
+ * \param[in,out] N The address of the modulus structure to populate.
+ * Must be initialized.
+ * \param[in] id The mbedtls_ecp_group_id for which to initialise the modulus.
+ * \param[in] ctype The mbedtls_ecp_curve_type identifier for a coordinate modulus (P)
+ * or a scalar modulus (N).
+ *
+ * \return \c 0 if successful.
+ * \return #MBEDTLS_ERR_ECP_BAD_INPUT_DATA if the given MPIs do not
+ * have the correct number of limbs.
+ *
+ */
MBEDTLS_STATIC_TESTABLE
int mbedtls_ecp_modulus_setup(mbedtls_mpi_mod_modulus *N,
const mbedtls_ecp_group_id id,
diff --git a/tests/suites/test_suite_ecp.data b/tests/suites/test_suite_ecp.data
index 8d83898..3fbad92 100644
--- a/tests/suites/test_suite_ecp.data
+++ b/tests/suites/test_suite_ecp.data
@@ -1145,8 +1145,8 @@
ecp_setup_negative_test #27 Invalid Moduli Type
depends_on:MBEDTLS_ECP_DP_CURVE448_ENABLED
-ecp_mod_setup:"fffffffffffffffffffffffe26f2fc17f69466a74defd8d":MBEDTLS_ECP_DP_CURVE448:MBEDTLS_ECP_MOD_SCALAR+1:MBEDTLS_ERR_ECP_BAD_INPUT_DATA
+ecp_mod_setup:"fffffffffffffffffffffffe26f2fc17f69466a74defd8d":MBEDTLS_ECP_DP_CURVE448:MBEDTLS_ECP_MOD_NONE:MBEDTLS_ERR_ECP_BAD_INPUT_DATA
ecp_setup_negative_test #28 Invalid Curve Type
depends_on:MBEDTLS_ECP_DP_CURVE448_ENABLED
-ecp_mod_setup:"fffffffffffffffffffffffe26f2fc17f69466a74defd8d":MBEDTLS_ECP_DP_CURVE448+1:MBEDTLS_ECP_MOD_SCALAR:MBEDTLS_ERR_ECP_BAD_INPUT_DATA
+ecp_mod_setup:"fffffffffffffffffffffffe26f2fc17f69466a74defd8d":MBEDTLS_ECP_DP_NONE:MBEDTLS_ECP_MOD_SCALAR:MBEDTLS_ERR_ECP_BAD_INPUT_DATA