mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2025-12-08 02:02:16 +03:00
Remove MBEDTLS_ECP_ALT and associated options
Also removed are all options of the form MBEDTLS_ECP_XXX_ALT as well as MBEDTLS_ECP_NO_FALLBACK. Signed-off-by: Thomas Daubney <thomas.daubney@arm.com>
This commit is contained in:
145
library/ecp.c
145
library/ecp.c
@@ -31,35 +31,6 @@
|
||||
|
||||
#include "common.h"
|
||||
|
||||
/**
|
||||
* \brief Function level alternative implementation.
|
||||
*
|
||||
* The MBEDTLS_ECP_INTERNAL_ALT macro enables alternative implementations to
|
||||
* replace certain functions in this module. The alternative implementations are
|
||||
* typically hardware accelerators and need to activate the hardware before the
|
||||
* computation starts and deactivate it after it finishes. The
|
||||
* mbedtls_internal_ecp_init() and mbedtls_internal_ecp_free() functions serve
|
||||
* this purpose.
|
||||
*
|
||||
* To preserve the correct functionality the following conditions must hold:
|
||||
*
|
||||
* - The alternative implementation must be activated by
|
||||
* mbedtls_internal_ecp_init() before any of the replaceable functions is
|
||||
* called.
|
||||
* - mbedtls_internal_ecp_free() must \b only be called when the alternative
|
||||
* implementation is activated.
|
||||
* - mbedtls_internal_ecp_init() must \b not be called when the alternative
|
||||
* implementation is activated.
|
||||
* - Public functions must not return while the alternative implementation is
|
||||
* activated.
|
||||
* - Replaceable functions are guarded by \c MBEDTLS_ECP_XXX_ALT macros and
|
||||
* before calling them an \code if( mbedtls_internal_ecp_grp_capable( grp ) )
|
||||
* \endcode ensures that the alternative implementation supports the current
|
||||
* group.
|
||||
*/
|
||||
#if defined(MBEDTLS_ECP_INTERNAL_ALT)
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_ECP_LIGHT)
|
||||
|
||||
#include "mbedtls/ecp.h"
|
||||
@@ -72,12 +43,8 @@
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#if !defined(MBEDTLS_ECP_ALT)
|
||||
|
||||
#include "mbedtls/platform.h"
|
||||
|
||||
#include "ecp_internal_alt.h"
|
||||
|
||||
#if defined(MBEDTLS_SELF_TEST)
|
||||
/*
|
||||
* Counts of point addition and doubling, and field multiplications.
|
||||
@@ -1317,15 +1284,6 @@ static int ecp_normalize_jac(const mbedtls_ecp_group *grp, mbedtls_ecp_point *pt
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if defined(MBEDTLS_ECP_NORMALIZE_JAC_ALT)
|
||||
if (mbedtls_internal_ecp_grp_capable(grp)) {
|
||||
return mbedtls_internal_ecp_normalize_jac(grp, pt);
|
||||
}
|
||||
#endif /* MBEDTLS_ECP_NORMALIZE_JAC_ALT */
|
||||
|
||||
#if defined(MBEDTLS_ECP_NO_FALLBACK) && defined(MBEDTLS_ECP_NORMALIZE_JAC_ALT)
|
||||
return MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE;
|
||||
#else
|
||||
int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
|
||||
mbedtls_mpi T;
|
||||
mbedtls_mpi_init(&T);
|
||||
@@ -1343,7 +1301,6 @@ cleanup:
|
||||
mbedtls_mpi_free(&T);
|
||||
|
||||
return ret;
|
||||
#endif /* !defined(MBEDTLS_ECP_NO_FALLBACK) || !defined(MBEDTLS_ECP_NORMALIZE_JAC_ALT) */
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -1364,15 +1321,6 @@ static int ecp_normalize_jac_many(const mbedtls_ecp_group *grp,
|
||||
return ecp_normalize_jac(grp, *T);
|
||||
}
|
||||
|
||||
#if defined(MBEDTLS_ECP_NORMALIZE_JAC_MANY_ALT)
|
||||
if (mbedtls_internal_ecp_grp_capable(grp)) {
|
||||
return mbedtls_internal_ecp_normalize_jac_many(grp, T, T_size);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_ECP_NO_FALLBACK) && defined(MBEDTLS_ECP_NORMALIZE_JAC_MANY_ALT)
|
||||
return MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE;
|
||||
#else
|
||||
int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
|
||||
size_t i;
|
||||
mbedtls_mpi *c, t;
|
||||
@@ -1447,7 +1395,6 @@ cleanup:
|
||||
mbedtls_free(c);
|
||||
|
||||
return ret;
|
||||
#endif /* !defined(MBEDTLS_ECP_NO_FALLBACK) || !defined(MBEDTLS_ECP_NORMALIZE_JAC_MANY_ALT) */
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -1491,15 +1438,6 @@ static int ecp_double_jac(const mbedtls_ecp_group *grp, mbedtls_ecp_point *R,
|
||||
dbl_count++;
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_ECP_DOUBLE_JAC_ALT)
|
||||
if (mbedtls_internal_ecp_grp_capable(grp)) {
|
||||
return mbedtls_internal_ecp_double_jac(grp, R, P);
|
||||
}
|
||||
#endif /* MBEDTLS_ECP_DOUBLE_JAC_ALT */
|
||||
|
||||
#if defined(MBEDTLS_ECP_NO_FALLBACK) && defined(MBEDTLS_ECP_DOUBLE_JAC_ALT)
|
||||
return MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE;
|
||||
#else
|
||||
int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
|
||||
|
||||
/* Special case for A = -3 */
|
||||
@@ -1557,7 +1495,6 @@ static int ecp_double_jac(const mbedtls_ecp_group *grp, mbedtls_ecp_point *R,
|
||||
cleanup:
|
||||
|
||||
return ret;
|
||||
#endif /* !defined(MBEDTLS_ECP_NO_FALLBACK) || !defined(MBEDTLS_ECP_DOUBLE_JAC_ALT) */
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -1588,15 +1525,6 @@ static int ecp_add_mixed(const mbedtls_ecp_group *grp, mbedtls_ecp_point *R,
|
||||
add_count++;
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_ECP_ADD_MIXED_ALT)
|
||||
if (mbedtls_internal_ecp_grp_capable(grp)) {
|
||||
return mbedtls_internal_ecp_add_mixed(grp, R, P, Q);
|
||||
}
|
||||
#endif /* MBEDTLS_ECP_ADD_MIXED_ALT */
|
||||
|
||||
#if defined(MBEDTLS_ECP_NO_FALLBACK) && defined(MBEDTLS_ECP_ADD_MIXED_ALT)
|
||||
return MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE;
|
||||
#else
|
||||
int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
|
||||
|
||||
/* NOTE: Aliasing between input and output is allowed, so one has to make
|
||||
@@ -1668,7 +1596,6 @@ static int ecp_add_mixed(const mbedtls_ecp_group *grp, mbedtls_ecp_point *R,
|
||||
cleanup:
|
||||
|
||||
return ret;
|
||||
#endif /* !defined(MBEDTLS_ECP_NO_FALLBACK) || !defined(MBEDTLS_ECP_ADD_MIXED_ALT) */
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -1681,15 +1608,6 @@ cleanup:
|
||||
static int ecp_randomize_jac(const mbedtls_ecp_group *grp, mbedtls_ecp_point *pt,
|
||||
int (*f_rng)(void *, unsigned char *, size_t), void *p_rng)
|
||||
{
|
||||
#if defined(MBEDTLS_ECP_RANDOMIZE_JAC_ALT)
|
||||
if (mbedtls_internal_ecp_grp_capable(grp)) {
|
||||
return mbedtls_internal_ecp_randomize_jac(grp, pt, f_rng, p_rng);
|
||||
}
|
||||
#endif /* MBEDTLS_ECP_RANDOMIZE_JAC_ALT */
|
||||
|
||||
#if defined(MBEDTLS_ECP_NO_FALLBACK) && defined(MBEDTLS_ECP_RANDOMIZE_JAC_ALT)
|
||||
return MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE;
|
||||
#else
|
||||
int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
|
||||
mbedtls_mpi l;
|
||||
|
||||
@@ -1718,7 +1636,6 @@ cleanup:
|
||||
ret = MBEDTLS_ERR_ECP_RANDOM_FAILED;
|
||||
}
|
||||
return ret;
|
||||
#endif /* !defined(MBEDTLS_ECP_NO_FALLBACK) || !defined(MBEDTLS_ECP_RANDOMIZE_JAC_ALT) */
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -2422,15 +2339,6 @@ cleanup:
|
||||
*/
|
||||
static int ecp_normalize_mxz(const mbedtls_ecp_group *grp, mbedtls_ecp_point *P)
|
||||
{
|
||||
#if defined(MBEDTLS_ECP_NORMALIZE_MXZ_ALT)
|
||||
if (mbedtls_internal_ecp_grp_capable(grp)) {
|
||||
return mbedtls_internal_ecp_normalize_mxz(grp, P);
|
||||
}
|
||||
#endif /* MBEDTLS_ECP_NORMALIZE_MXZ_ALT */
|
||||
|
||||
#if defined(MBEDTLS_ECP_NO_FALLBACK) && defined(MBEDTLS_ECP_NORMALIZE_MXZ_ALT)
|
||||
return MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE;
|
||||
#else
|
||||
int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
|
||||
MPI_ECP_INV(&P->Z, &P->Z);
|
||||
MPI_ECP_MUL(&P->X, &P->X, &P->Z);
|
||||
@@ -2438,7 +2346,6 @@ static int ecp_normalize_mxz(const mbedtls_ecp_group *grp, mbedtls_ecp_point *P)
|
||||
|
||||
cleanup:
|
||||
return ret;
|
||||
#endif /* !defined(MBEDTLS_ECP_NO_FALLBACK) || !defined(MBEDTLS_ECP_NORMALIZE_MXZ_ALT) */
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -2452,15 +2359,6 @@ cleanup:
|
||||
static int ecp_randomize_mxz(const mbedtls_ecp_group *grp, mbedtls_ecp_point *P,
|
||||
int (*f_rng)(void *, unsigned char *, size_t), void *p_rng)
|
||||
{
|
||||
#if defined(MBEDTLS_ECP_RANDOMIZE_MXZ_ALT)
|
||||
if (mbedtls_internal_ecp_grp_capable(grp)) {
|
||||
return mbedtls_internal_ecp_randomize_mxz(grp, P, f_rng, p_rng);
|
||||
}
|
||||
#endif /* MBEDTLS_ECP_RANDOMIZE_MXZ_ALT */
|
||||
|
||||
#if defined(MBEDTLS_ECP_NO_FALLBACK) && defined(MBEDTLS_ECP_RANDOMIZE_MXZ_ALT)
|
||||
return MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE;
|
||||
#else
|
||||
int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
|
||||
mbedtls_mpi l;
|
||||
mbedtls_mpi_init(&l);
|
||||
@@ -2478,7 +2376,6 @@ cleanup:
|
||||
ret = MBEDTLS_ERR_ECP_RANDOM_FAILED;
|
||||
}
|
||||
return ret;
|
||||
#endif /* !defined(MBEDTLS_ECP_NO_FALLBACK) || !defined(MBEDTLS_ECP_RANDOMIZE_MXZ_ALT) */
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -2502,15 +2399,6 @@ static int ecp_double_add_mxz(const mbedtls_ecp_group *grp,
|
||||
const mbedtls_mpi *d,
|
||||
mbedtls_mpi T[4])
|
||||
{
|
||||
#if defined(MBEDTLS_ECP_DOUBLE_ADD_MXZ_ALT)
|
||||
if (mbedtls_internal_ecp_grp_capable(grp)) {
|
||||
return mbedtls_internal_ecp_double_add_mxz(grp, R, S, P, Q, d);
|
||||
}
|
||||
#endif /* MBEDTLS_ECP_DOUBLE_ADD_MXZ_ALT */
|
||||
|
||||
#if defined(MBEDTLS_ECP_NO_FALLBACK) && defined(MBEDTLS_ECP_DOUBLE_ADD_MXZ_ALT)
|
||||
return MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE;
|
||||
#else
|
||||
int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
|
||||
|
||||
MPI_ECP_ADD(&T[0], &P->X, &P->Z); /* Pp := PX + PZ */
|
||||
@@ -2535,7 +2423,6 @@ static int ecp_double_add_mxz(const mbedtls_ecp_group *grp,
|
||||
cleanup:
|
||||
|
||||
return ret;
|
||||
#endif /* !defined(MBEDTLS_ECP_NO_FALLBACK) || !defined(MBEDTLS_ECP_DOUBLE_ADD_MXZ_ALT) */
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -2629,9 +2516,6 @@ static int ecp_mul_restartable_internal(mbedtls_ecp_group *grp, mbedtls_ecp_poin
|
||||
mbedtls_ecp_restart_ctx *rs_ctx)
|
||||
{
|
||||
int ret = MBEDTLS_ERR_ECP_BAD_INPUT_DATA;
|
||||
#if defined(MBEDTLS_ECP_INTERNAL_ALT)
|
||||
char is_grp_capable = 0;
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_ECP_RESTARTABLE)
|
||||
/* reset ops count for this call if top-level */
|
||||
@@ -2642,12 +2526,6 @@ static int ecp_mul_restartable_internal(mbedtls_ecp_group *grp, mbedtls_ecp_poin
|
||||
(void) rs_ctx;
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_ECP_INTERNAL_ALT)
|
||||
if ((is_grp_capable = mbedtls_internal_ecp_grp_capable(grp))) {
|
||||
MBEDTLS_MPI_CHK(mbedtls_internal_ecp_init(grp));
|
||||
}
|
||||
#endif /* MBEDTLS_ECP_INTERNAL_ALT */
|
||||
|
||||
int restarting = 0;
|
||||
#if defined(MBEDTLS_ECP_RESTARTABLE)
|
||||
restarting = (rs_ctx != NULL && rs_ctx->rsm != NULL);
|
||||
@@ -2676,12 +2554,6 @@ static int ecp_mul_restartable_internal(mbedtls_ecp_group *grp, mbedtls_ecp_poin
|
||||
|
||||
cleanup:
|
||||
|
||||
#if defined(MBEDTLS_ECP_INTERNAL_ALT)
|
||||
if (is_grp_capable) {
|
||||
mbedtls_internal_ecp_free(grp);
|
||||
}
|
||||
#endif /* MBEDTLS_ECP_INTERNAL_ALT */
|
||||
|
||||
#if defined(MBEDTLS_ECP_RESTARTABLE)
|
||||
if (rs_ctx != NULL) {
|
||||
rs_ctx->depth--;
|
||||
@@ -2808,9 +2680,6 @@ int mbedtls_ecp_muladd_restartable(
|
||||
mbedtls_ecp_point *pmP = &mP;
|
||||
mbedtls_ecp_point *pR = R;
|
||||
mbedtls_mpi tmp[4];
|
||||
#if defined(MBEDTLS_ECP_INTERNAL_ALT)
|
||||
char is_grp_capable = 0;
|
||||
#endif
|
||||
if (mbedtls_ecp_get_type(grp) != MBEDTLS_ECP_TYPE_SHORT_WEIERSTRASS) {
|
||||
return MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE;
|
||||
}
|
||||
@@ -2849,12 +2718,6 @@ mul2:
|
||||
#endif
|
||||
MBEDTLS_MPI_CHK(mbedtls_ecp_mul_shortcuts(grp, pR, n, Q, rs_ctx));
|
||||
|
||||
#if defined(MBEDTLS_ECP_INTERNAL_ALT)
|
||||
if ((is_grp_capable = mbedtls_internal_ecp_grp_capable(grp))) {
|
||||
MBEDTLS_MPI_CHK(mbedtls_internal_ecp_init(grp));
|
||||
}
|
||||
#endif /* MBEDTLS_ECP_INTERNAL_ALT */
|
||||
|
||||
#if defined(MBEDTLS_ECP_RESTARTABLE)
|
||||
if (rs_ctx != NULL && rs_ctx->ma != NULL) {
|
||||
rs_ctx->ma->state = ecp_rsma_add;
|
||||
@@ -2884,12 +2747,6 @@ cleanup:
|
||||
|
||||
mpi_free_many(tmp, sizeof(tmp) / sizeof(mbedtls_mpi));
|
||||
|
||||
#if defined(MBEDTLS_ECP_INTERNAL_ALT)
|
||||
if (is_grp_capable) {
|
||||
mbedtls_internal_ecp_free(grp);
|
||||
}
|
||||
#endif /* MBEDTLS_ECP_INTERNAL_ALT */
|
||||
|
||||
mbedtls_ecp_point_free(&mP);
|
||||
|
||||
ECP_RS_LEAVE(ma);
|
||||
@@ -3698,6 +3555,4 @@ cleanup:
|
||||
|
||||
#endif /* MBEDTLS_SELF_TEST */
|
||||
|
||||
#endif /* !MBEDTLS_ECP_ALT */
|
||||
|
||||
#endif /* MBEDTLS_ECP_LIGHT */
|
||||
|
||||
Reference in New Issue
Block a user