mbed TLS v2.16.3: ecdsa.h Source File

mbed TLS v2.16.3

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
75 typedef mbedtls_ecp_keypair mbedtls_ecdsa_context;
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 {
107 mbedtls_ecp_restart_ctx ecp;
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
114 } mbedtls_ecdsa_restart_ctx;
115
116 #else /* MBEDTLS_ECP_RESTARTABLE */
117
118 /* Now we can declare functions that take a pointer to that */
119 typedef void mbedtls_ecdsa_restart_ctx;
120
121 #endif /* MBEDTLS_ECP_RESTARTABLE */
122
159 int mbedtls_ecdsa_sign( mbedtls_ecp_group *grp, mbedtls_mpi *r, mbedtls_mpi *s,
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
212 int mbedtls_ecdsa_sign_det( mbedtls_ecp_group *grp, mbedtls_mpi *r,
213 mbedtls_mpi *s, const mbedtls_mpi *d,
214 const unsigned char *buf, size_t blen,
215 mbedtls_md_type_t md_alg );
255 int mbedtls_ecdsa_sign_det_ext( mbedtls_ecp_group *grp, mbedtls_mpi *r,
256 mbedtls_mpi *s, const mbedtls_mpi *d,
257 const unsigned char *buf, size_t blen,
258 mbedtls_md_type_t md_alg,
259 int (*f_rng_blind)(void *, unsigned char *,
260 size_t),
261 void *p_rng_blind );
262 #endif /* MBEDTLS_ECDSA_DETERMINISTIC */
263
296 int mbedtls_ecdsa_verify( mbedtls_ecp_group *grp,
297 const unsigned char *buf, size_t blen,
298 const mbedtls_ecp_point *Q, const mbedtls_mpi *r,
299 const mbedtls_mpi *s);
300
348 int mbedtls_ecdsa_write_signature( mbedtls_ecdsa_context *ctx,
349 mbedtls_md_type_t md_alg,
350 const unsigned char *hash, size_t hlen,
351 unsigned char *sig, size_t *slen,
352 int (*f_rng)(void *, unsigned char *, size_t),
353 void *p_rng );
354
394 int mbedtls_ecdsa_write_signature_restartable( mbedtls_ecdsa_context *ctx,
395 mbedtls_md_type_t md_alg,
396 const unsigned char *hash, size_t hlen,
397 unsigned char *sig, size_t *slen,
398 int (*f_rng)(void *, unsigned char *, size_t),
399 void *p_rng,
400 mbedtls_ecdsa_restart_ctx *rs_ctx );
401
402 #if defined(MBEDTLS_ECDSA_DETERMINISTIC)
403 #if ! defined(MBEDTLS_DEPRECATED_REMOVED)
404 #if defined(MBEDTLS_DEPRECATED_WARNING)
405 #define MBEDTLS_DEPRECATED __attribute__((deprecated))
406 #else
407 #define MBEDTLS_DEPRECATED
408 #endif
409
452 int mbedtls_ecdsa_write_signature_det( mbedtls_ecdsa_context *ctx,
453 const unsigned char *hash, size_t hlen,
454 unsigned char *sig, size_t *slen,
455 mbedtls_md_type_t md_alg ) MBEDTLS_DEPRECATED;
456 #undef MBEDTLS_DEPRECATED
457 #endif /* MBEDTLS_DEPRECATED_REMOVED */
458 #endif /* MBEDTLS_ECDSA_DETERMINISTIC */
459
487 int mbedtls_ecdsa_read_signature( mbedtls_ecdsa_context *ctx,
488 const unsigned char *hash, size_t hlen,
489 const unsigned char *sig, size_t slen );
490
522 int mbedtls_ecdsa_read_signature_restartable( mbedtls_ecdsa_context *ctx,
523 const unsigned char *hash, size_t hlen,
524 const unsigned char *sig, size_t slen,
525 mbedtls_ecdsa_restart_ctx *rs_ctx );
526
543 int mbedtls_ecdsa_genkey( mbedtls_ecdsa_context *ctx, mbedtls_ecp_group_id gid,
544 int (*f_rng)(void *, unsigned char *, size_t), void *p_rng );
545
561 int mbedtls_ecdsa_from_keypair( mbedtls_ecdsa_context *ctx,
562 const mbedtls_ecp_keypair *key );
563
570 void mbedtls_ecdsa_init( mbedtls_ecdsa_context *ctx );
571
579 void mbedtls_ecdsa_free( mbedtls_ecdsa_context *ctx );
580
581 #if defined(MBEDTLS_ECP_RESTARTABLE)
582
588 void mbedtls_ecdsa_restart_init( mbedtls_ecdsa_restart_ctx *ctx );
589
597 void mbedtls_ecdsa_restart_free( mbedtls_ecdsa_restart_ctx *ctx );
598 #endif /* MBEDTLS_ECP_RESTARTABLE */
599
600 #ifdef __cplusplus
601 }
602 #endif
603
604 #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:173
ecp.h
This file provides an API for Elliptic Curves over GF(P) (ECP).
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_DEPRECATED
#define MBEDTLS_DEPRECATED
Definition: ecdsa.h:407
mbedtls_mpi
MPI structure.
Definition: bignum.h:185
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:320
mbedtls_ecdsa_restart_ctx
void mbedtls_ecdsa_restart_ctx
Definition: ecdsa.h:119
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_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:332
mbedtls_ecp_group_id
mbedtls_ecp_group_id
Definition: ecp.h:77
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.
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:124
mbedtls_ecdsa_context
mbedtls_ecp_keypair mbedtls_ecdsa_context
The ECDSA context structure.
Definition: ecdsa.h:75
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.