blob: 3440a84fe94f1b83fb92b12ceb28276909bcbdbf [file] [log] [blame]
Manuel Pégourié-Gonnard2aea1412013-01-26 16:33:44 +01001/**
2 * \file ecdsa.h
3 *
4 * \brief Elliptic curve DSA
5 *
Manuel Pégourié-Gonnard6fb81872015-07-27 11:11:48 +02006 * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
Manuel Pégourié-Gonnard37ff1402015-09-04 14:21:07 +02007 * SPDX-License-Identifier: Apache-2.0
8 *
9 * Licensed under the Apache License, Version 2.0 (the "License"); you may
10 * not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
12 *
13 * http://www.apache.org/licenses/LICENSE-2.0
14 *
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
17 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
Manuel Pégourié-Gonnard2aea1412013-01-26 16:33:44 +010020 *
Manuel Pégourié-Gonnardfe446432015-03-06 13:17:10 +000021 * This file is part of mbed TLS (https://tls.mbed.org)
Manuel Pégourié-Gonnard2aea1412013-01-26 16:33:44 +010022 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020023#ifndef MBEDTLS_ECDSA_H
24#define MBEDTLS_ECDSA_H
Manuel Pégourié-Gonnard2aea1412013-01-26 16:33:44 +010025
Manuel Pégourié-Gonnardbdc96762013-10-03 11:50:39 +020026#include "ecp.h"
Manuel Pégourié-Gonnard887aa5b2014-04-04 13:57:20 +020027#include "md.h"
Manuel Pégourié-Gonnard4daaef72014-01-06 14:25:56 +010028
Manuel Pégourié-Gonnard63e93192015-03-31 11:15:48 +020029/*
30 * RFC 4492 page 20:
31 *
32 * Ecdsa-Sig-Value ::= SEQUENCE {
33 * r INTEGER,
34 * s INTEGER
35 * }
36 *
37 * Size is at most
38 * 1 (tag) + 1 (len) + 1 (initial 0) + ECP_MAX_BYTES for each of r and s,
39 * twice that + 1 (tag) + 2 (len) for the sequence
40 * (assuming ECP_MAX_BYTES is less than 126 for r and s,
41 * and less than 124 (total len <= 255) for the sequence)
42 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020043#if MBEDTLS_ECP_MAX_BYTES > 124
44#error "MBEDTLS_ECP_MAX_BYTES bigger than expected, please fix MBEDTLS_ECDSA_MAX_LEN"
Manuel Pégourié-Gonnard63e93192015-03-31 11:15:48 +020045#endif
Manuel Pégourié-Gonnard5bf262d2015-03-31 11:46:01 +020046/** Maximum size of an ECDSA signature in bytes */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020047#define MBEDTLS_ECDSA_MAX_LEN ( 3 + 2 * ( 3 + MBEDTLS_ECP_MAX_BYTES ) )
Manuel Pégourié-Gonnard63e93192015-03-31 11:15:48 +020048
Manuel Pégourié-Gonnard32aa4372017-04-21 10:29:13 +020049#ifdef __cplusplus
50extern "C" {
51#endif
52
Manuel Pégourié-Gonnardbec2f452013-06-27 10:17:07 +020053/**
54 * \brief ECDSA context structure
Manuel Pégourié-Gonnardeaf55be2017-08-23 14:40:21 +020055 *
56 * \warning Performing multiple operations concurrently on the same
57 * ECDSA context is not supported; objects of this type
58 * should not be shared between multiple threads.
Manuel Pégourié-Gonnardbec2f452013-06-27 10:17:07 +020059 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020060typedef mbedtls_ecp_keypair mbedtls_ecdsa_context;
Manuel Pégourié-Gonnardbec2f452013-06-27 10:17:07 +020061
Manuel Pégourié-Gonnard32aa4372017-04-21 10:29:13 +020062#if defined(MBEDTLS_ECP_RESTARTABLE)
63
64/**
Manuel Pégourié-Gonnarda0c5bcc2017-04-21 11:33:57 +020065 * \brief Internal restart context for ecdsa_verify()
66 *
67 * \note Opaque struct
68 */
69typedef struct mbedtls_ecdsa_restart_ver mbedtls_ecdsa_restart_ver_ctx;
70
71/**
Manuel Pégourié-Gonnardb90883d2017-04-25 11:33:10 +020072 * \brief Internal restart context for ecdsa_sign()
73 *
74 * \note Opaque struct, defined in ecdsa.c
75 */
76typedef struct mbedtls_ecdsa_restart_sig mbedtls_ecdsa_restart_sig_ctx;
77
78#if defined(MBEDTLS_ECDSA_DETERMINISTIC)
79/**
80 * \brief Internal restart context for ecdsa_sign_det()
81 *
82 * \note Opaque struct, defined in ecdsa.c
83 */
84typedef struct mbedtls_ecdsa_restart_det mbedtls_ecdsa_restart_det_ctx;
85#endif
86
87/**
Manuel Pégourié-Gonnard32aa4372017-04-21 10:29:13 +020088 * \brief General context for resuming ECDSA operations
89 */
90typedef struct
91{
Manuel Pégourié-Gonnard722e5152017-04-21 11:04:47 +020092 mbedtls_ecp_restart_ctx ecp; /*!< base context (admin+ecp info) */
Manuel Pégourié-Gonnarda0c5bcc2017-04-21 11:33:57 +020093 mbedtls_ecdsa_restart_ver_ctx *ver; /*!< ecdsa_verify() sub-context */
Manuel Pégourié-Gonnardb90883d2017-04-25 11:33:10 +020094 mbedtls_ecdsa_restart_sig_ctx *sig; /*!< ecdsa_sign() sub-context */
95#if defined(MBEDTLS_ECDSA_DETERMINISTIC)
96 mbedtls_ecdsa_restart_det_ctx *det; /*!< ecdsa_sign_det() sub-context */
97#endif
Manuel Pégourié-Gonnard32aa4372017-04-21 10:29:13 +020098} mbedtls_ecdsa_restart_ctx;
99
100#else /* MBEDTLS_ECP_RESTARTABLE */
101
102/* Now we can declare functions that take a pointer to that */
103typedef void mbedtls_ecdsa_restart_ctx;
104
105#endif /* MBEDTLS_ECP_RESTARTABLE */
Manuel Pégourié-Gonnard2aea1412013-01-26 16:33:44 +0100106
107/**
Manuel Pégourié-Gonnardb309ab22013-01-26 17:24:59 +0100108 * \brief Compute ECDSA signature of a previously hashed message
109 *
Manuel Pégourié-Gonnardb8cfe3f2015-03-31 11:04:45 +0200110 * \note The deterministic version is usually prefered.
111 *
Manuel Pégourié-Gonnardb309ab22013-01-26 17:24:59 +0100112 * \param grp ECP group
113 * \param r First output integer
114 * \param s Second output integer
115 * \param d Private signing key
116 * \param buf Message hash
117 * \param blen Length of buf
118 * \param f_rng RNG function
119 * \param p_rng RNG parameter
120 *
Janos Follath0a5154b2017-03-10 11:31:41 +0000121 * \note If the bitlength of the message hash is larger than the
122 * bitlength of the group order, then the hash is truncated as
123 * prescribed by SEC1 4.1.3 step 5.
124 *
Manuel Pégourié-Gonnardb309ab22013-01-26 17:24:59 +0100125 * \return 0 if successful,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200126 * or a MBEDTLS_ERR_ECP_XXX or MBEDTLS_MPI_XXX error code
Manuel Pégourié-Gonnardb309ab22013-01-26 17:24:59 +0100127 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200128int mbedtls_ecdsa_sign( mbedtls_ecp_group *grp, mbedtls_mpi *r, mbedtls_mpi *s,
129 const mbedtls_mpi *d, const unsigned char *buf, size_t blen,
Manuel Pégourié-Gonnardb309ab22013-01-26 17:24:59 +0100130 int (*f_rng)(void *, unsigned char *, size_t), void *p_rng );
131
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200132#if defined(MBEDTLS_ECDSA_DETERMINISTIC)
Manuel Pégourié-Gonnard4daaef72014-01-06 14:25:56 +0100133/**
Manuel Pégourié-Gonnardb8cfe3f2015-03-31 11:04:45 +0200134 * \brief Compute ECDSA signature of a previously hashed message,
135 * deterministic version (RFC 6979).
Manuel Pégourié-Gonnard4daaef72014-01-06 14:25:56 +0100136 *
137 * \param grp ECP group
138 * \param r First output integer
139 * \param s Second output integer
140 * \param d Private signing key
141 * \param buf Message hash
142 * \param blen Length of buf
143 * \param md_alg MD algorithm used to hash the message
144 *
Janos Follath0a5154b2017-03-10 11:31:41 +0000145 * \note If the bitlength of the message hash is larger than the
146 * bitlength of the group order, then the hash is truncated as
147 * prescribed by SEC1 4.1.3 step 5.
148 *
Manuel Pégourié-Gonnard4daaef72014-01-06 14:25:56 +0100149 * \return 0 if successful,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200150 * or a MBEDTLS_ERR_ECP_XXX or MBEDTLS_MPI_XXX error code
Manuel Pégourié-Gonnard4daaef72014-01-06 14:25:56 +0100151 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200152int mbedtls_ecdsa_sign_det( mbedtls_ecp_group *grp, mbedtls_mpi *r, mbedtls_mpi *s,
153 const mbedtls_mpi *d, const unsigned char *buf, size_t blen,
154 mbedtls_md_type_t md_alg );
155#endif /* MBEDTLS_ECDSA_DETERMINISTIC */
Manuel Pégourié-Gonnard4daaef72014-01-06 14:25:56 +0100156
Manuel Pégourié-Gonnardb309ab22013-01-26 17:24:59 +0100157/**
Manuel Pégourié-Gonnard3aeb5a72013-01-26 18:05:50 +0100158 * \brief Verify ECDSA signature of a previously hashed message
159 *
160 * \param grp ECP group
161 * \param buf Message hash
162 * \param blen Length of buf
163 * \param Q Public key to use for verification
164 * \param r First integer of the signature
165 * \param s Second integer of the signature
166 *
Janos Follath0a5154b2017-03-10 11:31:41 +0000167 * \note If the bitlength of the message hash is larger than the
168 * bitlength of the group order, then the hash is truncated as
169 * prescribed by SEC1 4.1.4 step 3.
170 *
Manuel Pégourié-Gonnard3aeb5a72013-01-26 18:05:50 +0100171 * \return 0 if successful,
Manuel Pégourié-Gonnard1ed25052017-04-21 10:04:02 +0200172 * MBEDTLS_ERR_ECP_VERIFY_FAILED if signature is invalid
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200173 * or a MBEDTLS_ERR_ECP_XXX or MBEDTLS_MPI_XXX error code
Manuel Pégourié-Gonnard3aeb5a72013-01-26 18:05:50 +0100174 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200175int mbedtls_ecdsa_verify( mbedtls_ecp_group *grp,
Manuel Pégourié-Gonnard3aeb5a72013-01-26 18:05:50 +0100176 const unsigned char *buf, size_t blen,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200177 const mbedtls_ecp_point *Q, const mbedtls_mpi *r, const mbedtls_mpi *s);
Manuel Pégourié-Gonnard3aeb5a72013-01-26 18:05:50 +0100178
179/**
Manuel Pégourié-Gonnardaa431612013-08-09 17:10:27 +0200180 * \brief Compute ECDSA signature and write it to buffer,
181 * serialized as defined in RFC 4492 page 20.
Paul Bakker6838bd12013-09-30 13:56:38 +0200182 * (Not thread-safe to use same context in multiple threads)
Manuel Pégourié-Gonnardb694b482013-08-08 13:30:57 +0200183 *
Janos Follath0a5154b2017-03-10 11:31:41 +0000184 * \note The deterministic version (RFC 6979) is used if
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200185 * MBEDTLS_ECDSA_DETERMINISTIC is defined.
Manuel Pégourié-Gonnarddfdcac92015-03-31 11:41:42 +0200186 *
Manuel Pégourié-Gonnardb694b482013-08-08 13:30:57 +0200187 * \param ctx ECDSA context
Manuel Pégourié-Gonnarddfdcac92015-03-31 11:41:42 +0200188 * \param md_alg Algorithm that was used to hash the message
Manuel Pégourié-Gonnardb694b482013-08-08 13:30:57 +0200189 * \param hash Message hash
190 * \param hlen Length of hash
191 * \param sig Buffer that will hold the signature
192 * \param slen Length of the signature written
193 * \param f_rng RNG function
194 * \param p_rng RNG parameter
195 *
196 * \note The "sig" buffer must be at least as large as twice the
Manuel Pégourié-Gonnard5bf262d2015-03-31 11:46:01 +0200197 * size of the curve used, plus 9 (eg. 73 bytes if a 256-bit
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200198 * curve is used). MBEDTLS_ECDSA_MAX_LEN is always safe.
Manuel Pégourié-Gonnardb694b482013-08-08 13:30:57 +0200199 *
Janos Follath0a5154b2017-03-10 11:31:41 +0000200 * \note If the bitlength of the message hash is larger than the
201 * bitlength of the group order, then the hash is truncated as
202 * prescribed by SEC1 4.1.3 step 5.
203 *
Manuel Pégourié-Gonnardb694b482013-08-08 13:30:57 +0200204 * \return 0 if successful,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200205 * or a MBEDTLS_ERR_ECP_XXX, MBEDTLS_ERR_MPI_XXX or
206 * MBEDTLS_ERR_ASN1_XXX error code
Manuel Pégourié-Gonnardb694b482013-08-08 13:30:57 +0200207 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200208int mbedtls_ecdsa_write_signature( mbedtls_ecdsa_context *ctx, mbedtls_md_type_t md_alg,
Manuel Pégourié-Gonnardb694b482013-08-08 13:30:57 +0200209 const unsigned char *hash, size_t hlen,
210 unsigned char *sig, size_t *slen,
211 int (*f_rng)(void *, unsigned char *, size_t),
212 void *p_rng );
213
Manuel Pégourié-Gonnardaddb10e2017-04-21 12:54:46 +0200214/**
215 * \brief Restartable version of \c mbedtls_ecdsa_write_signature()
216 *
217 * \note Performs the same job as \c mbedtls_ecdsa_write_signature()
218 * but can return early and restart according to the limit
219 * set with \c mbedtls_ecp_set_max_ops() to reduce blocking.
220 *
221 * \param ctx ECDSA context
222 * \param md_alg Algorithm that was used to hash the message
223 * \param hash Message hash
224 * \param hlen Length of hash
225 * \param sig Buffer that will hold the signature
226 * \param slen Length of the signature written
227 * \param f_rng RNG function
228 * \param p_rng RNG parameter
229 * \param rs_ctx Restart context
230 *
231 * \return See \c mbedtls_ecdsa_write_signature(), or
232 * MBEDTLS_ERR_ECP_IN_PROGRESS if maximum number of
233 * operations was reached: see \c mbedtls_ecp_set_max_ops().
234 */
235int mbedtls_ecdsa_write_signature_restartable( mbedtls_ecdsa_context *ctx,
236 mbedtls_md_type_t md_alg,
237 const unsigned char *hash, size_t hlen,
238 unsigned char *sig, size_t *slen,
239 int (*f_rng)(void *, unsigned char *, size_t),
240 void *p_rng,
241 mbedtls_ecdsa_restart_ctx *rs_ctx );
242
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200243#if defined(MBEDTLS_ECDSA_DETERMINISTIC)
244#if ! defined(MBEDTLS_DEPRECATED_REMOVED)
245#if defined(MBEDTLS_DEPRECATED_WARNING)
246#define MBEDTLS_DEPRECATED __attribute__((deprecated))
Manuel Pégourié-Gonnarddfdcac92015-03-31 11:41:42 +0200247#else
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200248#define MBEDTLS_DEPRECATED
Manuel Pégourié-Gonnarddfdcac92015-03-31 11:41:42 +0200249#endif
Manuel Pégourié-Gonnard937340b2014-01-06 10:27:16 +0100250/**
251 * \brief Compute ECDSA signature and write it to buffer,
252 * serialized as defined in RFC 4492 page 20.
253 * Deterministic version, RFC 6979.
254 * (Not thread-safe to use same context in multiple threads)
255 *
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200256 * \deprecated Superseded by mbedtls_ecdsa_write_signature() in 2.0.0
Manuel Pégourié-Gonnarddfdcac92015-03-31 11:41:42 +0200257 *
Manuel Pégourié-Gonnard937340b2014-01-06 10:27:16 +0100258 * \param ctx ECDSA context
259 * \param hash Message hash
260 * \param hlen Length of hash
261 * \param sig Buffer that will hold the signature
262 * \param slen Length of the signature written
263 * \param md_alg MD algorithm used to hash the message
264 *
265 * \note The "sig" buffer must be at least as large as twice the
Manuel Pégourié-Gonnard5bf262d2015-03-31 11:46:01 +0200266 * size of the curve used, plus 9 (eg. 73 bytes if a 256-bit
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200267 * curve is used). MBEDTLS_ECDSA_MAX_LEN is always safe.
Manuel Pégourié-Gonnard937340b2014-01-06 10:27:16 +0100268 *
Janos Follath0a5154b2017-03-10 11:31:41 +0000269 * \note If the bitlength of the message hash is larger than the
270 * bitlength of the group order, then the hash is truncated as
271 * prescribed by SEC1 4.1.3 step 5.
272 *
Manuel Pégourié-Gonnard937340b2014-01-06 10:27:16 +0100273 * \return 0 if successful,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200274 * or a MBEDTLS_ERR_ECP_XXX, MBEDTLS_ERR_MPI_XXX or
275 * MBEDTLS_ERR_ASN1_XXX error code
Manuel Pégourié-Gonnard937340b2014-01-06 10:27:16 +0100276 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200277int mbedtls_ecdsa_write_signature_det( mbedtls_ecdsa_context *ctx,
Manuel Pégourié-Gonnard937340b2014-01-06 10:27:16 +0100278 const unsigned char *hash, size_t hlen,
279 unsigned char *sig, size_t *slen,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200280 mbedtls_md_type_t md_alg ) MBEDTLS_DEPRECATED;
281#undef MBEDTLS_DEPRECATED
282#endif /* MBEDTLS_DEPRECATED_REMOVED */
283#endif /* MBEDTLS_ECDSA_DETERMINISTIC */
Manuel Pégourié-Gonnard937340b2014-01-06 10:27:16 +0100284
Manuel Pégourié-Gonnardb694b482013-08-08 13:30:57 +0200285/**
286 * \brief Read and verify an ECDSA signature
287 *
288 * \param ctx ECDSA context
289 * \param hash Message hash
290 * \param hlen Size of hash
291 * \param sig Signature to read and verify
292 * \param slen Size of sig
293 *
Janos Follath0a5154b2017-03-10 11:31:41 +0000294 * \note If the bitlength of the message hash is larger than the
295 * bitlength of the group order, then the hash is truncated as
296 * prescribed by SEC1 4.1.4 step 3.
297 *
Manuel Pégourié-Gonnardb694b482013-08-08 13:30:57 +0200298 * \return 0 if successful,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200299 * MBEDTLS_ERR_ECP_BAD_INPUT_DATA if signature is invalid,
300 * MBEDTLS_ERR_ECP_SIG_LEN_MISMATCH if the signature is
Manuel Pégourié-Gonnard35e95dd2014-04-08 12:17:41 +0200301 * valid but its actual length is less than siglen,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200302 * or a MBEDTLS_ERR_ECP_XXX or MBEDTLS_ERR_MPI_XXX error code
Manuel Pégourié-Gonnardb694b482013-08-08 13:30:57 +0200303 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200304int mbedtls_ecdsa_read_signature( mbedtls_ecdsa_context *ctx,
Manuel Pégourié-Gonnardb694b482013-08-08 13:30:57 +0200305 const unsigned char *hash, size_t hlen,
306 const unsigned char *sig, size_t slen );
307
308/**
Manuel Pégourié-Gonnard32aa4372017-04-21 10:29:13 +0200309 * \brief Restartable version of \c mbedtls_ecdsa_read_signature()
310 *
311 * \note Performs the same job as \c mbedtls_ecdsa_read_signature()
312 * but can return early and restart according to the limit
313 * set with \c mbedtls_ecp_set_max_ops() to reduce blocking.
314 *
315 * \param ctx ECDSA context
316 * \param hash Message hash
317 * \param hlen Size of hash
318 * \param sig Signature to read and verify
319 * \param slen Size of sig
320 * \param rs_ctx Restart context
321 *
322 * \return See \c mbedtls_ecdsa_read_signature(), or
323 * MBEDTLS_ERR_ECP_IN_PROGRESS if maximum number of
324 * operations was reached: see \c mbedtls_ecp_set_max_ops().
325 */
326int mbedtls_ecdsa_read_signature_restartable( mbedtls_ecdsa_context *ctx,
327 const unsigned char *hash, size_t hlen,
328 const unsigned char *sig, size_t slen,
329 mbedtls_ecdsa_restart_ctx *rs_ctx );
330
331/**
Manuel Pégourié-Gonnard8eebd012013-08-09 16:21:34 +0200332 * \brief Generate an ECDSA keypair on the given curve
333 *
334 * \param ctx ECDSA context in which the keypair should be stored
Paul Bakkerdcbfdcc2013-09-10 16:16:50 +0200335 * \param gid Group (elliptic curve) to use. One of the various
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200336 * MBEDTLS_ECP_DP_XXX macros depending on configuration.
Manuel Pégourié-Gonnard8eebd012013-08-09 16:21:34 +0200337 * \param f_rng RNG function
338 * \param p_rng RNG parameter
339 *
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200340 * \return 0 on success, or a MBEDTLS_ERR_ECP_XXX code.
Manuel Pégourié-Gonnard8eebd012013-08-09 16:21:34 +0200341 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200342int mbedtls_ecdsa_genkey( mbedtls_ecdsa_context *ctx, mbedtls_ecp_group_id gid,
Manuel Pégourié-Gonnard8eebd012013-08-09 16:21:34 +0200343 int (*f_rng)(void *, unsigned char *, size_t), void *p_rng );
344
345/**
Manuel Pégourié-Gonnardf4999932013-08-12 17:02:59 +0200346 * \brief Set an ECDSA context from an EC key pair
347 *
348 * \param ctx ECDSA context to set
349 * \param key EC key to use
350 *
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200351 * \return 0 on success, or a MBEDTLS_ERR_ECP_XXX code.
Manuel Pégourié-Gonnardf4999932013-08-12 17:02:59 +0200352 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200353int mbedtls_ecdsa_from_keypair( mbedtls_ecdsa_context *ctx, const mbedtls_ecp_keypair *key );
Manuel Pégourié-Gonnardf4999932013-08-12 17:02:59 +0200354
355/**
Manuel Pégourié-Gonnard7c8934e2013-06-27 12:54:02 +0200356 * \brief Initialize context
357 *
358 * \param ctx Context to initialize
359 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200360void mbedtls_ecdsa_init( mbedtls_ecdsa_context *ctx );
Manuel Pégourié-Gonnard7c8934e2013-06-27 12:54:02 +0200361
362/**
363 * \brief Free context
364 *
365 * \param ctx Context to free
366 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200367void mbedtls_ecdsa_free( mbedtls_ecdsa_context *ctx );
Manuel Pégourié-Gonnard7c8934e2013-06-27 12:54:02 +0200368
Manuel Pégourié-Gonnard32aa4372017-04-21 10:29:13 +0200369#if defined(MBEDTLS_ECP_RESTARTABLE)
370/**
371 * \brief Initialize a restart context
372 */
373void mbedtls_ecdsa_restart_init( mbedtls_ecdsa_restart_ctx *ctx );
374
375/**
376 * \brief Free the components of a restart context
377 */
378void mbedtls_ecdsa_restart_free( mbedtls_ecdsa_restart_ctx *ctx );
379#endif /* MBEDTLS_ECP_RESTARTABLE */
380
Manuel Pégourié-Gonnard2aea1412013-01-26 16:33:44 +0100381#ifdef __cplusplus
382}
383#endif
384
Paul Bakker9af723c2014-05-01 13:03:14 +0200385#endif /* ecdsa.h */