mbed TLS v2.0.0
ecp.h
Go to the documentation of this file.
1 
24 #ifndef MBEDTLS_ECP_H
25 #define MBEDTLS_ECP_H
26 
27 #include "bignum.h"
28 
29 /*
30  * ECP error codes
31  */
32 #define MBEDTLS_ERR_ECP_BAD_INPUT_DATA -0x4F80
33 #define MBEDTLS_ERR_ECP_BUFFER_TOO_SMALL -0x4F00
34 #define MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE -0x4E80
35 #define MBEDTLS_ERR_ECP_VERIFY_FAILED -0x4E00
36 #define MBEDTLS_ERR_ECP_ALLOC_FAILED -0x4D80
37 #define MBEDTLS_ERR_ECP_RANDOM_FAILED -0x4D00
38 #define MBEDTLS_ERR_ECP_INVALID_KEY -0x4C80
39 #define MBEDTLS_ERR_ECP_SIG_LEN_MISMATCH -0x4C00
41 #ifdef __cplusplus
42 extern "C" {
43 #endif
44 
54 typedef enum
55 {
70 
76 #define MBEDTLS_ECP_DP_MAX 12
77 
81 typedef struct
82 {
84  uint16_t tls_id;
85  uint16_t bit_size;
86  const char *name;
88 
98 typedef struct
99 {
103 }
105 
130 typedef struct
131 {
138  size_t pbits;
139  size_t nbits;
140  unsigned int h;
141  int (*modp)(mbedtls_mpi *);
142  int (*t_pre)(mbedtls_ecp_point *, void *);
143  int (*t_post)(mbedtls_ecp_point *, void *);
144  void *t_data;
146  size_t T_size;
147 }
149 
157 typedef struct
158 {
162 }
164 
173 #if !defined(MBEDTLS_ECP_MAX_BITS)
174 
177 #define MBEDTLS_ECP_MAX_BITS 521
178 #endif
179 
180 #define MBEDTLS_ECP_MAX_BYTES ( ( MBEDTLS_ECP_MAX_BITS + 7 ) / 8 )
181 #define MBEDTLS_ECP_MAX_PT_LEN ( 2 * MBEDTLS_ECP_MAX_BYTES + 1 )
182 
183 #if !defined(MBEDTLS_ECP_WINDOW_SIZE)
184 /*
185  * Maximum "window" size used for point multiplication.
186  * Default: 6.
187  * Minimum value: 2. Maximum value: 7.
188  *
189  * Result is an array of at most ( 1 << ( MBEDTLS_ECP_WINDOW_SIZE - 1 ) )
190  * points used for point multiplication. This value is directly tied to EC
191  * peak memory usage, so decreasing it by one should roughly cut memory usage
192  * by two (if large curves are in use).
193  *
194  * Reduction in size may reduce speed, but larger curves are impacted first.
195  * Sample performances (in ECDHE handshakes/s, with FIXED_POINT_OPTIM = 1):
196  * w-size: 6 5 4 3 2
197  * 521 145 141 135 120 97
198  * 384 214 209 198 177 146
199  * 256 320 320 303 262 226
200 
201  * 224 475 475 453 398 342
202  * 192 640 640 633 587 476
203  */
204 #define MBEDTLS_ECP_WINDOW_SIZE 6
205 #endif /* MBEDTLS_ECP_WINDOW_SIZE */
206 
207 #if !defined(MBEDTLS_ECP_FIXED_POINT_OPTIM)
208 /*
209  * Trade memory for speed on fixed-point multiplication.
210  *
211  * This speeds up repeated multiplication of the generator (that is, the
212  * multiplication in ECDSA signatures, and half of the multiplications in
213  * ECDSA verification and ECDHE) by a factor roughly 3 to 4.
214  *
215  * The cost is increasing EC peak memory usage by a factor roughly 2.
216  *
217  * Change this value to 0 to reduce peak memory usage.
218  */
219 #define MBEDTLS_ECP_FIXED_POINT_OPTIM 1
220 #endif /* MBEDTLS_ECP_FIXED_POINT_OPTIM */
221 
222 /* \} name SECTION: Module settings */
223 
224 /*
225  * Point formats, from RFC 4492's enum ECPointFormat
226  */
227 #define MBEDTLS_ECP_PF_UNCOMPRESSED 0
228 #define MBEDTLS_ECP_PF_COMPRESSED 1
230 /*
231  * Some other constants from RFC 4492
232  */
233 #define MBEDTLS_ECP_TLS_NAMED_CURVE 3
241 const mbedtls_ecp_curve_info *mbedtls_ecp_curve_list( void );
242 
251 
260 
269 
278 
283 
288 
293 
298 
303 
308 
319 
330 
340 
349 
361  const char *x, const char *y );
362 
378  int format, size_t *olen,
379  unsigned char *buf, size_t buflen );
380 
400  const unsigned char *buf, size_t ilen );
401 
417  const unsigned char **buf, size_t len );
418 
434  int format, size_t *olen,
435  unsigned char *buf, size_t blen );
436 
451 
465 int mbedtls_ecp_tls_read_group( mbedtls_ecp_group *grp, const unsigned char **buf, size_t len );
466 
478 int mbedtls_ecp_tls_write_group( const mbedtls_ecp_group *grp, size_t *olen,
479  unsigned char *buf, size_t blen );
480 
508  const mbedtls_mpi *m, const mbedtls_ecp_point *P,
509  int (*f_rng)(void *, unsigned char *, size_t), void *p_rng );
510 
532  const mbedtls_mpi *m, const mbedtls_ecp_point *P,
533  const mbedtls_mpi *n, const mbedtls_ecp_point *Q );
534 
557 
571 int mbedtls_ecp_check_privkey( const mbedtls_ecp_group *grp, const mbedtls_mpi *d );
572 
590  int (*f_rng)(void *, unsigned char *, size_t),
591  void *p_rng );
592 
605  int (*f_rng)(void *, unsigned char *, size_t), void *p_rng );
606 
618 
619 #if defined(MBEDTLS_SELF_TEST)
620 
625 int mbedtls_ecp_self_test( int verbose );
626 #endif
627 
628 #ifdef __cplusplus
629 }
630 #endif
631 
632 #endif /* ecp.h */
uint16_t tls_id
Definition: ecp.h:84
int mbedtls_ecp_is_zero(mbedtls_ecp_point *pt)
Tell if a point is zero.
mbedtls_mpi N
Definition: ecp.h:137
mbedtls_mpi Z
Definition: ecp.h:102
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)
Multiplication and addition of two points by integers: R = m * P + n * Q (Not thread-safe to use same...
int mbedtls_ecp_check_pub_priv(const mbedtls_ecp_keypair *pub, const mbedtls_ecp_keypair *prv)
Check a public-private key pair.
int mbedtls_ecp_point_read_binary(const mbedtls_ecp_group *grp, mbedtls_ecp_point *P, const unsigned char *buf, size_t ilen)
Import a point from unsigned binary data.
mbedtls_mpi Y
Definition: ecp.h:101
mbedtls_ecp_group grp
Definition: ecp.h:159
int mbedtls_ecp_group_load(mbedtls_ecp_group *grp, mbedtls_ecp_group_id index)
Set a group using well-known domain parameters.
ECP key pair structure.
Definition: ecp.h:157
int mbedtls_ecp_set_zero(mbedtls_ecp_point *pt)
Set a point to zero.
int mbedtls_ecp_copy(mbedtls_ecp_point *P, const mbedtls_ecp_point *Q)
Copy the contents of point Q into P.
const mbedtls_ecp_group_id * mbedtls_ecp_grp_id_list(void)
Get the list of supported curves in order of preferrence (grp_id only)
int mbedtls_ecp_group_copy(mbedtls_ecp_group *dst, const mbedtls_ecp_group *src)
Copy the contents of a group object.
size_t nbits
Definition: ecp.h:139
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)
Generate a keypair.
void mbedtls_ecp_point_free(mbedtls_ecp_point *pt)
Free the components of a point.
void mbedtls_ecp_keypair_init(mbedtls_ecp_keypair *key)
Initialize a key pair (as an invalid one)
size_t pbits
Definition: ecp.h:138
mbedtls_mpi X
Definition: ecp.h:100
Curve information for use by other modules.
Definition: ecp.h:81
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)
Generate a keypair.
ECP group structure.
Definition: ecp.h:130
int mbedtls_ecp_check_privkey(const mbedtls_ecp_group *grp, const mbedtls_mpi *d)
Check that an mbedtls_mpi is a valid private key for this curve.
mbedtls_ecp_group_id id
Definition: ecp.h:132
const mbedtls_ecp_curve_info * mbedtls_ecp_curve_info_from_grp_id(mbedtls_ecp_group_id grp_id)
Get 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)
Write the TLS ECParameters record for a group.
void mbedtls_ecp_group_free(mbedtls_ecp_group *grp)
Free 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)
Multiplication by an integer: R = m * P (Not thread-safe to use same group in multiple threads) ...
int mbedtls_ecp_check_pubkey(const mbedtls_ecp_group *grp, const mbedtls_ecp_point *pt)
Check that a point is a valid public key on this curve.
mbedtls_mpi A
Definition: ecp.h:134
mbedtls_mpi P
Definition: ecp.h:133
void mbedtls_ecp_keypair_free(mbedtls_ecp_keypair *key)
Free the components of a key pair.
int mbedtls_ecp_tls_read_group(mbedtls_ecp_group *grp, const unsigned char **buf, size_t len)
Set a group from a TLS ECParameters record.
mbedtls_ecp_point Q
Definition: ecp.h:161
void * t_data
Definition: ecp.h:144
void mbedtls_ecp_point_init(mbedtls_ecp_point *pt)
Initialize a point (as zero)
mbedtls_ecp_group_id
Domain parameters (curve, subgroup and generator) identifiers.
Definition: ecp.h:54
int mbedtls_ecp_point_read_string(mbedtls_ecp_point *P, int radix, const char *x, const char *y)
Import a non-zero point from two ASCII strings.
int mbedtls_ecp_self_test(int verbose)
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)
Export a point into unsigned binary data.
const mbedtls_ecp_curve_info * mbedtls_ecp_curve_info_from_tls_id(uint16_t tls_id)
Get 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)
Import a point from a TLS ECPoint record.
mbedtls_ecp_group_id grp_id
Definition: ecp.h:83
mbedtls_mpi d
Definition: ecp.h:160
unsigned int h
Definition: ecp.h:140
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)
Export a point as a TLS ECPoint record.
size_t T_size
Definition: ecp.h:146
mbedtls_ecp_point * T
Definition: ecp.h:145
mbedtls_ecp_point G
Definition: ecp.h:136
MPI structure.
Definition: bignum.h:144
ECP point structure (jacobian coordinates)
Definition: ecp.h:98
const mbedtls_ecp_curve_info * mbedtls_ecp_curve_info_from_name(const char *name)
Get curve information from a human-readable name.
const char * name
Definition: ecp.h:86
uint16_t bit_size
Definition: ecp.h:85
mbedtls_mpi B
Definition: ecp.h:135
void mbedtls_ecp_group_init(mbedtls_ecp_group *grp)
Initialize a group (to something meaningless)