ReactOS 0.4.15-dev-7924-g5949c20
ecdsa.h
Go to the documentation of this file.
1
13/*
14 * Copyright The Mbed TLS Contributors
15 * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
16 *
17 * This file is provided under the Apache License 2.0, or the
18 * GNU General Public License v2.0 or later.
19 *
20 * **********
21 * Apache License 2.0:
22 *
23 * Licensed under the Apache License, Version 2.0 (the "License"); you may
24 * not use this file except in compliance with the License.
25 * You may obtain a copy of the License at
26 *
27 * http://www.apache.org/licenses/LICENSE-2.0
28 *
29 * Unless required by applicable law or agreed to in writing, software
30 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
31 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
32 * See the License for the specific language governing permissions and
33 * limitations under the License.
34 *
35 * **********
36 *
37 * **********
38 * GNU General Public License v2.0 or later:
39 *
40 * This program is free software; you can redistribute it and/or modify
41 * it under the terms of the GNU General Public License as published by
42 * the Free Software Foundation; either version 2 of the License, or
43 * (at your option) any later version.
44 *
45 * This program is distributed in the hope that it will be useful,
46 * but WITHOUT ANY WARRANTY; without even the implied warranty of
47 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
48 * GNU General Public License for more details.
49 *
50 * You should have received a copy of the GNU General Public License along
51 * with this program; if not, write to the Free Software Foundation, Inc.,
52 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
53 *
54 * **********
55 */
56
57#ifndef MBEDTLS_ECDSA_H
58#define MBEDTLS_ECDSA_H
59
60#if !defined(MBEDTLS_CONFIG_FILE)
61#include "config.h"
62#else
63#include MBEDTLS_CONFIG_FILE
64#endif
65
66#include "ecp.h"
67#include "md.h"
68
69/*
70 * RFC-4492 page 20:
71 *
72 * Ecdsa-Sig-Value ::= SEQUENCE {
73 * r INTEGER,
74 * s INTEGER
75 * }
76 *
77 * Size is at most
78 * 1 (tag) + 1 (len) + 1 (initial 0) + ECP_MAX_BYTES for each of r and s,
79 * twice that + 1 (tag) + 2 (len) for the sequence
80 * (assuming ECP_MAX_BYTES is less than 126 for r and s,
81 * and less than 124 (total len <= 255) for the sequence)
82 */
83#if MBEDTLS_ECP_MAX_BYTES > 124
84#error "MBEDTLS_ECP_MAX_BYTES bigger than expected, please fix MBEDTLS_ECDSA_MAX_LEN"
85#endif
87#define MBEDTLS_ECDSA_MAX_LEN ( 3 + 2 * ( 3 + MBEDTLS_ECP_MAX_BYTES ) )
88
89#ifdef __cplusplus
90extern "C" {
91#endif
92
101
102#if defined(MBEDTLS_ECP_RESTARTABLE)
103
109typedef struct mbedtls_ecdsa_restart_ver mbedtls_ecdsa_restart_ver_ctx;
110
116typedef struct mbedtls_ecdsa_restart_sig mbedtls_ecdsa_restart_sig_ctx;
117
118#if defined(MBEDTLS_ECDSA_DETERMINISTIC)
124typedef struct mbedtls_ecdsa_restart_det mbedtls_ecdsa_restart_det_ctx;
125#endif
126
130typedef struct
131{
134 mbedtls_ecdsa_restart_ver_ctx *ver;
135 mbedtls_ecdsa_restart_sig_ctx *sig;
136#if defined(MBEDTLS_ECDSA_DETERMINISTIC)
137 mbedtls_ecdsa_restart_det_ctx *det;
138#endif
140
141#else /* MBEDTLS_ECP_RESTARTABLE */
142
143/* Now we can declare functions that take a pointer to that */
145
146#endif /* MBEDTLS_ECP_RESTARTABLE */
147
185 const mbedtls_mpi *d, const unsigned char *buf, size_t blen,
186 int (*f_rng)(void *, unsigned char *, size_t), void *p_rng );
187
188#if defined(MBEDTLS_ECDSA_DETERMINISTIC)
238 mbedtls_mpi *s, const mbedtls_mpi *d,
239 const unsigned char *buf, size_t blen,
240 mbedtls_md_type_t md_alg );
281 mbedtls_mpi *s, const mbedtls_mpi *d,
282 const unsigned char *buf, size_t blen,
283 mbedtls_md_type_t md_alg,
284 int (*f_rng_blind)(void *, unsigned char *,
285 size_t),
286 void *p_rng_blind );
287#endif /* MBEDTLS_ECDSA_DETERMINISTIC */
288
322 const unsigned char *buf, size_t blen,
323 const mbedtls_ecp_point *Q, const mbedtls_mpi *r,
324 const mbedtls_mpi *s);
325
374 mbedtls_md_type_t md_alg,
375 const unsigned char *hash, size_t hlen,
376 unsigned char *sig, size_t *slen,
377 int (*f_rng)(void *, unsigned char *, size_t),
378 void *p_rng );
379
420 mbedtls_md_type_t md_alg,
421 const unsigned char *hash, size_t hlen,
422 unsigned char *sig, size_t *slen,
423 int (*f_rng)(void *, unsigned char *, size_t),
424 void *p_rng,
426
427#if defined(MBEDTLS_ECDSA_DETERMINISTIC)
428#if ! defined(MBEDTLS_DEPRECATED_REMOVED)
429#if defined(MBEDTLS_DEPRECATED_WARNING)
430#define MBEDTLS_DEPRECATED __attribute__((deprecated))
431#else
432#define MBEDTLS_DEPRECATED
433#endif
478 const unsigned char *hash, size_t hlen,
479 unsigned char *sig, size_t *slen,
481#undef MBEDTLS_DEPRECATED
482#endif /* MBEDTLS_DEPRECATED_REMOVED */
483#endif /* MBEDTLS_ECDSA_DETERMINISTIC */
484
513 const unsigned char *hash, size_t hlen,
514 const unsigned char *sig, size_t slen );
515
548 const unsigned char *hash, size_t hlen,
549 const unsigned char *sig, size_t slen,
551
569 int (*f_rng)(void *, unsigned char *, size_t), void *p_rng );
570
587 const mbedtls_ecp_keypair *key );
588
596
605
606#if defined(MBEDTLS_ECP_RESTARTABLE)
613void mbedtls_ecdsa_restart_init( mbedtls_ecdsa_restart_ctx *ctx );
614
622void mbedtls_ecdsa_restart_free( mbedtls_ecdsa_restart_ctx *ctx );
623#endif /* MBEDTLS_ECP_RESTARTABLE */
624
625#ifdef __cplusplus
626}
627#endif
628
629#endif /* ecdsa.h */
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.
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.
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.
void mbedtls_ecdsa_free(mbedtls_ecdsa_context *ctx)
This function frees an ECDSA context.
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.
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...
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.
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...
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.
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_keypair mbedtls_ecdsa_context
The ECDSA context structure.
Definition: ecdsa.h:100
#define MBEDTLS_DEPRECATED
Definition: ecdsa.h:432
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.
void mbedtls_ecdsa_restart_ctx
Definition: ecdsa.h:144
void mbedtls_ecdsa_init(mbedtls_ecdsa_context *ctx)
This function initializes an ECDSA context.
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.
This file provides an API for Elliptic Curves over GF(P) (ECP).
mbedtls_ecp_group_id
Definition: ecp.h:103
GLdouble s
Definition: gl.h:2039
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
#define d
Definition: ke_i.h:81
This file contains the generic message-digest wrapper.
mbedtls_md_type_t
Supported message digests.
Definition: md.h:83
Definition: _hash_fun.h:40
Definition: copy.c:22
The ECP group structure.
Definition: ecp.h:233
The ECP key-pair structure.
Definition: ecp.h:398
The ECP point structure, in Jacobian coordinates.
Definition: ecp.h:150
MPI structure.
Definition: bignum.h:211