mbed TLS v2.2.0
ecp_alt.h
Go to the documentation of this file.
1 
21 #ifndef MBEDTLS_ECP_ALT_H
22 #define MBEDTLS_ECP_ALT_H
23 
24 #if !defined(MBEDTLS_CONFIG_FILE)
25 #include "config.h"
26 #else
27 #include MBEDTLS_CONFIG_FILE
28 #endif
29 
30 /***************************************************************************/
35 /***************************************************************************/
41 #if defined( MBEDTLS_ECP_ALT )
42 /* SiliconLabs CRYPTO hardware acceleration implementation */
43 
44 #include "cryptodrv.h"
45 
46 #ifdef __cplusplus
47 extern "C" {
48 #endif
49 
59 typedef enum
60 {
75 
81 #define MBEDTLS_ECP_DP_MAX 12
82 
86 typedef struct
87 {
88  mbedtls_ecp_group_id grp_id;
89  uint16_t tls_id;
90  uint16_t bit_size;
91  const char *name;
93 
103 typedef struct
104 {
105  mbedtls_mpi X;
106  mbedtls_mpi Y;
107  mbedtls_mpi Z;
108 }
110 
135 typedef struct
136 {
138  mbedtls_mpi P;
139  mbedtls_mpi A;
140  mbedtls_mpi B;
142  mbedtls_mpi N;
143  size_t pbits;
144  size_t nbits;
145  unsigned int h;
146  int (*modp)(mbedtls_mpi *);
147  int (*t_pre)(mbedtls_ecp_point *, void *);
148  int (*t_post)(mbedtls_ecp_point *, void *);
149  void *t_data;
150  mbedtls_ecp_point *T;
151  size_t T_size;
153  CRYPTODRV_Context_t cryptodrv_ctx;
154 }
156 
164 typedef struct
165 {
166  mbedtls_ecp_group grp;
167  mbedtls_mpi d;
169 }
171 
180 #if !defined(MBEDTLS_ECP_MAX_BITS)
181 
184 #define MBEDTLS_ECP_MAX_BITS 521
185 #endif
186 
187 #define MBEDTLS_ECP_MAX_BYTES ( ( MBEDTLS_ECP_MAX_BITS + 7 ) / 8 )
188 #define MBEDTLS_ECP_MAX_PT_LEN ( 2 * MBEDTLS_ECP_MAX_BYTES + 1 )
189 
190 #if !defined(MBEDTLS_ECP_WINDOW_SIZE)
191 /*
192  * Maximum "window" size used for point multiplication.
193  * Default: 6.
194  * Minimum value: 2. Maximum value: 7.
195  *
196  * Result is an array of at most ( 1 << ( MBEDTLS_ECP_WINDOW_SIZE - 1 ) )
197  * points used for point multiplication. This value is directly tied to EC
198  * peak memory usage, so decreasing it by one should roughly cut memory usage
199  * by two (if large curves are in use).
200  *
201  * Reduction in size may reduce speed, but larger curves are impacted first.
202  * Sample performances (in ECDHE handshakes/s, with FIXED_POINT_OPTIM = 1):
203  * w-size: 6 5 4 3 2
204  * 521 145 141 135 120 97
205  * 384 214 209 198 177 146
206  * 256 320 320 303 262 226
207 
208  * 224 475 475 453 398 342
209  * 192 640 640 633 587 476
210  */
211 #define MBEDTLS_ECP_WINDOW_SIZE 6
212 #endif /* MBEDTLS_ECP_WINDOW_SIZE */
213 
214 #if !defined(MBEDTLS_ECP_FIXED_POINT_OPTIM)
215 /*
216  * Trade memory for speed on fixed-point multiplication.
217  *
218  * This speeds up repeated multiplication of the generator (that is, the
219  * multiplication in ECDSA signatures, and half of the multiplications in
220  * ECDSA verification and ECDHE) by a factor roughly 3 to 4.
221  *
222  * The cost is increasing EC peak memory usage by a factor roughly 2.
223  *
224  * Change this value to 0 to reduce peak memory usage.
225  */
226 #define MBEDTLS_ECP_FIXED_POINT_OPTIM 1
227 #endif /* MBEDTLS_ECP_FIXED_POINT_OPTIM */
228 
229 /* \} name SECTION: Module settings */
230 
231 /*
232  * Point formats, from RFC 4492's enum ECPointFormat
233  */
234 #define MBEDTLS_ECP_PF_UNCOMPRESSED 0
235 #define MBEDTLS_ECP_PF_COMPRESSED 1
237 /*
238  * Some other constants from RFC 4492
239  */
240 #define MBEDTLS_ECP_TLS_NAMED_CURVE 3
260 int mbedtls_ecp_set_device_instance(mbedtls_ecp_group *grp,
261  unsigned int devno);
262 
280 int mbedtls_ecp_set_device_lock_wait_ticks(mbedtls_ecp_group *grp,
281  int ticks);
282 
290 
299 
308 
317 
326 
331 
336 
341 
346 
351 
356 
367 
378 
388 
397 
411  const mbedtls_ecp_point *Q );
412 
424  const char *x, const char *y );
425 
441  int format, size_t *olen,
442  unsigned char *buf, size_t buflen );
443 
463  const unsigned char *buf, size_t ilen );
464 
480  const unsigned char **buf, size_t len );
481 
497  int format, size_t *olen,
498  unsigned char *buf, size_t blen );
499 
514 
528 int mbedtls_ecp_tls_read_group( mbedtls_ecp_group *grp, const unsigned char **buf, size_t len );
529 
541 int mbedtls_ecp_tls_write_group( const mbedtls_ecp_group *grp, size_t *olen,
542  unsigned char *buf, size_t blen );
543 
571  const mbedtls_mpi *m, const mbedtls_ecp_point *P,
572  int (*f_rng)(void *, unsigned char *, size_t), void *p_rng );
573 
595  const mbedtls_mpi *m, const mbedtls_ecp_point *P,
596  const mbedtls_mpi *n, const mbedtls_ecp_point *Q );
597 
620 
634 int mbedtls_ecp_check_privkey( const mbedtls_ecp_group *grp, const mbedtls_mpi *d );
635 
654  const mbedtls_ecp_point *G,
656  int (*f_rng)(void *, unsigned char *, size_t),
657  void *p_rng );
658 
676  int (*f_rng)(void *, unsigned char *, size_t),
677  void *p_rng );
678 
691  int (*f_rng)(void *, unsigned char *, size_t), void *p_rng );
692 
704 
705 #if defined(MBEDTLS_SELF_TEST)
706 
711 int mbedtls_ecp_self_test( int verbose );
712 #endif
713 
714 #ifdef __cplusplus
715 }
716 #endif
717 
718 #endif /* #if defined( MBEDTLS_ECP_ALT ) */
719 
723 #endif /* #ifndef MBEDTLS_ECP_ALT_H */
int mbedtls_ecp_is_zero(mbedtls_ecp_point *pt)
Tell if a point is zero.
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.
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:163
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.
Compatibility names (set of defines)
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)
Curve information for use by other modules.
Definition: ecp.h:87
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:136
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.
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.
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.
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:60
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_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.
CRYPTODRV operation context.
Definition: cryptodrv.h:98
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.
int mbedtls_ecp_point_cmp(const mbedtls_ecp_point *P, const mbedtls_ecp_point *Q)
Compare 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)
Export a point as a TLS ECPoint record.
MPI structure.
Definition: bignum.h:143
ECP point structure (jacobian coordinates)
Definition: ecp.h:104
const mbedtls_ecp_curve_info * mbedtls_ecp_curve_info_from_name(const char *name)
Get curve information from a human-readable name.
const mbedtls_ecp_curve_info * mbedtls_ecp_curve_list(void)
Get the list of supported curves in order of preferrence (full information)
void mbedtls_ecp_group_init(mbedtls_ecp_group *grp)
Initialize a group (to something meaningless)