mbed TLS v1.3.21
ecdsa.h
Go to the documentation of this file.
1 
24 #ifndef POLARSSL_ECDSA_H
25 #define POLARSSL_ECDSA_H
26 
27 #include "ecp.h"
28 #include "md.h"
29 /*
30  * RFC 4492 page 20:
31  *
32  * Ecdsa-Sig-Value ::= SEQUENCE {
33  * r INTEGER,
34  * s INTEGER
35  * }
36  *
37  * Size is at most
38  * 1 (tag) + 1 (len) + 1 (initial 0) + ECP_MAX_BYTES for each of r and s,
39  * twice that + 1 (tag) + 2 (len) for the sequence
40  * (assuming ECP_MAX_BYTES is less than 126 for r and s,
41  * and less than 124 (total len <= 255) for the sequence)
42  *
43  */
45 #define POLARSSL_ECDSA_MAX_LEN ( 3 + 2 * ( 3 + POLARSSL_ECP_MAX_BYTES ) )
46 
52 typedef struct
53 {
55  mpi d;
57  mpi r;
58  mpi s;
59 }
61 
62 #ifdef __cplusplus
63 extern "C" {
64 #endif
65 
85 int ecdsa_sign( ecp_group *grp, mpi *r, mpi *s,
86  const mpi *d, const unsigned char *buf, size_t blen,
87  int (*f_rng)(void *, unsigned char *, size_t), void *p_rng );
88 
89 #if defined(POLARSSL_ECDSA_DETERMINISTIC)
90 
109 int ecdsa_sign_det( ecp_group *grp, mpi *r, mpi *s,
110  const mpi *d, const unsigned char *buf, size_t blen,
111  md_type_t md_alg );
112 #endif /* POLARSSL_ECDSA_DETERMINISTIC */
113 
132 int ecdsa_verify( ecp_group *grp,
133  const unsigned char *buf, size_t blen,
134  const ecp_point *Q, const mpi *r, const mpi *s);
135 
162  const unsigned char *hash, size_t hlen,
163  unsigned char *sig, size_t *slen,
164  int (*f_rng)(void *, unsigned char *, size_t),
165  void *p_rng );
166 
167 #if defined(POLARSSL_ECDSA_DETERMINISTIC)
168 
190  const unsigned char *hash, size_t hlen,
191  unsigned char *sig, size_t *slen,
192  md_type_t md_alg );
193 #endif /* POLARSSL_ECDSA_DETERMINISTIC */
194 
215  const unsigned char *hash, size_t hlen,
216  const unsigned char *sig, size_t slen );
217 
230  int (*f_rng)(void *, unsigned char *, size_t), void *p_rng );
231 
240 int ecdsa_from_keypair( ecdsa_context *ctx, const ecp_keypair *key );
241 
247 void ecdsa_init( ecdsa_context *ctx );
248 
254 void ecdsa_free( ecdsa_context *ctx );
255 
261 int ecdsa_self_test( int verbose );
262 
263 #ifdef __cplusplus
264 }
265 #endif
266 
267 #endif /* ecdsa.h */
int ecdsa_from_keypair(ecdsa_context *ctx, const ecp_keypair *key)
Set an ECDSA context from an EC key pair.
int ecdsa_verify(ecp_group *grp, const unsigned char *buf, size_t blen, const ecp_point *Q, const mpi *r, const mpi *s)
Verify ECDSA signature of a previously hashed message.
Elliptic curves over GF(p)
int ecdsa_write_signature(ecdsa_context *ctx, const unsigned char *hash, size_t hlen, unsigned char *sig, size_t *slen, int(*f_rng)(void *, unsigned char *, size_t), void *p_rng)
Compute ECDSA signature and write it to buffer, serialized as defined in RFC 4492 page 20...
int ecdsa_sign(ecp_group *grp, mpi *r, mpi *s, const mpi *d, const unsigned char *buf, size_t blen, int(*f_rng)(void *, unsigned char *, size_t), void *p_rng)
Compute ECDSA signature of a previously hashed message.
ECP group structure.
Definition: ecp.h:133
int ecdsa_self_test(int verbose)
Checkup routine.
ecp_group grp
Definition: ecdsa.h:54
ECP key pair structure.
Definition: ecp.h:160
MPI structure.
Definition: bignum.h:183
md_type_t
Definition: md.h:45
ECP point structure (jacobian coordinates)
Definition: ecp.h:101
ECDSA context structure.
Definition: ecdsa.h:52
int ecdsa_read_signature(ecdsa_context *ctx, const unsigned char *hash, size_t hlen, const unsigned char *sig, size_t slen)
Read and verify an ECDSA signature.
ecp_point Q
Definition: ecdsa.h:56
void ecdsa_init(ecdsa_context *ctx)
Initialize context.
Generic message digest wrapper.
ecp_group_id
Domain parameters (curve, subgroup and generator) identifiers.
Definition: ecp.h:54
int ecdsa_genkey(ecdsa_context *ctx, ecp_group_id gid, int(*f_rng)(void *, unsigned char *, size_t), void *p_rng)
Generate an ECDSA keypair on the given curve.
int ecdsa_sign_det(ecp_group *grp, mpi *r, mpi *s, const mpi *d, const unsigned char *buf, size_t blen, md_type_t md_alg)
Compute ECDSA signature of a previously hashed message (deterministic version)
void ecdsa_free(ecdsa_context *ctx)
Free context.
int ecdsa_write_signature_det(ecdsa_context *ctx, const unsigned char *hash, size_t hlen, unsigned char *sig, size_t *slen, md_type_t md_alg)
Compute ECDSA signature and write it to buffer, serialized as defined in RFC 4492 page 20...