mbed TLS v2.12.0

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
61 typedef mbedtls_ecp_keypair mbedtls_ecdsa_context;
62
63 #ifdef __cplusplus
64 extern "C" {
65 #endif
66
94 int mbedtls_ecdsa_sign( mbedtls_ecp_group *grp, mbedtls_mpi *r, mbedtls_mpi *s,
95 const mbedtls_mpi *d, const unsigned char *buf, size_t blen,
96 int (*f_rng)(void *, unsigned char *, size_t), void *p_rng );
97
98 #if defined(MBEDTLS_ECDSA_DETERMINISTIC)
99
127 int mbedtls_ecdsa_sign_det( mbedtls_ecp_group *grp, mbedtls_mpi *r, mbedtls_mpi *s,
128 const mbedtls_mpi *d, const unsigned char *buf, size_t blen,
129 mbedtls_md_type_t md_alg );
130 #endif /* MBEDTLS_ECDSA_DETERMINISTIC */
131
157 int mbedtls_ecdsa_verify( mbedtls_ecp_group *grp,
158 const unsigned char *buf, size_t blen,
159 const mbedtls_ecp_point *Q, const mbedtls_mpi *r, const mbedtls_mpi *s);
160
202 int mbedtls_ecdsa_write_signature( mbedtls_ecdsa_context *ctx, mbedtls_md_type_t md_alg,
203 const unsigned char *hash, size_t hlen,
204 unsigned char *sig, size_t *slen,
205 int (*f_rng)(void *, unsigned char *, size_t),
206 void *p_rng );
207
208 #if defined(MBEDTLS_ECDSA_DETERMINISTIC)
209 #if ! defined(MBEDTLS_DEPRECATED_REMOVED)
210 #if defined(MBEDTLS_DEPRECATED_WARNING)
211 #define MBEDTLS_DEPRECATED __attribute__((deprecated))
212 #else
213 #define MBEDTLS_DEPRECATED
214 #endif
215
255 int mbedtls_ecdsa_write_signature_det( mbedtls_ecdsa_context *ctx,
256 const unsigned char *hash, size_t hlen,
257 unsigned char *sig, size_t *slen,
258 mbedtls_md_type_t md_alg ) MBEDTLS_DEPRECATED;
259 #undef MBEDTLS_DEPRECATED
260 #endif /* MBEDTLS_DEPRECATED_REMOVED */
261 #endif /* MBEDTLS_ECDSA_DETERMINISTIC */
262
287 int mbedtls_ecdsa_read_signature( mbedtls_ecdsa_context *ctx,
288 const unsigned char *hash, size_t hlen,
289 const unsigned char *sig, size_t slen );
290
305 int mbedtls_ecdsa_genkey( mbedtls_ecdsa_context *ctx, mbedtls_ecp_group_id gid,
306 int (*f_rng)(void *, unsigned char *, size_t), void *p_rng );
307
319 int mbedtls_ecdsa_from_keypair( mbedtls_ecdsa_context *ctx, const mbedtls_ecp_keypair *key );
320
326 void mbedtls_ecdsa_init( mbedtls_ecdsa_context *ctx );
327
333 void mbedtls_ecdsa_free( mbedtls_ecdsa_context *ctx );
334
335 #ifdef __cplusplus
336 }
337 #endif
338
339 #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:254
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:159
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_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:61
mbedtls_ecp_group_id
mbedtls_ecp_group_id
Definition: ecp.h:67
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.
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:114
mbedtls_md_type_t
mbedtls_md_type_t
Supported message digests.
Definition: md.h:56
MBEDTLS_DEPRECATED
#define MBEDTLS_DEPRECATED
Definition: ecdsa.h:213
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...