mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2025-03-23 16:20:49 +00:00
ecp: introduce new ECP_LIGHT symbol
Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
This commit is contained in:
parent
6a327a5fdc
commit
fd122f4e95
@ -105,6 +105,13 @@
|
||||
#define MBEDTLS_MD_LIGHT
|
||||
#endif
|
||||
|
||||
/* MBEDTLS_ECP_C is now a subset of MBEDTLS_ECP_LIGHT which contains the
|
||||
* arithmetic part. As a consequence if MBEDTLS_ECP_C is required for
|
||||
* some reason, then MBEDTLS_ECP_LIGHT should be enabled as well. */
|
||||
#if defined(MBEDTLS_ECP_C)
|
||||
#define MBEDTLS_ECP_LIGHT
|
||||
#endif
|
||||
|
||||
/* If MBEDTLS_PSA_CRYPTO_C is defined, make sure MBEDTLS_PSA_CRYPTO_CLIENT
|
||||
* is defined as well to include all PSA code.
|
||||
*/
|
||||
|
@ -454,7 +454,7 @@
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_PK_C) && \
|
||||
!defined(MBEDTLS_RSA_C) && !defined(MBEDTLS_ECP_C)
|
||||
!defined(MBEDTLS_RSA_C) && !defined(MBEDTLS_ECP_LIGHT)
|
||||
#error "MBEDTLS_PK_C defined, but not all prerequisites"
|
||||
#endif
|
||||
|
||||
|
@ -312,7 +312,7 @@ mbedtls_ecp_group;
|
||||
/**
|
||||
* The maximum size of the groups, that is, of \c N and \c P.
|
||||
*/
|
||||
#if !defined(MBEDTLS_ECP_C)
|
||||
#if !defined(MBEDTLS_ECP_LIGHT)
|
||||
/* Dummy definition to help code that has optional ECP support and
|
||||
* defines an MBEDTLS_ECP_MAX_BYTES-sized array unconditionally. */
|
||||
#define MBEDTLS_ECP_MAX_BITS 1
|
||||
@ -343,9 +343,9 @@ mbedtls_ecp_group;
|
||||
#define MBEDTLS_ECP_MAX_BITS 192
|
||||
#elif defined(MBEDTLS_ECP_DP_SECP192R1_ENABLED)
|
||||
#define MBEDTLS_ECP_MAX_BITS 192
|
||||
#else
|
||||
#else /* !MBEDTLS_ECP_LIGHT */
|
||||
#error "Missing definition of MBEDTLS_ECP_MAX_BITS"
|
||||
#endif
|
||||
#endif /* !MBEDTLS_ECP_LIGHT */
|
||||
|
||||
#define MBEDTLS_ECP_MAX_BYTES ((MBEDTLS_ECP_MAX_BITS + 7) / 8)
|
||||
#define MBEDTLS_ECP_MAX_PT_LEN (2 * MBEDTLS_ECP_MAX_BYTES + 1)
|
||||
|
@ -70,7 +70,7 @@
|
||||
#if defined(MBEDTLS_ECP_INTERNAL_ALT)
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_ECP_C)
|
||||
#if defined(MBEDTLS_ECP_LIGHT)
|
||||
|
||||
#include "mbedtls/ecp.h"
|
||||
#include "mbedtls/threading.h"
|
||||
@ -93,7 +93,10 @@
|
||||
* Counts of point addition and doubling, and field multiplications.
|
||||
* Used to test resistance of point multiplication to simple timing attacks.
|
||||
*/
|
||||
static unsigned long add_count, dbl_count, mul_count;
|
||||
#if defined(MBEDTLS_ECP_C)
|
||||
static unsigned long add_count, dbl_count;
|
||||
#endif /* MBEDTLS_ECP_C */
|
||||
static unsigned long mul_count;
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_ECP_RESTARTABLE)
|
||||
@ -320,6 +323,7 @@ int mbedtls_ecp_check_budget(const mbedtls_ecp_group *grp,
|
||||
|
||||
#endif /* MBEDTLS_ECP_RESTARTABLE */
|
||||
|
||||
#if defined(MBEDTLS_ECP_C)
|
||||
static void mpi_init_many(mbedtls_mpi *arr, size_t size)
|
||||
{
|
||||
while (size--) {
|
||||
@ -333,6 +337,7 @@ static void mpi_free_many(mbedtls_mpi *arr, size_t size)
|
||||
mbedtls_mpi_free(arr++);
|
||||
}
|
||||
}
|
||||
#endif /* MBEDTLS_ECP_C */
|
||||
|
||||
/*
|
||||
* List of supported curves:
|
||||
@ -1306,7 +1311,10 @@ cleanup:
|
||||
mbedtls_mpi_free(&exp);
|
||||
return ret;
|
||||
}
|
||||
#endif /* MBEDTLS_ECP_SHORT_WEIERSTRASS_ENABLED */
|
||||
|
||||
#if defined(MBEDTLS_ECP_C)
|
||||
#if defined(MBEDTLS_ECP_SHORT_WEIERSTRASS_ENABLED)
|
||||
/*
|
||||
* For curves in short Weierstrass form, we do all the internal operations in
|
||||
* Jacobian coordinates.
|
||||
@ -2723,6 +2731,7 @@ int mbedtls_ecp_mul(mbedtls_ecp_group *grp, mbedtls_ecp_point *R,
|
||||
{
|
||||
return mbedtls_ecp_mul_restartable(grp, R, m, P, f_rng, p_rng, NULL);
|
||||
}
|
||||
#endif /* MBEDTLS_ECP_C */
|
||||
|
||||
#if defined(MBEDTLS_ECP_SHORT_WEIERSTRASS_ENABLED)
|
||||
/*
|
||||
@ -2763,6 +2772,7 @@ cleanup:
|
||||
}
|
||||
#endif /* MBEDTLS_ECP_SHORT_WEIERSTRASS_ENABLED */
|
||||
|
||||
#if defined(MBEDTLS_ECP_C)
|
||||
#if defined(MBEDTLS_ECP_SHORT_WEIERSTRASS_ENABLED)
|
||||
/*
|
||||
* R = m * P with shortcuts for m == 0, m == 1 and m == -1
|
||||
@ -2914,6 +2924,7 @@ int mbedtls_ecp_muladd(mbedtls_ecp_group *grp, mbedtls_ecp_point *R,
|
||||
return mbedtls_ecp_muladd_restartable(grp, R, m, P, n, Q, NULL);
|
||||
}
|
||||
#endif /* MBEDTLS_ECP_SHORT_WEIERSTRASS_ENABLED */
|
||||
#endif /* MBEDTLS_ECP_C */
|
||||
|
||||
#if defined(MBEDTLS_ECP_MONTGOMERY_ENABLED)
|
||||
#if defined(MBEDTLS_ECP_DP_CURVE25519_ENABLED)
|
||||
@ -3159,6 +3170,7 @@ int mbedtls_ecp_gen_privkey(const mbedtls_ecp_group *grp,
|
||||
return MBEDTLS_ERR_ECP_BAD_INPUT_DATA;
|
||||
}
|
||||
|
||||
#if defined(MBEDTLS_ECP_C)
|
||||
/*
|
||||
* Generate a keypair with configurable base point
|
||||
*/
|
||||
@ -3200,6 +3212,7 @@ int mbedtls_ecp_gen_key(mbedtls_ecp_group_id grp_id, mbedtls_ecp_keypair *key,
|
||||
|
||||
return mbedtls_ecp_gen_keypair(&key->grp, &key->d, &key->Q, f_rng, p_rng);
|
||||
}
|
||||
#endif /* MBEDTLS_ECP_C */
|
||||
|
||||
#define ECP_CURVE25519_KEY_SIZE 32
|
||||
#define ECP_CURVE448_KEY_SIZE 56
|
||||
@ -3316,7 +3329,7 @@ cleanup:
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
#if defined(MBEDTLS_ECP_C)
|
||||
/*
|
||||
* Check a public-private key pair
|
||||
*/
|
||||
@ -3357,6 +3370,7 @@ cleanup:
|
||||
|
||||
return ret;
|
||||
}
|
||||
#endif /* MBEDTLS_ECP_C */
|
||||
|
||||
/*
|
||||
* Export generic key-pair parameters.
|
||||
@ -3383,6 +3397,7 @@ int mbedtls_ecp_export(const mbedtls_ecp_keypair *key, mbedtls_ecp_group *grp,
|
||||
|
||||
#if defined(MBEDTLS_SELF_TEST)
|
||||
|
||||
#if defined(MBEDTLS_ECP_C)
|
||||
/*
|
||||
* PRNG for test - !!!INSECURE NEVER USE IN PRODUCTION!!!
|
||||
*
|
||||
@ -3490,12 +3505,14 @@ cleanup:
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
#endif /* MBEDTLS_ECP_C */
|
||||
|
||||
/*
|
||||
* Checkup routine
|
||||
*/
|
||||
int mbedtls_ecp_self_test(int verbose)
|
||||
{
|
||||
#if defined(MBEDTLS_ECP_C)
|
||||
int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
|
||||
mbedtls_ecp_group grp;
|
||||
mbedtls_ecp_point R, P;
|
||||
@ -3609,10 +3626,14 @@ cleanup:
|
||||
}
|
||||
|
||||
return ret;
|
||||
#else /* MBEDTLS_ECP_C */
|
||||
(void) verbose;
|
||||
return 0;
|
||||
#endif /* MBEDTLS_ECP_C */
|
||||
}
|
||||
|
||||
#endif /* MBEDTLS_SELF_TEST */
|
||||
|
||||
#endif /* !MBEDTLS_ECP_ALT */
|
||||
|
||||
#endif /* MBEDTLS_ECP_C */
|
||||
#endif /* MBEDTLS_ECP_LIGHT */
|
||||
|
Loading…
x
Reference in New Issue
Block a user