mbed TLS v1.3.19
|
Elliptic curves over GF(p) More...
#include "bignum.h"
Go to the source code of this file.
Data Structures | |
struct | ecp_curve_info |
Curve information for use by other modules. More... | |
struct | ecp_point |
ECP point structure (jacobian coordinates) More... | |
struct | ecp_group |
ECP group structure. More... | |
struct | ecp_keypair |
ECP key pair structure. More... | |
Macros | |
#define | POLARSSL_ERR_ECP_BAD_INPUT_DATA -0x4F80 |
Bad input parameters to function. More... | |
#define | POLARSSL_ERR_ECP_BUFFER_TOO_SMALL -0x4F00 |
The buffer is too small to write to. More... | |
#define | POLARSSL_ERR_ECP_FEATURE_UNAVAILABLE -0x4E80 |
Requested curve not available. More... | |
#define | POLARSSL_ERR_ECP_VERIFY_FAILED -0x4E00 |
The signature is not valid. More... | |
#define | POLARSSL_ERR_ECP_MALLOC_FAILED -0x4D80 |
Memory allocation failed. More... | |
#define | POLARSSL_ERR_ECP_RANDOM_FAILED -0x4D00 |
Generation of random value, such as (ephemeral) key, failed. More... | |
#define | POLARSSL_ERR_ECP_INVALID_KEY -0x4C80 |
Invalid private or public key. More... | |
#define | POLARSSL_ERR_ECP_SIG_LEN_MISMATCH -0x4C00 |
Signature is valid but shorter than the user-supplied length. More... | |
#define | POLARSSL_ECP_DP_MAX 12 |
Number of supported curves (plus one for NONE). More... | |
#define | POLARSSL_ECP_PF_UNCOMPRESSED 0 |
Uncompressed point format. More... | |
#define | POLARSSL_ECP_PF_COMPRESSED 1 |
Compressed point format. More... | |
#define | POLARSSL_ECP_TLS_NAMED_CURVE 3 |
ECCurveType's named_curve. More... | |
SECTION: Module settings | |
The configuration options you can set for this module are in this section. Either change them in config.h or define them on the compiler command line. | |
#define | POLARSSL_ECP_MAX_BITS 521 |
Maximum size of the groups (that is, of N and P) More... | |
#define | POLARSSL_ECP_MAX_BYTES ( ( POLARSSL_ECP_MAX_BITS + 7 ) / 8 ) |
#define | POLARSSL_ECP_MAX_PT_LEN ( 2 * POLARSSL_ECP_MAX_BYTES + 1 ) |
#define | POLARSSL_ECP_WINDOW_SIZE 6 |
Maximum window size used. More... | |
#define | POLARSSL_ECP_FIXED_POINT_OPTIM 1 |
Enable fixed-point speed-up. More... | |
Enumerations | |
enum | ecp_group_id { POLARSSL_ECP_DP_NONE = 0, POLARSSL_ECP_DP_SECP192R1, POLARSSL_ECP_DP_SECP224R1, POLARSSL_ECP_DP_SECP256R1, POLARSSL_ECP_DP_SECP384R1, POLARSSL_ECP_DP_SECP521R1, POLARSSL_ECP_DP_BP256R1, POLARSSL_ECP_DP_BP384R1, POLARSSL_ECP_DP_BP512R1, POLARSSL_ECP_DP_M221, POLARSSL_ECP_DP_M255, POLARSSL_ECP_DP_M383, POLARSSL_ECP_DP_M511, POLARSSL_ECP_DP_SECP192K1, POLARSSL_ECP_DP_SECP224K1, POLARSSL_ECP_DP_SECP256K1 } |
Domain parameters (curve, subgroup and generator) identifiers. More... | |
Functions | |
const ecp_curve_info * | ecp_curve_list (void) |
Get the list of supported curves in order of preferrence (full information) More... | |
const ecp_group_id * | ecp_grp_id_list (void) |
Get the list of supported curves in order of preferrence (grp_id only) More... | |
const ecp_curve_info * | ecp_curve_info_from_grp_id (ecp_group_id grp_id) |
Get curve information from an internal group identifier. More... | |
const ecp_curve_info * | ecp_curve_info_from_tls_id (uint16_t tls_id) |
Get curve information from a TLS NamedCurve value. More... | |
const ecp_curve_info * | ecp_curve_info_from_name (const char *name) |
Get curve information from a human-readable name. More... | |
void | ecp_point_init (ecp_point *pt) |
Initialize a point (as zero) More... | |
void | ecp_group_init (ecp_group *grp) |
Initialize a group (to something meaningless) More... | |
void | ecp_keypair_init (ecp_keypair *key) |
Initialize a key pair (as an invalid one) More... | |
void | ecp_point_free (ecp_point *pt) |
Free the components of a point. More... | |
void | ecp_group_free (ecp_group *grp) |
Free the components of an ECP group. More... | |
void | ecp_keypair_free (ecp_keypair *key) |
Free the components of a key pair. More... | |
int | ecp_copy (ecp_point *P, const ecp_point *Q) |
Copy the contents of point Q into P. More... | |
int | ecp_group_copy (ecp_group *dst, const ecp_group *src) |
Copy the contents of a group object. More... | |
int | ecp_set_zero (ecp_point *pt) |
Set a point to zero. More... | |
int | ecp_is_zero (ecp_point *pt) |
Tell if a point is zero. More... | |
int | ecp_point_read_string (ecp_point *P, int radix, const char *x, const char *y) |
Import a non-zero point from two ASCII strings. More... | |
int | ecp_point_write_binary (const ecp_group *grp, const ecp_point *P, int format, size_t *olen, unsigned char *buf, size_t buflen) |
Export a point into unsigned binary data. More... | |
int | ecp_point_read_binary (const ecp_group *grp, ecp_point *P, const unsigned char *buf, size_t ilen) |
Import a point from unsigned binary data. More... | |
int | ecp_tls_read_point (const ecp_group *grp, ecp_point *pt, const unsigned char **buf, size_t len) |
Import a point from a TLS ECPoint record. More... | |
int | ecp_tls_write_point (const ecp_group *grp, const ecp_point *pt, int format, size_t *olen, unsigned char *buf, size_t blen) |
Export a point as a TLS ECPoint record. More... | |
int | ecp_group_read_string (ecp_group *grp, int radix, const char *p, const char *b, const char *gx, const char *gy, const char *n) |
Import an ECP group from null-terminated ASCII strings. More... | |
int | ecp_use_known_dp (ecp_group *grp, ecp_group_id index) |
Set a group using well-known domain parameters. More... | |
int | ecp_tls_read_group (ecp_group *grp, const unsigned char **buf, size_t len) |
Set a group from a TLS ECParameters record. More... | |
int | ecp_tls_write_group (const ecp_group *grp, size_t *olen, unsigned char *buf, size_t blen) |
Write the TLS ECParameters record for a group. More... | |
int | ecp_add (const ecp_group *grp, ecp_point *R, const ecp_point *P, const ecp_point *Q) |
Addition: R = P + Q. More... | |
int | ecp_sub (const ecp_group *grp, ecp_point *R, const ecp_point *P, const ecp_point *Q) |
Subtraction: R = P - Q. More... | |
int | ecp_mul (ecp_group *grp, ecp_point *R, const mpi *m, const ecp_point *P, int(*f_rng)(void *, unsigned char *, size_t), void *p_rng) |
Multiplication by an integer: R = m * P (Not thread-safe to use same group in multiple threads) More... | |
int | ecp_check_pubkey (const ecp_group *grp, const ecp_point *pt) |
Check that a point is a valid public key on this curve. More... | |
int | ecp_check_privkey (const ecp_group *grp, const mpi *d) |
Check that an mpi is a valid private key for this curve. More... | |
int | ecp_gen_keypair (ecp_group *grp, mpi *d, ecp_point *Q, int(*f_rng)(void *, unsigned char *, size_t), void *p_rng) |
Generate a keypair. More... | |
int | ecp_gen_key (ecp_group_id grp_id, ecp_keypair *key, int(*f_rng)(void *, unsigned char *, size_t), void *p_rng) |
Generate a keypair. More... | |
int | ecp_check_pub_priv (const ecp_keypair *pub, const ecp_keypair *prv) |
Check a public-private key pair. More... | |
int | ecp_self_test (int verbose) |
Checkup routine. More... | |
Elliptic curves over GF(p)
Copyright (C) 2006-2013, ARM Limited, All Rights Reserved
This file is part of mbed TLS (https://tls.mbed.org)
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
Definition in file ecp.h.
#define POLARSSL_ECP_DP_MAX 12 |
#define POLARSSL_ECP_FIXED_POINT_OPTIM 1 |
#define POLARSSL_ECP_MAX_BITS 521 |
#define POLARSSL_ECP_MAX_BYTES ( ( POLARSSL_ECP_MAX_BITS + 7 ) / 8 ) |
#define POLARSSL_ECP_MAX_PT_LEN ( 2 * POLARSSL_ECP_MAX_BYTES + 1 ) |
#define POLARSSL_ECP_PF_UNCOMPRESSED 0 |
#define POLARSSL_ECP_TLS_NAMED_CURVE 3 |
#define POLARSSL_ERR_ECP_BAD_INPUT_DATA -0x4F80 |
#define POLARSSL_ERR_ECP_BUFFER_TOO_SMALL -0x4F00 |
#define POLARSSL_ERR_ECP_FEATURE_UNAVAILABLE -0x4E80 |
#define POLARSSL_ERR_ECP_INVALID_KEY -0x4C80 |
#define POLARSSL_ERR_ECP_MALLOC_FAILED -0x4D80 |
#define POLARSSL_ERR_ECP_RANDOM_FAILED -0x4D00 |
#define POLARSSL_ERR_ECP_SIG_LEN_MISMATCH -0x4C00 |
#define POLARSSL_ERR_ECP_VERIFY_FAILED -0x4E00 |
enum ecp_group_id |
Domain parameters (curve, subgroup and generator) identifiers.
Only curves over prime fields are supported.
Addition: R = P + Q.
grp | ECP group |
R | Destination point |
P | Left-hand point |
Q | Right-hand point |
Check that an mpi is a valid private key for this curve.
grp | Group used |
d | Integer to check |
int ecp_check_pub_priv | ( | const ecp_keypair * | pub, |
const ecp_keypair * | prv | ||
) |
Check a public-private key pair.
pub | Keypair structure holding a public key |
prv | Keypair structure holding a private (plus public) key |
Check that a point is a valid public key on this curve.
grp | Curve/group the point should belong to |
pt | Point to check |
Copy the contents of point Q into P.
P | Destination point |
Q | Source point |
const ecp_curve_info* ecp_curve_info_from_grp_id | ( | ecp_group_id | grp_id | ) |
Get curve information from an internal group identifier.
grp_id | A POLARSSL_ECP_DP_XXX value |
const ecp_curve_info* ecp_curve_info_from_name | ( | const char * | name | ) |
Get curve information from a human-readable name.
name | The name |
const ecp_curve_info* ecp_curve_info_from_tls_id | ( | uint16_t | tls_id | ) |
Get curve information from a TLS NamedCurve value.
tls_id | A POLARSSL_ECP_DP_XXX value |
const ecp_curve_info* ecp_curve_list | ( | void | ) |
Get the list of supported curves in order of preferrence (full information)
int ecp_gen_key | ( | ecp_group_id | grp_id, |
ecp_keypair * | key, | ||
int(*)(void *, unsigned char *, size_t) | f_rng, | ||
void * | p_rng | ||
) |
Generate a keypair.
grp_id | ECP group identifier |
key | Destination keypair |
f_rng | RNG function |
p_rng | RNG parameter |
int ecp_gen_keypair | ( | ecp_group * | grp, |
mpi * | d, | ||
ecp_point * | Q, | ||
int(*)(void *, unsigned char *, size_t) | f_rng, | ||
void * | p_rng | ||
) |
Generate a keypair.
grp | ECP group |
d | Destination MPI (secret part) |
Q | Destination point (public part) |
f_rng | RNG function |
p_rng | RNG parameter |
Copy the contents of a group object.
dst | Destination group |
src | Source group |
void ecp_group_free | ( | ecp_group * | grp | ) |
Free the components of an ECP group.
void ecp_group_init | ( | ecp_group * | grp | ) |
Initialize a group (to something meaningless)
int ecp_group_read_string | ( | ecp_group * | grp, |
int | radix, | ||
const char * | p, | ||
const char * | b, | ||
const char * | gx, | ||
const char * | gy, | ||
const char * | n | ||
) |
Import an ECP group from null-terminated ASCII strings.
grp | Destination group |
radix | Input numeric base |
p | Prime modulus of the base field |
b | Constant term in the equation |
gx | The generator's X coordinate |
gy | The generator's Y coordinate |
n | The generator's order |
const ecp_group_id* ecp_grp_id_list | ( | void | ) |
Get the list of supported curves in order of preferrence (grp_id only)
int ecp_is_zero | ( | ecp_point * | pt | ) |
Tell if a point is zero.
pt | Point to test |
void ecp_keypair_free | ( | ecp_keypair * | key | ) |
Free the components of a key pair.
void ecp_keypair_init | ( | ecp_keypair * | key | ) |
Initialize a key pair (as an invalid one)
int ecp_mul | ( | ecp_group * | grp, |
ecp_point * | R, | ||
const mpi * | m, | ||
const ecp_point * | P, | ||
int(*)(void *, unsigned char *, size_t) | f_rng, | ||
void * | p_rng | ||
) |
Multiplication by an integer: R = m * P (Not thread-safe to use same group in multiple threads)
grp | ECP group |
R | Destination point |
m | Integer by which to multiply |
P | Point to multiply |
f_rng | RNG function (see notes) |
p_rng | RNG parameter |
void ecp_point_free | ( | ecp_point * | pt | ) |
Free the components of a point.
void ecp_point_init | ( | ecp_point * | pt | ) |
Initialize a point (as zero)
int ecp_point_read_binary | ( | const ecp_group * | grp, |
ecp_point * | P, | ||
const unsigned char * | buf, | ||
size_t | ilen | ||
) |
Import a point from unsigned binary data.
grp | Group to which the point should belong |
P | Point to import |
buf | Input buffer |
ilen | Actual length of input |
int ecp_point_read_string | ( | ecp_point * | P, |
int | radix, | ||
const char * | x, | ||
const char * | y | ||
) |
Import a non-zero point from two ASCII strings.
P | Destination point |
radix | Input numeric base |
x | First affine coordinate as a null-terminated string |
y | Second affine coordinate as a null-terminated string |
int ecp_point_write_binary | ( | const ecp_group * | grp, |
const ecp_point * | P, | ||
int | format, | ||
size_t * | olen, | ||
unsigned char * | buf, | ||
size_t | buflen | ||
) |
Export a point into unsigned binary data.
grp | Group to which the point should belong |
P | Point to export |
format | Point format, should be a POLARSSL_ECP_PF_XXX macro |
olen | Length of the actual output |
buf | Output buffer |
buflen | Length of the output buffer |
int ecp_self_test | ( | int | verbose | ) |
Checkup routine.
int ecp_set_zero | ( | ecp_point * | pt | ) |
Set a point to zero.
pt | Destination point |
Subtraction: R = P - Q.
grp | ECP group |
R | Destination point |
P | Left-hand point |
Q | Right-hand point |
int ecp_tls_read_group | ( | ecp_group * | grp, |
const unsigned char ** | buf, | ||
size_t | len | ||
) |
Set a group from a TLS ECParameters record.
grp | Destination group |
buf | &(Start of input buffer) |
len | Buffer length |
int ecp_tls_read_point | ( | const ecp_group * | grp, |
ecp_point * | pt, | ||
const unsigned char ** | buf, | ||
size_t | len | ||
) |
Import a point from a TLS ECPoint record.
grp | ECP group used |
pt | Destination point |
buf | $(Start of input buffer) |
len | Buffer length |
int ecp_tls_write_group | ( | const ecp_group * | grp, |
size_t * | olen, | ||
unsigned char * | buf, | ||
size_t | blen | ||
) |
Write the TLS ECParameters record for a group.
grp | ECP group used |
olen | Number of bytes actually written |
buf | Buffer to write to |
blen | Buffer length |
int ecp_tls_write_point | ( | const ecp_group * | grp, |
const ecp_point * | pt, | ||
int | format, | ||
size_t * | olen, | ||
unsigned char * | buf, | ||
size_t | blen | ||
) |
Export a point as a TLS ECPoint record.
grp | ECP group used |
pt | Point to export |
format | Export format |
olen | length of data written |
buf | Buffer to write to |
blen | Buffer length |
int ecp_use_known_dp | ( | ecp_group * | grp, |
ecp_group_id | index | ||
) |
Set a group using well-known domain parameters.
grp | Destination group |
index | Index in the list of well-known domain parameters |