mbed TLS v2.16.2
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 #if !defined(MBEDTLS_CONFIG_FILE)
36 #include "config.h"
37 #else
38 #include MBEDTLS_CONFIG_FILE
39 #endif
40 
41 #include "ecp.h"
42 #include "md.h"
43 
44 /*
45  * RFC-4492 page 20:
46  *
47  * Ecdsa-Sig-Value ::= SEQUENCE {
48  * r INTEGER,
49  * s INTEGER
50  * }
51  *
52  * Size is at most
53  * 1 (tag) + 1 (len) + 1 (initial 0) + ECP_MAX_BYTES for each of r and s,
54  * twice that + 1 (tag) + 2 (len) for the sequence
55  * (assuming ECP_MAX_BYTES is less than 126 for r and s,
56  * and less than 124 (total len <= 255) for the sequence)
57  */
58 #if MBEDTLS_ECP_MAX_BYTES > 124
59 #error "MBEDTLS_ECP_MAX_BYTES bigger than expected, please fix MBEDTLS_ECDSA_MAX_LEN"
60 #endif
61 
62 #define MBEDTLS_ECDSA_MAX_LEN ( 3 + 2 * ( 3 + MBEDTLS_ECP_MAX_BYTES ) )
63 
64 #ifdef __cplusplus
65 extern "C" {
66 #endif
67 
76 
77 #if defined(MBEDTLS_ECP_RESTARTABLE)
78 
84 typedef struct mbedtls_ecdsa_restart_ver mbedtls_ecdsa_restart_ver_ctx;
85 
91 typedef struct mbedtls_ecdsa_restart_sig mbedtls_ecdsa_restart_sig_ctx;
92 
93 #if defined(MBEDTLS_ECDSA_DETERMINISTIC)
94 
99 typedef struct mbedtls_ecdsa_restart_det mbedtls_ecdsa_restart_det_ctx;
100 #endif
101 
105 typedef struct
106 {
109  mbedtls_ecdsa_restart_ver_ctx *ver;
110  mbedtls_ecdsa_restart_sig_ctx *sig;
111 #if defined(MBEDTLS_ECDSA_DETERMINISTIC)
112  mbedtls_ecdsa_restart_det_ctx *det;
113 #endif
115 
116 #else /* MBEDTLS_ECP_RESTARTABLE */
117 
118 /* Now we can declare functions that take a pointer to that */
120 
121 #endif /* MBEDTLS_ECP_RESTARTABLE */
122 
160  const mbedtls_mpi *d, const unsigned char *buf, size_t blen,
161  int (*f_rng)(void *, unsigned char *, size_t), void *p_rng );
162 
163 #if defined(MBEDTLS_ECDSA_DETERMINISTIC)
164 
200  mbedtls_mpi *s, const mbedtls_mpi *d,
201  const unsigned char *buf, size_t blen,
202  mbedtls_md_type_t md_alg );
203 #endif /* MBEDTLS_ECDSA_DETERMINISTIC */
204 
238  const unsigned char *buf, size_t blen,
239  const mbedtls_ecp_point *Q, const mbedtls_mpi *r,
240  const mbedtls_mpi *s);
241 
290  mbedtls_md_type_t md_alg,
291  const unsigned char *hash, size_t hlen,
292  unsigned char *sig, size_t *slen,
293  int (*f_rng)(void *, unsigned char *, size_t),
294  void *p_rng );
295 
336  mbedtls_md_type_t md_alg,
337  const unsigned char *hash, size_t hlen,
338  unsigned char *sig, size_t *slen,
339  int (*f_rng)(void *, unsigned char *, size_t),
340  void *p_rng,
341  mbedtls_ecdsa_restart_ctx *rs_ctx );
342 
343 #if defined(MBEDTLS_ECDSA_DETERMINISTIC)
344 #if ! defined(MBEDTLS_DEPRECATED_REMOVED)
345 #if defined(MBEDTLS_DEPRECATED_WARNING)
346 #define MBEDTLS_DEPRECATED __attribute__((deprecated))
347 #else
348 #define MBEDTLS_DEPRECATED
349 #endif
350 
394  const unsigned char *hash, size_t hlen,
395  unsigned char *sig, size_t *slen,
397 #undef MBEDTLS_DEPRECATED
398 #endif /* MBEDTLS_DEPRECATED_REMOVED */
399 #endif /* MBEDTLS_ECDSA_DETERMINISTIC */
400 
429  const unsigned char *hash, size_t hlen,
430  const unsigned char *sig, size_t slen );
431 
464  const unsigned char *hash, size_t hlen,
465  const unsigned char *sig, size_t slen,
466  mbedtls_ecdsa_restart_ctx *rs_ctx );
467 
485  int (*f_rng)(void *, unsigned char *, size_t), void *p_rng );
486 
503  const mbedtls_ecp_keypair *key );
504 
512 
521 
522 #if defined(MBEDTLS_ECP_RESTARTABLE)
523 
529 void mbedtls_ecdsa_restart_init( mbedtls_ecdsa_restart_ctx *ctx );
530 
538 void mbedtls_ecdsa_restart_free( mbedtls_ecdsa_restart_ctx *ctx );
539 #endif /* MBEDTLS_ECP_RESTARTABLE */
540 
541 #ifdef __cplusplus
542 }
543 #endif
544 
545 #endif /* ecdsa.h */
void mbedtls_ecdsa_free(mbedtls_ecdsa_context *ctx)
This function frees an ECDSA context.
This file provides an API for Elliptic Curves over GF(P) (ECP).
The ECP key-pair structure.
Definition: ecp.h:332
Configuration options (set of defines)
void mbedtls_ecdsa_restart_ctx
Definition: ecdsa.h:119
void mbedtls_ecdsa_init(mbedtls_ecdsa_context *ctx)
This function initializes an ECDSA context.
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.
The ECP group structure.
Definition: ecp.h:173
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.
int mbedtls_ecdsa_from_keypair(mbedtls_ecdsa_context *ctx, const mbedtls_ecp_keypair *key)
This function sets up an ECDSA context from an EC key pair.
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.
void mbedtls_ecp_restart_ctx
Definition: ecp.h:320
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_ecp_keypair mbedtls_ecdsa_context
The ECDSA context structure.
Definition: ecdsa.h:75
mbedtls_ecp_group_id
Definition: ecp.h:77
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.
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.
This file contains the generic message-digest wrapper.
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...
MPI structure.
Definition: bignum.h:185
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.
The ECP point structure, in Jacobian coordinates.
Definition: ecp.h:124
mbedtls_md_type_t
Supported message digests.
Definition: md.h:58
#define MBEDTLS_DEPRECATED
Definition: ecdsa.h:348
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...