27 #ifndef POLARSSL_ECP_H
28 #define POLARSSL_ECP_H
35 #define POLARSSL_ERR_ECP_BAD_INPUT_DATA -0x4F80
36 #define POLARSSL_ERR_ECP_BUFFER_TOO_SMALL -0x4F00
37 #define POLARSSL_ERR_ECP_FEATURE_UNAVAILABLE -0x4E80
38 #define POLARSSL_ERR_ECP_VERIFY_FAILED -0x4E00
39 #define POLARSSL_ERR_ECP_MALLOC_FAILED -0x4D80
40 #define POLARSSL_ERR_ECP_RANDOM_FAILED -0x4D00
41 #define POLARSSL_ERR_ECP_INVALID_KEY -0x4C80
72 #define POLARSSL_ECP_DP_MAX 9
155 #define POLARSSL_ECP_MAX_BITS 521
156 #define POLARSSL_ECP_MAX_BYTES ( ( POLARSSL_ECP_MAX_BITS + 7 ) / 8 )
157 #define POLARSSL_ECP_MAX_PT_LEN ( 2 * POLARSSL_ECP_MAX_BYTES + 1 )
169 #define POLARSSL_ECP_WINDOW_SIZE 8
174 #define POLARSSL_ECP_PF_UNCOMPRESSED 0
175 #define POLARSSL_ECP_PF_COMPRESSED 1
180 #define POLARSSL_ECP_TLS_NAMED_CURVE 3
187 const ecp_curve_info *ecp_curve_list( void );
289 const char *x,
const char *y );
306 int format,
size_t *olen,
307 unsigned char *buf,
size_t buflen );
326 const unsigned char *buf,
size_t ilen );
341 const unsigned char **buf,
size_t len );
358 int format,
size_t *olen,
359 unsigned char *buf,
size_t blen );
377 const char *p,
const char *b,
378 const char *gx,
const char *gy,
const char *n);
420 unsigned char *buf,
size_t blen );
481 int (*f_rng)(
void *,
unsigned char *,
size_t),
void *p_rng );
539 int (*f_rng)(
void *,
unsigned char *,
size_t),
int ecp_sub(const ecp_group *grp, ecp_point *R, const ecp_point *P, const ecp_point *Q)
Subtraction: R = P - Q.
int ecp_check_privkey(const ecp_group *grp, const mpi *d)
Check that an mpi is a valid private key for this curve.
void ecp_keypair_init(ecp_keypair *key)
Initialize a key pair (as an invalid one)
int ecp_group_copy(ecp_group *dst, const ecp_group *src)
Copy the contents of a group object.
int ecp_self_test(int verbose)
Checkup routine.
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) ...
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.
Multi-precision integer library.
ECP point structure (jacobian coordinates)
int ecp_is_zero(ecp_point *pt)
Tell if a point is zero.
void ecp_point_init(ecp_point *pt)
Initialize a point (as zero)
const ecp_curve_info * ecp_curve_info_from_grp_id(ecp_group_id grp_id)
Get curve information from an internal group identifier.
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.
void ecp_group_free(ecp_group *grp)
Free the components of an ECP group.
Curve information for use by other modules.
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.
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.
int ecp_use_known_dp(ecp_group *grp, ecp_group_id index)
Set a group using well-known domain parameters.
int ecp_copy(ecp_point *P, const ecp_point *Q)
Copy the contents of point Q into P.
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.
ecp_group_id
Domain parameters (curve, subgroup and generator) identifiers.
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.
void ecp_group_init(ecp_group *grp)
Initialize a group (to something meaningless)
int ecp_tls_read_group(ecp_group *grp, const unsigned char **buf, size_t len)
Set a group from a TLS ECParameters record.
int ecp_check_pubkey(const ecp_group *grp, const ecp_point *pt)
Check that a point is a valid public key on this curve.
const ecp_curve_info * ecp_curve_info_from_tls_id(uint16_t tls_id)
Get curve information from a TLS NamedCurve value.
int ecp_add(const ecp_group *grp, ecp_point *R, const ecp_point *P, const ecp_point *Q)
Addition: R = P + Q.
int ecp_set_zero(ecp_point *pt)
Set a point to zero.
void ecp_keypair_free(ecp_keypair *key)
Free the components of a key pair.
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.
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.
void ecp_point_free(ecp_point *pt)
Free the components of a point.