37 #if !defined(MBEDTLS_CONFIG_FILE) 40 #include MBEDTLS_CONFIG_FILE 45 #if (defined(__ARMCC_VERSION) || defined(_MSC_VER)) && \ 46 !defined(inline) && !defined(__cplusplus) 47 #define inline __inline 54 #define MBEDTLS_ERR_ECP_BAD_INPUT_DATA -0x4F80 56 #define MBEDTLS_ERR_ECP_BUFFER_TOO_SMALL -0x4F00 58 #define MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE -0x4E80 60 #define MBEDTLS_ERR_ECP_VERIFY_FAILED -0x4E00 62 #define MBEDTLS_ERR_ECP_ALLOC_FAILED -0x4D80 64 #define MBEDTLS_ERR_ECP_RANDOM_FAILED -0x4D00 66 #define MBEDTLS_ERR_ECP_INVALID_KEY -0x4C80 68 #define MBEDTLS_ERR_ECP_SIG_LEN_MISMATCH -0x4C00 72 #define MBEDTLS_ERR_ECP_HW_ACCEL_FAILED -0x4B80 75 #define MBEDTLS_ERR_ECP_IN_PROGRESS -0x4B00 79 #if defined(MBEDTLS_ECP_DP_SECP192R1_ENABLED) || \ 80 defined(MBEDTLS_ECP_DP_SECP224R1_ENABLED) || \ 81 defined(MBEDTLS_ECP_DP_SECP256R1_ENABLED) || \ 82 defined(MBEDTLS_ECP_DP_SECP384R1_ENABLED) || \ 83 defined(MBEDTLS_ECP_DP_SECP521R1_ENABLED) || \ 84 defined(MBEDTLS_ECP_DP_BP256R1_ENABLED) || \ 85 defined(MBEDTLS_ECP_DP_BP384R1_ENABLED) || \ 86 defined(MBEDTLS_ECP_DP_BP512R1_ENABLED) || \ 87 defined(MBEDTLS_ECP_DP_SECP192K1_ENABLED) || \ 88 defined(MBEDTLS_ECP_DP_SECP224K1_ENABLED) || \ 89 defined(MBEDTLS_ECP_DP_SECP256K1_ENABLED) 90 #define MBEDTLS_ECP_SHORT_WEIERSTRASS_ENABLED 92 #if defined(MBEDTLS_ECP_DP_CURVE25519_ENABLED) || \ 93 defined(MBEDTLS_ECP_DP_CURVE448_ENABLED) 94 #define MBEDTLS_ECP_MONTGOMERY_ENABLED 147 #define MBEDTLS_ECP_DP_MAX 12 187 #if !defined(MBEDTLS_ECP_C) 188 #define MBEDTLS_ECP_MAX_BITS_MIN 0 190 #elif defined(MBEDTLS_ECP_DP_SECP521R1_ENABLED) 191 #define MBEDTLS_ECP_MAX_BITS_MIN 521 192 #elif defined(MBEDTLS_ECP_DP_BP512R1_ENABLED) 193 #define MBEDTLS_ECP_MAX_BITS_MIN 512 194 #elif defined(MBEDTLS_ECP_DP_CURVE448_ENABLED) 195 #define MBEDTLS_ECP_MAX_BITS_MIN 448 196 #elif defined(MBEDTLS_ECP_DP_BP384R1_ENABLED) 197 #define MBEDTLS_ECP_MAX_BITS_MIN 384 198 #elif defined(MBEDTLS_ECP_DP_SECP384R1_ENABLED) 199 #define MBEDTLS_ECP_MAX_BITS_MIN 384 200 #elif defined(MBEDTLS_ECP_DP_BP256R1_ENABLED) 201 #define MBEDTLS_ECP_MAX_BITS_MIN 256 202 #elif defined(MBEDTLS_ECP_DP_SECP256K1_ENABLED) 203 #define MBEDTLS_ECP_MAX_BITS_MIN 256 204 #elif defined(MBEDTLS_ECP_DP_SECP256R1_ENABLED) 205 #define MBEDTLS_ECP_MAX_BITS_MIN 256 206 #elif defined(MBEDTLS_ECP_DP_CURVE25519_ENABLED) 207 #define MBEDTLS_ECP_MAX_BITS_MIN 255 208 #elif defined(MBEDTLS_ECP_DP_SECP224K1_ENABLED) 209 #define MBEDTLS_ECP_MAX_BITS_MIN 225 // n is slightly above 2^224 210 #elif defined(MBEDTLS_ECP_DP_SECP224R1_ENABLED) 211 #define MBEDTLS_ECP_MAX_BITS_MIN 224 212 #elif defined(MBEDTLS_ECP_DP_SECP192K1_ENABLED) 213 #define MBEDTLS_ECP_MAX_BITS_MIN 192 214 #elif defined(MBEDTLS_ECP_DP_SECP192R1_ENABLED) 215 #define MBEDTLS_ECP_MAX_BITS_MIN 192 217 #error "MBEDTLS_ECP_C enabled, but no curve?" 220 #if !defined(MBEDTLS_ECP_ALT) 317 #if defined(MBEDTLS_ECP_MAX_BITS) 319 #if MBEDTLS_ECP_MAX_BITS < MBEDTLS_ECP_MAX_BITS_MIN 320 #error "MBEDTLS_ECP_MAX_BITS is smaller than the largest supported curve" 323 #elif defined(MBEDTLS_ECP_C) 327 #define MBEDTLS_ECP_MAX_BITS MBEDTLS_ECP_MAX_BITS_MIN 333 #define MBEDTLS_ECP_MAX_BITS 1 336 #define MBEDTLS_ECP_MAX_BYTES ((MBEDTLS_ECP_MAX_BITS + 7) / 8) 337 #define MBEDTLS_ECP_MAX_PT_LEN (2 * MBEDTLS_ECP_MAX_BYTES + 1) 339 #if !defined(MBEDTLS_ECP_WINDOW_SIZE) 360 #define MBEDTLS_ECP_WINDOW_SIZE 4 363 #if !defined(MBEDTLS_ECP_FIXED_POINT_OPTIM) 375 #define MBEDTLS_ECP_FIXED_POINT_OPTIM 1 384 #if defined(MBEDTLS_ECP_RESTARTABLE) 391 typedef struct mbedtls_ecp_restart_mul mbedtls_ecp_restart_mul_ctx;
398 typedef struct mbedtls_ecp_restart_muladd mbedtls_ecp_restart_muladd_ctx;
406 mbedtls_ecp_restart_mul_ctx *rsm;
407 mbedtls_ecp_restart_muladd_ctx *ma;
413 #define MBEDTLS_ECP_OPS_CHK 3 414 #define MBEDTLS_ECP_OPS_DBL 8 415 #define MBEDTLS_ECP_OPS_ADD 11 416 #define MBEDTLS_ECP_OPS_INV 120 429 int mbedtls_ecp_check_budget(const mbedtls_ecp_group *grp, 434 #define MBEDTLS_ECP_BUDGET(ops) \ 435 MBEDTLS_MPI_CHK(mbedtls_ecp_check_budget(grp, rs_ctx, \ 440 #define MBEDTLS_ECP_BUDGET(ops) 465 #define MBEDTLS_ECP_PF_UNCOMPRESSED 0 466 #define MBEDTLS_ECP_PF_COMPRESSED 1 471 #define MBEDTLS_ECP_TLS_NAMED_CURVE 3 473 #if defined(MBEDTLS_ECP_RESTARTABLE) 531 void mbedtls_ecp_set_max_ops(
unsigned max_ops);
539 int mbedtls_ecp_restart_is_enabled(
void);
660 #if defined(MBEDTLS_ECP_RESTARTABLE) 756 const char *x,
const char *y);
785 int format,
size_t *olen,
786 unsigned char *buf,
size_t buflen);
812 const unsigned char *buf,
size_t ilen);
834 const unsigned char **buf,
size_t len);
860 int format,
size_t *olen,
861 unsigned char *buf,
size_t blen);
900 const unsigned char **buf,
size_t len);
921 const unsigned char **buf,
943 unsigned char *buf,
size_t blen);
983 int (*f_rng)(
void *,
unsigned char *,
size_t),
void *p_rng);
1017 int (*f_rng)(
void *,
unsigned char *,
size_t),
void *p_rng,
1020 #if defined(MBEDTLS_ECP_SHORT_WEIERSTRASS_ENABLED) 1038 return grp->
A.
p == NULL;
1196 int (*f_rng)(
void *,
unsigned char *,
size_t),
1229 int (*f_rng)(
void *,
unsigned char *,
size_t),
1257 int (*f_rng)(
void *,
unsigned char *,
size_t),
1274 int (*f_rng)(
void *,
unsigned char *,
size_t),
1296 const unsigned char *buf,
size_t buflen);
1315 unsigned char *buf,
size_t buflen);
1337 #if defined(MBEDTLS_SELF_TEST)
int(* modp)(mbedtls_mpi *)
int mbedtls_ecp_is_zero(mbedtls_ecp_point *pt)
This function checks if a point is the point at infinity.
int mbedtls_ecp_mul_restartable(mbedtls_ecp_group *grp, mbedtls_ecp_point *R, const mbedtls_mpi *m, const mbedtls_ecp_point *P, int(*f_rng)(void *, unsigned char *, size_t), void *p_rng, mbedtls_ecp_restart_ctx *rs_ctx)
This function performs multiplication of a point by an integer: R = m * P in a restartable way...
int(* t_post)(mbedtls_ecp_point *, void *)
int mbedtls_ecp_muladd(mbedtls_ecp_group *grp, mbedtls_ecp_point *R, const mbedtls_mpi *m, const mbedtls_ecp_point *P, const mbedtls_mpi *n, const mbedtls_ecp_point *Q)
This function performs multiplication and addition of two points by integers: R = m * P + n * Q...
int mbedtls_ecp_check_pub_priv(const mbedtls_ecp_keypair *pub, const mbedtls_ecp_keypair *prv)
This function checks that the keypair objects pub and prv have the same group and the same public poi...
int mbedtls_ecp_point_read_binary(const mbedtls_ecp_group *grp, mbedtls_ecp_point *P, const unsigned char *buf, size_t ilen)
This function imports a point from unsigned binary data.
mbedtls_ecp_curve_type mbedtls_ecp_get_type(const mbedtls_ecp_group *grp)
int mbedtls_ecp_muladd_restartable(mbedtls_ecp_group *grp, mbedtls_ecp_point *R, const mbedtls_mpi *m, const mbedtls_ecp_point *P, const mbedtls_mpi *n, const mbedtls_ecp_point *Q, mbedtls_ecp_restart_ctx *rs_ctx)
This function performs multiplication and addition of two points by integers: R = m * P + n * Q in a ...
struct mbedtls_ecp_curve_info mbedtls_ecp_curve_info
The ECP key-pair structure.
int mbedtls_ecp_set_zero(mbedtls_ecp_point *pt)
This function sets a point to the point at infinity.
int mbedtls_ecp_copy(mbedtls_ecp_point *P, const mbedtls_ecp_point *Q)
This function copies the contents of point Q into point P.
const mbedtls_ecp_group_id * mbedtls_ecp_grp_id_list(void)
This function retrieves the list of internal group identifiers of all supported curves in the order o...
int mbedtls_ecp_group_copy(mbedtls_ecp_group *dst, const mbedtls_ecp_group *src)
This function copies the contents of group src into group dst.
Configuration options (set of defines)
struct mbedtls_ecp_group mbedtls_ecp_group
The ECP group structure.
int mbedtls_ecp_gen_keypair(mbedtls_ecp_group *grp, mbedtls_mpi *d, mbedtls_ecp_point *Q, int(*f_rng)(void *, unsigned char *, size_t), void *p_rng)
This function generates an ECP keypair.
void mbedtls_ecp_point_free(mbedtls_ecp_point *pt)
This function frees the components of a point.
int mbedtls_ecp_gen_privkey(const mbedtls_ecp_group *grp, mbedtls_mpi *d, int(*f_rng)(void *, unsigned char *, size_t), void *p_rng)
This function generates a private key.
void mbedtls_ecp_keypair_init(mbedtls_ecp_keypair *key)
This function initializes a key pair as an invalid one.
Multi-precision integer library.
int mbedtls_ecp_gen_key(mbedtls_ecp_group_id grp_id, mbedtls_ecp_keypair *key, int(*f_rng)(void *, unsigned char *, size_t), void *p_rng)
This function generates an ECP key.
int mbedtls_ecp_check_privkey(const mbedtls_ecp_group *grp, const mbedtls_mpi *d)
This function checks that an mbedtls_mpi is a valid private key for this curve.
const mbedtls_ecp_curve_info * mbedtls_ecp_curve_info_from_grp_id(mbedtls_ecp_group_id grp_id)
This function retrieves curve information from an internal group identifier.
int mbedtls_ecp_tls_write_group(const mbedtls_ecp_group *grp, size_t *olen, unsigned char *buf, size_t blen)
This function exports an elliptic curve as a TLS ECParameters record as defined in RFC 4492...
void mbedtls_ecp_group_free(mbedtls_ecp_group *grp)
This function frees the components of an ECP group.
int mbedtls_ecp_mul(mbedtls_ecp_group *grp, mbedtls_ecp_point *R, const mbedtls_mpi *m, const mbedtls_ecp_point *P, int(*f_rng)(void *, unsigned char *, size_t), void *p_rng)
This function performs a scalar multiplication of a point by an integer: R = m * P.
int mbedtls_ecp_check_pubkey(const mbedtls_ecp_group *grp, const mbedtls_ecp_point *pt)
This function checks that a point is a valid public key on this curve.
int mbedtls_ecp_write_key(mbedtls_ecp_keypair *key, unsigned char *buf, size_t buflen)
This function exports an elliptic curve private key.
static int mbedtls_ecp_group_a_is_minus_3(const mbedtls_ecp_group *grp)
This function checks if domain parameter A of the curve is -3.
void mbedtls_ecp_keypair_free(mbedtls_ecp_keypair *key)
This function frees the components of a key pair.
struct mbedtls_ecp_keypair mbedtls_ecp_keypair
The ECP key-pair structure.
int mbedtls_ecp_tls_read_group(mbedtls_ecp_group *grp, const unsigned char **buf, size_t len)
This function sets up an ECP group context from a TLS ECParameters record as defined in RFC 4492...
void mbedtls_ecp_restart_ctx
void mbedtls_ecp_point_init(mbedtls_ecp_point *pt)
This function initializes a point as zero.
int mbedtls_ecp_point_read_string(mbedtls_ecp_point *P, int radix, const char *x, const char *y)
This function imports a non-zero point from two ASCII strings.
int mbedtls_ecp_self_test(int verbose)
The ECP checkup routine.
int mbedtls_ecp_point_write_binary(const mbedtls_ecp_group *grp, const mbedtls_ecp_point *P, int format, size_t *olen, unsigned char *buf, size_t buflen)
This function exports a point into unsigned binary data.
const mbedtls_ecp_curve_info * mbedtls_ecp_curve_info_from_tls_id(uint16_t tls_id)
This function retrieves curve information from a TLS NamedCurve value.
int mbedtls_ecp_tls_read_point(const mbedtls_ecp_group *grp, mbedtls_ecp_point *pt, const unsigned char **buf, size_t len)
This function imports a point from a TLS ECPoint record.
mbedtls_ecp_group_id grp_id
int mbedtls_ecp_tls_read_group_id(mbedtls_ecp_group_id *grp, const unsigned char **buf, size_t len)
This function extracts an elliptic curve group ID from a TLS ECParameters record as defined in RFC 44...
int mbedtls_ecp_gen_keypair_base(mbedtls_ecp_group *grp, const mbedtls_ecp_point *G, mbedtls_mpi *d, mbedtls_ecp_point *Q, int(*f_rng)(void *, unsigned char *, size_t), void *p_rng)
This function generates a keypair with a configurable base point.
int mbedtls_ecp_point_cmp(const mbedtls_ecp_point *P, const mbedtls_ecp_point *Q)
This function compares two points.
int mbedtls_ecp_tls_write_point(const mbedtls_ecp_group *grp, const mbedtls_ecp_point *pt, int format, size_t *olen, unsigned char *buf, size_t blen)
This function exports a point as a TLS ECPoint record defined in RFC 4492, Section 5...
struct mbedtls_ecp_point mbedtls_ecp_point
The ECP point structure, in Jacobian coordinates.
The ECP point structure, in Jacobian coordinates.
const mbedtls_ecp_curve_info * mbedtls_ecp_curve_info_from_name(const char *name)
This function retrieves curve information from a human-readable name.
const mbedtls_ecp_curve_info * mbedtls_ecp_curve_list(void)
This function retrieves the information defined in mbedtls_ecp_curve_info() for all supported curves...
int mbedtls_ecp_read_key(mbedtls_ecp_group_id grp_id, mbedtls_ecp_keypair *key, const unsigned char *buf, size_t buflen)
This function reads an elliptic curve private key.
int(* t_pre)(mbedtls_ecp_point *, void *)
int mbedtls_ecp_group_load(mbedtls_ecp_group *grp, mbedtls_ecp_group_id id)
This function sets up an ECP group context from a standardized set of domain parameters.
void mbedtls_ecp_group_init(mbedtls_ecp_group *grp)
This function initializes an ECP group context without loading any domain parameters.