RetroArch
ecp.h
Go to the documentation of this file.
1 
23 #ifndef MBEDTLS_ECP_H
24 #define MBEDTLS_ECP_H
25 
26 #include "bignum.h"
27 
28 /*
29  * ECP error codes
30  */
31 #define MBEDTLS_ERR_ECP_BAD_INPUT_DATA -0x4F80
32 #define MBEDTLS_ERR_ECP_BUFFER_TOO_SMALL -0x4F00
33 #define MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE -0x4E80
34 #define MBEDTLS_ERR_ECP_VERIFY_FAILED -0x4E00
35 #define MBEDTLS_ERR_ECP_ALLOC_FAILED -0x4D80
36 #define MBEDTLS_ERR_ECP_RANDOM_FAILED -0x4D00
37 #define MBEDTLS_ERR_ECP_INVALID_KEY -0x4C80
38 #define MBEDTLS_ERR_ECP_SIG_LEN_MISMATCH -0x4C00
40 #if !defined(MBEDTLS_ECP_ALT)
41 /*
42  * default mbed TLS elliptic curve arithmetic implementation
43  *
44  * (in case MBEDTLS_ECP_ALT is defined then the developer has to provide an
45  * alternative implementation for the whole module and it will replace this
46  * one.)
47  */
48 
49 #ifdef __cplusplus
50 extern "C" {
51 #endif
52 
62 typedef enum
63 {
78 
84 #define MBEDTLS_ECP_DP_MAX 12
85 
89 typedef struct
90 {
94  const char *name;
96 
106 typedef struct
107 {
111 }
113 
138 typedef struct
139 {
146  size_t pbits;
147  size_t nbits;
148  unsigned int h;
149  int (*modp)(mbedtls_mpi *);
150  int (*t_pre)(mbedtls_ecp_point *, void *);
151  int (*t_post)(mbedtls_ecp_point *, void *);
152  void *t_data;
154  size_t T_size;
155 }
157 
165 typedef struct
166 {
170 }
172 
181 #if !defined(MBEDTLS_ECP_MAX_BITS)
182 
185 #define MBEDTLS_ECP_MAX_BITS 521
186 #endif
187 
188 #define MBEDTLS_ECP_MAX_BYTES ( ( MBEDTLS_ECP_MAX_BITS + 7 ) / 8 )
189 #define MBEDTLS_ECP_MAX_PT_LEN ( 2 * MBEDTLS_ECP_MAX_BYTES + 1 )
190 
191 #if !defined(MBEDTLS_ECP_WINDOW_SIZE)
192 /*
193  * Maximum "window" size used for point multiplication.
194  * Default: 6.
195  * Minimum value: 2. Maximum value: 7.
196  *
197  * Result is an array of at most ( 1 << ( MBEDTLS_ECP_WINDOW_SIZE - 1 ) )
198  * points used for point multiplication. This value is directly tied to EC
199  * peak memory usage, so decreasing it by one should roughly cut memory usage
200  * by two (if large curves are in use).
201  *
202  * Reduction in size may reduce speed, but larger curves are impacted first.
203  * Sample performances (in ECDHE handshakes/s, with FIXED_POINT_OPTIM = 1):
204  * w-size: 6 5 4 3 2
205  * 521 145 141 135 120 97
206  * 384 214 209 198 177 146
207  * 256 320 320 303 262 226
208 
209  * 224 475 475 453 398 342
210  * 192 640 640 633 587 476
211  */
212 #define MBEDTLS_ECP_WINDOW_SIZE 6
213 #endif /* MBEDTLS_ECP_WINDOW_SIZE */
214 
215 #if !defined(MBEDTLS_ECP_FIXED_POINT_OPTIM)
216 /*
217  * Trade memory for speed on fixed-point multiplication.
218  *
219  * This speeds up repeated multiplication of the generator (that is, the
220  * multiplication in ECDSA signatures, and half of the multiplications in
221  * ECDSA verification and ECDHE) by a factor roughly 3 to 4.
222  *
223  * The cost is increasing EC peak memory usage by a factor roughly 2.
224  *
225  * Change this value to 0 to reduce peak memory usage.
226  */
227 #define MBEDTLS_ECP_FIXED_POINT_OPTIM 1
228 #endif /* MBEDTLS_ECP_FIXED_POINT_OPTIM */
229 
230 /* \} name SECTION: Module settings */
231 
232 /*
233  * Point formats, from RFC 4492's enum ECPointFormat
234  */
235 #define MBEDTLS_ECP_PF_UNCOMPRESSED 0
236 #define MBEDTLS_ECP_PF_COMPRESSED 1
238 /*
239  * Some other constants from RFC 4492
240  */
241 #define MBEDTLS_ECP_TLS_NAMED_CURVE 3
249 const mbedtls_ecp_curve_info *mbedtls_ecp_curve_list( void );
250 
259 
268 
277 
286 
291 
296 
301 
306 
311 
316 
327 
338 
348 
357 
371  const mbedtls_ecp_point *Q );
372 
384  const char *x, const char *y );
385 
401  int format, size_t *olen,
402  unsigned char *buf, size_t buflen );
403 
423  const unsigned char *buf, size_t ilen );
424 
440  const unsigned char **buf, size_t len );
441 
457  int format, size_t *olen,
458  unsigned char *buf, size_t blen );
459 
474 
488 int mbedtls_ecp_tls_read_group( mbedtls_ecp_group *grp, const unsigned char **buf, size_t len );
489 
501 int mbedtls_ecp_tls_write_group( const mbedtls_ecp_group *grp, size_t *olen,
502  unsigned char *buf, size_t blen );
503 
531  const mbedtls_mpi *m, const mbedtls_ecp_point *P,
532  int (*f_rng)(void *, unsigned char *, size_t), void *p_rng );
533 
555  const mbedtls_mpi *m, const mbedtls_ecp_point *P,
556  const mbedtls_mpi *n, const mbedtls_ecp_point *Q );
557 
580 
594 int mbedtls_ecp_check_privkey( const mbedtls_ecp_group *grp, const mbedtls_mpi *d );
595 
614  const mbedtls_ecp_point *G,
616  int (*f_rng)(void *, unsigned char *, size_t),
617  void *p_rng );
618 
636  int (*f_rng)(void *, unsigned char *, size_t),
637  void *p_rng );
638 
651  int (*f_rng)(void *, unsigned char *, size_t), void *p_rng );
652 
664 
665 #if defined(MBEDTLS_SELF_TEST)
666 
672 int mbedtls_ecp_self_test( int verbose );
673 
674 #endif /* MBEDTLS_SELF_TEST */
675 
676 #ifdef __cplusplus
677 }
678 #endif
679 
680 #else /* MBEDTLS_ECP_ALT */
681 #include "ecp_alt.h"
682 #endif /* MBEDTLS_ECP_ALT */
683 
684 #endif /* ecp.h */
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.
Definition: ecp.c:2008
GLuint const GLchar * name
Definition: glext.h:6671
void mbedtls_ecp_group_free(mbedtls_ecp_group *grp)
Free the components of an ECP group.
Definition: ecp.c:323
static const unsigned char pt[MAX_TESTS][64]
Definition: gcm.c:573
mbedtls_mpi X
Definition: ecp.h:108
ECP group structure.
Definition: ecp.h:138
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.
Definition: ecp.c:1862
#define G(L)
Definition: lstate.h:205
size_t nbits
Definition: ecp.h:147
int mbedtls_ecp_group_load(mbedtls_ecp_group *grp, mbedtls_ecp_group_id index)
Set a group using well-known domain parameters.
Definition: ecp_curves.c:693
mbedtls_mpi N
Definition: ecp.h:145
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:8418
mbedtls_mpi P
Definition: ecp.h:141
Definition: ecp.h:66
int mbedtls_ecp_set_zero(mbedtls_ecp_point *pt)
Set a point to zero.
Definition: ecp.c:388
mbedtls_mpi d
Definition: ecp.h:168
Definition: ecp.h:75
GLenum GLsizei len
Definition: glext.h:7389
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.
Definition: ecp.c:1997
#define P(a, b, c, d, k, s, t)
mbedtls_ecp_group_id id
Definition: ecp.h:140
Definition: ecp.h:76
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.
Definition: ecp.c:597
const mbedtls_ecp_group_id * mbedtls_ecp_grp_id_list(void)
Get the list of supported curves in order of preferrence (grp_id only)
Definition: ecp.c:179
#define R(t)
size_t T_size
Definition: ecp.h:154
const mbedtls_ecp_curve_info * mbedtls_ecp_curve_info_from_name(const char *name)
Get curve information from a human-readable name.
Definition: ecp.c:241
Definition: ecp.h:64
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.
Definition: ecp.c:427
Definition: ecp.h:71
Definition: ecp.h:72
void mbedtls_ecp_keypair_free(mbedtls_ecp_keypair *key)
Free the components of a key pair.
Definition: ecp.c:352
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.
Definition: ecp.c:538
const char * name
Definition: ecp.h:94
void mbedtls_ecp_keypair_init(mbedtls_ecp_keypair *key)
Initialize a key pair (as an invalid one)
Definition: ecp.c:297
Definition: ecp.h:67
Definition: ecp.h:65
mbedtls_mpi Y
Definition: ecp.h:109
Definition: ecp.h:69
uint16_t bit_size
Definition: ecp.h:93
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.
Definition: ecp.c:499
void mbedtls_ecp_group_init(mbedtls_ecp_group *grp)
Initialize a group (to something meaningless)
Definition: ecp.c:286
GLint GLint GLint GLint GLint GLint y
Definition: glext.h:6295
Definition: ecp.h:70
GLenum src
Definition: glext.h:6980
mbedtls_mpi A
Definition: ecp.h:142
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)
Definition: ecp.c:1672
GLint GLint GLint GLint GLint x
Definition: glext.h:6295
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.
Definition: ecp.c:630
int mbedtls_ecp_is_zero(mbedtls_ecp_point *pt)
Tell if a point is zero.
Definition: ecp.c:403
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.
Definition: ecp.c:205
mbedtls_mpi B
Definition: ecp.h:143
GLuint index
Definition: glext.h:6671
int mbedtls_ecp_self_test(int verbose)
Checkup routine.
Definition: ecp.c:2066
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.
Definition: ecp.c:569
mbedtls_ecp_point G
Definition: ecp.h:144
void * t_data
Definition: ecp.h:152
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)
Generate a keypair with configurable base point.
Definition: ecp.c:1915
ECP point structure (jacobian coordinates)
Definition: ecp.h:106
MPI structure.
Definition: bignum.h:179
const mbedtls_ecp_curve_info * mbedtls_ecp_curve_info_from_tls_id(uint16_t tls_id)
Get curve information from a TLS NamedCurve value.
Definition: ecp.c:223
Definition: ecp.h:68
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
Definition: glext.h:6293
int mbedtls_ecp_copy(mbedtls_ecp_point *P, const mbedtls_ecp_point *Q)
Copy the contents of point Q into P.
Definition: ecp.c:365
int mbedtls_ecp_check_pub_priv(const mbedtls_ecp_keypair *pub, const mbedtls_ecp_keypair *prv)
Check a public-private key pair.
Definition: ecp.c:2022
void mbedtls_ecp_point_free(mbedtls_ecp_point *pt)
Free the components of a point.
Definition: ecp.c:310
mbedtls_ecp_group_id grp_id
Definition: ecp.h:91
Multi-precision integer library.
GLenum GLenum dst
Definition: glext.h:6980
void mbedtls_ecp_point_init(mbedtls_ecp_point *pt)
Initialize a point (as zero)
Definition: ecp.c:273
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...
Definition: ecp.c:1802
mbedtls_ecp_point * T
Definition: ecp.h:153
size_t pbits
Definition: ecp.h:146
mbedtls_ecp_group grp
Definition: ecp.h:167
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.
Definition: ecp.c:443
Definition: ecp.h:74
int mbedtls_ecp_point_cmp(const mbedtls_ecp_point *P, const mbedtls_ecp_point *Q)
Compare two points.
Definition: ecp.c:411
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.
Definition: ecp.c:1882
unsigned short uint16_t
Definition: stdint.h:125
mbedtls_ecp_group_id
Definition: ecp.h:62
uint16_t tls_id
Definition: ecp.h:92
mbedtls_mpi Z
Definition: ecp.h:110
GLdouble n
Definition: glext.h:8396
int mbedtls_ecp_group_copy(mbedtls_ecp_group *dst, const mbedtls_ecp_group *src)
Copy the contents of a group object.
Definition: ecp.c:380
const GLfloat * m
Definition: glext.h:11755
ECP key pair structure.
Definition: ecp.h:165
unsigned int h
Definition: ecp.h:148
Definition: ecp.h:89
Definition: ecp.h:73
mbedtls_ecp_point Q
Definition: ecp.h:169