mbed TLS v2.23.0: ecdsa.h Source File

mbed TLS v2.23.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 #if !defined(MBEDTLS_CONFIG_FILE)
36 #include "mbedtls/config.h"
37 #else
38 #include MBEDTLS_CONFIG_FILE
39 #endif
40
41 #include "mbedtls/ecp.h"
42 #include "mbedtls/md.h"
43
53 /*
54 * Ecdsa-Sig-Value ::= SEQUENCE {
55 * r INTEGER,
56 * s INTEGER
57 * }
58 *
59 * For each of r and s, the value (V) may include an extra initial "0" bit.
60 */
61 #define MBEDTLS_ECDSA_MAX_SIG_LEN( bits ) \
62 ( /*T,L of SEQUENCE*/ ( ( bits ) >= 61 * 8 ? 3 : 2 ) + \
63 /*T,L of r,s*/ 2 * ( ( ( bits ) >= 127 * 8 ? 3 : 2 ) + \
64 /*V of r,s*/ ( ( bits ) + 8 ) / 8 ) )
65
67 #define MBEDTLS_ECDSA_MAX_LEN MBEDTLS_ECDSA_MAX_SIG_LEN( MBEDTLS_ECP_MAX_BITS )
68
69 #ifdef __cplusplus
70 extern "C" {
71 #endif
72
80 typedef mbedtls_ecp_keypair mbedtls_ecdsa_context;
81
82 #if defined(MBEDTLS_ECP_RESTARTABLE)
83
89 typedef struct mbedtls_ecdsa_restart_ver mbedtls_ecdsa_restart_ver_ctx;
90
96 typedef struct mbedtls_ecdsa_restart_sig mbedtls_ecdsa_restart_sig_ctx;
97
98 #if defined(MBEDTLS_ECDSA_DETERMINISTIC)
99
104 typedef struct mbedtls_ecdsa_restart_det mbedtls_ecdsa_restart_det_ctx;
105 #endif
106
110 typedef struct
111 {
112 mbedtls_ecp_restart_ctx ecp;
114 mbedtls_ecdsa_restart_ver_ctx *ver;
115 mbedtls_ecdsa_restart_sig_ctx *sig;
116 #if defined(MBEDTLS_ECDSA_DETERMINISTIC)
117 mbedtls_ecdsa_restart_det_ctx *det;
118 #endif
119 } mbedtls_ecdsa_restart_ctx;
120
121 #else /* MBEDTLS_ECP_RESTARTABLE */
122
123 /* Now we can declare functions that take a pointer to that */
124 typedef void mbedtls_ecdsa_restart_ctx;
125
126 #endif /* MBEDTLS_ECP_RESTARTABLE */
127
136 int mbedtls_ecdsa_can_do( mbedtls_ecp_group_id gid );
137
174 int mbedtls_ecdsa_sign( mbedtls_ecp_group *grp, mbedtls_mpi *r, mbedtls_mpi *s,
175 const mbedtls_mpi *d, const unsigned char *buf, size_t blen,
176 int (*f_rng)(void *, unsigned char *, size_t), void *p_rng );
177
178 #if defined(MBEDTLS_ECDSA_DETERMINISTIC)
179 #if ! defined(MBEDTLS_DEPRECATED_REMOVED)
180 #if defined(MBEDTLS_DEPRECATED_WARNING)
181 #define MBEDTLS_DEPRECATED __attribute__((deprecated))
182 #else
183 #define MBEDTLS_DEPRECATED
184 #endif
185
233 int mbedtls_ecdsa_sign_det( mbedtls_ecp_group *grp, mbedtls_mpi *r,
234 mbedtls_mpi *s, const mbedtls_mpi *d,
235 const unsigned char *buf, size_t blen,
236 mbedtls_md_type_t md_alg ) MBEDTLS_DEPRECATED;
237 #undef MBEDTLS_DEPRECATED
238 #endif /* MBEDTLS_DEPRECATED_REMOVED */
239
279 int mbedtls_ecdsa_sign_det_ext( mbedtls_ecp_group *grp, mbedtls_mpi *r,
280 mbedtls_mpi *s, const mbedtls_mpi *d,
281 const unsigned char *buf, size_t blen,
282 mbedtls_md_type_t md_alg,
283 int (*f_rng_blind)(void *, unsigned char *, size_t),
284 void *p_rng_blind );
285 #endif /* MBEDTLS_ECDSA_DETERMINISTIC */
286
319 int mbedtls_ecdsa_verify( mbedtls_ecp_group *grp,
320 const unsigned char *buf, size_t blen,
321 const mbedtls_ecp_point *Q, const mbedtls_mpi *r,
322 const mbedtls_mpi *s);
323
372 int mbedtls_ecdsa_write_signature( mbedtls_ecdsa_context *ctx,
373 mbedtls_md_type_t md_alg,
374 const unsigned char *hash, size_t hlen,
375 unsigned char *sig, size_t *slen,
376 int (*f_rng)(void *, unsigned char *, size_t),
377 void *p_rng );
378
418 int mbedtls_ecdsa_write_signature_restartable( mbedtls_ecdsa_context *ctx,
419 mbedtls_md_type_t md_alg,
420 const unsigned char *hash, size_t hlen,
421 unsigned char *sig, size_t *slen,
422 int (*f_rng)(void *, unsigned char *, size_t),
423 void *p_rng,
424 mbedtls_ecdsa_restart_ctx *rs_ctx );
425
426 #if defined(MBEDTLS_ECDSA_DETERMINISTIC)
427 #if ! defined(MBEDTLS_DEPRECATED_REMOVED)
428 #if defined(MBEDTLS_DEPRECATED_WARNING)
429 #define MBEDTLS_DEPRECATED __attribute__((deprecated))
430 #else
431 #define MBEDTLS_DEPRECATED
432 #endif
433
476 int mbedtls_ecdsa_write_signature_det( mbedtls_ecdsa_context *ctx,
477 const unsigned char *hash, size_t hlen,
478 unsigned char *sig, size_t *slen,
479 mbedtls_md_type_t md_alg ) MBEDTLS_DEPRECATED;
480 #undef MBEDTLS_DEPRECATED
481 #endif /* MBEDTLS_DEPRECATED_REMOVED */
482 #endif /* MBEDTLS_ECDSA_DETERMINISTIC */
483
511 int mbedtls_ecdsa_read_signature( mbedtls_ecdsa_context *ctx,
512 const unsigned char *hash, size_t hlen,
513 const unsigned char *sig, size_t slen );
514
546 int mbedtls_ecdsa_read_signature_restartable( mbedtls_ecdsa_context *ctx,
547 const unsigned char *hash, size_t hlen,
548 const unsigned char *sig, size_t slen,
549 mbedtls_ecdsa_restart_ctx *rs_ctx );
550
567 int mbedtls_ecdsa_genkey( mbedtls_ecdsa_context *ctx, mbedtls_ecp_group_id gid,
568 int (*f_rng)(void *, unsigned char *, size_t), void *p_rng );
569
585 int mbedtls_ecdsa_from_keypair( mbedtls_ecdsa_context *ctx,
586 const mbedtls_ecp_keypair *key );
587
594 void mbedtls_ecdsa_init( mbedtls_ecdsa_context *ctx );
595
603 void mbedtls_ecdsa_free( mbedtls_ecdsa_context *ctx );
604
605 #if defined(MBEDTLS_ECP_RESTARTABLE)
606
612 void mbedtls_ecdsa_restart_init( mbedtls_ecdsa_restart_ctx *ctx );
613
621 void mbedtls_ecdsa_restart_free( mbedtls_ecdsa_restart_ctx *ctx );
622 #endif /* MBEDTLS_ECP_RESTARTABLE */
623
624 #ifdef __cplusplus
625 }
626 #endif
627
628 #endif /* ecdsa.h */
mbedtls_md_type_t
mbedtls_md_type_t
Supported message digests.
Definition: md.h:58
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_ecp_group
The ECP group structure.
Definition: ecp.h:184
ecp.h
This file provides an API for Elliptic Curves over GF(P) (ECP).
MBEDTLS_DEPRECATED
#define MBEDTLS_DEPRECATED
Definition: ecdsa.h:431
mbedtls_mpi
MPI structure.
Definition: bignum.h:187
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...
md.h
This file contains the generic message-digest wrapper.
mbedtls_ecp_restart_ctx
void mbedtls_ecp_restart_ctx
Definition: ecp.h:330
mbedtls_ecdsa_restart_ctx
void mbedtls_ecdsa_restart_ctx
Definition: ecdsa.h:124
mbedtls_ecdsa_from_keypair
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.
mbedtls_ecdsa_init
void mbedtls_ecdsa_init(mbedtls_ecdsa_context *ctx)
This function initializes an ECDSA context.
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_ecdsa_can_do
int mbedtls_ecdsa_can_do(mbedtls_ecp_group_id gid)
This function checks whether a given group can be used for ECDSA.
mbedtls_ecdsa_free
void mbedtls_ecdsa_free(mbedtls_ecdsa_context *ctx)
This function frees an ECDSA context.
mbedtls_ecp_keypair
The ECP key-pair structure.
Definition: ecp.h:343
mbedtls_ecp_group_id
mbedtls_ecp_group_id
Definition: ecp.h:78
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_ecdsa_sign_det_ext
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.
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.
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_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) MBEDTLS_DEPRECATED
This function computes the ECDSA signature of a previously-hashed message, deterministic version.
config.h
Configuration options (set of defines)
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_ecp_point
The ECP point structure, in Jacobian coordinates.
Definition: ecp.h:135
mbedtls_ecdsa_context
mbedtls_ecp_keypair mbedtls_ecdsa_context
The ECDSA context structure.
Definition: ecdsa.h:80
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.