mbed TLS v2.7.6
ecdsa.h
Go to the documentation of this file.
1 
12 /*
13  * Copyright (C) 2006-2018, Arm Limited (or its affiliates), All Rights Reserved
14  * SPDX-License-Identifier: Apache-2.0
15  *
16  * Licensed under the Apache License, Version 2.0 (the "License"); you may
17  * not use this file except in compliance with the License.
18  * You may obtain a copy of the License at
19  *
20  * http://www.apache.org/licenses/LICENSE-2.0
21  *
22  * Unless required by applicable law or agreed to in writing, software
23  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
24  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
25  * See the License for the specific language governing permissions and
26  * limitations under the License.
27  *
28  * This file is part of Mbed TLS (https://tls.mbed.org)
29  */
30 
31 #ifndef MBEDTLS_ECDSA_H
32 #define MBEDTLS_ECDSA_H
33 
34 #include "ecp.h"
35 #include "md.h"
36 
37 /*
38  * RFC-4492 page 20:
39  *
40  * Ecdsa-Sig-Value ::= SEQUENCE {
41  * r INTEGER,
42  * s INTEGER
43  * }
44  *
45  * Size is at most
46  * 1 (tag) + 1 (len) + 1 (initial 0) + ECP_MAX_BYTES for each of r and s,
47  * twice that + 1 (tag) + 2 (len) for the sequence
48  * (assuming ECP_MAX_BYTES is less than 126 for r and s,
49  * and less than 124 (total len <= 255) for the sequence)
50  */
51 #if MBEDTLS_ECP_MAX_BYTES > 124
52 #error "MBEDTLS_ECP_MAX_BYTES bigger than expected, please fix MBEDTLS_ECDSA_MAX_LEN"
53 #endif
54 
55 #define MBEDTLS_ECDSA_MAX_LEN ( 3 + 2 * ( 3 + MBEDTLS_ECP_MAX_BYTES ) )
56 
61 
62 #ifdef __cplusplus
63 extern "C" {
64 #endif
65 
93  const mbedtls_mpi *d, const unsigned char *buf, size_t blen,
94  int (*f_rng)(void *, unsigned char *, size_t), void *p_rng );
95 
96 #if defined(MBEDTLS_ECDSA_DETERMINISTIC)
97 
125  const mbedtls_mpi *d, const unsigned char *buf, size_t blen,
126  mbedtls_md_type_t md_alg );
127 #endif /* MBEDTLS_ECDSA_DETERMINISTIC */
128 
154  const unsigned char *buf, size_t blen,
155  const mbedtls_ecp_point *Q, const mbedtls_mpi *r, const mbedtls_mpi *s);
156 
199  const unsigned char *hash, size_t hlen,
200  unsigned char *sig, size_t *slen,
201  int (*f_rng)(void *, unsigned char *, size_t),
202  void *p_rng );
203 
204 #if defined(MBEDTLS_ECDSA_DETERMINISTIC)
205 #if ! defined(MBEDTLS_DEPRECATED_REMOVED)
206 #if defined(MBEDTLS_DEPRECATED_WARNING)
207 #define MBEDTLS_DEPRECATED __attribute__((deprecated))
208 #else
209 #define MBEDTLS_DEPRECATED
210 #endif
211 
251  const unsigned char *hash, size_t hlen,
252  unsigned char *sig, size_t *slen,
254 #undef MBEDTLS_DEPRECATED
255 #endif /* MBEDTLS_DEPRECATED_REMOVED */
256 #endif /* MBEDTLS_ECDSA_DETERMINISTIC */
257 
283  const unsigned char *hash, size_t hlen,
284  const unsigned char *sig, size_t slen );
285 
301  int (*f_rng)(void *, unsigned char *, size_t), void *p_rng );
302 
315 
322 
329 
330 #ifdef __cplusplus
331 }
332 #endif
333 
334 #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:167
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:140
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(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:60
mbedtls_ecp_group_id
Definition: ecp.h:64
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:180
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:108
mbedtls_md_type_t
Enumeration of supported message digests.
Definition: md.h:56
#define MBEDTLS_DEPRECATED
Definition: ecdsa.h:209
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...