blob: 18178c115e6c992a52392b237f8aba90262befae [file] [log] [blame]
Manuel Pégourié-Gonnard39d2adb2012-10-31 09:26:55 +01001/**
2 * \file ecp.h
3 *
Rose Zadikb2e111a2018-04-20 10:13:48 +01004 * \brief This file provides an API for Elliptic Curves over GF(P) (ECP).
Manuel Pégourié-Gonnard39d2adb2012-10-31 09:26:55 +01005 *
Rose Zadikb2e111a2018-04-20 10:13:48 +01006 * The use of ECP in cryptography and TLS is defined in
7 * <em>Standards for Efficient Cryptography Group (SECG): SEC1
8 * Elliptic Curve Cryptography</em> and
Rose Zadikd3c9bfc2018-04-17 10:56:55 +01009 * <em>RFC-4492: Elliptic Curve Cryptography (ECC) Cipher Suites
10 * for Transport Layer Security (TLS)</em>.
Rose Zadika7a61552018-04-24 13:14:01 +010011 *
Rose Zadikd3c9bfc2018-04-17 10:56:55 +010012 * <em>RFC-2409: The Internet Key Exchange (IKE)</em> defines ECP
13 * group types.
Rose Zadika7a61552018-04-24 13:14:01 +010014 *
Darryl Greena40a1012018-01-05 15:33:17 +000015 */
Rose Zadikd3c9bfc2018-04-17 10:56:55 +010016
Darryl Greena40a1012018-01-05 15:33:17 +000017/*
Bence Szépkútia2947ac2020-08-19 16:37:36 +020018 * Copyright The Mbed TLS Contributors
Bence Szépkútif744bd72020-06-05 13:02:18 +020019 * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
20 *
21 * This file is provided under the Apache License 2.0, or the
22 * GNU General Public License v2.0 or later.
23 *
24 * **********
25 * Apache License 2.0:
Manuel Pégourié-Gonnard37ff1402015-09-04 14:21:07 +020026 *
27 * Licensed under the Apache License, Version 2.0 (the "License"); you may
28 * not use this file except in compliance with the License.
29 * You may obtain a copy of the License at
30 *
31 * http://www.apache.org/licenses/LICENSE-2.0
32 *
33 * Unless required by applicable law or agreed to in writing, software
34 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
35 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
36 * See the License for the specific language governing permissions and
37 * limitations under the License.
Manuel Pégourié-Gonnard39d2adb2012-10-31 09:26:55 +010038 *
Bence Szépkútif744bd72020-06-05 13:02:18 +020039 * **********
40 *
41 * **********
42 * GNU General Public License v2.0 or later:
43 *
44 * This program is free software; you can redistribute it and/or modify
45 * it under the terms of the GNU General Public License as published by
46 * the Free Software Foundation; either version 2 of the License, or
47 * (at your option) any later version.
48 *
49 * This program is distributed in the hope that it will be useful,
50 * but WITHOUT ANY WARRANTY; without even the implied warranty of
51 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
52 * GNU General Public License for more details.
53 *
54 * You should have received a copy of the GNU General Public License along
55 * with this program; if not, write to the Free Software Foundation, Inc.,
56 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
57 *
58 * **********
Manuel Pégourié-Gonnard39d2adb2012-10-31 09:26:55 +010059 */
Rose Zadika7a61552018-04-24 13:14:01 +010060
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020061#ifndef MBEDTLS_ECP_H
62#define MBEDTLS_ECP_H
Manuel Pégourié-Gonnard39d2adb2012-10-31 09:26:55 +010063
Ron Eldor8b0cf2e2018-02-14 16:02:41 +020064#if !defined(MBEDTLS_CONFIG_FILE)
65#include "config.h"
66#else
67#include MBEDTLS_CONFIG_FILE
68#endif
69
Manuel Pégourié-Gonnardbdc96762013-10-03 11:50:39 +020070#include "bignum.h"
Manuel Pégourié-Gonnard39d2adb2012-10-31 09:26:55 +010071
72/*
Manuel Pégourié-Gonnard7cfcea32012-11-05 10:06:12 +010073 * ECP error codes
Manuel Pégourié-Gonnard39d2adb2012-10-31 09:26:55 +010074 */
Gilles Peskine1990fab2021-07-26 18:48:10 +020075/** Bad input parameters to function. */
76#define MBEDTLS_ERR_ECP_BAD_INPUT_DATA -0x4F80
77/** The buffer is too small to write to. */
78#define MBEDTLS_ERR_ECP_BUFFER_TOO_SMALL -0x4F00
79/** The requested feature is not available, for example, the requested curve is not supported. */
80#define MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE -0x4E80
81/** The signature is not valid. */
82#define MBEDTLS_ERR_ECP_VERIFY_FAILED -0x4E00
83/** Memory allocation failed. */
84#define MBEDTLS_ERR_ECP_ALLOC_FAILED -0x4D80
85/** Generation of random value, such as ephemeral key, failed. */
86#define MBEDTLS_ERR_ECP_RANDOM_FAILED -0x4D00
87/** Invalid private or public key. */
88#define MBEDTLS_ERR_ECP_INVALID_KEY -0x4C80
89/** The buffer contains a valid signature followed by more data. */
90#define MBEDTLS_ERR_ECP_SIG_LEN_MISMATCH -0x4C00
Ron Eldor9924bdc2018-10-04 10:59:13 +030091
92/* MBEDTLS_ERR_ECP_HW_ACCEL_FAILED is deprecated and should not be used. */
Gilles Peskine1990fab2021-07-26 18:48:10 +020093/** The ECP hardware accelerator failed. */
94#define MBEDTLS_ERR_ECP_HW_ACCEL_FAILED -0x4B80
Ron Eldor9924bdc2018-10-04 10:59:13 +030095
Gilles Peskine1990fab2021-07-26 18:48:10 +020096/** Operation in progress, call again with the same parameters to continue. */
97#define MBEDTLS_ERR_ECP_IN_PROGRESS -0x4B00
Manuel Pégourié-Gonnard883f3132012-11-02 09:40:25 +010098
Paul Bakker407a0da2013-06-27 14:29:21 +020099#ifdef __cplusplus
100extern "C" {
101#endif
102
Manuel Pégourié-Gonnard39d2adb2012-10-31 09:26:55 +0100103/**
Rose Zadikd76ac582018-04-23 06:29:34 +0100104 * Domain-parameter identifiers: curve, subgroup, and generator.
Manuel Pégourié-Gonnard70380392013-09-16 16:19:53 +0200105 *
Rose Zadikd3c9bfc2018-04-17 10:56:55 +0100106 * \note Only curves over prime fields are supported.
Manuel Pégourié-Gonnard70380392013-09-16 16:19:53 +0200107 *
108 * \warning This library does not support validation of arbitrary domain
Rose Zadikf56cb342018-04-19 12:49:10 +0100109 * parameters. Therefore, only standardized domain parameters from trusted
Manuel Pégourié-Gonnarde3a062b2015-05-11 18:46:47 +0200110 * sources should be used. See mbedtls_ecp_group_load().
Manuel Pégourié-Gonnard70380392013-09-16 16:19:53 +0200111 */
112typedef enum
113{
Rose Zadikd3c9bfc2018-04-17 10:56:55 +0100114 MBEDTLS_ECP_DP_NONE = 0, /*!< Curve not defined. */
Rose Zadikb2e111a2018-04-20 10:13:48 +0100115 MBEDTLS_ECP_DP_SECP192R1, /*!< Domain parameters for the 192-bit curve defined by FIPS 186-4 and SEC1. */
116 MBEDTLS_ECP_DP_SECP224R1, /*!< Domain parameters for the 224-bit curve defined by FIPS 186-4 and SEC1. */
117 MBEDTLS_ECP_DP_SECP256R1, /*!< Domain parameters for the 256-bit curve defined by FIPS 186-4 and SEC1. */
118 MBEDTLS_ECP_DP_SECP384R1, /*!< Domain parameters for the 384-bit curve defined by FIPS 186-4 and SEC1. */
119 MBEDTLS_ECP_DP_SECP521R1, /*!< Domain parameters for the 521-bit curve defined by FIPS 186-4 and SEC1. */
Rose Zadikd3c9bfc2018-04-17 10:56:55 +0100120 MBEDTLS_ECP_DP_BP256R1, /*!< Domain parameters for 256-bit Brainpool curve. */
121 MBEDTLS_ECP_DP_BP384R1, /*!< Domain parameters for 384-bit Brainpool curve. */
122 MBEDTLS_ECP_DP_BP512R1, /*!< Domain parameters for 512-bit Brainpool curve. */
Rose Zadikb2e111a2018-04-20 10:13:48 +0100123 MBEDTLS_ECP_DP_CURVE25519, /*!< Domain parameters for Curve25519. */
Rose Zadikd3c9bfc2018-04-17 10:56:55 +0100124 MBEDTLS_ECP_DP_SECP192K1, /*!< Domain parameters for 192-bit "Koblitz" curve. */
125 MBEDTLS_ECP_DP_SECP224K1, /*!< Domain parameters for 224-bit "Koblitz" curve. */
126 MBEDTLS_ECP_DP_SECP256K1, /*!< Domain parameters for 256-bit "Koblitz" curve. */
Jaeden Amerofe0669f2018-04-27 17:43:32 +0100127 MBEDTLS_ECP_DP_CURVE448, /*!< Domain parameters for Curve448. */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200128} mbedtls_ecp_group_id;
Manuel Pégourié-Gonnard70380392013-09-16 16:19:53 +0200129
130/**
Rose Zadikf56cb342018-04-19 12:49:10 +0100131 * The number of supported curves, plus one for #MBEDTLS_ECP_DP_NONE.
Manuel Pégourié-Gonnard66153662013-12-03 14:12:26 +0100132 *
Rose Zadikd3c9bfc2018-04-17 10:56:55 +0100133 * \note Montgomery curves are currently excluded.
Manuel Pégourié-Gonnardf24b4a72013-09-23 18:14:50 +0200134 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200135#define MBEDTLS_ECP_DP_MAX 12
Manuel Pégourié-Gonnardf24b4a72013-09-23 18:14:50 +0200136
137/**
Rose Zadikd3c9bfc2018-04-17 10:56:55 +0100138 * Curve information, for use by other modules.
Manuel Pégourié-Gonnard568c9cf2013-09-16 17:30:04 +0200139 */
Dawid Drozd428cc522018-07-24 10:02:47 +0200140typedef struct mbedtls_ecp_curve_info
Manuel Pégourié-Gonnard568c9cf2013-09-16 17:30:04 +0200141{
Rose Zadikd3c9bfc2018-04-17 10:56:55 +0100142 mbedtls_ecp_group_id grp_id; /*!< An internal identifier. */
143 uint16_t tls_id; /*!< The TLS NamedCurve identifier. */
Rose Zadikb2e111a2018-04-20 10:13:48 +0100144 uint16_t bit_size; /*!< The curve size in bits. */
Rose Zadikd3c9bfc2018-04-17 10:56:55 +0100145 const char *name; /*!< A human-friendly name. */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200146} mbedtls_ecp_curve_info;
Manuel Pégourié-Gonnard568c9cf2013-09-16 17:30:04 +0200147
148/**
Rose Zadikf56cb342018-04-19 12:49:10 +0100149 * \brief The ECP point structure, in Jacobian coordinates.
Manuel Pégourié-Gonnardae180d02012-11-02 18:14:40 +0100150 *
Manuel Pégourié-Gonnard1c2782c2012-11-19 20:16:28 +0100151 * \note All functions expect and return points satisfying
Rose Zadikf56cb342018-04-19 12:49:10 +0100152 * the following condition: <code>Z == 0</code> or
Rose Zadika7a61552018-04-24 13:14:01 +0100153 * <code>Z == 1</code>. Other values of \p Z are
Rose Zadikf56cb342018-04-19 12:49:10 +0100154 * used only by internal functions.
155 * The point is zero, or "at infinity", if <code>Z == 0</code>.
Rose Zadika7a61552018-04-24 13:14:01 +0100156 * Otherwise, \p X and \p Y are its standard (affine)
Rose Zadikf56cb342018-04-19 12:49:10 +0100157 * coordinates.
Manuel Pégourié-Gonnard39d2adb2012-10-31 09:26:55 +0100158 */
Dawid Drozd428cc522018-07-24 10:02:47 +0200159typedef struct mbedtls_ecp_point
Manuel Pégourié-Gonnard39d2adb2012-10-31 09:26:55 +0100160{
Rose Zadikd3c9bfc2018-04-17 10:56:55 +0100161 mbedtls_mpi X; /*!< The X coordinate of the ECP point. */
162 mbedtls_mpi Y; /*!< The Y coordinate of the ECP point. */
163 mbedtls_mpi Z; /*!< The Z coordinate of the ECP point. */
Manuel Pégourié-Gonnard39d2adb2012-10-31 09:26:55 +0100164}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200165mbedtls_ecp_point;
Manuel Pégourié-Gonnard39d2adb2012-10-31 09:26:55 +0100166
Gilles Peskineeaf74422021-06-02 23:21:07 +0200167/* Determine the minimum safe value of MBEDTLS_ECP_MAX_BITS. */
168#if !defined(MBEDTLS_ECP_C)
169#define MBEDTLS_ECP_MAX_BITS_MIN 0
170/* Note: the curves must be listed in DECREASING size! */
171#elif defined(MBEDTLS_ECP_DP_SECP521R1_ENABLED)
172#define MBEDTLS_ECP_MAX_BITS_MIN 521
173#elif defined(MBEDTLS_ECP_DP_BP512R1_ENABLED)
174#define MBEDTLS_ECP_MAX_BITS_MIN 512
175#elif defined(MBEDTLS_ECP_DP_CURVE448_ENABLED)
176#define MBEDTLS_ECP_MAX_BITS_MIN 448
177#elif defined(MBEDTLS_ECP_DP_BP384R1_ENABLED)
178#define MBEDTLS_ECP_MAX_BITS_MIN 384
179#elif defined(MBEDTLS_ECP_DP_SECP384R1_ENABLED)
180#define MBEDTLS_ECP_MAX_BITS_MIN 384
181#elif defined(MBEDTLS_ECP_DP_BP256R1_ENABLED)
182#define MBEDTLS_ECP_MAX_BITS_MIN 256
183#elif defined(MBEDTLS_ECP_DP_SECP256K1_ENABLED)
184#define MBEDTLS_ECP_MAX_BITS_MIN 256
185#elif defined(MBEDTLS_ECP_DP_SECP256R1_ENABLED)
186#define MBEDTLS_ECP_MAX_BITS_MIN 256
187#elif defined(MBEDTLS_ECP_DP_CURVE25519_ENABLED)
188#define MBEDTLS_ECP_MAX_BITS_MIN 255
189#elif defined(MBEDTLS_ECP_DP_SECP224K1_ENABLED)
190#define MBEDTLS_ECP_MAX_BITS_MIN 225 // n is slightly above 2^224
191#elif defined(MBEDTLS_ECP_DP_SECP224R1_ENABLED)
192#define MBEDTLS_ECP_MAX_BITS_MIN 224
193#elif defined(MBEDTLS_ECP_DP_SECP192K1_ENABLED)
194#define MBEDTLS_ECP_MAX_BITS_MIN 192
195#elif defined(MBEDTLS_ECP_DP_SECP192R1_ENABLED)
196#define MBEDTLS_ECP_MAX_BITS_MIN 192
197#else
198#error "MBEDTLS_ECP_C enabled, but no curve?"
199#endif
200
Manuel Pégourié-Gonnard39d2adb2012-10-31 09:26:55 +0100201#if !defined(MBEDTLS_ECP_ALT)
202/*
203 * default mbed TLS elliptic curve arithmetic implementation
204 *
205 * (in case MBEDTLS_ECP_ALT is defined then the developer has to provide an
206 * alternative implementation for the whole module and it will replace this
207 * one.)
208 */
209
Manuel Pégourié-Gonnard39d2adb2012-10-31 09:26:55 +0100210/**
Rose Zadikd3c9bfc2018-04-17 10:56:55 +0100211 * \brief The ECP group structure.
Manuel Pégourié-Gonnard39d2adb2012-10-31 09:26:55 +0100212 *
Rose Zadikd3c9bfc2018-04-17 10:56:55 +0100213 * We consider two types of curve equations:
Rose Zadikb2e111a2018-04-20 10:13:48 +0100214 * <ul><li>Short Weierstrass: <code>y^2 = x^3 + A x + B mod P</code>
Rose Zadikd3c9bfc2018-04-17 10:56:55 +0100215 * (SEC1 + RFC-4492)</li>
Rose Zadikf56cb342018-04-19 12:49:10 +0100216 * <li>Montgomery: <code>y^2 = x^3 + A x^2 + x mod P</code> (Curve25519,
Rose Zadikb2e111a2018-04-20 10:13:48 +0100217 * Curve448)</li></ul>
Rose Zadikf56cb342018-04-19 12:49:10 +0100218 * In both cases, the generator (\p G) for a prime-order subgroup is fixed.
Manuel Pégourié-Gonnard39d2adb2012-10-31 09:26:55 +0100219 *
Rose Zadikd3c9bfc2018-04-17 10:56:55 +0100220 * For Short Weierstrass, this subgroup is the whole curve, and its
Rose Zadikf56cb342018-04-19 12:49:10 +0100221 * cardinality is denoted by \p N. Our code requires that \p N is an
Rose Zadikb2e111a2018-04-20 10:13:48 +0100222 * odd prime as mbedtls_ecp_mul() requires an odd number, and
223 * mbedtls_ecdsa_sign() requires that it is prime for blinding purposes.
Manuel Pégourié-Gonnard39d2adb2012-10-31 09:26:55 +0100224 *
Rose Zadikf56cb342018-04-19 12:49:10 +0100225 * For Montgomery curves, we do not store \p A, but <code>(A + 2) / 4</code>,
Rose Zadika7a61552018-04-24 13:14:01 +0100226 * which is the quantity used in the formulas. Additionally, \p nbits is
Rose Zadikf56cb342018-04-19 12:49:10 +0100227 * not the size of \p N but the required size for private keys.
Manuel Pégourié-Gonnard47123252012-11-10 14:44:24 +0100228 *
Rose Zadika7a61552018-04-24 13:14:01 +0100229 * If \p modp is NULL, reduction modulo \p P is done using a generic algorithm.
230 * Otherwise, \p modp must point to a function that takes an \p mbedtls_mpi in the
231 * range of <code>0..2^(2*pbits)-1</code>, and transforms it in-place to an integer
232 * which is congruent mod \p P to the given MPI, and is close enough to \p pbits
233 * in size, so that it may be efficiently brought in the 0..P-1 range by a few
234 * additions or subtractions. Therefore, it is only an approximative modular
235 * reduction. It must return 0 on success and non-zero on failure.
Rose Zadikd3c9bfc2018-04-17 10:56:55 +0100236 *
Janos Follathc3b680b2018-12-05 16:01:13 +0000237 * \note Alternative implementations must keep the group IDs distinct. If
238 * two group structures have the same ID, then they must be
239 * identical.
240 *
Manuel Pégourié-Gonnard39d2adb2012-10-31 09:26:55 +0100241 */
Dawid Drozd428cc522018-07-24 10:02:47 +0200242typedef struct mbedtls_ecp_group
Manuel Pégourié-Gonnard39d2adb2012-10-31 09:26:55 +0100243{
Rose Zadikd3c9bfc2018-04-17 10:56:55 +0100244 mbedtls_ecp_group_id id; /*!< An internal group identifier. */
Rose Zadikf56cb342018-04-19 12:49:10 +0100245 mbedtls_mpi P; /*!< The prime modulus of the base field. */
Rose Zadikb2e111a2018-04-20 10:13:48 +0100246 mbedtls_mpi A; /*!< For Short Weierstrass: \p A in the equation. For
247 Montgomery curves: <code>(A + 2) / 4</code>. */
248 mbedtls_mpi B; /*!< For Short Weierstrass: \p B in the equation.
249 For Montgomery curves: unused. */
Rose Zadikf56cb342018-04-19 12:49:10 +0100250 mbedtls_ecp_point G; /*!< The generator of the subgroup used. */
Rose Zadikd3c9bfc2018-04-17 10:56:55 +0100251 mbedtls_mpi N; /*!< The order of \p G. */
252 size_t pbits; /*!< The number of bits in \p P.*/
Rose Zadikb2e111a2018-04-20 10:13:48 +0100253 size_t nbits; /*!< For Short Weierstrass: The number of bits in \p P.
Rose Zadika7a61552018-04-24 13:14:01 +0100254 For Montgomery curves: the number of bits in the
Rose Zadikd76ac582018-04-23 06:29:34 +0100255 private keys. */
Rose Zadikd3c9bfc2018-04-17 10:56:55 +0100256 unsigned int h; /*!< \internal 1 if the constants are static. */
Rose Zadika7a61552018-04-24 13:14:01 +0100257 int (*modp)(mbedtls_mpi *); /*!< The function for fast pseudo-reduction
Rose Zadikf56cb342018-04-19 12:49:10 +0100258 mod \p P (see above).*/
Rose Zadikd3c9bfc2018-04-17 10:56:55 +0100259 int (*t_pre)(mbedtls_ecp_point *, void *); /*!< Unused. */
260 int (*t_post)(mbedtls_ecp_point *, void *); /*!< Unused. */
261 void *t_data; /*!< Unused. */
262 mbedtls_ecp_point *T; /*!< Pre-computed points for ecp_mul_comb(). */
Rose Zadikb2e111a2018-04-20 10:13:48 +0100263 size_t T_size; /*!< The number of pre-computed points. */
Manuel Pégourié-Gonnard39d2adb2012-10-31 09:26:55 +0100264}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200265mbedtls_ecp_group;
Manuel Pégourié-Gonnard39d2adb2012-10-31 09:26:55 +0100266
Darryl Greenb7797592019-01-04 16:18:06 +0000267/**
268 * \name SECTION: Module settings
269 *
270 * The configuration options you can set for this module are in this section.
271 * Either change them in config.h, or define them using the compiler command line.
272 * \{
273 */
274
Gilles Peskineeaf74422021-06-02 23:21:07 +0200275#if defined(MBEDTLS_ECP_MAX_BITS)
276
277#if MBEDTLS_ECP_MAX_BITS < MBEDTLS_ECP_MAX_BITS_MIN
278#error "MBEDTLS_ECP_MAX_BITS is smaller than the largest supported curve"
279#endif
280
281#else
Darryl Greenb7797592019-01-04 16:18:06 +0000282/**
283 * The maximum size of the groups, that is, of \c N and \c P.
284 */
285#define MBEDTLS_ECP_MAX_BITS 521 /**< The maximum size of groups, in bits. */
286#endif
287
288#define MBEDTLS_ECP_MAX_BYTES ( ( MBEDTLS_ECP_MAX_BITS + 7 ) / 8 )
289#define MBEDTLS_ECP_MAX_PT_LEN ( 2 * MBEDTLS_ECP_MAX_BYTES + 1 )
290
291#if !defined(MBEDTLS_ECP_WINDOW_SIZE)
292/*
293 * Maximum "window" size used for point multiplication.
294 * Default: 6.
295 * Minimum value: 2. Maximum value: 7.
296 *
297 * Result is an array of at most ( 1 << ( MBEDTLS_ECP_WINDOW_SIZE - 1 ) )
298 * points used for point multiplication. This value is directly tied to EC
299 * peak memory usage, so decreasing it by one should roughly cut memory usage
300 * by two (if large curves are in use).
301 *
302 * Reduction in size may reduce speed, but larger curves are impacted first.
303 * Sample performances (in ECDHE handshakes/s, with FIXED_POINT_OPTIM = 1):
304 * w-size: 6 5 4 3 2
305 * 521 145 141 135 120 97
306 * 384 214 209 198 177 146
307 * 256 320 320 303 262 226
308 * 224 475 475 453 398 342
309 * 192 640 640 633 587 476
310 */
311#define MBEDTLS_ECP_WINDOW_SIZE 6 /**< The maximum window size used. */
312#endif /* MBEDTLS_ECP_WINDOW_SIZE */
313
314#if !defined(MBEDTLS_ECP_FIXED_POINT_OPTIM)
315/*
316 * Trade memory for speed on fixed-point multiplication.
317 *
318 * This speeds up repeated multiplication of the generator (that is, the
319 * multiplication in ECDSA signatures, and half of the multiplications in
320 * ECDSA verification and ECDHE) by a factor roughly 3 to 4.
321 *
322 * The cost is increasing EC peak memory usage by a factor roughly 2.
323 *
324 * Change this value to 0 to reduce peak memory usage.
325 */
326#define MBEDTLS_ECP_FIXED_POINT_OPTIM 1 /**< Enable fixed-point speed-up. */
327#endif /* MBEDTLS_ECP_FIXED_POINT_OPTIM */
328
329/* \} name SECTION: Module settings */
330
331#else /* MBEDTLS_ECP_ALT */
332#include "ecp_alt.h"
333#endif /* MBEDTLS_ECP_ALT */
334
Manuel Pégourié-Gonnard4b9c51e2017-04-20 15:50:26 +0200335#if defined(MBEDTLS_ECP_RESTARTABLE)
Manuel Pégourié-Gonnardb5a50e72017-04-20 16:06:13 +0200336
Manuel Pégourié-Gonnardb739a712017-04-19 10:11:56 +0200337/**
Manuel Pégourié-Gonnard3cade222017-04-20 09:31:00 +0200338 * \brief Internal restart context for multiplication
339 *
340 * \note Opaque struct
341 */
342typedef struct mbedtls_ecp_restart_mul mbedtls_ecp_restart_mul_ctx;
343
344/**
Manuel Pégourié-Gonnard54dd6522017-04-20 13:36:18 +0200345 * \brief Internal restart context for ecp_muladd()
346 *
347 * \note Opaque struct
348 */
349typedef struct mbedtls_ecp_restart_muladd mbedtls_ecp_restart_muladd_ctx;
350
351/**
Manuel Pégourié-Gonnardb739a712017-04-19 10:11:56 +0200352 * \brief General context for resuming ECC operations
353 */
354typedef struct
355{
Manuel Pégourié-Gonnard646393b2017-04-20 10:03:45 +0200356 unsigned ops_done; /*!< current ops count */
Manuel Pégourié-Gonnard3a256122017-04-20 11:20:26 +0200357 unsigned depth; /*!< call depth (0 = top-level) */
Manuel Pégourié-Gonnard646393b2017-04-20 10:03:45 +0200358 mbedtls_ecp_restart_mul_ctx *rsm; /*!< ecp_mul_comb() sub-context */
Manuel Pégourié-Gonnard54dd6522017-04-20 13:36:18 +0200359 mbedtls_ecp_restart_muladd_ctx *ma; /*!< ecp_muladd() sub-context */
Manuel Pégourié-Gonnardb739a712017-04-19 10:11:56 +0200360} mbedtls_ecp_restart_ctx;
Manuel Pégourié-Gonnardb5a50e72017-04-20 16:06:13 +0200361
Manuel Pégourié-Gonnardc7511482017-04-20 16:31:00 +0200362/*
363 * Operation counts for restartable functions
364 */
Manuel Pégourié-Gonnard5314f232017-04-21 12:36:59 +0200365#define MBEDTLS_ECP_OPS_CHK 3 /*!< basic ops count for ecp_check_pubkey() */
Manuel Pégourié-Gonnardc7511482017-04-20 16:31:00 +0200366#define MBEDTLS_ECP_OPS_DBL 8 /*!< basic ops count for ecp_double_jac() */
367#define MBEDTLS_ECP_OPS_ADD 11 /*!< basic ops count for see ecp_add_mixed() */
368#define MBEDTLS_ECP_OPS_INV 120 /*!< empirical equivalent for mpi_mod_inv() */
369
370/**
371 * \brief Internal; for restartable functions in other modules.
372 * Check and update basic ops budget.
373 *
374 * \param grp Group structure
375 * \param rs_ctx Restart context
376 * \param ops Number of basic ops to do
377 *
Manuel Pégourié-Gonnard12e4a8b2018-09-12 10:55:15 +0200378 * \return \c 0 if doing \p ops basic ops is still allowed,
379 * \return #MBEDTLS_ERR_ECP_IN_PROGRESS otherwise.
Manuel Pégourié-Gonnardc7511482017-04-20 16:31:00 +0200380 */
381int mbedtls_ecp_check_budget( const mbedtls_ecp_group *grp,
382 mbedtls_ecp_restart_ctx *rs_ctx,
383 unsigned ops );
384
385/* Utility macro for checking and updating ops budget */
Hanno Beckerabdf67e2018-10-26 13:28:32 +0100386#define MBEDTLS_ECP_BUDGET( ops ) \
387 MBEDTLS_MPI_CHK( mbedtls_ecp_check_budget( grp, rs_ctx, \
388 (unsigned) (ops) ) );
Manuel Pégourié-Gonnardc7511482017-04-20 16:31:00 +0200389
Manuel Pégourié-Gonnardb5a50e72017-04-20 16:06:13 +0200390#else /* MBEDTLS_ECP_RESTARTABLE */
391
Manuel Pégourié-Gonnardc7511482017-04-20 16:31:00 +0200392#define MBEDTLS_ECP_BUDGET( ops ) /* no-op; for compatibility */
393
Manuel Pégourié-Gonnardb5a50e72017-04-20 16:06:13 +0200394/* We want to declare restartable versions of existing functions anyway */
395typedef void mbedtls_ecp_restart_ctx;
396
Manuel Pégourié-Gonnard4b9c51e2017-04-20 15:50:26 +0200397#endif /* MBEDTLS_ECP_RESTARTABLE */
Manuel Pégourié-Gonnardb739a712017-04-19 10:11:56 +0200398
Paul Bakker088c5c52014-04-25 11:11:10 +0200399/**
Jaeden Amero89453432018-04-24 17:15:38 +0100400 * \brief The ECP key-pair structure.
Ron Eldor05d0e512018-04-16 17:40:04 +0300401 *
Jaeden Amero89453432018-04-24 17:15:38 +0100402 * A generic key-pair that may be used for ECDSA and fixed ECDH, for example.
Ron Eldor05d0e512018-04-16 17:40:04 +0300403 *
Jaeden Amero89453432018-04-24 17:15:38 +0100404 * \note Members are deliberately in the same order as in the
405 * ::mbedtls_ecdsa_context structure.
Ron Eldor05d0e512018-04-16 17:40:04 +0300406 */
Dawid Drozd428cc522018-07-24 10:02:47 +0200407typedef struct mbedtls_ecp_keypair
Ron Eldor05d0e512018-04-16 17:40:04 +0300408{
409 mbedtls_ecp_group grp; /*!< Elliptic curve and base point */
410 mbedtls_mpi d; /*!< our secret value */
411 mbedtls_ecp_point Q; /*!< our public value */
412}
413mbedtls_ecp_keypair;
414
Manuel Pégourié-Gonnard37d218a2012-11-24 15:19:55 +0100415/*
Manuel Pégourié-Gonnard00794052013-02-09 19:00:07 +0100416 * Point formats, from RFC 4492's enum ECPointFormat
Manuel Pégourié-Gonnard37d218a2012-11-24 15:19:55 +0100417 */
Rose Zadikd3c9bfc2018-04-17 10:56:55 +0100418#define MBEDTLS_ECP_PF_UNCOMPRESSED 0 /**< Uncompressed point format. */
419#define MBEDTLS_ECP_PF_COMPRESSED 1 /**< Compressed point format. */
Manuel Pégourié-Gonnard37d218a2012-11-24 15:19:55 +0100420
Manuel Pégourié-Gonnard1a967282013-02-09 17:03:58 +0100421/*
Manuel Pégourié-Gonnard00794052013-02-09 19:00:07 +0100422 * Some other constants from RFC 4492
Manuel Pégourié-Gonnard1a967282013-02-09 17:03:58 +0100423 */
Rose Zadikd3c9bfc2018-04-17 10:56:55 +0100424#define MBEDTLS_ECP_TLS_NAMED_CURVE 3 /**< The named_curve of ECCurveType. */
Manuel Pégourié-Gonnard1a967282013-02-09 17:03:58 +0100425
Manuel Pégourié-Gonnard4b9c51e2017-04-20 15:50:26 +0200426#if defined(MBEDTLS_ECP_RESTARTABLE)
Manuel Pégourié-Gonnard054433c2017-03-22 11:18:33 +0100427/**
428 * \brief Set the maximum number of basic operations done in a row.
429 *
430 * If more operations are needed to complete a computation,
Manuel Pégourié-Gonnard12e4a8b2018-09-12 10:55:15 +0200431 * #MBEDTLS_ERR_ECP_IN_PROGRESS will be returned by the
Manuel Pégourié-Gonnard8467e682017-04-20 09:47:06 +0200432 * function performing the computation. It is then the
433 * caller's responsibility to either call again with the same
Manuel Pégourié-Gonnard7037e222017-08-23 14:30:36 +0200434 * parameters until it returns 0 or an error code; or to free
Manuel Pégourié-Gonnard8467e682017-04-20 09:47:06 +0200435 * the restart context if the operation is to be aborted.
Manuel Pégourié-Gonnard054433c2017-03-22 11:18:33 +0100436 *
Manuel Pégourié-Gonnard7037e222017-08-23 14:30:36 +0200437 * It is strictly required that all input parameters and the
438 * restart context be the same on successive calls for the
439 * same operation, but output parameters need not be the
440 * same; they must not be used until the function finally
441 * returns 0.
442 *
Manuel Pégourié-Gonnard32df9112018-10-15 13:29:21 +0200443 * This only applies to functions whose documentation
444 * mentions they may return #MBEDTLS_ERR_ECP_IN_PROGRESS (or
445 * #MBEDTLS_ERR_SSL_CRYPTO_IN_PROGRESS for functions in the
446 * SSL module). For functions that accept a "restart context"
447 * argument, passing NULL disables restart and makes the
448 * function equivalent to the function with the same name
449 * with \c _restartable removed. For functions in the ECDH
450 * module, restart is disabled unless the function accepts
451 * an "ECDH context" argument and
452 * mbedtls_ecdh_enable_restart() was previously called on
453 * that context. For function in the SSL module, restart is
454 * only enabled for specific sides and key exchanges
455 * (currently only for clients and ECDHE-ECDSA).
Manuel Pégourié-Gonnard8f28add2017-04-19 10:20:49 +0200456 *
Manuel Pégourié-Gonnard054433c2017-03-22 11:18:33 +0100457 * \param max_ops Maximum number of basic operations done in a row.
458 * Default: 0 (unlimited).
459 * Lower (non-zero) values mean ECC functions will block for
460 * a lesser maximum amount of time.
461 *
Manuel Pégourié-Gonnarde6854492017-03-20 14:35:19 +0100462 * \note A "basic operation" is defined as a rough equivalent of a
463 * multiplication in GF(p) for the NIST P-256 curve.
464 * As an indication, with default settings, a scalar
465 * multiplication (full run of \c mbedtls_ecp_mul()) is:
466 * - about 3300 basic operations for P-256
467 * - about 9400 basic operations for P-384
Manuel Pégourié-Gonnard054433c2017-03-22 11:18:33 +0100468 *
Manuel Pégourié-Gonnarde58f65a2017-03-20 14:59:54 +0100469 * \note Very low values are not always respected: sometimes
Manuel Pégourié-Gonnard1c678e02017-03-20 13:39:39 +0100470 * functions need to block for a minimum number of
471 * operations, and will do so even if max_ops is set to a
472 * lower value. That minimum depends on the curve size, and
473 * can be made lower by decreasing the value of
Manuel Pégourié-Gonnard7037e222017-08-23 14:30:36 +0200474 * \c MBEDTLS_ECP_WINDOW_SIZE. As an indication, here is the
475 * lowest effective value for various curves and values of
476 * that parameter (w for short):
477 * w=6 w=5 w=4 w=3 w=2
478 * P-256 208 208 160 136 124
479 * P-384 682 416 320 272 248
480 * P-521 1364 832 640 544 496
Manuel Pégourié-Gonnarde58f65a2017-03-20 14:59:54 +0100481 *
Manuel Pégourié-Gonnard12e4a8b2018-09-12 10:55:15 +0200482 * \note This setting is currently ignored by Curve25519.
Manuel Pégourié-Gonnard054433c2017-03-22 11:18:33 +0100483 */
484void mbedtls_ecp_set_max_ops( unsigned max_ops );
Manuel Pégourié-Gonnarda0c5bcc2017-04-21 11:33:57 +0200485
486/**
487 * \brief Check if restart is enabled (max_ops != 0)
488 *
Manuel Pégourié-Gonnard12e4a8b2018-09-12 10:55:15 +0200489 * \return \c 0 if \c max_ops == 0 (restart disabled)
490 * \return \c 1 otherwise (restart enabled)
Manuel Pégourié-Gonnarda0c5bcc2017-04-21 11:33:57 +0200491 */
Manuel Pégourié-Gonnardb843b152018-10-16 10:41:31 +0200492int mbedtls_ecp_restart_is_enabled( void );
Manuel Pégourié-Gonnard4b9c51e2017-04-20 15:50:26 +0200493#endif /* MBEDTLS_ECP_RESTARTABLE */
Manuel Pégourié-Gonnard054433c2017-03-22 11:18:33 +0100494
Manuel Pégourié-Gonnard39d2adb2012-10-31 09:26:55 +0100495/**
Rose Zadikd3c9bfc2018-04-17 10:56:55 +0100496 * \brief This function retrieves the information defined in
Rose Zadikf56cb342018-04-19 12:49:10 +0100497 * mbedtls_ecp_curve_info() for all supported curves in order
Rose Zadikd3c9bfc2018-04-17 10:56:55 +0100498 * of preference.
Manuel Pégourié-Gonnardda179e42013-09-18 15:31:24 +0200499 *
Rose Zadikd3c9bfc2018-04-17 10:56:55 +0100500 * \return A statically allocated array. The last entry is 0.
Manuel Pégourié-Gonnardda179e42013-09-18 15:31:24 +0200501 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200502const mbedtls_ecp_curve_info *mbedtls_ecp_curve_list( void );
Manuel Pégourié-Gonnardda179e42013-09-18 15:31:24 +0200503
504/**
Rose Zadikf56cb342018-04-19 12:49:10 +0100505 * \brief This function retrieves the list of internal group
506 * identifiers of all supported curves in the order of
507 * preference.
Manuel Pégourié-Gonnardac719412014-02-04 14:48:50 +0100508 *
509 * \return A statically allocated array,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200510 * terminated with MBEDTLS_ECP_DP_NONE.
Manuel Pégourié-Gonnardac719412014-02-04 14:48:50 +0100511 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200512const mbedtls_ecp_group_id *mbedtls_ecp_grp_id_list( void );
Manuel Pégourié-Gonnardac719412014-02-04 14:48:50 +0100513
514/**
Rose Zadikd3c9bfc2018-04-17 10:56:55 +0100515 * \brief This function retrieves curve information from an internal
516 * group identifier.
Manuel Pégourié-Gonnardcae6f3e2013-10-23 20:19:57 +0200517 *
Rose Zadikd3c9bfc2018-04-17 10:56:55 +0100518 * \param grp_id An \c MBEDTLS_ECP_DP_XXX value.
Manuel Pégourié-Gonnardcae6f3e2013-10-23 20:19:57 +0200519 *
Rose Zadikf56cb342018-04-19 12:49:10 +0100520 * \return The associated curve information on success.
521 * \return NULL on failure.
Manuel Pégourié-Gonnardcae6f3e2013-10-23 20:19:57 +0200522 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200523const mbedtls_ecp_curve_info *mbedtls_ecp_curve_info_from_grp_id( mbedtls_ecp_group_id grp_id );
Manuel Pégourié-Gonnardcae6f3e2013-10-23 20:19:57 +0200524
525/**
Rose Zadika7a61552018-04-24 13:14:01 +0100526 * \brief This function retrieves curve information from a TLS
Rose Zadikd3c9bfc2018-04-17 10:56:55 +0100527 * NamedCurve value.
Manuel Pégourié-Gonnardcae6f3e2013-10-23 20:19:57 +0200528 *
Rose Zadikd3c9bfc2018-04-17 10:56:55 +0100529 * \param tls_id An \c MBEDTLS_ECP_DP_XXX value.
Manuel Pégourié-Gonnardcae6f3e2013-10-23 20:19:57 +0200530 *
Rose Zadikf56cb342018-04-19 12:49:10 +0100531 * \return The associated curve information on success.
532 * \return NULL on failure.
Manuel Pégourié-Gonnardcae6f3e2013-10-23 20:19:57 +0200533 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200534const mbedtls_ecp_curve_info *mbedtls_ecp_curve_info_from_tls_id( uint16_t tls_id );
Manuel Pégourié-Gonnardcae6f3e2013-10-23 20:19:57 +0200535
536/**
Rose Zadika7a61552018-04-24 13:14:01 +0100537 * \brief This function retrieves curve information from a
Rose Zadikd3c9bfc2018-04-17 10:56:55 +0100538 * human-readable name.
Manuel Pégourié-Gonnard0267e3d2013-11-30 15:10:14 +0100539 *
Rose Zadikd3c9bfc2018-04-17 10:56:55 +0100540 * \param name The human-readable name.
Manuel Pégourié-Gonnard0267e3d2013-11-30 15:10:14 +0100541 *
Rose Zadikf56cb342018-04-19 12:49:10 +0100542 * \return The associated curve information on success.
543 * \return NULL on failure.
Manuel Pégourié-Gonnard0267e3d2013-11-30 15:10:14 +0100544 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200545const mbedtls_ecp_curve_info *mbedtls_ecp_curve_info_from_name( const char *name );
Manuel Pégourié-Gonnard0267e3d2013-11-30 15:10:14 +0100546
547/**
Rose Zadikd3c9bfc2018-04-17 10:56:55 +0100548 * \brief This function initializes a point as zero.
549 *
550 * \param pt The point to initialize.
Manuel Pégourié-Gonnardae180d02012-11-02 18:14:40 +0100551 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200552void mbedtls_ecp_point_init( mbedtls_ecp_point *pt );
Manuel Pégourié-Gonnardae180d02012-11-02 18:14:40 +0100553
554/**
Rose Zadikf56cb342018-04-19 12:49:10 +0100555 * \brief This function initializes an ECP group context
Rose Zadika7a61552018-04-24 13:14:01 +0100556 * without loading any domain parameters.
Rose Zadikf56cb342018-04-19 12:49:10 +0100557 *
558 * \note After this function is called, domain parameters
559 * for various ECP groups can be loaded through the
Gilles Peskine4dc50bc2018-11-07 22:06:48 +0100560 * mbedtls_ecp_group_load() or mbedtls_ecp_tls_read_group()
Rose Zadikf56cb342018-04-19 12:49:10 +0100561 * functions.
Manuel Pégourié-Gonnardb505c272012-11-05 17:27:54 +0100562 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200563void mbedtls_ecp_group_init( mbedtls_ecp_group *grp );
Manuel Pégourié-Gonnardb505c272012-11-05 17:27:54 +0100564
565/**
Rose Zadikd3c9bfc2018-04-17 10:56:55 +0100566 * \brief This function initializes a key pair as an invalid one.
567 *
568 * \param key The key pair to initialize.
Manuel Pégourié-Gonnardb8c6e0e2013-07-01 13:40:52 +0200569 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200570void mbedtls_ecp_keypair_init( mbedtls_ecp_keypair *key );
Manuel Pégourié-Gonnardb8c6e0e2013-07-01 13:40:52 +0200571
572/**
Rose Zadikd3c9bfc2018-04-17 10:56:55 +0100573 * \brief This function frees the components of a point.
574 *
575 * \param pt The point to free.
Manuel Pégourié-Gonnard883f3132012-11-02 09:40:25 +0100576 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200577void mbedtls_ecp_point_free( mbedtls_ecp_point *pt );
Manuel Pégourié-Gonnard883f3132012-11-02 09:40:25 +0100578
579/**
Rose Zadikd3c9bfc2018-04-17 10:56:55 +0100580 * \brief This function frees the components of an ECP group.
Hanno Beckerebffa792018-12-14 15:07:50 +0000581 *
582 * \param grp The group to free. This may be \c NULL, in which
Hanno Becker486f1b32018-12-18 13:00:34 +0000583 * case this function returns immediately. If it is not
584 * \c NULL, it must point to an initialized ECP group.
Manuel Pégourié-Gonnard883f3132012-11-02 09:40:25 +0100585 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200586void mbedtls_ecp_group_free( mbedtls_ecp_group *grp );
Manuel Pégourié-Gonnard883f3132012-11-02 09:40:25 +0100587
588/**
Rose Zadikd3c9bfc2018-04-17 10:56:55 +0100589 * \brief This function frees the components of a key pair.
Hanno Beckerebffa792018-12-14 15:07:50 +0000590 *
591 * \param key The key pair to free. This may be \c NULL, in which
Hanno Becker486f1b32018-12-18 13:00:34 +0000592 * case this function returns immediately. If it is not
593 * \c NULL, it must point to an initialized ECP key pair.
Manuel Pégourié-Gonnardb8c6e0e2013-07-01 13:40:52 +0200594 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200595void mbedtls_ecp_keypair_free( mbedtls_ecp_keypair *key );
Manuel Pégourié-Gonnardb8c6e0e2013-07-01 13:40:52 +0200596
Manuel Pégourié-Gonnard4b9c51e2017-04-20 15:50:26 +0200597#if defined(MBEDTLS_ECP_RESTARTABLE)
Manuel Pégourié-Gonnardb739a712017-04-19 10:11:56 +0200598/**
Hanno Beckerebffa792018-12-14 15:07:50 +0000599 * \brief Initialize a restart context.
600 *
601 * \param ctx The restart context to initialize. This must
602 * not be \c NULL.
Manuel Pégourié-Gonnardb739a712017-04-19 10:11:56 +0200603 */
604void mbedtls_ecp_restart_init( mbedtls_ecp_restart_ctx *ctx );
605
606/**
Hanno Beckerebffa792018-12-14 15:07:50 +0000607 * \brief Free the components of a restart context.
608 *
609 * \param ctx The restart context to free. This may be \c NULL, in which
Hanno Becker486f1b32018-12-18 13:00:34 +0000610 * case this function returns immediately. If it is not
611 * \c NULL, it must point to an initialized restart context.
Manuel Pégourié-Gonnardb739a712017-04-19 10:11:56 +0200612 */
613void mbedtls_ecp_restart_free( mbedtls_ecp_restart_ctx *ctx );
Manuel Pégourié-Gonnard4b9c51e2017-04-20 15:50:26 +0200614#endif /* MBEDTLS_ECP_RESTARTABLE */
Manuel Pégourié-Gonnardb739a712017-04-19 10:11:56 +0200615
Manuel Pégourié-Gonnardb8c6e0e2013-07-01 13:40:52 +0200616/**
Rose Zadika7a61552018-04-24 13:14:01 +0100617 * \brief This function copies the contents of point \p Q into
Rose Zadikd3c9bfc2018-04-17 10:56:55 +0100618 * point \p P.
Manuel Pégourié-Gonnard883f3132012-11-02 09:40:25 +0100619 *
Hanno Beckerebffa792018-12-14 15:07:50 +0000620 * \param P The destination point. This must be initialized.
621 * \param Q The source point. This must be initialized.
Manuel Pégourié-Gonnard883f3132012-11-02 09:40:25 +0100622 *
Rose Zadikd3c9bfc2018-04-17 10:56:55 +0100623 * \return \c 0 on success.
Rose Zadikf56cb342018-04-19 12:49:10 +0100624 * \return #MBEDTLS_ERR_MPI_ALLOC_FAILED on memory-allocation failure.
Hanno Beckerebffa792018-12-14 15:07:50 +0000625 * \return Another negative error code for other kinds of failure.
Manuel Pégourié-Gonnard883f3132012-11-02 09:40:25 +0100626 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200627int mbedtls_ecp_copy( mbedtls_ecp_point *P, const mbedtls_ecp_point *Q );
Manuel Pégourié-Gonnard883f3132012-11-02 09:40:25 +0100628
629/**
Rose Zadika7a61552018-04-24 13:14:01 +0100630 * \brief This function copies the contents of group \p src into
Rose Zadikd3c9bfc2018-04-17 10:56:55 +0100631 * group \p dst.
Manuel Pégourié-Gonnarde09631b2013-08-12 15:44:31 +0200632 *
Hanno Beckerebffa792018-12-14 15:07:50 +0000633 * \param dst The destination group. This must be initialized.
634 * \param src The source group. This must be initialized.
Manuel Pégourié-Gonnarde09631b2013-08-12 15:44:31 +0200635 *
Rose Zadikd3c9bfc2018-04-17 10:56:55 +0100636 * \return \c 0 on success.
Rose Zadikf56cb342018-04-19 12:49:10 +0100637 * \return #MBEDTLS_ERR_MPI_ALLOC_FAILED on memory-allocation failure.
Hanno Beckerebffa792018-12-14 15:07:50 +0000638 * \return Another negative error code on other kinds of failure.
Manuel Pégourié-Gonnarde09631b2013-08-12 15:44:31 +0200639 */
Hanno Beckerebffa792018-12-14 15:07:50 +0000640int mbedtls_ecp_group_copy( mbedtls_ecp_group *dst,
641 const mbedtls_ecp_group *src );
Manuel Pégourié-Gonnarde09631b2013-08-12 15:44:31 +0200642
643/**
Hanno Beckerebffa792018-12-14 15:07:50 +0000644 * \brief This function sets a point to the point at infinity.
Manuel Pégourié-Gonnardcae6f3e2013-10-23 20:19:57 +0200645 *
Hanno Beckerebffa792018-12-14 15:07:50 +0000646 * \param pt The point to set. This must be initialized.
Manuel Pégourié-Gonnardcae6f3e2013-10-23 20:19:57 +0200647 *
Rose Zadikd3c9bfc2018-04-17 10:56:55 +0100648 * \return \c 0 on success.
Rose Zadikf56cb342018-04-19 12:49:10 +0100649 * \return #MBEDTLS_ERR_MPI_ALLOC_FAILED on memory-allocation failure.
Hanno Beckerebffa792018-12-14 15:07:50 +0000650 * \return Another negative error code on other kinds of failure.
Manuel Pégourié-Gonnardcae6f3e2013-10-23 20:19:57 +0200651 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200652int mbedtls_ecp_set_zero( mbedtls_ecp_point *pt );
Manuel Pégourié-Gonnardcae6f3e2013-10-23 20:19:57 +0200653
654/**
Hanno Beckerebffa792018-12-14 15:07:50 +0000655 * \brief This function checks if a point is the point at infinity.
Manuel Pégourié-Gonnardcae6f3e2013-10-23 20:19:57 +0200656 *
Hanno Beckerebffa792018-12-14 15:07:50 +0000657 * \param pt The point to test. This must be initialized.
Manuel Pégourié-Gonnardcae6f3e2013-10-23 20:19:57 +0200658 *
Rose Zadikf56cb342018-04-19 12:49:10 +0100659 * \return \c 1 if the point is zero.
660 * \return \c 0 if the point is non-zero.
Hanno Beckerebffa792018-12-14 15:07:50 +0000661 * \return A negative error code on failure.
Manuel Pégourié-Gonnardcae6f3e2013-10-23 20:19:57 +0200662 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200663int mbedtls_ecp_is_zero( mbedtls_ecp_point *pt );
Manuel Pégourié-Gonnardcae6f3e2013-10-23 20:19:57 +0200664
665/**
Rose Zadikd3c9bfc2018-04-17 10:56:55 +0100666 * \brief This function compares two points.
Manuel Pégourié-Gonnard6029a852015-08-11 15:44:41 +0200667 *
Rose Zadikd3c9bfc2018-04-17 10:56:55 +0100668 * \note This assumes that the points are normalized. Otherwise,
Manuel Pégourié-Gonnard6029a852015-08-11 15:44:41 +0200669 * they may compare as "not equal" even if they are.
670 *
Hanno Beckerebffa792018-12-14 15:07:50 +0000671 * \param P The first point to compare. This must be initialized.
672 * \param Q The second point to compare. This must be initialized.
Manuel Pégourié-Gonnard6029a852015-08-11 15:44:41 +0200673 *
Rose Zadikd3c9bfc2018-04-17 10:56:55 +0100674 * \return \c 0 if the points are equal.
675 * \return #MBEDTLS_ERR_ECP_BAD_INPUT_DATA if the points are not equal.
Manuel Pégourié-Gonnard6029a852015-08-11 15:44:41 +0200676 */
677int mbedtls_ecp_point_cmp( const mbedtls_ecp_point *P,
678 const mbedtls_ecp_point *Q );
679
680/**
Rose Zadika7a61552018-04-24 13:14:01 +0100681 * \brief This function imports a non-zero point from two ASCII
Rose Zadikd3c9bfc2018-04-17 10:56:55 +0100682 * strings.
Manuel Pégourié-Gonnard847395a2012-11-05 13:13:44 +0100683 *
Hanno Beckerebffa792018-12-14 15:07:50 +0000684 * \param P The destination point. This must be initialized.
Rose Zadikd3c9bfc2018-04-17 10:56:55 +0100685 * \param radix The numeric base of the input.
686 * \param x The first affine coordinate, as a null-terminated string.
687 * \param y The second affine coordinate, as a null-terminated string.
Manuel Pégourié-Gonnard847395a2012-11-05 13:13:44 +0100688 *
Rose Zadikd3c9bfc2018-04-17 10:56:55 +0100689 * \return \c 0 on success.
690 * \return An \c MBEDTLS_ERR_MPI_XXX error code on failure.
Manuel Pégourié-Gonnard847395a2012-11-05 13:13:44 +0100691 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200692int mbedtls_ecp_point_read_string( mbedtls_ecp_point *P, int radix,
Manuel Pégourié-Gonnard847395a2012-11-05 13:13:44 +0100693 const char *x, const char *y );
694
695/**
Rose Zadikd3c9bfc2018-04-17 10:56:55 +0100696 * \brief This function exports a point into unsigned binary data.
Manuel Pégourié-Gonnarde19feb52012-11-24 14:10:14 +0100697 *
Rose Zadikd3c9bfc2018-04-17 10:56:55 +0100698 * \param grp The group to which the point should belong.
Hanno Beckerebffa792018-12-14 15:07:50 +0000699 * This must be initialized and have group parameters
700 * set, for example through mbedtls_ecp_group_load().
701 * \param P The point to export. This must be initialized.
702 * \param format The point format. This must be either
703 * #MBEDTLS_ECP_PF_COMPRESSED or #MBEDTLS_ECP_PF_UNCOMPRESSED.
704 * \param olen The address at which to store the length of
Hanno Becker5edcfa52018-12-18 12:49:55 +0000705 * the output in Bytes. This must not be \c NULL.
Hanno Beckerebffa792018-12-14 15:07:50 +0000706 * \param buf The output buffer. This must be a writable buffer
707 * of length \p buflen Bytes.
708 * \param buflen The length of the output buffer \p buf in Bytes.
Manuel Pégourié-Gonnarde19feb52012-11-24 14:10:14 +0100709 *
Rose Zadikd3c9bfc2018-04-17 10:56:55 +0100710 * \return \c 0 on success.
Hanno Beckerebffa792018-12-14 15:07:50 +0000711 * \return #MBEDTLS_ERR_ECP_BUFFER_TOO_SMALL if the output buffer
712 * is too small to hold the point.
713 * \return Another negative error code on other kinds of failure.
Manuel Pégourié-Gonnarde19feb52012-11-24 14:10:14 +0100714 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200715int mbedtls_ecp_point_write_binary( const mbedtls_ecp_group *grp, const mbedtls_ecp_point *P,
Manuel Pégourié-Gonnard420f1eb2013-02-10 12:22:46 +0100716 int format, size_t *olen,
Manuel Pégourié-Gonnard7e860252013-02-10 10:58:48 +0100717 unsigned char *buf, size_t buflen );
Manuel Pégourié-Gonnarde19feb52012-11-24 14:10:14 +0100718
719/**
Rose Zadikd3c9bfc2018-04-17 10:56:55 +0100720 * \brief This function imports a point from unsigned binary data.
Manuel Pégourié-Gonnard5e402d82012-11-24 16:19:42 +0100721 *
Rose Zadikd3c9bfc2018-04-17 10:56:55 +0100722 * \note This function does not check that the point actually
Rose Zadika7a61552018-04-24 13:14:01 +0100723 * belongs to the given group, see mbedtls_ecp_check_pubkey()
Rose Zadikd3c9bfc2018-04-17 10:56:55 +0100724 * for that.
Manuel Pégourié-Gonnard5e402d82012-11-24 16:19:42 +0100725 *
Rose Zadikd3c9bfc2018-04-17 10:56:55 +0100726 * \param grp The group to which the point should belong.
Hanno Beckerebffa792018-12-14 15:07:50 +0000727 * This must be initialized and have group parameters
728 * set, for example through mbedtls_ecp_group_load().
729 * \param P The destination context to import the point to.
730 * This must be initialized.
731 * \param buf The input buffer. This must be a readable buffer
732 * of length \p ilen Bytes.
733 * \param ilen The length of the input buffer \p buf in Bytes.
Rose Zadikd3c9bfc2018-04-17 10:56:55 +0100734 *
735 * \return \c 0 on success.
Hanno Beckerebffa792018-12-14 15:07:50 +0000736 * \return #MBEDTLS_ERR_ECP_BAD_INPUT_DATA if the input is invalid.
Rose Zadikf56cb342018-04-19 12:49:10 +0100737 * \return #MBEDTLS_ERR_MPI_ALLOC_FAILED on memory-allocation failure.
Rose Zadikd3c9bfc2018-04-17 10:56:55 +0100738 * \return #MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE if the point format
Manuel Pégourié-Gonnard5246ee52014-03-19 16:18:38 +0100739 * is not implemented.
Manuel Pégourié-Gonnard5e402d82012-11-24 16:19:42 +0100740 */
Hanno Beckerebffa792018-12-14 15:07:50 +0000741int mbedtls_ecp_point_read_binary( const mbedtls_ecp_group *grp,
742 mbedtls_ecp_point *P,
743 const unsigned char *buf, size_t ilen );
Manuel Pégourié-Gonnard1a967282013-02-09 17:03:58 +0100744
Manuel Pégourié-Gonnard5e402d82012-11-24 16:19:42 +0100745/**
Rose Zadikd3c9bfc2018-04-17 10:56:55 +0100746 * \brief This function imports a point from a TLS ECPoint record.
Manuel Pégourié-Gonnardcae6f3e2013-10-23 20:19:57 +0200747 *
Janos Follath89ac8c92018-10-30 11:24:05 +0000748 * \note On function return, \p *buf is updated to point immediately
Rose Zadikf56cb342018-04-19 12:49:10 +0100749 * after the ECPoint record.
Manuel Pégourié-Gonnardcae6f3e2013-10-23 20:19:57 +0200750 *
Hanno Beckerebffa792018-12-14 15:07:50 +0000751 * \param grp The ECP group to use.
752 * This must be initialized and have group parameters
753 * set, for example through mbedtls_ecp_group_load().
Rose Zadikd3c9bfc2018-04-17 10:56:55 +0100754 * \param pt The destination point.
Rose Zadikf56cb342018-04-19 12:49:10 +0100755 * \param buf The address of the pointer to the start of the input buffer.
Rose Zadikd3c9bfc2018-04-17 10:56:55 +0100756 * \param len The length of the buffer.
Manuel Pégourié-Gonnard150c4f62014-11-21 09:14:52 +0100757 *
Rose Zadikd3c9bfc2018-04-17 10:56:55 +0100758 * \return \c 0 on success.
Janos Follath89ac8c92018-10-30 11:24:05 +0000759 * \return An \c MBEDTLS_ERR_MPI_XXX error code on initialization
760 * failure.
Rose Zadikd3c9bfc2018-04-17 10:56:55 +0100761 * \return #MBEDTLS_ERR_ECP_BAD_INPUT_DATA if input is invalid.
Manuel Pégourié-Gonnardcae6f3e2013-10-23 20:19:57 +0200762 */
Hanno Beckerebffa792018-12-14 15:07:50 +0000763int mbedtls_ecp_tls_read_point( const mbedtls_ecp_group *grp,
764 mbedtls_ecp_point *pt,
765 const unsigned char **buf, size_t len );
Manuel Pégourié-Gonnardcae6f3e2013-10-23 20:19:57 +0200766
767/**
Hanno Beckerebffa792018-12-14 15:07:50 +0000768 * \brief This function exports a point as a TLS ECPoint record
769 * defined in RFC 4492, Section 5.4.
Manuel Pégourié-Gonnardcae6f3e2013-10-23 20:19:57 +0200770 *
Hanno Beckerebffa792018-12-14 15:07:50 +0000771 * \param grp The ECP group to use.
772 * This must be initialized and have group parameters
773 * set, for example through mbedtls_ecp_group_load().
774 * \param pt The point to be exported. This must be initialized.
775 * \param format The point format to use. This must be either
776 * #MBEDTLS_ECP_PF_COMPRESSED or #MBEDTLS_ECP_PF_UNCOMPRESSED.
777 * \param olen The address at which to store the length in Bytes
778 * of the data written.
779 * \param buf The target buffer. This must be a writable buffer of
780 * length \p blen Bytes.
781 * \param blen The length of the target buffer \p buf in Bytes.
Manuel Pégourié-Gonnardcae6f3e2013-10-23 20:19:57 +0200782 *
Rose Zadikd3c9bfc2018-04-17 10:56:55 +0100783 * \return \c 0 on success.
Hanno Beckerebffa792018-12-14 15:07:50 +0000784 * \return #MBEDTLS_ERR_ECP_BAD_INPUT_DATA if the input is invalid.
785 * \return #MBEDTLS_ERR_ECP_BUFFER_TOO_SMALL if the target buffer
786 * is too small to hold the exported point.
787 * \return Another negative error code on other kinds of failure.
Manuel Pégourié-Gonnardcae6f3e2013-10-23 20:19:57 +0200788 */
Hanno Beckerebffa792018-12-14 15:07:50 +0000789int mbedtls_ecp_tls_write_point( const mbedtls_ecp_group *grp,
790 const mbedtls_ecp_point *pt,
791 int format, size_t *olen,
792 unsigned char *buf, size_t blen );
Manuel Pégourié-Gonnardcae6f3e2013-10-23 20:19:57 +0200793
794/**
Hanno Beckerebffa792018-12-14 15:07:50 +0000795 * \brief This function sets up an ECP group context
796 * from a standardized set of domain parameters.
Manuel Pégourié-Gonnarda5402fe2012-11-07 20:24:05 +0100797 *
Rose Zadikd3c9bfc2018-04-17 10:56:55 +0100798 * \note The index should be a value of the NamedCurve enum,
Rose Zadika7a61552018-04-24 13:14:01 +0100799 * as defined in <em>RFC-4492: Elliptic Curve Cryptography
Rose Zadikd3c9bfc2018-04-17 10:56:55 +0100800 * (ECC) Cipher Suites for Transport Layer Security (TLS)</em>,
801 * usually in the form of an \c MBEDTLS_ECP_DP_XXX macro.
Manuel Pégourié-Gonnarda5402fe2012-11-07 20:24:05 +0100802 *
Hanno Beckerebffa792018-12-14 15:07:50 +0000803 * \param grp The group context to setup. This must be initialized.
Rose Zadikf56cb342018-04-19 12:49:10 +0100804 * \param id The identifier of the domain parameter set to load.
Manuel Pégourié-Gonnarda5402fe2012-11-07 20:24:05 +0100805 *
Hanno Beckerebffa792018-12-14 15:07:50 +0000806 * \return \c 0 on success.
807 * \return #MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE if \p id doesn't
808 * correspond to a known group.
809 * \return Another negative error code on other kinds of failure.
Manuel Pégourié-Gonnarda5402fe2012-11-07 20:24:05 +0100810 */
Hanno Becker61937d42017-04-26 15:01:23 +0100811int mbedtls_ecp_group_load( mbedtls_ecp_group *grp, mbedtls_ecp_group_id id );
Manuel Pégourié-Gonnard1a967282013-02-09 17:03:58 +0100812
813/**
Hanno Beckerebffa792018-12-14 15:07:50 +0000814 * \brief This function sets up an ECP group context from a TLS
815 * ECParameters record as defined in RFC 4492, Section 5.4.
Manuel Pégourié-Gonnard1a967282013-02-09 17:03:58 +0100816 *
Hanno Beckerebffa792018-12-14 15:07:50 +0000817 * \note The read pointer \p buf is updated to point right after
818 * the ECParameters record on exit.
Manuel Pégourié-Gonnard1a967282013-02-09 17:03:58 +0100819 *
Hanno Beckerebffa792018-12-14 15:07:50 +0000820 * \param grp The group context to setup. This must be initialized.
Rose Zadikf56cb342018-04-19 12:49:10 +0100821 * \param buf The address of the pointer to the start of the input buffer.
Hanno Beckerebffa792018-12-14 15:07:50 +0000822 * \param len The length of the input buffer \c *buf in Bytes.
Manuel Pégourié-Gonnard150c4f62014-11-21 09:14:52 +0100823 *
Rose Zadikd3c9bfc2018-04-17 10:56:55 +0100824 * \return \c 0 on success.
Rose Zadikd3c9bfc2018-04-17 10:56:55 +0100825 * \return #MBEDTLS_ERR_ECP_BAD_INPUT_DATA if input is invalid.
Janos Follath89ac8c92018-10-30 11:24:05 +0000826 * \return #MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE if the group is not
Hanno Beckerebffa792018-12-14 15:07:50 +0000827 * recognized.
828 * \return Another negative error code on other kinds of failure.
Manuel Pégourié-Gonnard1a967282013-02-09 17:03:58 +0100829 */
Hanno Beckerebffa792018-12-14 15:07:50 +0000830int mbedtls_ecp_tls_read_group( mbedtls_ecp_group *grp,
831 const unsigned char **buf, size_t len );
Manuel Pégourié-Gonnarda5402fe2012-11-07 20:24:05 +0100832
833/**
Hanno Beckerebffa792018-12-14 15:07:50 +0000834 * \brief This function extracts an elliptic curve group ID from a
835 * TLS ECParameters record as defined in RFC 4492, Section 5.4.
Janos Follath89ac8c92018-10-30 11:24:05 +0000836 *
Hanno Beckerebffa792018-12-14 15:07:50 +0000837 * \note The read pointer \p buf is updated to point right after
838 * the ECParameters record on exit.
Janos Follath89ac8c92018-10-30 11:24:05 +0000839 *
Hanno Beckerebffa792018-12-14 15:07:50 +0000840 * \param grp The address at which to store the group id.
841 * This must not be \c NULL.
Janos Follath89ac8c92018-10-30 11:24:05 +0000842 * \param buf The address of the pointer to the start of the input buffer.
Hanno Beckerebffa792018-12-14 15:07:50 +0000843 * \param len The length of the input buffer \c *buf in Bytes.
Janos Follath89ac8c92018-10-30 11:24:05 +0000844 *
845 * \return \c 0 on success.
846 * \return #MBEDTLS_ERR_ECP_BAD_INPUT_DATA if input is invalid.
847 * \return #MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE if the group is not
Hanno Beckerebffa792018-12-14 15:07:50 +0000848 * recognized.
849 * \return Another negative error code on other kinds of failure.
Janos Follath89ac8c92018-10-30 11:24:05 +0000850 */
851int mbedtls_ecp_tls_read_group_id( mbedtls_ecp_group_id *grp,
Hanno Beckerebffa792018-12-14 15:07:50 +0000852 const unsigned char **buf,
853 size_t len );
Janos Follath89ac8c92018-10-30 11:24:05 +0000854/**
Hanno Beckerebffa792018-12-14 15:07:50 +0000855 * \brief This function exports an elliptic curve as a TLS
856 * ECParameters record as defined in RFC 4492, Section 5.4.
Manuel Pégourié-Gonnardb3258872013-02-10 12:06:19 +0100857 *
Hanno Beckerebffa792018-12-14 15:07:50 +0000858 * \param grp The ECP group to be exported.
859 * This must be initialized and have group parameters
860 * set, for example through mbedtls_ecp_group_load().
861 * \param olen The address at which to store the number of Bytes written.
862 * This must not be \c NULL.
863 * \param buf The buffer to write to. This must be a writable buffer
864 * of length \p blen Bytes.
865 * \param blen The length of the output buffer \p buf in Bytes.
Manuel Pégourié-Gonnardb3258872013-02-10 12:06:19 +0100866 *
Rose Zadikd3c9bfc2018-04-17 10:56:55 +0100867 * \return \c 0 on success.
Hanno Beckerebffa792018-12-14 15:07:50 +0000868 * \return #MBEDTLS_ERR_ECP_BUFFER_TOO_SMALL if the output
869 * buffer is too small to hold the exported group.
870 * \return Another negative error code on other kinds of failure.
Manuel Pégourié-Gonnardb3258872013-02-10 12:06:19 +0100871 */
Hanno Beckerebffa792018-12-14 15:07:50 +0000872int mbedtls_ecp_tls_write_group( const mbedtls_ecp_group *grp,
873 size_t *olen,
874 unsigned char *buf, size_t blen );
Manuel Pégourié-Gonnardb3258872013-02-10 12:06:19 +0100875
876/**
Hanno Becker5edcfa52018-12-18 12:49:55 +0000877 * \brief This function performs a scalar multiplication of a point
Hanno Beckerebffa792018-12-14 15:07:50 +0000878 * by an integer: \p R = \p m * \p P.
Manuel Pégourié-Gonnard39d2adb2012-10-31 09:26:55 +0100879 *
Rose Zadikd3c9bfc2018-04-17 10:56:55 +0100880 * It is not thread-safe to use same group in multiple threads.
Manuel Pégourié-Gonnard56cc88a2015-05-11 18:40:45 +0200881 *
Rose Zadikd3c9bfc2018-04-17 10:56:55 +0100882 * \note To prevent timing attacks, this function
883 * executes the exact same sequence of base-field
884 * operations for any valid \p m. It avoids any if-branch or
885 * array index depending on the value of \p m.
Manuel Pégourié-Gonnard56cc88a2015-05-11 18:40:45 +0200886 *
Rose Zadikd3c9bfc2018-04-17 10:56:55 +0100887 * \note If \p f_rng is not NULL, it is used to randomize
888 * intermediate results to prevent potential timing attacks
889 * targeting these results. We recommend always providing
890 * a non-NULL \p f_rng. The overhead is negligible.
Manuel Pégourié-Gonnardb34aeeb2020-06-04 10:20:12 +0200891 * Note: unless #MBEDTLS_ECP_NO_INTERNAL_RNG is defined, when
892 * \p f_rng is NULL, an internal RNG (seeded from the value
893 * of \p m) will be used instead.
Manuel Pégourié-Gonnard39d2adb2012-10-31 09:26:55 +0100894 *
Hanno Beckerebffa792018-12-14 15:07:50 +0000895 * \param grp The ECP group to use.
896 * This must be initialized and have group parameters
897 * set, for example through mbedtls_ecp_group_load().
898 * \param R The point in which to store the result of the calculation.
899 * This must be initialized.
900 * \param m The integer by which to multiply. This must be initialized.
901 * \param P The point to multiply. This must be initialized.
902 * \param f_rng The RNG function. This may be \c NULL if randomization
903 * of intermediate results isn't desired (discouraged).
904 * \param p_rng The RNG context to be passed to \p p_rng.
Rose Zadikd3c9bfc2018-04-17 10:56:55 +0100905 *
906 * \return \c 0 on success.
Rose Zadikf56cb342018-04-19 12:49:10 +0100907 * \return #MBEDTLS_ERR_ECP_INVALID_KEY if \p m is not a valid private
908 * key, or \p P is not a valid public key.
909 * \return #MBEDTLS_ERR_MPI_ALLOC_FAILED on memory-allocation failure.
Hanno Beckerebffa792018-12-14 15:07:50 +0000910 * \return Another negative error code on other kinds of failure.
Manuel Pégourié-Gonnardb739a712017-04-19 10:11:56 +0200911 */
912int mbedtls_ecp_mul( mbedtls_ecp_group *grp, mbedtls_ecp_point *R,
913 const mbedtls_mpi *m, const mbedtls_ecp_point *P,
914 int (*f_rng)(void *, unsigned char *, size_t), void *p_rng );
915
Manuel Pégourié-Gonnardb739a712017-04-19 10:11:56 +0200916/**
Manuel Pégourié-Gonnardda19f4c2018-06-12 12:40:54 +0200917 * \brief This function performs multiplication of a point by
918 * an integer: \p R = \p m * \p P in a restartable way.
Manuel Pégourié-Gonnardb739a712017-04-19 10:11:56 +0200919 *
Manuel Pégourié-Gonnard12e4a8b2018-09-12 10:55:15 +0200920 * \see mbedtls_ecp_mul()
Manuel Pégourié-Gonnardb739a712017-04-19 10:11:56 +0200921 *
Manuel Pégourié-Gonnardda19f4c2018-06-12 12:40:54 +0200922 * \note This function does the same as \c mbedtls_ecp_mul(), but
923 * it can return early and restart according to the limit set
924 * with \c mbedtls_ecp_set_max_ops() to reduce blocking.
925 *
Hanno Beckerebffa792018-12-14 15:07:50 +0000926 * \param grp The ECP group to use.
927 * This must be initialized and have group parameters
928 * set, for example through mbedtls_ecp_group_load().
929 * \param R The point in which to store the result of the calculation.
930 * This must be initialized.
931 * \param m The integer by which to multiply. This must be initialized.
932 * \param P The point to multiply. This must be initialized.
933 * \param f_rng The RNG function. This may be \c NULL if randomization
934 * of intermediate results isn't desired (discouraged).
935 * \param p_rng The RNG context to be passed to \p p_rng.
Manuel Pégourié-Gonnardf0bbd7e2018-10-15 13:22:41 +0200936 * \param rs_ctx The restart context (NULL disables restart).
Manuel Pégourié-Gonnardb739a712017-04-19 10:11:56 +0200937 *
Manuel Pégourié-Gonnard12e4a8b2018-09-12 10:55:15 +0200938 * \return \c 0 on success.
939 * \return #MBEDTLS_ERR_ECP_INVALID_KEY if \p m is not a valid private
940 * key, or \p P is not a valid public key.
941 * \return #MBEDTLS_ERR_MPI_ALLOC_FAILED on memory-allocation failure.
942 * \return #MBEDTLS_ERR_ECP_IN_PROGRESS if maximum number of
Manuel Pégourié-Gonnard8467e682017-04-20 09:47:06 +0200943 * operations was reached: see \c mbedtls_ecp_set_max_ops().
Hanno Beckerebffa792018-12-14 15:07:50 +0000944 * \return Another negative error code on other kinds of failure.
Manuel Pégourié-Gonnard39d2adb2012-10-31 09:26:55 +0100945 */
Manuel Pégourié-Gonnardb739a712017-04-19 10:11:56 +0200946int mbedtls_ecp_mul_restartable( mbedtls_ecp_group *grp, mbedtls_ecp_point *R,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200947 const mbedtls_mpi *m, const mbedtls_ecp_point *P,
Manuel Pégourié-Gonnardb739a712017-04-19 10:11:56 +0200948 int (*f_rng)(void *, unsigned char *, size_t), void *p_rng,
949 mbedtls_ecp_restart_ctx *rs_ctx );
Manuel Pégourié-Gonnard39d2adb2012-10-31 09:26:55 +0100950
951/**
Rose Zadika7a61552018-04-24 13:14:01 +0100952 * \brief This function performs multiplication and addition of two
Rose Zadikd3c9bfc2018-04-17 10:56:55 +0100953 * points by integers: \p R = \p m * \p P + \p n * \p Q
Manuel Pégourié-Gonnard56cc88a2015-05-11 18:40:45 +0200954 *
Rose Zadikd3c9bfc2018-04-17 10:56:55 +0100955 * It is not thread-safe to use same group in multiple threads.
Manuel Pégourié-Gonnard56cc88a2015-05-11 18:40:45 +0200956 *
Rose Zadika7a61552018-04-24 13:14:01 +0100957 * \note In contrast to mbedtls_ecp_mul(), this function does not
Rose Zadikd3c9bfc2018-04-17 10:56:55 +0100958 * guarantee a constant execution flow and timing.
Manuel Pégourié-Gonnard56cc88a2015-05-11 18:40:45 +0200959 *
Hanno Beckerebffa792018-12-14 15:07:50 +0000960 * \param grp The ECP group to use.
961 * This must be initialized and have group parameters
962 * set, for example through mbedtls_ecp_group_load().
963 * \param R The point in which to store the result of the calculation.
964 * This must be initialized.
Rose Zadikd3c9bfc2018-04-17 10:56:55 +0100965 * \param m The integer by which to multiply \p P.
Hanno Beckerebffa792018-12-14 15:07:50 +0000966 * This must be initialized.
967 * \param P The point to multiply by \p m. This must be initialized.
Rose Zadikd3c9bfc2018-04-17 10:56:55 +0100968 * \param n The integer by which to multiply \p Q.
Hanno Beckerebffa792018-12-14 15:07:50 +0000969 * This must be initialized.
Rose Zadikd3c9bfc2018-04-17 10:56:55 +0100970 * \param Q The point to be multiplied by \p n.
Hanno Beckerebffa792018-12-14 15:07:50 +0000971 * This must be initialized.
Manuel Pégourié-Gonnard56cc88a2015-05-11 18:40:45 +0200972 *
Rose Zadikd3c9bfc2018-04-17 10:56:55 +0100973 * \return \c 0 on success.
Rose Zadika7a61552018-04-24 13:14:01 +0100974 * \return #MBEDTLS_ERR_ECP_INVALID_KEY if \p m or \p n are not
975 * valid private keys, or \p P or \p Q are not valid public
Rose Zadikd3c9bfc2018-04-17 10:56:55 +0100976 * keys.
Rose Zadikf56cb342018-04-19 12:49:10 +0100977 * \return #MBEDTLS_ERR_MPI_ALLOC_FAILED on memory-allocation failure.
Hanno Beckerebffa792018-12-14 15:07:50 +0000978 * \return Another negative error code on other kinds of failure.
Manuel Pégourié-Gonnard56cc88a2015-05-11 18:40:45 +0200979 */
980int mbedtls_ecp_muladd( mbedtls_ecp_group *grp, mbedtls_ecp_point *R,
981 const mbedtls_mpi *m, const mbedtls_ecp_point *P,
982 const mbedtls_mpi *n, const mbedtls_ecp_point *Q );
983
Manuel Pégourié-Gonnard54dd6522017-04-20 13:36:18 +0200984/**
Manuel Pégourié-Gonnardda19f4c2018-06-12 12:40:54 +0200985 * \brief This function performs multiplication and addition of two
986 * points by integers: \p R = \p m * \p P + \p n * \p Q in a
Manuel Pégourié-Gonnard12e4a8b2018-09-12 10:55:15 +0200987 * restartable way.
Manuel Pégourié-Gonnard54dd6522017-04-20 13:36:18 +0200988 *
Manuel Pégourié-Gonnardda19f4c2018-06-12 12:40:54 +0200989 * \see \c mbedtls_ecp_muladd()
Manuel Pégourié-Gonnard54dd6522017-04-20 13:36:18 +0200990 *
Manuel Pégourié-Gonnardda19f4c2018-06-12 12:40:54 +0200991 * \note This function works the same as \c mbedtls_ecp_muladd(),
992 * but it can return early and restart according to the limit
993 * set with \c mbedtls_ecp_set_max_ops() to reduce blocking.
Manuel Pégourié-Gonnard54dd6522017-04-20 13:36:18 +0200994 *
Hanno Beckerebffa792018-12-14 15:07:50 +0000995 * \param grp The ECP group to use.
996 * This must be initialized and have group parameters
997 * set, for example through mbedtls_ecp_group_load().
998 * \param R The point in which to store the result of the calculation.
999 * This must be initialized.
Manuel Pégourié-Gonnardda19f4c2018-06-12 12:40:54 +02001000 * \param m The integer by which to multiply \p P.
Hanno Beckerebffa792018-12-14 15:07:50 +00001001 * This must be initialized.
1002 * \param P The point to multiply by \p m. This must be initialized.
Manuel Pégourié-Gonnardda19f4c2018-06-12 12:40:54 +02001003 * \param n The integer by which to multiply \p Q.
Hanno Beckerebffa792018-12-14 15:07:50 +00001004 * This must be initialized.
Manuel Pégourié-Gonnardda19f4c2018-06-12 12:40:54 +02001005 * \param Q The point to be multiplied by \p n.
Hanno Beckerebffa792018-12-14 15:07:50 +00001006 * This must be initialized.
Manuel Pégourié-Gonnardf0bbd7e2018-10-15 13:22:41 +02001007 * \param rs_ctx The restart context (NULL disables restart).
Manuel Pégourié-Gonnardda19f4c2018-06-12 12:40:54 +02001008 *
1009 * \return \c 0 on success.
1010 * \return #MBEDTLS_ERR_ECP_INVALID_KEY if \p m or \p n are not
1011 * valid private keys, or \p P or \p Q are not valid public
1012 * keys.
1013 * \return #MBEDTLS_ERR_MPI_ALLOC_FAILED on memory-allocation failure.
1014 * \return #MBEDTLS_ERR_ECP_IN_PROGRESS if maximum number of
Manuel Pégourié-Gonnard54dd6522017-04-20 13:36:18 +02001015 * operations was reached: see \c mbedtls_ecp_set_max_ops().
Hanno Beckerebffa792018-12-14 15:07:50 +00001016 * \return Another negative error code on other kinds of failure.
Manuel Pégourié-Gonnard54dd6522017-04-20 13:36:18 +02001017 */
1018int mbedtls_ecp_muladd_restartable(
1019 mbedtls_ecp_group *grp, mbedtls_ecp_point *R,
1020 const mbedtls_mpi *m, const mbedtls_ecp_point *P,
1021 const mbedtls_mpi *n, const mbedtls_ecp_point *Q,
1022 mbedtls_ecp_restart_ctx *rs_ctx );
Manuel Pégourié-Gonnard54dd6522017-04-20 13:36:18 +02001023
Manuel Pégourié-Gonnard56cc88a2015-05-11 18:40:45 +02001024/**
Rose Zadika7a61552018-04-24 13:14:01 +01001025 * \brief This function checks that a point is a valid public key
Rose Zadikd3c9bfc2018-04-17 10:56:55 +01001026 * on this curve.
Manuel Pégourié-Gonnardc8dc2952013-07-01 14:06:13 +02001027 *
Rose Zadika7a61552018-04-24 13:14:01 +01001028 * It only checks that the point is non-zero, has
1029 * valid coordinates and lies on the curve. It does not verify
1030 * that it is indeed a multiple of \p G. This additional
Rose Zadikd3c9bfc2018-04-17 10:56:55 +01001031 * check is computationally more expensive, is not required
1032 * by standards, and should not be necessary if the group
Rose Zadika7a61552018-04-24 13:14:01 +01001033 * used has a small cofactor. In particular, it is useless for
Rose Zadikd3c9bfc2018-04-17 10:56:55 +01001034 * the NIST groups which all have a cofactor of 1.
Manuel Pégourié-Gonnardc8dc2952013-07-01 14:06:13 +02001035 *
Rose Zadika7a61552018-04-24 13:14:01 +01001036 * \note This function uses bare components rather than an
1037 * ::mbedtls_ecp_keypair structure, to ease use with other
1038 * structures, such as ::mbedtls_ecdh_context or
Rose Zadikb2e111a2018-04-20 10:13:48 +01001039 * ::mbedtls_ecdsa_context.
Manuel Pégourié-Gonnardc8dc2952013-07-01 14:06:13 +02001040 *
Hanno Beckerebffa792018-12-14 15:07:50 +00001041 * \param grp The ECP group the point should belong to.
1042 * This must be initialized and have group parameters
1043 * set, for example through mbedtls_ecp_group_load().
1044 * \param pt The point to check. This must be initialized.
Manuel Pégourié-Gonnardc8dc2952013-07-01 14:06:13 +02001045 *
Rose Zadikd3c9bfc2018-04-17 10:56:55 +01001046 * \return \c 0 if the point is a valid public key.
Hanno Beckerebffa792018-12-14 15:07:50 +00001047 * \return #MBEDTLS_ERR_ECP_INVALID_KEY if the point is not
1048 * a valid public key for the given curve.
1049 * \return Another negative error code on other kinds of failure.
Manuel Pégourié-Gonnardc8dc2952013-07-01 14:06:13 +02001050 */
Hanno Beckerebffa792018-12-14 15:07:50 +00001051int mbedtls_ecp_check_pubkey( const mbedtls_ecp_group *grp,
1052 const mbedtls_ecp_point *pt );
Manuel Pégourié-Gonnardc8dc2952013-07-01 14:06:13 +02001053
1054/**
Hanno Beckerebffa792018-12-14 15:07:50 +00001055 * \brief This function checks that an \p mbedtls_mpi is a
1056 * valid private key for this curve.
Manuel Pégourié-Gonnardc8dc2952013-07-01 14:06:13 +02001057 *
Rose Zadika7a61552018-04-24 13:14:01 +01001058 * \note This function uses bare components rather than an
1059 * ::mbedtls_ecp_keypair structure to ease use with other
1060 * structures, such as ::mbedtls_ecdh_context or
Rose Zadikb2e111a2018-04-20 10:13:48 +01001061 * ::mbedtls_ecdsa_context.
Manuel Pégourié-Gonnardc8dc2952013-07-01 14:06:13 +02001062 *
Hanno Beckerebffa792018-12-14 15:07:50 +00001063 * \param grp The ECP group the private key should belong to.
1064 * This must be initialized and have group parameters
1065 * set, for example through mbedtls_ecp_group_load().
1066 * \param d The integer to check. This must be initialized.
Manuel Pégourié-Gonnardc8dc2952013-07-01 14:06:13 +02001067 *
Rose Zadikd3c9bfc2018-04-17 10:56:55 +01001068 * \return \c 0 if the point is a valid private key.
Hanno Beckerebffa792018-12-14 15:07:50 +00001069 * \return #MBEDTLS_ERR_ECP_INVALID_KEY if the point is not a valid
1070 * private key for the given curve.
1071 * \return Another negative error code on other kinds of failure.
Manuel Pégourié-Gonnardc8dc2952013-07-01 14:06:13 +02001072 */
Hanno Beckerebffa792018-12-14 15:07:50 +00001073int mbedtls_ecp_check_privkey( const mbedtls_ecp_group *grp,
1074 const mbedtls_mpi *d );
Manuel Pégourié-Gonnardc8dc2952013-07-01 14:06:13 +02001075
1076/**
Manuel Pégourié-Gonnardda19f4c2018-06-12 12:40:54 +02001077 * \brief This function generates a private key.
Manuel Pégourié-Gonnarda7937f92017-04-20 15:37:46 +02001078 *
Hanno Beckerebffa792018-12-14 15:07:50 +00001079 * \param grp The ECP group to generate a private key for.
1080 * This must be initialized and have group parameters
1081 * set, for example through mbedtls_ecp_group_load().
1082 * \param d The destination MPI (secret part). This must be initialized.
1083 * \param f_rng The RNG function. This must not be \c NULL.
1084 * \param p_rng The RNG parameter to be passed to \p f_rng. This may be
1085 * \c NULL if \p f_rng doesn't need a context argument.
Manuel Pégourié-Gonnarda7937f92017-04-20 15:37:46 +02001086 *
Manuel Pégourié-Gonnardda19f4c2018-06-12 12:40:54 +02001087 * \return \c 0 on success.
1088 * \return An \c MBEDTLS_ERR_ECP_XXX or \c MBEDTLS_MPI_XXX error code
1089 * on failure.
Manuel Pégourié-Gonnarda7937f92017-04-20 15:37:46 +02001090 */
1091int mbedtls_ecp_gen_privkey( const mbedtls_ecp_group *grp,
1092 mbedtls_mpi *d,
1093 int (*f_rng)(void *, unsigned char *, size_t),
1094 void *p_rng );
1095
1096/**
Rose Zadika7a61552018-04-24 13:14:01 +01001097 * \brief This function generates a keypair with a configurable base
Rose Zadikd3c9bfc2018-04-17 10:56:55 +01001098 * point.
Manuel Pégourié-Gonnardd9a3f472015-08-11 14:31:03 +02001099 *
Rose Zadika7a61552018-04-24 13:14:01 +01001100 * \note This function uses bare components rather than an
1101 * ::mbedtls_ecp_keypair structure to ease use with other
1102 * structures, such as ::mbedtls_ecdh_context or
Rose Zadikb2e111a2018-04-20 10:13:48 +01001103 * ::mbedtls_ecdsa_context.
Manuel Pégourié-Gonnardd9a3f472015-08-11 14:31:03 +02001104 *
Hanno Beckerebffa792018-12-14 15:07:50 +00001105 * \param grp The ECP group to generate a key pair for.
1106 * This must be initialized and have group parameters
1107 * set, for example through mbedtls_ecp_group_load().
1108 * \param G The base point to use. This must be initialized
1109 * and belong to \p grp. It replaces the default base
1110 * point \c grp->G used by mbedtls_ecp_gen_keypair().
Rose Zadikd3c9bfc2018-04-17 10:56:55 +01001111 * \param d The destination MPI (secret part).
Hanno Beckerebffa792018-12-14 15:07:50 +00001112 * This must be initialized.
Rose Zadikd3c9bfc2018-04-17 10:56:55 +01001113 * \param Q The destination point (public part).
Hanno Beckerebffa792018-12-14 15:07:50 +00001114 * This must be initialized.
1115 * \param f_rng The RNG function. This must not be \c NULL.
1116 * \param p_rng The RNG context to be passed to \p f_rng. This may
1117 * be \c NULL if \p f_rng doesn't need a context argument.
Manuel Pégourié-Gonnardd9a3f472015-08-11 14:31:03 +02001118 *
Rose Zadikd3c9bfc2018-04-17 10:56:55 +01001119 * \return \c 0 on success.
1120 * \return An \c MBEDTLS_ERR_ECP_XXX or \c MBEDTLS_MPI_XXX error code
1121 * on failure.
Manuel Pégourié-Gonnardd9a3f472015-08-11 14:31:03 +02001122 */
1123int mbedtls_ecp_gen_keypair_base( mbedtls_ecp_group *grp,
Hanno Beckerebffa792018-12-14 15:07:50 +00001124 const mbedtls_ecp_point *G,
1125 mbedtls_mpi *d, mbedtls_ecp_point *Q,
1126 int (*f_rng)(void *, unsigned char *, size_t),
1127 void *p_rng );
Manuel Pégourié-Gonnardd9a3f472015-08-11 14:31:03 +02001128
1129/**
Rose Zadikf56cb342018-04-19 12:49:10 +01001130 * \brief This function generates an ECP keypair.
Manuel Pégourié-Gonnard45a035a2013-01-26 14:42:45 +01001131 *
Rose Zadika7a61552018-04-24 13:14:01 +01001132 * \note This function uses bare components rather than an
1133 * ::mbedtls_ecp_keypair structure to ease use with other
1134 * structures, such as ::mbedtls_ecdh_context or
Rose Zadikb2e111a2018-04-20 10:13:48 +01001135 * ::mbedtls_ecdsa_context.
Manuel Pégourié-Gonnard45a035a2013-01-26 14:42:45 +01001136 *
Hanno Beckerebffa792018-12-14 15:07:50 +00001137 * \param grp The ECP group to generate a key pair for.
1138 * This must be initialized and have group parameters
1139 * set, for example through mbedtls_ecp_group_load().
Rose Zadikd3c9bfc2018-04-17 10:56:55 +01001140 * \param d The destination MPI (secret part).
Hanno Beckerebffa792018-12-14 15:07:50 +00001141 * This must be initialized.
Rose Zadikd3c9bfc2018-04-17 10:56:55 +01001142 * \param Q The destination point (public part).
Hanno Beckerebffa792018-12-14 15:07:50 +00001143 * This must be initialized.
1144 * \param f_rng The RNG function. This must not be \c NULL.
1145 * \param p_rng The RNG context to be passed to \p f_rng. This may
1146 * be \c NULL if \p f_rng doesn't need a context argument.
Manuel Pégourié-Gonnardc8dc2952013-07-01 14:06:13 +02001147 *
Rose Zadikd3c9bfc2018-04-17 10:56:55 +01001148 * \return \c 0 on success.
1149 * \return An \c MBEDTLS_ERR_ECP_XXX or \c MBEDTLS_MPI_XXX error code
1150 * on failure.
Manuel Pégourié-Gonnard45a035a2013-01-26 14:42:45 +01001151 */
Hanno Beckerebffa792018-12-14 15:07:50 +00001152int mbedtls_ecp_gen_keypair( mbedtls_ecp_group *grp, mbedtls_mpi *d,
1153 mbedtls_ecp_point *Q,
1154 int (*f_rng)(void *, unsigned char *, size_t),
1155 void *p_rng );
Manuel Pégourié-Gonnard45a035a2013-01-26 14:42:45 +01001156
1157/**
Rose Zadikf56cb342018-04-19 12:49:10 +01001158 * \brief This function generates an ECP key.
Manuel Pégourié-Gonnard104ee1d2013-11-30 14:13:16 +01001159 *
Rose Zadikd3c9bfc2018-04-17 10:56:55 +01001160 * \param grp_id The ECP group identifier.
Hanno Beckerebffa792018-12-14 15:07:50 +00001161 * \param key The destination key. This must be initialized.
1162 * \param f_rng The RNG function to use. This must not be \c NULL.
1163 * \param p_rng The RNG context to be passed to \p f_rng. This may
1164 * be \c NULL if \p f_rng doesn't need a context argument.
Manuel Pégourié-Gonnard104ee1d2013-11-30 14:13:16 +01001165 *
Rose Zadikd3c9bfc2018-04-17 10:56:55 +01001166 * \return \c 0 on success.
1167 * \return An \c MBEDTLS_ERR_ECP_XXX or \c MBEDTLS_MPI_XXX error code
1168 * on failure.
Manuel Pégourié-Gonnard104ee1d2013-11-30 14:13:16 +01001169 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001170int mbedtls_ecp_gen_key( mbedtls_ecp_group_id grp_id, mbedtls_ecp_keypair *key,
Hanno Beckerebffa792018-12-14 15:07:50 +00001171 int (*f_rng)(void *, unsigned char *, size_t),
1172 void *p_rng );
Manuel Pégourié-Gonnard104ee1d2013-11-30 14:13:16 +01001173
Manuel Pégourié-Gonnard30668d62014-11-06 15:25:32 +01001174/**
Rose Zadika7a61552018-04-24 13:14:01 +01001175 * \brief This function checks that the keypair objects
Rose Zadikb2e111a2018-04-20 10:13:48 +01001176 * \p pub and \p prv have the same group and the
1177 * same public point, and that the private key in
1178 * \p prv is consistent with the public key.
Manuel Pégourié-Gonnard30668d62014-11-06 15:25:32 +01001179 *
Hanno Beckerebffa792018-12-14 15:07:50 +00001180 * \param pub The keypair structure holding the public key. This
1181 * must be initialized. If it contains a private key, that
1182 * part is ignored.
Rose Zadikb2e111a2018-04-20 10:13:48 +01001183 * \param prv The keypair structure holding the full keypair.
Hanno Beckerebffa792018-12-14 15:07:50 +00001184 * This must be initialized.
Manuel Pégourié-Gonnard30668d62014-11-06 15:25:32 +01001185 *
Rose Zadika7a61552018-04-24 13:14:01 +01001186 * \return \c 0 on success, meaning that the keys are valid and match.
Rose Zadikb2e111a2018-04-20 10:13:48 +01001187 * \return #MBEDTLS_ERR_ECP_BAD_INPUT_DATA if the keys are invalid or do not match.
Rose Zadika7a61552018-04-24 13:14:01 +01001188 * \return An \c MBEDTLS_ERR_ECP_XXX or an \c MBEDTLS_ERR_MPI_XXX
Rose Zadikb2e111a2018-04-20 10:13:48 +01001189 * error code on calculation failure.
Manuel Pégourié-Gonnard30668d62014-11-06 15:25:32 +01001190 */
Hanno Beckerebffa792018-12-14 15:07:50 +00001191int mbedtls_ecp_check_pub_priv( const mbedtls_ecp_keypair *pub,
1192 const mbedtls_ecp_keypair *prv );
Manuel Pégourié-Gonnard30668d62014-11-06 15:25:32 +01001193
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001194#if defined(MBEDTLS_SELF_TEST)
Janos Follathb0697532016-08-18 12:38:46 +01001195
Manuel Pégourié-Gonnard104ee1d2013-11-30 14:13:16 +01001196/**
Rose Zadikd3c9bfc2018-04-17 10:56:55 +01001197 * \brief The ECP checkup routine.
Manuel Pégourié-Gonnard39d2adb2012-10-31 09:26:55 +01001198 *
Rose Zadikd3c9bfc2018-04-17 10:56:55 +01001199 * \return \c 0 on success.
1200 * \return \c 1 on failure.
Manuel Pégourié-Gonnard39d2adb2012-10-31 09:26:55 +01001201 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001202int mbedtls_ecp_self_test( int verbose );
Janos Follathb0697532016-08-18 12:38:46 +01001203
Janos Follath372697b2016-10-28 16:53:11 +01001204#endif /* MBEDTLS_SELF_TEST */
Manuel Pégourié-Gonnard39d2adb2012-10-31 09:26:55 +01001205
1206#ifdef __cplusplus
1207}
1208#endif
1209
Paul Bakker9af723c2014-05-01 13:03:14 +02001210#endif /* ecp.h */