blob: 8725cee2f97e759022610f47ec7f1adc312b5fcc [file] [log] [blame]
Manuel Pégourié-Gonnard2aea1412013-01-26 16:33:44 +01001/**
2 * \file ecdsa.h
3 *
Rose Zadikbff87d92018-01-25 21:58:53 +00004 * \brief The Elliptic Curve Digital Signature Algorithm (ECDSA).
5 *
6 * ECDSA is defined in <em>Standards for Efficient Cryptography Group (SECG):
7 * SEC1 Elliptic Curve Cryptography</em>.
8 * The use of ECDSA for TLS is defined in <em>RFC-4492: Elliptic Curve
9 * Cryptography (ECC) Cipher Suites for Transport Layer Security (TLS)</em>.
10 *
Darryl Greena40a1012018-01-05 15:33:17 +000011 */
12/*
Rose Zadikbff87d92018-01-25 21:58:53 +000013 * Copyright (C) 2006-2018, Arm Limited (or its affiliates), All Rights Reserved
Manuel Pégourié-Gonnard37ff1402015-09-04 14:21:07 +020014 * SPDX-License-Identifier: Apache-2.0
15 *
16 * Licensed under the Apache License, Version 2.0 (the "License"); you may
17 * not use this file except in compliance with the License.
18 * You may obtain a copy of the License at
19 *
20 * http://www.apache.org/licenses/LICENSE-2.0
21 *
22 * Unless required by applicable law or agreed to in writing, software
23 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
24 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
25 * See the License for the specific language governing permissions and
26 * limitations under the License.
Manuel Pégourié-Gonnard2aea1412013-01-26 16:33:44 +010027 *
Rose Zadikbff87d92018-01-25 21:58:53 +000028 * This file is part of Mbed TLS (https://tls.mbed.org)
Manuel Pégourié-Gonnard2aea1412013-01-26 16:33:44 +010029 */
Rose Zadikbff87d92018-01-25 21:58:53 +000030
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020031#ifndef MBEDTLS_ECDSA_H
32#define MBEDTLS_ECDSA_H
Manuel Pégourié-Gonnard2aea1412013-01-26 16:33:44 +010033
Manuel Pégourié-Gonnardbdc96762013-10-03 11:50:39 +020034#include "ecp.h"
Manuel Pégourié-Gonnard887aa5b2014-04-04 13:57:20 +020035#include "md.h"
Manuel Pégourié-Gonnard4daaef72014-01-06 14:25:56 +010036
Manuel Pégourié-Gonnard63e93192015-03-31 11:15:48 +020037/*
Rose Zadikbff87d92018-01-25 21:58:53 +000038 * RFC-4492 page 20:
Manuel Pégourié-Gonnard63e93192015-03-31 11:15:48 +020039 *
40 * Ecdsa-Sig-Value ::= SEQUENCE {
41 * r INTEGER,
42 * s INTEGER
43 * }
44 *
45 * Size is at most
46 * 1 (tag) + 1 (len) + 1 (initial 0) + ECP_MAX_BYTES for each of r and s,
47 * twice that + 1 (tag) + 2 (len) for the sequence
48 * (assuming ECP_MAX_BYTES is less than 126 for r and s,
49 * and less than 124 (total len <= 255) for the sequence)
50 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020051#if MBEDTLS_ECP_MAX_BYTES > 124
52#error "MBEDTLS_ECP_MAX_BYTES bigger than expected, please fix MBEDTLS_ECDSA_MAX_LEN"
Manuel Pégourié-Gonnard63e93192015-03-31 11:15:48 +020053#endif
Manuel Pégourié-Gonnard63e93192015-03-31 11:15:48 +020054
Manuel Pégourié-Gonnardbec2f452013-06-27 10:17:07 +020055/**
Gilles Peskine9a8bb672017-11-02 17:09:49 +010056 * \brief Maximum ECDSA signature size for a given curve bit size
57 *
58 * \param bits Curve size in bits
59 * \return Maximum signature size in bytes
60 *
61 * \note This macro returns a compile-time constant if its argument
62 * is one. It may evaluate its argument multiple times; if
63 * this is a problem, call the function
64 * mbedtls_ecdsa_max_sig_len instead.
65 */
66#define MBEDTLS_ECDSA_MAX_SIG_LEN( bits ) \
67 ( /*T,L of SEQUENCE*/ ( ( bits ) >= 61 * 8 ? 3 : 2 ) + \
68 /*T,L of r,s*/ 2 * ( ( ( bits ) >= 127 * 8 ? 3 : 2 ) + \
69 /*V of r,s*/ ( ( bits ) + 8 ) / 8 ) )
70
71/**
72 * \brief Maximum ECDSA signature size for a given curve bit size
73 *
74 * \param bits Curve size in bits
75 * \return Maximum signature size in bytes
76 *
77 * \note If you need a compile-time constant, call the macro
78 * MBEDTLS_ECDSA_MAX_SIG_LEN instead.
79 */
80static inline size_t mbedtls_ecdsa_max_sig_len( size_t bits )
81{
82 return( MBEDTLS_ECDSA_MAX_SIG_LEN( bits ) );
83}
84
Andrzej Kurek49241632018-02-08 09:03:21 -050085/** The maximal size of an ECDSA signature in Bytes. */
Unknown60b25f02018-02-06 03:17:59 -050086#define MBEDTLS_ECDSA_MAX_LEN (MBEDTLS_ECDSA_MAX_SIG_LEN( \
87 8 * MBEDTLS_ECP_MAX_BYTES ) )
Manuel Pégourié-Gonnardbec2f452013-06-27 10:17:07 +020088/**
Rose Zadikbff87d92018-01-25 21:58:53 +000089 * \brief The ECDSA context structure.
Manuel Pégourié-Gonnardbec2f452013-06-27 10:17:07 +020090 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020091typedef mbedtls_ecp_keypair mbedtls_ecdsa_context;
Manuel Pégourié-Gonnardbec2f452013-06-27 10:17:07 +020092
Manuel Pégourié-Gonnard2aea1412013-01-26 16:33:44 +010093#ifdef __cplusplus
94extern "C" {
95#endif
96
97/**
Rose Zadikbff87d92018-01-25 21:58:53 +000098 * \brief This function computes the ECDSA signature of a
99 * previously-hashed message.
Manuel Pégourié-Gonnardb309ab22013-01-26 17:24:59 +0100100 *
Rose Zadikbff87d92018-01-25 21:58:53 +0000101 * \note The deterministic version is usually preferred.
Manuel Pégourié-Gonnardb8cfe3f2015-03-31 11:04:45 +0200102 *
Rose Zadikbff87d92018-01-25 21:58:53 +0000103 * \param grp The ECP group.
104 * \param r The first output integer.
105 * \param s The second output integer.
106 * \param d The private signing key.
107 * \param buf The message hash.
108 * \param blen The length of \p buf.
109 * \param f_rng The RNG function.
110 * \param p_rng The RNG parameter.
Manuel Pégourié-Gonnardb309ab22013-01-26 17:24:59 +0100111 *
Janos Follath0a5154b2017-03-10 11:31:41 +0000112 * \note If the bitlength of the message hash is larger than the
Rose Zadikbff87d92018-01-25 21:58:53 +0000113 * bitlength of the group order, then the hash is truncated
114 * as defined in <em>Standards for Efficient Cryptography Group
115 * (SECG): SEC1 Elliptic Curve Cryptography</em>, section
116 * 4.1.3, step 5.
Janos Follath0a5154b2017-03-10 11:31:41 +0000117 *
Rose Zadikbff87d92018-01-25 21:58:53 +0000118 * \return \c 0 on success, or an \c MBEDTLS_ERR_ECP_XXX
119 * or \c MBEDTLS_MPI_XXX error code on failure.
120 *
121 * \see ecp.h
Manuel Pégourié-Gonnardb309ab22013-01-26 17:24:59 +0100122 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200123int mbedtls_ecdsa_sign( mbedtls_ecp_group *grp, mbedtls_mpi *r, mbedtls_mpi *s,
124 const mbedtls_mpi *d, const unsigned char *buf, size_t blen,
Manuel Pégourié-Gonnardb309ab22013-01-26 17:24:59 +0100125 int (*f_rng)(void *, unsigned char *, size_t), void *p_rng );
126
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200127#if defined(MBEDTLS_ECDSA_DETERMINISTIC)
Manuel Pégourié-Gonnard4daaef72014-01-06 14:25:56 +0100128/**
Rose Zadikbff87d92018-01-25 21:58:53 +0000129 * \brief This function computes the ECDSA signature of a
130 * previously-hashed message, deterministic version.
131 * For more information, see <em>RFC-6979: Deterministic
132 * Usage of the Digital Signature Algorithm (DSA) and Elliptic
133 * Curve Digital Signature Algorithm (ECDSA)</em>.
Manuel Pégourié-Gonnard4daaef72014-01-06 14:25:56 +0100134 *
Rose Zadikbff87d92018-01-25 21:58:53 +0000135 * \param grp The ECP group.
136 * \param r The first output integer.
137 * \param s The second output integer.
138 * \param d The private signing key.
139 * \param buf The message hash.
140 * \param blen The length of \p buf.
141 * \param md_alg The MD algorithm used to hash the message.
Manuel Pégourié-Gonnard4daaef72014-01-06 14:25:56 +0100142 *
Janos Follath0a5154b2017-03-10 11:31:41 +0000143 * \note If the bitlength of the message hash is larger than the
144 * bitlength of the group order, then the hash is truncated as
Rose Zadikbff87d92018-01-25 21:58:53 +0000145 * defined in <em>Standards for Efficient Cryptography Group
146 * (SECG): SEC1 Elliptic Curve Cryptography</em>, section
147 * 4.1.3, step 5.
Janos Follath0a5154b2017-03-10 11:31:41 +0000148 *
Rose Zadikbff87d92018-01-25 21:58:53 +0000149 * \return \c 0 on success,
150 * or an \c MBEDTLS_ERR_ECP_XXX or \c MBEDTLS_MPI_XXX
151 * error code on failure.
152 *
153 * \see ecp.h
Manuel Pégourié-Gonnard4daaef72014-01-06 14:25:56 +0100154 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200155int mbedtls_ecdsa_sign_det( mbedtls_ecp_group *grp, mbedtls_mpi *r, mbedtls_mpi *s,
156 const mbedtls_mpi *d, const unsigned char *buf, size_t blen,
157 mbedtls_md_type_t md_alg );
158#endif /* MBEDTLS_ECDSA_DETERMINISTIC */
Manuel Pégourié-Gonnard4daaef72014-01-06 14:25:56 +0100159
Manuel Pégourié-Gonnardb309ab22013-01-26 17:24:59 +0100160/**
Rose Zadikbff87d92018-01-25 21:58:53 +0000161 * \brief This function verifies the ECDSA signature of a
162 * previously-hashed message.
Manuel Pégourié-Gonnard3aeb5a72013-01-26 18:05:50 +0100163 *
Rose Zadikbff87d92018-01-25 21:58:53 +0000164 * \param grp The ECP group.
165 * \param buf The message hash.
166 * \param blen The length of \p buf.
167 * \param Q The public key to use for verification.
168 * \param r The first integer of the signature.
169 * \param s The second integer of the signature.
Manuel Pégourié-Gonnard3aeb5a72013-01-26 18:05:50 +0100170 *
Janos Follath0a5154b2017-03-10 11:31:41 +0000171 * \note If the bitlength of the message hash is larger than the
172 * bitlength of the group order, then the hash is truncated as
Rose Zadikbff87d92018-01-25 21:58:53 +0000173 * defined in <em>Standards for Efficient Cryptography Group
174 * (SECG): SEC1 Elliptic Curve Cryptography</em>, section
175 * 4.1.4, step 3.
Janos Follath0a5154b2017-03-10 11:31:41 +0000176 *
Rose Zadikbff87d92018-01-25 21:58:53 +0000177 * \return \c 0 on success,
178 * #MBEDTLS_ERR_ECP_BAD_INPUT_DATA if signature is invalid,
179 * or an \c MBEDTLS_ERR_ECP_XXX or \c MBEDTLS_MPI_XXX
180 * error code on failure for any other reason.
181 *
182 * \see ecp.h
Manuel Pégourié-Gonnard3aeb5a72013-01-26 18:05:50 +0100183 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200184int mbedtls_ecdsa_verify( mbedtls_ecp_group *grp,
Manuel Pégourié-Gonnard3aeb5a72013-01-26 18:05:50 +0100185 const unsigned char *buf, size_t blen,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200186 const mbedtls_ecp_point *Q, const mbedtls_mpi *r, const mbedtls_mpi *s);
Manuel Pégourié-Gonnard3aeb5a72013-01-26 18:05:50 +0100187
188/**
Rose Zadikbff87d92018-01-25 21:58:53 +0000189 * \brief This function computes the ECDSA signature and writes it
190 * to a buffer, serialized as defined in <em>RFC-4492:
191 * Elliptic Curve Cryptography (ECC) Cipher Suites for
192 * Transport Layer Security (TLS)</em>.
Manuel Pégourié-Gonnardb694b482013-08-08 13:30:57 +0200193 *
Rose Zadikbff87d92018-01-25 21:58:53 +0000194 * \warning It is not thread-safe to use the same context in
195 * multiple threads.
Manuel Pégourié-Gonnarddfdcac92015-03-31 11:41:42 +0200196 *
Rose Zadikbff87d92018-01-25 21:58:53 +0000197 * \note The deterministic version is used if
198 * #MBEDTLS_ECDSA_DETERMINISTIC is defined. For more
199 * information, see <em>RFC-6979: Deterministic Usage
200 * of the Digital Signature Algorithm (DSA) and Elliptic
201 * Curve Digital Signature Algorithm (ECDSA)</em>.
Manuel Pégourié-Gonnardb694b482013-08-08 13:30:57 +0200202 *
Rose Zadikbff87d92018-01-25 21:58:53 +0000203 * \param ctx The ECDSA context.
204 * \param md_alg The message digest that was used to hash the message.
205 * \param hash The message hash.
206 * \param hlen The length of the hash.
207 * \param sig The buffer that holds the signature.
208 * \param slen The length of the signature written.
209 * \param f_rng The RNG function.
210 * \param p_rng The RNG parameter.
211 *
212 * \note The \p sig buffer must be at least twice as large as the
213 * size of the curve used, plus 9. For example, 73 Bytes if
214 * a 256-bit curve is used. A buffer length of
215 * #MBEDTLS_ECDSA_MAX_LEN is always safe.
Manuel Pégourié-Gonnardb694b482013-08-08 13:30:57 +0200216 *
Janos Follath0a5154b2017-03-10 11:31:41 +0000217 * \note If the bitlength of the message hash is larger than the
218 * bitlength of the group order, then the hash is truncated as
Rose Zadikbff87d92018-01-25 21:58:53 +0000219 * defined in <em>Standards for Efficient Cryptography Group
220 * (SECG): SEC1 Elliptic Curve Cryptography</em>, section
221 * 4.1.3, step 5.
Janos Follath0a5154b2017-03-10 11:31:41 +0000222 *
Rose Zadikbff87d92018-01-25 21:58:53 +0000223 * \return \c 0 on success,
224 * or an \c MBEDTLS_ERR_ECP_XXX, \c MBEDTLS_ERR_MPI_XXX or
225 * \c MBEDTLS_ERR_ASN1_XXX error code on failure.
226 *
227 * \see ecp.h
Manuel Pégourié-Gonnardb694b482013-08-08 13:30:57 +0200228 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200229int mbedtls_ecdsa_write_signature( mbedtls_ecdsa_context *ctx, mbedtls_md_type_t md_alg,
Manuel Pégourié-Gonnardb694b482013-08-08 13:30:57 +0200230 const unsigned char *hash, size_t hlen,
231 unsigned char *sig, size_t *slen,
232 int (*f_rng)(void *, unsigned char *, size_t),
233 void *p_rng );
234
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200235#if defined(MBEDTLS_ECDSA_DETERMINISTIC)
236#if ! defined(MBEDTLS_DEPRECATED_REMOVED)
237#if defined(MBEDTLS_DEPRECATED_WARNING)
238#define MBEDTLS_DEPRECATED __attribute__((deprecated))
Manuel Pégourié-Gonnarddfdcac92015-03-31 11:41:42 +0200239#else
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200240#define MBEDTLS_DEPRECATED
Manuel Pégourié-Gonnarddfdcac92015-03-31 11:41:42 +0200241#endif
Manuel Pégourié-Gonnard937340b2014-01-06 10:27:16 +0100242/**
Rose Zadikbff87d92018-01-25 21:58:53 +0000243 * \brief This function computes an ECDSA signature and writes it to a buffer,
244 * serialized as defined in <em>RFC-4492: Elliptic Curve Cryptography
245 * (ECC) Cipher Suites for Transport Layer Security (TLS)</em>.
246 *
247 * The deterministic version is defined in <em>RFC-6979:
248 * Deterministic Usage of the Digital Signature Algorithm (DSA) and
249 * Elliptic Curve Digital Signature Algorithm (ECDSA)</em>.
250 *
251 * \warning It is not thread-safe to use the same context in
252 * multiple threads.
253
Manuel Pégourié-Gonnard937340b2014-01-06 10:27:16 +0100254 *
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 *
Rose Zadikbff87d92018-01-25 21:58:53 +0000257 * \param ctx The ECDSA context.
258 * \param hash The Message hash.
259 * \param hlen The length of the hash.
260 * \param sig The buffer that holds the signature.
261 * \param slen The length of the signature written.
262 * \param md_alg The MD algorithm used to hash the message.
Manuel Pégourié-Gonnard937340b2014-01-06 10:27:16 +0100263 *
Rose Zadikbff87d92018-01-25 21:58:53 +0000264 * \note The \p sig buffer must be at least twice as large as the
265 * size of the curve used, plus 9. For example, 73 Bytes if a
266 * 256-bit curve is used. A buffer length of
267 * #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
Rose Zadikbff87d92018-01-25 21:58:53 +0000271 * defined in <em>Standards for Efficient Cryptography Group
272 * (SECG): SEC1 Elliptic Curve Cryptography</em>, section
273 * 4.1.3, step 5.
Janos Follath0a5154b2017-03-10 11:31:41 +0000274 *
Rose Zadikbff87d92018-01-25 21:58:53 +0000275 * \return \c 0 on success,
276 * or an \c MBEDTLS_ERR_ECP_XXX, \c MBEDTLS_ERR_MPI_XXX or
277 * \c MBEDTLS_ERR_ASN1_XXX error code on failure.
278 *
279 * \see ecp.h
Manuel Pégourié-Gonnard937340b2014-01-06 10:27:16 +0100280 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200281int mbedtls_ecdsa_write_signature_det( mbedtls_ecdsa_context *ctx,
Manuel Pégourié-Gonnard937340b2014-01-06 10:27:16 +0100282 const unsigned char *hash, size_t hlen,
283 unsigned char *sig, size_t *slen,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200284 mbedtls_md_type_t md_alg ) MBEDTLS_DEPRECATED;
285#undef MBEDTLS_DEPRECATED
286#endif /* MBEDTLS_DEPRECATED_REMOVED */
287#endif /* MBEDTLS_ECDSA_DETERMINISTIC */
Manuel Pégourié-Gonnard937340b2014-01-06 10:27:16 +0100288
Manuel Pégourié-Gonnardb694b482013-08-08 13:30:57 +0200289/**
Unknown6f21aed2018-02-07 08:02:31 -0500290 * \brief Convert a signature from numbers to ASN.1
Gilles Peskinebce41d32017-11-02 17:14:18 +0100291 *
292 * \param r First number of the signature
293 * \param s Second number of the signature
294 * \param sig Buffer that will hold the signature
295 * \param slen Length of the signature written
296 * \param ssize Size of the sig buffer
297 *
298 * \note The size of the buffer \c ssize should be at least
299 * `MBEDTLS_ECDSA_MAX_SIG_LEN(grp->pbits)` bytes long if
300 * the signature was produced from curve \c grp,
301 * otherwise this function will return an error.
Unknown6f21aed2018-02-07 08:02:31 -0500302 * The output ASN.1 SEQUENCE format is as follows:
303 * Ecdsa-Sig-Value ::= SEQUENCE {
304 * r INTEGER,
305 * s INTEGER
306 * }
Gilles Peskinebce41d32017-11-02 17:14:18 +0100307 *
308 * \return 0 if successful,
309 * or a MBEDTLS_ERR_MPI_XXX or MBEDTLS_ERR_ASN1_XXX error code
310 *
311 */
Unknowna2c40622018-02-06 03:24:02 -0500312int mbedtls_ecdsa_signature_to_asn1( const mbedtls_mpi *r, const mbedtls_mpi *s,
Gilles Peskinebce41d32017-11-02 17:14:18 +0100313 unsigned char *sig, size_t *slen,
314 size_t ssize );
315
316/**
Rose Zadikbff87d92018-01-25 21:58:53 +0000317 * \brief This function reads and verifies an ECDSA signature.
Manuel Pégourié-Gonnardb694b482013-08-08 13:30:57 +0200318 *
Rose Zadikbff87d92018-01-25 21:58:53 +0000319 * \param ctx The ECDSA context.
320 * \param hash The message hash.
321 * \param hlen The size of the hash.
322 * \param sig The signature to read and verify.
323 * \param slen The size of \p sig.
Manuel Pégourié-Gonnardb694b482013-08-08 13:30:57 +0200324 *
Janos Follath0a5154b2017-03-10 11:31:41 +0000325 * \note If the bitlength of the message hash is larger than the
326 * bitlength of the group order, then the hash is truncated as
Rose Zadikbff87d92018-01-25 21:58:53 +0000327 * defined in <em>Standards for Efficient Cryptography Group
328 * (SECG): SEC1 Elliptic Curve Cryptography</em>, section
329 * 4.1.4, step 3.
Janos Follath0a5154b2017-03-10 11:31:41 +0000330 *
Rose Zadikbff87d92018-01-25 21:58:53 +0000331 * \return \c 0 on success,
332 * #MBEDTLS_ERR_ECP_BAD_INPUT_DATA if signature is invalid,
333 * #MBEDTLS_ERR_ECP_SIG_LEN_MISMATCH if the signature is
334 * valid but its actual length is less than \p siglen,
335 * or an \c MBEDTLS_ERR_ECP_XXX or \c MBEDTLS_ERR_MPI_XXX
336 * error code on failure for any other reason.
337 *
338 * \see ecp.h
Manuel Pégourié-Gonnardb694b482013-08-08 13:30:57 +0200339 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200340int mbedtls_ecdsa_read_signature( mbedtls_ecdsa_context *ctx,
Manuel Pégourié-Gonnardb694b482013-08-08 13:30:57 +0200341 const unsigned char *hash, size_t hlen,
342 const unsigned char *sig, size_t slen );
343
344/**
Rose Zadikbff87d92018-01-25 21:58:53 +0000345 * \brief This function generates an ECDSA keypair on the given curve.
Manuel Pégourié-Gonnard8eebd012013-08-09 16:21:34 +0200346 *
Rose Zadikbff87d92018-01-25 21:58:53 +0000347 * \param ctx The ECDSA context to store the keypair in.
348 * \param gid The elliptic curve to use. One of the various
349 * \c MBEDTLS_ECP_DP_XXX macros depending on configuration.
350 * \param f_rng The RNG function.
351 * \param p_rng The RNG parameter.
Manuel Pégourié-Gonnard8eebd012013-08-09 16:21:34 +0200352 *
Rose Zadikbff87d92018-01-25 21:58:53 +0000353 * \return \c 0 on success, or an \c MBEDTLS_ERR_ECP_XXX code on
354 * failure.
355 *
356 * \see ecp.h
Manuel Pégourié-Gonnard8eebd012013-08-09 16:21:34 +0200357 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200358int mbedtls_ecdsa_genkey( mbedtls_ecdsa_context *ctx, mbedtls_ecp_group_id gid,
Manuel Pégourié-Gonnard8eebd012013-08-09 16:21:34 +0200359 int (*f_rng)(void *, unsigned char *, size_t), void *p_rng );
360
361/**
Rose Zadikbff87d92018-01-25 21:58:53 +0000362 * \brief This function sets an ECDSA context from an EC key pair.
Manuel Pégourié-Gonnardf4999932013-08-12 17:02:59 +0200363 *
Rose Zadikbff87d92018-01-25 21:58:53 +0000364 * \param ctx The ECDSA context to set.
365 * \param key The EC key to use.
Manuel Pégourié-Gonnardf4999932013-08-12 17:02:59 +0200366 *
Rose Zadikbff87d92018-01-25 21:58:53 +0000367 * \return \c 0 on success, or an \c MBEDTLS_ERR_ECP_XXX code on
368 * failure.
369 *
370 * \see ecp.h
Manuel Pégourié-Gonnardf4999932013-08-12 17:02:59 +0200371 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200372int mbedtls_ecdsa_from_keypair( mbedtls_ecdsa_context *ctx, const mbedtls_ecp_keypair *key );
Manuel Pégourié-Gonnardf4999932013-08-12 17:02:59 +0200373
374/**
Rose Zadikbff87d92018-01-25 21:58:53 +0000375 * \brief This function initializes an ECDSA context.
Manuel Pégourié-Gonnard7c8934e2013-06-27 12:54:02 +0200376 *
Rose Zadikbff87d92018-01-25 21:58:53 +0000377 * \param ctx The ECDSA context to initialize.
Manuel Pégourié-Gonnard7c8934e2013-06-27 12:54:02 +0200378 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200379void mbedtls_ecdsa_init( mbedtls_ecdsa_context *ctx );
Manuel Pégourié-Gonnard7c8934e2013-06-27 12:54:02 +0200380
381/**
Rose Zadikbff87d92018-01-25 21:58:53 +0000382 * \brief This function frees an ECDSA context.
Manuel Pégourié-Gonnard7c8934e2013-06-27 12:54:02 +0200383 *
Rose Zadikbff87d92018-01-25 21:58:53 +0000384 * \param ctx The ECDSA context to free.
Manuel Pégourié-Gonnard7c8934e2013-06-27 12:54:02 +0200385 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200386void mbedtls_ecdsa_free( mbedtls_ecdsa_context *ctx );
Manuel Pégourié-Gonnard7c8934e2013-06-27 12:54:02 +0200387
Manuel Pégourié-Gonnard2aea1412013-01-26 16:33:44 +0100388#ifdef __cplusplus
389}
390#endif
391
Paul Bakker9af723c2014-05-01 13:03:14 +0200392#endif /* ecdsa.h */