mbed TLS v2.7.17
ecdsa.h
Go to the documentation of this file.
1 
12 /*
13  * Copyright The Mbed TLS Contributors
14  * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
15  *
16  * This file is provided under the Apache License 2.0, or the
17  * GNU General Public License v2.0 or later.
18  *
19  * **********
20  * Apache License 2.0:
21  *
22  * Licensed under the Apache License, Version 2.0 (the "License"); you may
23  * not use this file except in compliance with the License.
24  * You may obtain a copy of the License at
25  *
26  * http://www.apache.org/licenses/LICENSE-2.0
27  *
28  * Unless required by applicable law or agreed to in writing, software
29  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
30  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
31  * See the License for the specific language governing permissions and
32  * limitations under the License.
33  *
34  * **********
35  *
36  * **********
37  * GNU General Public License v2.0 or later:
38  *
39  * This program is free software; you can redistribute it and/or modify
40  * it under the terms of the GNU General Public License as published by
41  * the Free Software Foundation; either version 2 of the License, or
42  * (at your option) any later version.
43  *
44  * This program is distributed in the hope that it will be useful,
45  * but WITHOUT ANY WARRANTY; without even the implied warranty of
46  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
47  * GNU General Public License for more details.
48  *
49  * You should have received a copy of the GNU General Public License along
50  * with this program; if not, write to the Free Software Foundation, Inc.,
51  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
52  *
53  * **********
54  */
55 
56 #ifndef MBEDTLS_ECDSA_H
57 #define MBEDTLS_ECDSA_H
58 
59 #if !defined(MBEDTLS_CONFIG_FILE)
60 #include "config.h"
61 #else
62 #include MBEDTLS_CONFIG_FILE
63 #endif
64 
65 #include "ecp.h"
66 #include "md.h"
67 
68 /*
69  * RFC-4492 page 20:
70  *
71  * Ecdsa-Sig-Value ::= SEQUENCE {
72  * r INTEGER,
73  * s INTEGER
74  * }
75  *
76  * Size is at most
77  * 1 (tag) + 1 (len) + 1 (initial 0) + ECP_MAX_BYTES for each of r and s,
78  * twice that + 1 (tag) + 2 (len) for the sequence
79  * (assuming ECP_MAX_BYTES is less than 126 for r and s,
80  * and less than 124 (total len <= 255) for the sequence)
81  */
82 #if MBEDTLS_ECP_MAX_BYTES > 124
83 #error "MBEDTLS_ECP_MAX_BYTES bigger than expected, please fix MBEDTLS_ECDSA_MAX_LEN"
84 #endif
85 
86 #define MBEDTLS_ECDSA_MAX_LEN ( 3 + 2 * ( 3 + MBEDTLS_ECP_MAX_BYTES ) )
87 
92 
93 #ifdef __cplusplus
94 extern "C" {
95 #endif
96 
124  const mbedtls_mpi *d, const unsigned char *buf, size_t blen,
125  int (*f_rng)(void *, unsigned char *, size_t), void *p_rng );
126 
127 #if defined(MBEDTLS_ECDSA_DETERMINISTIC)
128 
170  mbedtls_mpi *s, const mbedtls_mpi *d,
171  const unsigned char *buf, size_t blen,
172  mbedtls_md_type_t md_alg );
213  mbedtls_mpi *s, const mbedtls_mpi *d,
214  const unsigned char *buf, size_t blen,
215  mbedtls_md_type_t md_alg,
216  int (*f_rng_blind)(void *, unsigned char *,
217  size_t),
218  void *p_rng_blind );
219 #endif /* MBEDTLS_ECDSA_DETERMINISTIC */
220 
246  const unsigned char *buf, size_t blen,
247  const mbedtls_ecp_point *Q, const mbedtls_mpi *r, const mbedtls_mpi *s);
248 
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 
296 #if defined(MBEDTLS_ECDSA_DETERMINISTIC)
297 #if ! defined(MBEDTLS_DEPRECATED_REMOVED)
298 #if defined(MBEDTLS_DEPRECATED_WARNING)
299 #define MBEDTLS_DEPRECATED __attribute__((deprecated))
300 #else
301 #define MBEDTLS_DEPRECATED
302 #endif
303 
343  const unsigned char *hash, size_t hlen,
344  unsigned char *sig, size_t *slen,
346 #undef MBEDTLS_DEPRECATED
347 #endif /* MBEDTLS_DEPRECATED_REMOVED */
348 #endif /* MBEDTLS_ECDSA_DETERMINISTIC */
349 
375  const unsigned char *hash, size_t hlen,
376  const unsigned char *sig, size_t slen );
377 
393  int (*f_rng)(void *, unsigned char *, size_t), void *p_rng );
394 
407 
414 
421 
422 #ifdef __cplusplus
423 }
424 #endif
425 
426 #endif /* ecdsa.h */
void mbedtls_ecdsa_free(mbedtls_ecdsa_context *ctx)
This function frees an ECDSA context.
Elliptic curves over GF(p)
ECP key pair structure.
Definition: ecp.h:198
Configuration options (set of defines)
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.
ECP group structure.
Definition: ecp.h:171
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 an ECDSA context from an EC key pair.
int mbedtls_ecdsa_sign_det_ext(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, int(*f_rng_blind)(void *, unsigned char *, size_t), void *p_rng_blind)
This function computes the ECDSA signature of a previously-hashed message, deterministic version...
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:91
mbedtls_ecp_group_id
Definition: ecp.h:95
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.
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:205
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.
ECP point structure (jacobian coordinates)
Definition: ecp.h:139
mbedtls_md_type_t
Enumeration of supported message digests.
Definition: md.h:81
#define MBEDTLS_DEPRECATED
Definition: ecdsa.h:301
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...