mbed TLS v2.14.1

ecdsa.h
Go to the documentation of this file.
1
13 /*
14 * Copyright (C) 2006-2018, Arm Limited (or its affiliates), All Rights Reserved
15 * SPDX-License-Identifier: Apache-2.0
16 *
17 * Licensed under the Apache License, Version 2.0 (the "License"); you may
18 * not use this file except in compliance with the License.
19 * You may obtain a copy of the License at
20 *
21 * http://www.apache.org/licenses/LICENSE-2.0
22 *
23 * Unless required by applicable law or agreed to in writing, software
24 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
25 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
26 * See the License for the specific language governing permissions and
27 * limitations under the License.
28 *
29 * This file is part of Mbed TLS (https://tls.mbed.org)
30 */
31
32 #ifndef MBEDTLS_ECDSA_H
33 #define MBEDTLS_ECDSA_H
34
35 #include "ecp.h"
36 #include "md.h"
37
38 /*
39 * RFC-4492 page 20:
40 *
41 * Ecdsa-Sig-Value ::= SEQUENCE {
42 * r INTEGER,
43 * s INTEGER
44 * }
45 *
46 * Size is at most
47 * 1 (tag) + 1 (len) + 1 (initial 0) + ECP_MAX_BYTES for each of r and s,
48 * twice that + 1 (tag) + 2 (len) for the sequence
49 * (assuming ECP_MAX_BYTES is less than 126 for r and s,
50 * and less than 124 (total len <= 255) for the sequence)
51 */
52 #if MBEDTLS_ECP_MAX_BYTES > 124
53 #error "MBEDTLS_ECP_MAX_BYTES bigger than expected, please fix MBEDTLS_ECDSA_MAX_LEN"
54 #endif
55
56 #define MBEDTLS_ECDSA_MAX_LEN ( 3 + 2 * ( 3 + MBEDTLS_ECP_MAX_BYTES ) )
57
58 #ifdef __cplusplus
59 extern "C" {
60 #endif
61
69 typedef mbedtls_ecp_keypair mbedtls_ecdsa_context;
70
71 #if defined(MBEDTLS_ECP_RESTARTABLE)
72
78 typedef struct mbedtls_ecdsa_restart_ver mbedtls_ecdsa_restart_ver_ctx;
79
85 typedef struct mbedtls_ecdsa_restart_sig mbedtls_ecdsa_restart_sig_ctx;
86
87 #if defined(MBEDTLS_ECDSA_DETERMINISTIC)
88
93 typedef struct mbedtls_ecdsa_restart_det mbedtls_ecdsa_restart_det_ctx;
94 #endif
95
99 typedef struct
100 {
101 mbedtls_ecp_restart_ctx ecp;
103 mbedtls_ecdsa_restart_ver_ctx *ver;
104 mbedtls_ecdsa_restart_sig_ctx *sig;
105 #if defined(MBEDTLS_ECDSA_DETERMINISTIC)
106 mbedtls_ecdsa_restart_det_ctx *det;
107 #endif
108 } mbedtls_ecdsa_restart_ctx;
109
110 #else /* MBEDTLS_ECP_RESTARTABLE */
111
112 /* Now we can declare functions that take a pointer to that */
113 typedef void mbedtls_ecdsa_restart_ctx;
114
115 #endif /* MBEDTLS_ECP_RESTARTABLE */
116
144 int mbedtls_ecdsa_sign( mbedtls_ecp_group *grp, mbedtls_mpi *r, mbedtls_mpi *s,
145 const mbedtls_mpi *d, const unsigned char *buf, size_t blen,
146 int (*f_rng)(void *, unsigned char *, size_t), void *p_rng );
147
148 #if defined(MBEDTLS_ECDSA_DETERMINISTIC)
149
177 int mbedtls_ecdsa_sign_det( mbedtls_ecp_group *grp, mbedtls_mpi *r, mbedtls_mpi *s,
178 const mbedtls_mpi *d, const unsigned char *buf, size_t blen,
179 mbedtls_md_type_t md_alg );
180 #endif /* MBEDTLS_ECDSA_DETERMINISTIC */
181
207 int mbedtls_ecdsa_verify( mbedtls_ecp_group *grp,
208 const unsigned char *buf, size_t blen,
209 const mbedtls_ecp_point *Q, const mbedtls_mpi *r, const mbedtls_mpi *s);
210
252 int mbedtls_ecdsa_write_signature( mbedtls_ecdsa_context *ctx, mbedtls_md_type_t md_alg,
253 const unsigned char *hash, size_t hlen,
254 unsigned char *sig, size_t *slen,
255 int (*f_rng)(void *, unsigned char *, size_t),
256 void *p_rng );
257
284 int mbedtls_ecdsa_write_signature_restartable( mbedtls_ecdsa_context *ctx,
285 mbedtls_md_type_t md_alg,
286 const unsigned char *hash, size_t hlen,
287 unsigned char *sig, size_t *slen,
288 int (*f_rng)(void *, unsigned char *, size_t),
289 void *p_rng,
290 mbedtls_ecdsa_restart_ctx *rs_ctx );
291
292 #if defined(MBEDTLS_ECDSA_DETERMINISTIC)
293 #if ! defined(MBEDTLS_DEPRECATED_REMOVED)
294 #if defined(MBEDTLS_DEPRECATED_WARNING)
295 #define MBEDTLS_DEPRECATED __attribute__((deprecated))
296 #else
297 #define MBEDTLS_DEPRECATED
298 #endif
299
339 int mbedtls_ecdsa_write_signature_det( mbedtls_ecdsa_context *ctx,
340 const unsigned char *hash, size_t hlen,
341 unsigned char *sig, size_t *slen,
342 mbedtls_md_type_t md_alg ) MBEDTLS_DEPRECATED;
343 #undef MBEDTLS_DEPRECATED
344 #endif /* MBEDTLS_DEPRECATED_REMOVED */
345 #endif /* MBEDTLS_ECDSA_DETERMINISTIC */
346
371 int mbedtls_ecdsa_read_signature( mbedtls_ecdsa_context *ctx,
372 const unsigned char *hash, size_t hlen,
373 const unsigned char *sig, size_t slen );
374
401 int mbedtls_ecdsa_read_signature_restartable( mbedtls_ecdsa_context *ctx,
402 const unsigned char *hash, size_t hlen,
403 const unsigned char *sig, size_t slen,
404 mbedtls_ecdsa_restart_ctx *rs_ctx );
405
420 int mbedtls_ecdsa_genkey( mbedtls_ecdsa_context *ctx, mbedtls_ecp_group_id gid,
421 int (*f_rng)(void *, unsigned char *, size_t), void *p_rng );
422
434 int mbedtls_ecdsa_from_keypair( mbedtls_ecdsa_context *ctx, const mbedtls_ecp_keypair *key );
435
441 void mbedtls_ecdsa_init( mbedtls_ecdsa_context *ctx );
442
448 void mbedtls_ecdsa_free( mbedtls_ecdsa_context *ctx );
449
450 #if defined(MBEDTLS_ECP_RESTARTABLE)
451
454 void mbedtls_ecdsa_restart_init( mbedtls_ecdsa_restart_ctx *ctx );
455
459 void mbedtls_ecdsa_restart_free( mbedtls_ecdsa_restart_ctx *ctx );
460 #endif /* MBEDTLS_ECP_RESTARTABLE */
461
462 #ifdef __cplusplus
463 }
464 #endif
465
466 #endif /* ecdsa.h */
mbedtls_ecdsa_free
void mbedtls_ecdsa_free(mbedtls_ecdsa_context *ctx)
This function frees an ECDSA context.
ecp.h
This file provides an API for Elliptic Curves over GF(P) (ECP).
mbedtls_ecp_keypair
The ECP key-pair structure.
Definition: ecp.h:322
mbedtls_ecdsa_restart_ctx
void mbedtls_ecdsa_restart_ctx
Definition: ecdsa.h:113
mbedtls_ecdsa_init
void mbedtls_ecdsa_init(mbedtls_ecdsa_context *ctx)
This function initializes an ECDSA context.
mbedtls_ecdsa_verify
int mbedtls_ecdsa_verify(mbedtls_ecp_group *grp, const unsigned char *buf, size_t blen, const mbedtls_ecp_point *Q, const mbedtls_mpi *r, const mbedtls_mpi *s)
This function verifies the ECDSA signature of a previously-hashed message.
mbedtls_ecp_group
The ECP group structure.
Definition: ecp.h:163
mbedtls_ecdsa_sign
int mbedtls_ecdsa_sign(mbedtls_ecp_group *grp, mbedtls_mpi *r, mbedtls_mpi *s, const mbedtls_mpi *d, const unsigned char *buf, size_t blen, int(*f_rng)(void *, unsigned char *, size_t), void *p_rng)
This function computes the ECDSA signature of a previously-hashed message.
mbedtls_ecdsa_from_keypair
int mbedtls_ecdsa_from_keypair(mbedtls_ecdsa_context *ctx, const mbedtls_ecp_keypair *key)
This function sets an ECDSA context from an EC key pair.
mbedtls_ecdsa_write_signature_restartable
int mbedtls_ecdsa_write_signature_restartable(mbedtls_ecdsa_context *ctx, mbedtls_md_type_t md_alg, const unsigned char *hash, size_t hlen, unsigned char *sig, size_t *slen, int(*f_rng)(void *, unsigned char *, size_t), void *p_rng, mbedtls_ecdsa_restart_ctx *rs_ctx)
This function computes the ECDSA signature and writes it to a buffer, in a restartable way...
mbedtls_ecp_restart_ctx
void mbedtls_ecp_restart_ctx
Definition: ecp.h:248
mbedtls_ecdsa_sign_det
int mbedtls_ecdsa_sign_det(mbedtls_ecp_group *grp, mbedtls_mpi *r, mbedtls_mpi *s, const mbedtls_mpi *d, const unsigned char *buf, size_t blen, mbedtls_md_type_t md_alg)
This function computes the ECDSA signature of a previously-hashed message, deterministic version...
mbedtls_ecdsa_context
mbedtls_ecp_keypair mbedtls_ecdsa_context
The ECDSA context structure.
Definition: ecdsa.h:69
mbedtls_ecp_group_id
mbedtls_ecp_group_id
Definition: ecp.h:71
mbedtls_ecdsa_genkey
int mbedtls_ecdsa_genkey(mbedtls_ecdsa_context *ctx, mbedtls_ecp_group_id gid, int(*f_rng)(void *, unsigned char *, size_t), void *p_rng)
This function generates an ECDSA keypair on the given curve.
mbedtls_ecdsa_read_signature_restartable
int mbedtls_ecdsa_read_signature_restartable(mbedtls_ecdsa_context *ctx, const unsigned char *hash, size_t hlen, const unsigned char *sig, size_t slen, mbedtls_ecdsa_restart_ctx *rs_ctx)
This function reads and verifies an ECDSA signature, in a restartable way.
md.h
This file contains the generic message-digest wrapper.
mbedtls_ecdsa_write_signature_det
int mbedtls_ecdsa_write_signature_det(mbedtls_ecdsa_context *ctx, const unsigned char *hash, size_t hlen, unsigned char *sig, size_t *slen, mbedtls_md_type_t md_alg) MBEDTLS_DEPRECATED
This function computes an ECDSA signature and writes it to a buffer, serialized as defined in RFC-449...
mbedtls_mpi
MPI structure.
Definition: bignum.h:180
mbedtls_ecdsa_read_signature
int mbedtls_ecdsa_read_signature(mbedtls_ecdsa_context *ctx, const unsigned char *hash, size_t hlen, const unsigned char *sig, size_t slen)
This function reads and verifies an ECDSA signature.
mbedtls_ecp_point
The ECP point structure, in Jacobian coordinates.
Definition: ecp.h:118
mbedtls_md_type_t
mbedtls_md_type_t
Supported message digests.
Definition: md.h:58
MBEDTLS_DEPRECATED
#define MBEDTLS_DEPRECATED
Definition: ecdsa.h:297
mbedtls_ecdsa_write_signature
int mbedtls_ecdsa_write_signature(mbedtls_ecdsa_context *ctx, mbedtls_md_type_t md_alg, const unsigned char *hash, size_t hlen, unsigned char *sig, size_t *slen, int(*f_rng)(void *, unsigned char *, size_t), void *p_rng)
This function computes the ECDSA signature and writes it to a buffer, serialized as defined in RFC-44...