blob: 77842526cc2d66f074d5451d9f24357104cb4e00 [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
55 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020056typedef mbedtls_ecp_keypair mbedtls_ecdsa_context;
Manuel Pégourié-Gonnardbec2f452013-06-27 10:17:07 +020057
Manuel Pégourié-Gonnard32aa4372017-04-21 10:29:13 +020058#if defined(MBEDTLS_ECP_RESTARTABLE)
59
60/**
Manuel Pégourié-Gonnarda0c5bcc2017-04-21 11:33:57 +020061 * \brief Internal restart context for ecdsa_verify()
62 *
63 * \note Opaque struct
64 */
65typedef struct mbedtls_ecdsa_restart_ver mbedtls_ecdsa_restart_ver_ctx;
66
67/**
Manuel Pégourié-Gonnardb90883d2017-04-25 11:33:10 +020068 * \brief Internal restart context for ecdsa_sign()
69 *
70 * \note Opaque struct, defined in ecdsa.c
71 */
72typedef struct mbedtls_ecdsa_restart_sig mbedtls_ecdsa_restart_sig_ctx;
73
74#if defined(MBEDTLS_ECDSA_DETERMINISTIC)
75/**
76 * \brief Internal restart context for ecdsa_sign_det()
77 *
78 * \note Opaque struct, defined in ecdsa.c
79 */
80typedef struct mbedtls_ecdsa_restart_det mbedtls_ecdsa_restart_det_ctx;
81#endif
82
83/**
Manuel Pégourié-Gonnard32aa4372017-04-21 10:29:13 +020084 * \brief General context for resuming ECDSA operations
85 */
86typedef struct
87{
Manuel Pégourié-Gonnard722e5152017-04-21 11:04:47 +020088 mbedtls_ecp_restart_ctx ecp; /*!< base context (admin+ecp info) */
Manuel Pégourié-Gonnarda0c5bcc2017-04-21 11:33:57 +020089 mbedtls_ecdsa_restart_ver_ctx *ver; /*!< ecdsa_verify() sub-context */
Manuel Pégourié-Gonnardb90883d2017-04-25 11:33:10 +020090 mbedtls_ecdsa_restart_sig_ctx *sig; /*!< ecdsa_sign() sub-context */
91#if defined(MBEDTLS_ECDSA_DETERMINISTIC)
92 mbedtls_ecdsa_restart_det_ctx *det; /*!< ecdsa_sign_det() sub-context */
93#endif
Manuel Pégourié-Gonnard1f596062017-05-09 10:42:40 +020094#if defined(MBEDTLS_PK_C)
95 mbedtls_ecdsa_context *ecdsa; /*!< used by the PK layer */
96#endif
Manuel Pégourié-Gonnard32aa4372017-04-21 10:29:13 +020097} mbedtls_ecdsa_restart_ctx;
98
99#else /* MBEDTLS_ECP_RESTARTABLE */
100
101/* Now we can declare functions that take a pointer to that */
102typedef void mbedtls_ecdsa_restart_ctx;
103
104#endif /* MBEDTLS_ECP_RESTARTABLE */
Manuel Pégourié-Gonnard2aea1412013-01-26 16:33:44 +0100105
106/**
Manuel Pégourié-Gonnardb309ab22013-01-26 17:24:59 +0100107 * \brief Compute ECDSA signature of a previously hashed message
108 *
Manuel Pégourié-Gonnardb8cfe3f2015-03-31 11:04:45 +0200109 * \note The deterministic version is usually prefered.
110 *
Manuel Pégourié-Gonnardb309ab22013-01-26 17:24:59 +0100111 * \param grp ECP group
112 * \param r First output integer
113 * \param s Second output integer
114 * \param d Private signing key
115 * \param buf Message hash
116 * \param blen Length of buf
117 * \param f_rng RNG function
118 * \param p_rng RNG parameter
119 *
Janos Follath0a5154b2017-03-10 11:31:41 +0000120 * \note If the bitlength of the message hash is larger than the
121 * bitlength of the group order, then the hash is truncated as
122 * prescribed by SEC1 4.1.3 step 5.
123 *
Manuel Pégourié-Gonnardb309ab22013-01-26 17:24:59 +0100124 * \return 0 if successful,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200125 * or a MBEDTLS_ERR_ECP_XXX or MBEDTLS_MPI_XXX error code
Manuel Pégourié-Gonnardb309ab22013-01-26 17:24:59 +0100126 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200127int mbedtls_ecdsa_sign( mbedtls_ecp_group *grp, mbedtls_mpi *r, mbedtls_mpi *s,
128 const mbedtls_mpi *d, const unsigned char *buf, size_t blen,
Manuel Pégourié-Gonnardb309ab22013-01-26 17:24:59 +0100129 int (*f_rng)(void *, unsigned char *, size_t), void *p_rng );
130
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200131#if defined(MBEDTLS_ECDSA_DETERMINISTIC)
Manuel Pégourié-Gonnard4daaef72014-01-06 14:25:56 +0100132/**
Manuel Pégourié-Gonnardb8cfe3f2015-03-31 11:04:45 +0200133 * \brief Compute ECDSA signature of a previously hashed message,
134 * deterministic version (RFC 6979).
Manuel Pégourié-Gonnard4daaef72014-01-06 14:25:56 +0100135 *
136 * \param grp ECP group
137 * \param r First output integer
138 * \param s Second output integer
139 * \param d Private signing key
140 * \param buf Message hash
141 * \param blen Length of buf
142 * \param md_alg MD algorithm used to hash the message
143 *
Janos Follath0a5154b2017-03-10 11:31:41 +0000144 * \note If the bitlength of the message hash is larger than the
145 * bitlength of the group order, then the hash is truncated as
146 * prescribed by SEC1 4.1.3 step 5.
147 *
Manuel Pégourié-Gonnard4daaef72014-01-06 14:25:56 +0100148 * \return 0 if successful,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200149 * or a MBEDTLS_ERR_ECP_XXX or MBEDTLS_MPI_XXX error code
Manuel Pégourié-Gonnard4daaef72014-01-06 14:25:56 +0100150 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200151int mbedtls_ecdsa_sign_det( mbedtls_ecp_group *grp, mbedtls_mpi *r, mbedtls_mpi *s,
152 const mbedtls_mpi *d, const unsigned char *buf, size_t blen,
153 mbedtls_md_type_t md_alg );
154#endif /* MBEDTLS_ECDSA_DETERMINISTIC */
Manuel Pégourié-Gonnard4daaef72014-01-06 14:25:56 +0100155
Manuel Pégourié-Gonnardb309ab22013-01-26 17:24:59 +0100156/**
Manuel Pégourié-Gonnard3aeb5a72013-01-26 18:05:50 +0100157 * \brief Verify ECDSA signature of a previously hashed message
158 *
159 * \param grp ECP group
160 * \param buf Message hash
161 * \param blen Length of buf
162 * \param Q Public key to use for verification
163 * \param r First integer of the signature
164 * \param s Second integer of the signature
165 *
Janos Follath0a5154b2017-03-10 11:31:41 +0000166 * \note If the bitlength of the message hash is larger than the
167 * bitlength of the group order, then the hash is truncated as
168 * prescribed by SEC1 4.1.4 step 3.
169 *
Manuel Pégourié-Gonnard3aeb5a72013-01-26 18:05:50 +0100170 * \return 0 if successful,
Manuel Pégourié-Gonnard1ed25052017-04-21 10:04:02 +0200171 * MBEDTLS_ERR_ECP_VERIFY_FAILED if signature is invalid
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200172 * or a MBEDTLS_ERR_ECP_XXX or MBEDTLS_MPI_XXX error code
Manuel Pégourié-Gonnard3aeb5a72013-01-26 18:05:50 +0100173 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200174int mbedtls_ecdsa_verify( mbedtls_ecp_group *grp,
Manuel Pégourié-Gonnard3aeb5a72013-01-26 18:05:50 +0100175 const unsigned char *buf, size_t blen,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200176 const mbedtls_ecp_point *Q, const mbedtls_mpi *r, const mbedtls_mpi *s);
Manuel Pégourié-Gonnard3aeb5a72013-01-26 18:05:50 +0100177
178/**
Manuel Pégourié-Gonnardaa431612013-08-09 17:10:27 +0200179 * \brief Compute ECDSA signature and write it to buffer,
180 * serialized as defined in RFC 4492 page 20.
Paul Bakker6838bd12013-09-30 13:56:38 +0200181 * (Not thread-safe to use same context in multiple threads)
Manuel Pégourié-Gonnardb694b482013-08-08 13:30:57 +0200182 *
Janos Follath0a5154b2017-03-10 11:31:41 +0000183 * \note The deterministic version (RFC 6979) is used if
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200184 * MBEDTLS_ECDSA_DETERMINISTIC is defined.
Manuel Pégourié-Gonnarddfdcac92015-03-31 11:41:42 +0200185 *
Manuel Pégourié-Gonnardb694b482013-08-08 13:30:57 +0200186 * \param ctx ECDSA context
Manuel Pégourié-Gonnarddfdcac92015-03-31 11:41:42 +0200187 * \param md_alg Algorithm that was used to hash the message
Manuel Pégourié-Gonnardb694b482013-08-08 13:30:57 +0200188 * \param hash Message hash
189 * \param hlen Length of hash
190 * \param sig Buffer that will hold the signature
191 * \param slen Length of the signature written
192 * \param f_rng RNG function
193 * \param p_rng RNG parameter
194 *
195 * \note The "sig" buffer must be at least as large as twice the
Manuel Pégourié-Gonnard5bf262d2015-03-31 11:46:01 +0200196 * size of the curve used, plus 9 (eg. 73 bytes if a 256-bit
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200197 * curve is used). MBEDTLS_ECDSA_MAX_LEN is always safe.
Manuel Pégourié-Gonnardb694b482013-08-08 13:30:57 +0200198 *
Janos Follath0a5154b2017-03-10 11:31:41 +0000199 * \note If the bitlength of the message hash is larger than the
200 * bitlength of the group order, then the hash is truncated as
201 * prescribed by SEC1 4.1.3 step 5.
202 *
Manuel Pégourié-Gonnardb694b482013-08-08 13:30:57 +0200203 * \return 0 if successful,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200204 * or a MBEDTLS_ERR_ECP_XXX, MBEDTLS_ERR_MPI_XXX or
205 * MBEDTLS_ERR_ASN1_XXX error code
Manuel Pégourié-Gonnardb694b482013-08-08 13:30:57 +0200206 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200207int mbedtls_ecdsa_write_signature( mbedtls_ecdsa_context *ctx, mbedtls_md_type_t md_alg,
Manuel Pégourié-Gonnardb694b482013-08-08 13:30:57 +0200208 const unsigned char *hash, size_t hlen,
209 unsigned char *sig, size_t *slen,
210 int (*f_rng)(void *, unsigned char *, size_t),
211 void *p_rng );
212
Manuel Pégourié-Gonnardaddb10e2017-04-21 12:54:46 +0200213/**
214 * \brief Restartable version of \c mbedtls_ecdsa_write_signature()
215 *
216 * \note Performs the same job as \c mbedtls_ecdsa_write_signature()
217 * but can return early and restart according to the limit
218 * set with \c mbedtls_ecp_set_max_ops() to reduce blocking.
219 *
220 * \param ctx ECDSA context
221 * \param md_alg Algorithm that was used to hash the message
222 * \param hash Message hash
223 * \param hlen Length of hash
224 * \param sig Buffer that will hold the signature
225 * \param slen Length of the signature written
226 * \param f_rng RNG function
227 * \param p_rng RNG parameter
228 * \param rs_ctx Restart context
229 *
230 * \return See \c mbedtls_ecdsa_write_signature(), or
231 * MBEDTLS_ERR_ECP_IN_PROGRESS if maximum number of
232 * operations was reached: see \c mbedtls_ecp_set_max_ops().
233 */
234int mbedtls_ecdsa_write_signature_restartable( mbedtls_ecdsa_context *ctx,
235 mbedtls_md_type_t md_alg,
236 const unsigned char *hash, size_t hlen,
237 unsigned char *sig, size_t *slen,
238 int (*f_rng)(void *, unsigned char *, size_t),
239 void *p_rng,
240 mbedtls_ecdsa_restart_ctx *rs_ctx );
241
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200242#if defined(MBEDTLS_ECDSA_DETERMINISTIC)
243#if ! defined(MBEDTLS_DEPRECATED_REMOVED)
244#if defined(MBEDTLS_DEPRECATED_WARNING)
245#define MBEDTLS_DEPRECATED __attribute__((deprecated))
Manuel Pégourié-Gonnarddfdcac92015-03-31 11:41:42 +0200246#else
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200247#define MBEDTLS_DEPRECATED
Manuel Pégourié-Gonnarddfdcac92015-03-31 11:41:42 +0200248#endif
Manuel Pégourié-Gonnard937340b2014-01-06 10:27:16 +0100249/**
250 * \brief Compute ECDSA signature and write it to buffer,
251 * serialized as defined in RFC 4492 page 20.
252 * Deterministic version, RFC 6979.
253 * (Not thread-safe to use same context in multiple threads)
254 *
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200255 * \deprecated Superseded by mbedtls_ecdsa_write_signature() in 2.0.0
Manuel Pégourié-Gonnarddfdcac92015-03-31 11:41:42 +0200256 *
Manuel Pégourié-Gonnard937340b2014-01-06 10:27:16 +0100257 * \param ctx ECDSA context
258 * \param hash Message hash
259 * \param hlen Length of hash
260 * \param sig Buffer that will hold the signature
261 * \param slen Length of the signature written
262 * \param md_alg MD algorithm used to hash the message
263 *
264 * \note The "sig" buffer must be at least as large as twice the
Manuel Pégourié-Gonnard5bf262d2015-03-31 11:46:01 +0200265 * size of the curve used, plus 9 (eg. 73 bytes if a 256-bit
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200266 * curve is used). MBEDTLS_ECDSA_MAX_LEN is always safe.
Manuel Pégourié-Gonnard937340b2014-01-06 10:27:16 +0100267 *
Janos Follath0a5154b2017-03-10 11:31:41 +0000268 * \note If the bitlength of the message hash is larger than the
269 * bitlength of the group order, then the hash is truncated as
270 * prescribed by SEC1 4.1.3 step 5.
271 *
Manuel Pégourié-Gonnard937340b2014-01-06 10:27:16 +0100272 * \return 0 if successful,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200273 * or a MBEDTLS_ERR_ECP_XXX, MBEDTLS_ERR_MPI_XXX or
274 * MBEDTLS_ERR_ASN1_XXX error code
Manuel Pégourié-Gonnard937340b2014-01-06 10:27:16 +0100275 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200276int mbedtls_ecdsa_write_signature_det( mbedtls_ecdsa_context *ctx,
Manuel Pégourié-Gonnard937340b2014-01-06 10:27:16 +0100277 const unsigned char *hash, size_t hlen,
278 unsigned char *sig, size_t *slen,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200279 mbedtls_md_type_t md_alg ) MBEDTLS_DEPRECATED;
280#undef MBEDTLS_DEPRECATED
281#endif /* MBEDTLS_DEPRECATED_REMOVED */
282#endif /* MBEDTLS_ECDSA_DETERMINISTIC */
Manuel Pégourié-Gonnard937340b2014-01-06 10:27:16 +0100283
Manuel Pégourié-Gonnardb694b482013-08-08 13:30:57 +0200284/**
285 * \brief Read and verify an ECDSA signature
286 *
287 * \param ctx ECDSA context
288 * \param hash Message hash
289 * \param hlen Size of hash
290 * \param sig Signature to read and verify
291 * \param slen Size of sig
292 *
Janos Follath0a5154b2017-03-10 11:31:41 +0000293 * \note If the bitlength of the message hash is larger than the
294 * bitlength of the group order, then the hash is truncated as
295 * prescribed by SEC1 4.1.4 step 3.
296 *
Manuel Pégourié-Gonnardb694b482013-08-08 13:30:57 +0200297 * \return 0 if successful,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200298 * MBEDTLS_ERR_ECP_BAD_INPUT_DATA if signature is invalid,
299 * MBEDTLS_ERR_ECP_SIG_LEN_MISMATCH if the signature is
Manuel Pégourié-Gonnard35e95dd2014-04-08 12:17:41 +0200300 * valid but its actual length is less than siglen,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200301 * or a MBEDTLS_ERR_ECP_XXX or MBEDTLS_ERR_MPI_XXX error code
Manuel Pégourié-Gonnardb694b482013-08-08 13:30:57 +0200302 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200303int mbedtls_ecdsa_read_signature( mbedtls_ecdsa_context *ctx,
Manuel Pégourié-Gonnardb694b482013-08-08 13:30:57 +0200304 const unsigned char *hash, size_t hlen,
305 const unsigned char *sig, size_t slen );
306
307/**
Manuel Pégourié-Gonnard32aa4372017-04-21 10:29:13 +0200308 * \brief Restartable version of \c mbedtls_ecdsa_read_signature()
309 *
310 * \note Performs the same job as \c mbedtls_ecdsa_read_signature()
311 * but can return early and restart according to the limit
312 * set with \c mbedtls_ecp_set_max_ops() to reduce blocking.
313 *
314 * \param ctx ECDSA context
315 * \param hash Message hash
316 * \param hlen Size of hash
317 * \param sig Signature to read and verify
318 * \param slen Size of sig
319 * \param rs_ctx Restart context
320 *
321 * \return See \c mbedtls_ecdsa_read_signature(), or
322 * MBEDTLS_ERR_ECP_IN_PROGRESS if maximum number of
323 * operations was reached: see \c mbedtls_ecp_set_max_ops().
324 */
325int mbedtls_ecdsa_read_signature_restartable( mbedtls_ecdsa_context *ctx,
326 const unsigned char *hash, size_t hlen,
327 const unsigned char *sig, size_t slen,
328 mbedtls_ecdsa_restart_ctx *rs_ctx );
329
330/**
Manuel Pégourié-Gonnard8eebd012013-08-09 16:21:34 +0200331 * \brief Generate an ECDSA keypair on the given curve
332 *
333 * \param ctx ECDSA context in which the keypair should be stored
Paul Bakkerdcbfdcc2013-09-10 16:16:50 +0200334 * \param gid Group (elliptic curve) to use. One of the various
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200335 * MBEDTLS_ECP_DP_XXX macros depending on configuration.
Manuel Pégourié-Gonnard8eebd012013-08-09 16:21:34 +0200336 * \param f_rng RNG function
337 * \param p_rng RNG parameter
338 *
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200339 * \return 0 on success, or a MBEDTLS_ERR_ECP_XXX code.
Manuel Pégourié-Gonnard8eebd012013-08-09 16:21:34 +0200340 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200341int mbedtls_ecdsa_genkey( mbedtls_ecdsa_context *ctx, mbedtls_ecp_group_id gid,
Manuel Pégourié-Gonnard8eebd012013-08-09 16:21:34 +0200342 int (*f_rng)(void *, unsigned char *, size_t), void *p_rng );
343
344/**
Manuel Pégourié-Gonnardf4999932013-08-12 17:02:59 +0200345 * \brief Set an ECDSA context from an EC key pair
346 *
347 * \param ctx ECDSA context to set
348 * \param key EC key to use
349 *
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200350 * \return 0 on success, or a MBEDTLS_ERR_ECP_XXX code.
Manuel Pégourié-Gonnardf4999932013-08-12 17:02:59 +0200351 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200352int mbedtls_ecdsa_from_keypair( mbedtls_ecdsa_context *ctx, const mbedtls_ecp_keypair *key );
Manuel Pégourié-Gonnardf4999932013-08-12 17:02:59 +0200353
354/**
Manuel Pégourié-Gonnard7c8934e2013-06-27 12:54:02 +0200355 * \brief Initialize context
356 *
357 * \param ctx Context to initialize
358 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200359void mbedtls_ecdsa_init( mbedtls_ecdsa_context *ctx );
Manuel Pégourié-Gonnard7c8934e2013-06-27 12:54:02 +0200360
361/**
362 * \brief Free context
363 *
364 * \param ctx Context to free
365 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200366void mbedtls_ecdsa_free( mbedtls_ecdsa_context *ctx );
Manuel Pégourié-Gonnard7c8934e2013-06-27 12:54:02 +0200367
Manuel Pégourié-Gonnard32aa4372017-04-21 10:29:13 +0200368#if defined(MBEDTLS_ECP_RESTARTABLE)
369/**
370 * \brief Initialize a restart context
371 */
372void mbedtls_ecdsa_restart_init( mbedtls_ecdsa_restart_ctx *ctx );
373
374/**
375 * \brief Free the components of a restart context
376 */
377void mbedtls_ecdsa_restart_free( mbedtls_ecdsa_restart_ctx *ctx );
378#endif /* MBEDTLS_ECP_RESTARTABLE */
379
Manuel Pégourié-Gonnard2aea1412013-01-26 16:33:44 +0100380#ifdef __cplusplus
381}
382#endif
383
Paul Bakker9af723c2014-05-01 13:03:14 +0200384#endif /* ecdsa.h */