blob: bac1bd007822053db76cdcc129d2d7c7195df663 [file] [log] [blame]
Manuel Pégourié-Gonnard39d2adb2012-10-31 09:26:55 +01001/**
2 * \file ecp.h
3 *
4 * \brief Elliptic curves over GF(p)
5 *
Manuel Pégourié-Gonnarda658a402015-01-23 09:45:19 +00006 * Copyright (C) 2006-2013, ARM Limited, All Rights Reserved
Manuel Pégourié-Gonnard39d2adb2012-10-31 09:26:55 +01007 *
Manuel Pégourié-Gonnardfe446432015-03-06 13:17:10 +00008 * This file is part of mbed TLS (https://tls.mbed.org)
Manuel Pégourié-Gonnard39d2adb2012-10-31 09:26:55 +01009 *
Manuel Pégourié-Gonnard39d2adb2012-10-31 09:26:55 +010010 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License along
21 * with this program; if not, write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020024#ifndef MBEDTLS_ECP_H
25#define MBEDTLS_ECP_H
Manuel Pégourié-Gonnard39d2adb2012-10-31 09:26:55 +010026
Manuel Pégourié-Gonnardbdc96762013-10-03 11:50:39 +020027#include "bignum.h"
Manuel Pégourié-Gonnard39d2adb2012-10-31 09:26:55 +010028
29/*
Manuel Pégourié-Gonnard7cfcea32012-11-05 10:06:12 +010030 * ECP error codes
Manuel Pégourié-Gonnard39d2adb2012-10-31 09:26:55 +010031 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020032#define MBEDTLS_ERR_ECP_BAD_INPUT_DATA -0x4F80 /**< Bad input parameters to function. */
33#define MBEDTLS_ERR_ECP_BUFFER_TOO_SMALL -0x4F00 /**< The buffer is too small to write to. */
34#define MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE -0x4E80 /**< Requested curve not available. */
35#define MBEDTLS_ERR_ECP_VERIFY_FAILED -0x4E00 /**< The signature is not valid. */
Manuel Pégourié-Gonnard6a8ca332015-05-28 09:33:39 +020036#define MBEDTLS_ERR_ECP_ALLOC_FAILED -0x4D80 /**< Memory allocation failed. */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020037#define MBEDTLS_ERR_ECP_RANDOM_FAILED -0x4D00 /**< Generation of random value, such as (ephemeral) key, failed. */
38#define MBEDTLS_ERR_ECP_INVALID_KEY -0x4C80 /**< Invalid private or public key. */
39#define MBEDTLS_ERR_ECP_SIG_LEN_MISMATCH -0x4C00 /**< Signature is valid but shorter than the user-supplied length. */
Manuel Pégourié-Gonnard883f3132012-11-02 09:40:25 +010040
Paul Bakker407a0da2013-06-27 14:29:21 +020041#ifdef __cplusplus
42extern "C" {
43#endif
44
Manuel Pégourié-Gonnard39d2adb2012-10-31 09:26:55 +010045/**
Manuel Pégourié-Gonnard70380392013-09-16 16:19:53 +020046 * Domain parameters (curve, subgroup and generator) identifiers.
47 *
48 * Only curves over prime fields are supported.
49 *
50 * \warning This library does not support validation of arbitrary domain
51 * parameters. Therefore, only well-known domain parameters from trusted
Manuel Pégourié-Gonnarde3a062b2015-05-11 18:46:47 +020052 * sources should be used. See mbedtls_ecp_group_load().
Manuel Pégourié-Gonnard70380392013-09-16 16:19:53 +020053 */
54typedef enum
55{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020056 MBEDTLS_ECP_DP_NONE = 0,
57 MBEDTLS_ECP_DP_SECP192R1, /*!< 192-bits NIST curve */
58 MBEDTLS_ECP_DP_SECP224R1, /*!< 224-bits NIST curve */
59 MBEDTLS_ECP_DP_SECP256R1, /*!< 256-bits NIST curve */
60 MBEDTLS_ECP_DP_SECP384R1, /*!< 384-bits NIST curve */
61 MBEDTLS_ECP_DP_SECP521R1, /*!< 521-bits NIST curve */
62 MBEDTLS_ECP_DP_BP256R1, /*!< 256-bits Brainpool curve */
63 MBEDTLS_ECP_DP_BP384R1, /*!< 384-bits Brainpool curve */
64 MBEDTLS_ECP_DP_BP512R1, /*!< 512-bits Brainpool curve */
65 MBEDTLS_ECP_DP_M221, /*!< (not implemented yet) */
66 MBEDTLS_ECP_DP_M255, /*!< Curve25519 */
67 MBEDTLS_ECP_DP_M383, /*!< (not implemented yet) */
68 MBEDTLS_ECP_DP_M511, /*!< (not implemented yet) */
69 MBEDTLS_ECP_DP_SECP192K1, /*!< 192-bits "Koblitz" curve */
70 MBEDTLS_ECP_DP_SECP224K1, /*!< 224-bits "Koblitz" curve */
71 MBEDTLS_ECP_DP_SECP256K1, /*!< 256-bits "Koblitz" curve */
72} mbedtls_ecp_group_id;
Manuel Pégourié-Gonnard70380392013-09-16 16:19:53 +020073
74/**
Manuel Pégourié-Gonnard66153662013-12-03 14:12:26 +010075 * Number of supported curves (plus one for NONE).
76 *
77 * (Montgomery curves excluded for now.)
Manuel Pégourié-Gonnardf24b4a72013-09-23 18:14:50 +020078 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020079#define MBEDTLS_ECP_DP_MAX 12
Manuel Pégourié-Gonnardf24b4a72013-09-23 18:14:50 +020080
81/**
Manuel Pégourié-Gonnardda179e42013-09-18 15:31:24 +020082 * Curve information for use by other modules
Manuel Pégourié-Gonnard568c9cf2013-09-16 17:30:04 +020083 */
84typedef struct
85{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020086 mbedtls_ecp_group_id grp_id; /*!< Internal identifier */
Manuel Pégourié-Gonnard797f48a2015-06-18 15:45:05 +020087 uint16_t tls_id; /*!< TLS NamedCurve identifier */
88 uint16_t bit_size; /*!< Curve size in bits */
89 const char *name; /*!< Human-friendly name */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020090} mbedtls_ecp_curve_info;
Manuel Pégourié-Gonnard568c9cf2013-09-16 17:30:04 +020091
92/**
Manuel Pégourié-Gonnard1c2782c2012-11-19 20:16:28 +010093 * \brief ECP point structure (jacobian coordinates)
Manuel Pégourié-Gonnardae180d02012-11-02 18:14:40 +010094 *
Manuel Pégourié-Gonnard1c2782c2012-11-19 20:16:28 +010095 * \note All functions expect and return points satisfying
96 * the following condition: Z == 0 or Z == 1. (Other
97 * values of Z are used by internal functions only.)
98 * The point is zero, or "at infinity", if Z == 0.
99 * Otherwise, X and Y are its standard (affine) coordinates.
Manuel Pégourié-Gonnard39d2adb2012-10-31 09:26:55 +0100100 */
101typedef struct
102{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200103 mbedtls_mpi X; /*!< the point's X coordinate */
104 mbedtls_mpi Y; /*!< the point's Y coordinate */
105 mbedtls_mpi Z; /*!< the point's Z coordinate */
Manuel Pégourié-Gonnard39d2adb2012-10-31 09:26:55 +0100106}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200107mbedtls_ecp_point;
Manuel Pégourié-Gonnard39d2adb2012-10-31 09:26:55 +0100108
109/**
110 * \brief ECP group structure
111 *
Manuel Pégourié-Gonnard7a949d32013-12-05 10:26:01 +0100112 * We consider two types of curves equations:
113 * 1. Short Weierstrass y^2 = x^3 + A x + B mod P (SEC1 + RFC 4492)
114 * 2. Montgomery, y^2 = x^3 + A x^2 + x mod P (M255 + draft)
115 * In both cases, a generator G for a prime-order subgroup is fixed. In the
116 * short weierstrass, this subgroup is actually the whole curve, and its
117 * cardinal is denoted by N.
Manuel Pégourié-Gonnard62aad142012-11-10 00:27:12 +0100118 *
Manuel Pégourié-Gonnarddd75c312014-03-31 11:55:42 +0200119 * In the case of Short Weierstrass curves, our code requires that N is an odd
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200120 * prime. (Use odd in mbedtls_ecp_mul() and prime in mbedtls_ecdsa_sign() for blinding.)
Manuel Pégourié-Gonnarddd75c312014-03-31 11:55:42 +0200121 *
Manuel Pégourié-Gonnard7a949d32013-12-05 10:26:01 +0100122 * In the case of Montgomery curves, we don't store A but (A + 2) / 4 which is
Paul Bakker75342a62014-04-08 17:35:40 +0200123 * the quantity actually used in the formulas. Also, nbits is not the size of N
Manuel Pégourié-Gonnard7a949d32013-12-05 10:26:01 +0100124 * but the required size for private keys.
Manuel Pégourié-Gonnard47123252012-11-10 14:44:24 +0100125 *
Manuel Pégourié-Gonnardc9727702013-09-16 18:56:28 +0200126 * If modp is NULL, reduction modulo P is done using a generic algorithm.
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200127 * Otherwise, it must point to a function that takes an mbedtls_mpi in the range
Manuel Pégourié-Gonnardc9727702013-09-16 18:56:28 +0200128 * 0..2^(2*pbits)-1 and transforms it in-place in an integer of little more
129 * than pbits, so that the integer may be efficiently brought in the 0..P-1
130 * range by a few additions or substractions. It must return 0 on success and
131 * non-zero on failure.
Manuel Pégourié-Gonnard39d2adb2012-10-31 09:26:55 +0100132 */
133typedef struct
134{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200135 mbedtls_ecp_group_id id; /*!< internal group identifier */
136 mbedtls_mpi P; /*!< prime modulus of the base field */
137 mbedtls_mpi A; /*!< 1. A in the equation, or 2. (A + 2) / 4 */
138 mbedtls_mpi B; /*!< 1. B in the equation, or 2. unused */
139 mbedtls_ecp_point G; /*!< generator of the (sub)group used */
140 mbedtls_mpi N; /*!< 1. the order of G, or 2. unused */
Manuel Pégourié-Gonnardcd7458a2013-10-08 13:11:30 +0200141 size_t pbits; /*!< number of bits in P */
Manuel Pégourié-Gonnard7a949d32013-12-05 10:26:01 +0100142 size_t nbits; /*!< number of bits in 1. P, or 2. private keys */
Manuel Pégourié-Gonnard1f82b042013-12-06 12:51:50 +0100143 unsigned int h; /*!< internal: 1 if the constants are static */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200144 int (*modp)(mbedtls_mpi *); /*!< function for fast reduction mod P */
145 int (*t_pre)(mbedtls_ecp_point *, void *); /*!< unused */
146 int (*t_post)(mbedtls_ecp_point *, void *); /*!< unused */
Manuel Pégourié-Gonnard7a949d32013-12-05 10:26:01 +0100147 void *t_data; /*!< unused */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200148 mbedtls_ecp_point *T; /*!< pre-computed points for ecp_mul_comb() */
Manuel Pégourié-Gonnardcd7458a2013-10-08 13:11:30 +0200149 size_t T_size; /*!< number for pre-computed points */
Manuel Pégourié-Gonnard39d2adb2012-10-31 09:26:55 +0100150}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200151mbedtls_ecp_group;
Manuel Pégourié-Gonnard39d2adb2012-10-31 09:26:55 +0100152
153/**
Manuel Pégourié-Gonnardb8c6e0e2013-07-01 13:40:52 +0200154 * \brief ECP key pair structure
155 *
156 * A generic key pair that could be used for ECDSA, fixed ECDH, etc.
Manuel Pégourié-Gonnard09162dd2013-08-14 18:16:50 +0200157 *
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200158 * \note Members purposefully in the same order as struc mbedtls_ecdsa_context.
Manuel Pégourié-Gonnardb8c6e0e2013-07-01 13:40:52 +0200159 */
160typedef struct
161{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200162 mbedtls_ecp_group grp; /*!< Elliptic curve and base point */
163 mbedtls_mpi d; /*!< our secret value */
164 mbedtls_ecp_point Q; /*!< our public value */
Manuel Pégourié-Gonnardb8c6e0e2013-07-01 13:40:52 +0200165}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200166mbedtls_ecp_keypair;
Manuel Pégourié-Gonnardb8c6e0e2013-07-01 13:40:52 +0200167
Paul Bakker088c5c52014-04-25 11:11:10 +0200168/**
169 * \name SECTION: Module settings
170 *
171 * The configuration options you can set for this module are in this section.
172 * Either change them in config.h or define them on the compiler command line.
173 * \{
174 */
175
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200176#if !defined(MBEDTLS_ECP_MAX_BITS)
Manuel Pégourié-Gonnardb8c6e0e2013-07-01 13:40:52 +0200177/**
Manuel Pégourié-Gonnardb694b482013-08-08 13:30:57 +0200178 * Maximum size of the groups (that is, of N and P)
Manuel Pégourié-Gonnardb63f9e92012-11-21 13:00:58 +0100179 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200180#define MBEDTLS_ECP_MAX_BITS 521 /**< Maximum bit size of groups */
Paul Bakkere1b665e2013-12-11 16:02:58 +0100181#endif
182
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200183#define MBEDTLS_ECP_MAX_BYTES ( ( MBEDTLS_ECP_MAX_BITS + 7 ) / 8 )
184#define MBEDTLS_ECP_MAX_PT_LEN ( 2 * MBEDTLS_ECP_MAX_BYTES + 1 )
Manuel Pégourié-Gonnardb63f9e92012-11-21 13:00:58 +0100185
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200186#if !defined(MBEDTLS_ECP_WINDOW_SIZE)
Manuel Pégourié-Gonnard85556072012-11-17 19:54:20 +0100187/*
Manuel Pégourié-Gonnardc30200e2013-11-20 18:39:55 +0100188 * Maximum "window" size used for point multiplication.
189 * Default: 6.
190 * Minimum value: 2. Maximum value: 7.
Manuel Pégourié-Gonnard85556072012-11-17 19:54:20 +0100191 *
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200192 * Result is an array of at most ( 1 << ( MBEDTLS_ECP_WINDOW_SIZE - 1 ) )
Manuel Pégourié-Gonnard9e4191c2013-12-30 18:41:16 +0100193 * points used for point multiplication. This value is directly tied to EC
194 * peak memory usage, so decreasing it by one should roughly cut memory usage
195 * by two (if large curves are in use).
Manuel Pégourié-Gonnard85556072012-11-17 19:54:20 +0100196 *
Manuel Pégourié-Gonnard9e4191c2013-12-30 18:41:16 +0100197 * Reduction in size may reduce speed, but larger curves are impacted first.
198 * Sample performances (in ECDHE handshakes/s, with FIXED_POINT_OPTIM = 1):
199 * w-size: 6 5 4 3 2
200 * 521 145 141 135 120 97
201 * 384 214 209 198 177 146
202 * 256 320 320 303 262 226
Paul Bakker088c5c52014-04-25 11:11:10 +0200203
Manuel Pégourié-Gonnard9e4191c2013-12-30 18:41:16 +0100204 * 224 475 475 453 398 342
205 * 192 640 640 633 587 476
Manuel Pégourié-Gonnard85556072012-11-17 19:54:20 +0100206 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200207#define MBEDTLS_ECP_WINDOW_SIZE 6 /**< Maximum window size used */
208#endif /* MBEDTLS_ECP_WINDOW_SIZE */
Manuel Pégourié-Gonnard9e4191c2013-12-30 18:41:16 +0100209
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200210#if !defined(MBEDTLS_ECP_FIXED_POINT_OPTIM)
Manuel Pégourié-Gonnard9e4191c2013-12-30 18:41:16 +0100211/*
212 * Trade memory for speed on fixed-point multiplication.
213 *
214 * This speeds up repeated multiplication of the generator (that is, the
215 * multiplication in ECDSA signatures, and half of the multiplications in
216 * ECDSA verification and ECDHE) by a factor roughly 3 to 4.
217 *
218 * The cost is increasing EC peak memory usage by a factor roughly 2.
219 *
220 * Change this value to 0 to reduce peak memory usage.
221 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200222#define MBEDTLS_ECP_FIXED_POINT_OPTIM 1 /**< Enable fixed-point speed-up */
223#endif /* MBEDTLS_ECP_FIXED_POINT_OPTIM */
Manuel Pégourié-Gonnard85556072012-11-17 19:54:20 +0100224
Paul Bakker088c5c52014-04-25 11:11:10 +0200225/* \} name SECTION: Module settings */
226
Manuel Pégourié-Gonnard37d218a2012-11-24 15:19:55 +0100227/*
Manuel Pégourié-Gonnard00794052013-02-09 19:00:07 +0100228 * Point formats, from RFC 4492's enum ECPointFormat
Manuel Pégourié-Gonnard37d218a2012-11-24 15:19:55 +0100229 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200230#define MBEDTLS_ECP_PF_UNCOMPRESSED 0 /**< Uncompressed point format */
231#define MBEDTLS_ECP_PF_COMPRESSED 1 /**< Compressed point format */
Manuel Pégourié-Gonnard37d218a2012-11-24 15:19:55 +0100232
Manuel Pégourié-Gonnard1a967282013-02-09 17:03:58 +0100233/*
Manuel Pégourié-Gonnard00794052013-02-09 19:00:07 +0100234 * Some other constants from RFC 4492
Manuel Pégourié-Gonnard1a967282013-02-09 17:03:58 +0100235 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200236#define MBEDTLS_ECP_TLS_NAMED_CURVE 3 /**< ECCurveType's named_curve */
Manuel Pégourié-Gonnard1a967282013-02-09 17:03:58 +0100237
Manuel Pégourié-Gonnard39d2adb2012-10-31 09:26:55 +0100238/**
Manuel Pégourié-Gonnardac719412014-02-04 14:48:50 +0100239 * \brief Get the list of supported curves in order of preferrence
240 * (full information)
Manuel Pégourié-Gonnardda179e42013-09-18 15:31:24 +0200241 *
242 * \return A statically allocated array, the last entry is 0.
243 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200244const mbedtls_ecp_curve_info *mbedtls_ecp_curve_list( void );
Manuel Pégourié-Gonnardda179e42013-09-18 15:31:24 +0200245
246/**
Manuel Pégourié-Gonnardac719412014-02-04 14:48:50 +0100247 * \brief Get the list of supported curves in order of preferrence
248 * (grp_id only)
249 *
250 * \return A statically allocated array,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200251 * terminated with MBEDTLS_ECP_DP_NONE.
Manuel Pégourié-Gonnardac719412014-02-04 14:48:50 +0100252 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200253const mbedtls_ecp_group_id *mbedtls_ecp_grp_id_list( void );
Manuel Pégourié-Gonnardac719412014-02-04 14:48:50 +0100254
255/**
Manuel Pégourié-Gonnardcae6f3e2013-10-23 20:19:57 +0200256 * \brief Get curve information from an internal group identifier
257 *
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200258 * \param grp_id A MBEDTLS_ECP_DP_XXX value
Manuel Pégourié-Gonnardcae6f3e2013-10-23 20:19:57 +0200259 *
260 * \return The associated curve information or NULL
261 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200262const 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 +0200263
264/**
265 * \brief Get curve information from a TLS NamedCurve value
266 *
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200267 * \param tls_id A MBEDTLS_ECP_DP_XXX value
Manuel Pégourié-Gonnardcae6f3e2013-10-23 20:19:57 +0200268 *
269 * \return The associated curve information or NULL
270 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200271const mbedtls_ecp_curve_info *mbedtls_ecp_curve_info_from_tls_id( uint16_t tls_id );
Manuel Pégourié-Gonnardcae6f3e2013-10-23 20:19:57 +0200272
273/**
Manuel Pégourié-Gonnard0267e3d2013-11-30 15:10:14 +0100274 * \brief Get curve information from a human-readable name
275 *
276 * \param name The name
277 *
278 * \return The associated curve information or NULL
279 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200280const mbedtls_ecp_curve_info *mbedtls_ecp_curve_info_from_name( const char *name );
Manuel Pégourié-Gonnard0267e3d2013-11-30 15:10:14 +0100281
282/**
Manuel Pégourié-Gonnard847395a2012-11-05 13:13:44 +0100283 * \brief Initialize a point (as zero)
Manuel Pégourié-Gonnardae180d02012-11-02 18:14:40 +0100284 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200285void mbedtls_ecp_point_init( mbedtls_ecp_point *pt );
Manuel Pégourié-Gonnardae180d02012-11-02 18:14:40 +0100286
287/**
Manuel Pégourié-Gonnardb505c272012-11-05 17:27:54 +0100288 * \brief Initialize a group (to something meaningless)
289 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200290void mbedtls_ecp_group_init( mbedtls_ecp_group *grp );
Manuel Pégourié-Gonnardb505c272012-11-05 17:27:54 +0100291
292/**
Manuel Pégourié-Gonnardb8c6e0e2013-07-01 13:40:52 +0200293 * \brief Initialize a key pair (as an invalid one)
294 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200295void mbedtls_ecp_keypair_init( mbedtls_ecp_keypair *key );
Manuel Pégourié-Gonnardb8c6e0e2013-07-01 13:40:52 +0200296
297/**
Manuel Pégourié-Gonnard883f3132012-11-02 09:40:25 +0100298 * \brief Free the components of a point
299 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200300void mbedtls_ecp_point_free( mbedtls_ecp_point *pt );
Manuel Pégourié-Gonnard883f3132012-11-02 09:40:25 +0100301
302/**
303 * \brief Free the components of an ECP group
304 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200305void mbedtls_ecp_group_free( mbedtls_ecp_group *grp );
Manuel Pégourié-Gonnard883f3132012-11-02 09:40:25 +0100306
307/**
Manuel Pégourié-Gonnardb8c6e0e2013-07-01 13:40:52 +0200308 * \brief Free the components of a key pair
309 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200310void mbedtls_ecp_keypair_free( mbedtls_ecp_keypair *key );
Manuel Pégourié-Gonnardb8c6e0e2013-07-01 13:40:52 +0200311
312/**
Manuel Pégourié-Gonnard883f3132012-11-02 09:40:25 +0100313 * \brief Copy the contents of point Q into P
314 *
315 * \param P Destination point
316 * \param Q Source point
317 *
Manuel Pégourié-Gonnard7cfcea32012-11-05 10:06:12 +0100318 * \return 0 if successful,
Manuel Pégourié-Gonnard6a8ca332015-05-28 09:33:39 +0200319 * MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed
Manuel Pégourié-Gonnard883f3132012-11-02 09:40:25 +0100320 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200321int mbedtls_ecp_copy( mbedtls_ecp_point *P, const mbedtls_ecp_point *Q );
Manuel Pégourié-Gonnard883f3132012-11-02 09:40:25 +0100322
323/**
Manuel Pégourié-Gonnarde09631b2013-08-12 15:44:31 +0200324 * \brief Copy the contents of a group object
325 *
326 * \param dst Destination group
327 * \param src Source group
328 *
329 * \return 0 if successful,
Manuel Pégourié-Gonnard6a8ca332015-05-28 09:33:39 +0200330 * MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed
Manuel Pégourié-Gonnarde09631b2013-08-12 15:44:31 +0200331 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200332int mbedtls_ecp_group_copy( mbedtls_ecp_group *dst, const mbedtls_ecp_group *src );
Manuel Pégourié-Gonnarde09631b2013-08-12 15:44:31 +0200333
334/**
Manuel Pégourié-Gonnardcae6f3e2013-10-23 20:19:57 +0200335 * \brief Set a point to zero
336 *
337 * \param pt Destination point
338 *
339 * \return 0 if successful,
Manuel Pégourié-Gonnard6a8ca332015-05-28 09:33:39 +0200340 * MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed
Manuel Pégourié-Gonnardcae6f3e2013-10-23 20:19:57 +0200341 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200342int mbedtls_ecp_set_zero( mbedtls_ecp_point *pt );
Manuel Pégourié-Gonnardcae6f3e2013-10-23 20:19:57 +0200343
344/**
345 * \brief Tell if a point is zero
346 *
347 * \param pt Point to test
348 *
349 * \return 1 if point is zero, 0 otherwise
350 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200351int mbedtls_ecp_is_zero( mbedtls_ecp_point *pt );
Manuel Pégourié-Gonnardcae6f3e2013-10-23 20:19:57 +0200352
353/**
Manuel Pégourié-Gonnard847395a2012-11-05 13:13:44 +0100354 * \brief Import a non-zero point from two ASCII strings
355 *
356 * \param P Destination point
357 * \param radix Input numeric base
358 * \param x First affine coordinate as a null-terminated string
359 * \param y Second affine coordinate as a null-terminated string
360 *
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200361 * \return 0 if successful, or a MBEDTLS_ERR_MPI_XXX error code
Manuel Pégourié-Gonnard847395a2012-11-05 13:13:44 +0100362 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200363int mbedtls_ecp_point_read_string( mbedtls_ecp_point *P, int radix,
Manuel Pégourié-Gonnard847395a2012-11-05 13:13:44 +0100364 const char *x, const char *y );
365
366/**
Manuel Pégourié-Gonnard37d218a2012-11-24 15:19:55 +0100367 * \brief Export a point into unsigned binary data
Manuel Pégourié-Gonnarde19feb52012-11-24 14:10:14 +0100368 *
Manuel Pégourié-Gonnard5e402d82012-11-24 16:19:42 +0100369 * \param grp Group to which the point should belong
Manuel Pégourié-Gonnarde19feb52012-11-24 14:10:14 +0100370 * \param P Point to export
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200371 * \param format Point format, should be a MBEDTLS_ECP_PF_XXX macro
Manuel Pégourié-Gonnard00794052013-02-09 19:00:07 +0100372 * \param olen Length of the actual output
Manuel Pégourié-Gonnarde19feb52012-11-24 14:10:14 +0100373 * \param buf Output buffer
374 * \param buflen Length of the output buffer
375 *
Manuel Pégourié-Gonnard00794052013-02-09 19:00:07 +0100376 * \return 0 if successful,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200377 * or MBEDTLS_ERR_ECP_BAD_INPUT_DATA
378 * or MBEDTLS_ERR_ECP_BUFFER_TOO_SMALL
Manuel Pégourié-Gonnarde19feb52012-11-24 14:10:14 +0100379 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200380int mbedtls_ecp_point_write_binary( const mbedtls_ecp_group *grp, const mbedtls_ecp_point *P,
Manuel Pégourié-Gonnard420f1eb2013-02-10 12:22:46 +0100381 int format, size_t *olen,
Manuel Pégourié-Gonnard7e860252013-02-10 10:58:48 +0100382 unsigned char *buf, size_t buflen );
Manuel Pégourié-Gonnarde19feb52012-11-24 14:10:14 +0100383
384/**
Manuel Pégourié-Gonnard5e402d82012-11-24 16:19:42 +0100385 * \brief Import a point from unsigned binary data
386 *
387 * \param grp Group to which the point should belong
388 * \param P Point to import
Manuel Pégourié-Gonnard5e402d82012-11-24 16:19:42 +0100389 * \param buf Input buffer
390 * \param ilen Actual length of input
391 *
392 * \return 0 if successful,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200393 * MBEDTLS_ERR_ECP_BAD_INPUT_DATA if input is invalid,
Manuel Pégourié-Gonnard6a8ca332015-05-28 09:33:39 +0200394 * MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200395 * MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE if the point format
Manuel Pégourié-Gonnard5246ee52014-03-19 16:18:38 +0100396 * is not implemented.
Manuel Pégourié-Gonnard5e402d82012-11-24 16:19:42 +0100397 *
398 * \note This function does NOT check that the point actually
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200399 * belongs to the given group, see mbedtls_ecp_check_pubkey() for
Manuel Pégourié-Gonnard5e402d82012-11-24 16:19:42 +0100400 * that.
401 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200402int mbedtls_ecp_point_read_binary( const mbedtls_ecp_group *grp, mbedtls_ecp_point *P,
Manuel Pégourié-Gonnard7e860252013-02-10 10:58:48 +0100403 const unsigned char *buf, size_t ilen );
Manuel Pégourié-Gonnard1a967282013-02-09 17:03:58 +0100404
Manuel Pégourié-Gonnard5e402d82012-11-24 16:19:42 +0100405/**
Manuel Pégourié-Gonnardcae6f3e2013-10-23 20:19:57 +0200406 * \brief Import a point from a TLS ECPoint record
407 *
408 * \param grp ECP group used
409 * \param pt Destination point
410 * \param buf $(Start of input buffer)
411 * \param len Buffer length
412 *
Manuel Pégourié-Gonnard150c4f62014-11-21 09:14:52 +0100413 * \note buf is updated to point right after the ECPoint on exit
414 *
Manuel Pégourié-Gonnardeecb43c2015-05-12 12:56:41 +0200415 * \return 0 if successful,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200416 * MBEDTLS_ERR_MPI_XXX if initialization failed
417 * MBEDTLS_ERR_ECP_BAD_INPUT_DATA if input is invalid
Manuel Pégourié-Gonnardcae6f3e2013-10-23 20:19:57 +0200418 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200419int mbedtls_ecp_tls_read_point( const mbedtls_ecp_group *grp, mbedtls_ecp_point *pt,
Manuel Pégourié-Gonnardcae6f3e2013-10-23 20:19:57 +0200420 const unsigned char **buf, size_t len );
421
422/**
423 * \brief Export a point as a TLS ECPoint record
424 *
425 * \param grp ECP group used
426 * \param pt Point to export
427 * \param format Export format
428 * \param olen length of data written
429 * \param buf Buffer to write to
430 * \param blen Buffer length
431 *
432 * \return 0 if successful,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200433 * or MBEDTLS_ERR_ECP_BAD_INPUT_DATA
434 * or MBEDTLS_ERR_ECP_BUFFER_TOO_SMALL
Manuel Pégourié-Gonnardcae6f3e2013-10-23 20:19:57 +0200435 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200436int mbedtls_ecp_tls_write_point( const mbedtls_ecp_group *grp, const mbedtls_ecp_point *pt,
Manuel Pégourié-Gonnardcae6f3e2013-10-23 20:19:57 +0200437 int format, size_t *olen,
438 unsigned char *buf, size_t blen );
439
440/**
Manuel Pégourié-Gonnarda5402fe2012-11-07 20:24:05 +0100441 * \brief Set a group using well-known domain parameters
442 *
443 * \param grp Destination group
444 * \param index Index in the list of well-known domain parameters
445 *
Manuel Pégourié-Gonnardeecb43c2015-05-12 12:56:41 +0200446 * \return 0 if successful,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200447 * MBEDTLS_ERR_MPI_XXX if initialization failed
448 * MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE for unkownn groups
Manuel Pégourié-Gonnarda5402fe2012-11-07 20:24:05 +0100449 *
Manuel Pégourié-Gonnardaff37e52015-05-11 18:11:57 +0200450 * \note Index should be a value of RFC 4492's enum NamedCurve,
451 * usually in the form of a MBEDTLS_ECP_DP_XXX macro.
Manuel Pégourié-Gonnarda5402fe2012-11-07 20:24:05 +0100452 */
Manuel Pégourié-Gonnarde3a062b2015-05-11 18:46:47 +0200453int mbedtls_ecp_group_load( mbedtls_ecp_group *grp, mbedtls_ecp_group_id index );
Manuel Pégourié-Gonnard1a967282013-02-09 17:03:58 +0100454
455/**
Manuel Pégourié-Gonnard00794052013-02-09 19:00:07 +0100456 * \brief Set a group from a TLS ECParameters record
Manuel Pégourié-Gonnard1a967282013-02-09 17:03:58 +0100457 *
458 * \param grp Destination group
Manuel Pégourié-Gonnard7c145c62013-02-10 13:20:52 +0100459 * \param buf &(Start of input buffer)
Manuel Pégourié-Gonnard1a967282013-02-09 17:03:58 +0100460 * \param len Buffer length
461 *
Manuel Pégourié-Gonnard150c4f62014-11-21 09:14:52 +0100462 * \note buf is updated to point right after ECParameters on exit
463 *
Manuel Pégourié-Gonnardeecb43c2015-05-12 12:56:41 +0200464 * \return 0 if successful,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200465 * MBEDTLS_ERR_MPI_XXX if initialization failed
466 * MBEDTLS_ERR_ECP_BAD_INPUT_DATA if input is invalid
Manuel Pégourié-Gonnard1a967282013-02-09 17:03:58 +0100467 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200468int mbedtls_ecp_tls_read_group( mbedtls_ecp_group *grp, const unsigned char **buf, size_t len );
Manuel Pégourié-Gonnarda5402fe2012-11-07 20:24:05 +0100469
470/**
Manuel Pégourié-Gonnardb3258872013-02-10 12:06:19 +0100471 * \brief Write the TLS ECParameters record for a group
472 *
473 * \param grp ECP group used
474 * \param olen Number of bytes actually written
475 * \param buf Buffer to write to
476 * \param blen Buffer length
477 *
478 * \return 0 if successful,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200479 * or MBEDTLS_ERR_ECP_BUFFER_TOO_SMALL
Manuel Pégourié-Gonnardb3258872013-02-10 12:06:19 +0100480 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200481int mbedtls_ecp_tls_write_group( const mbedtls_ecp_group *grp, size_t *olen,
Manuel Pégourié-Gonnardb3258872013-02-10 12:06:19 +0100482 unsigned char *buf, size_t blen );
483
484/**
Manuel Pégourié-Gonnard39d2adb2012-10-31 09:26:55 +0100485 * \brief Multiplication by an integer: R = m * P
Paul Bakker6838bd12013-09-30 13:56:38 +0200486 * (Not thread-safe to use same group in multiple threads)
Manuel Pégourié-Gonnard39d2adb2012-10-31 09:26:55 +0100487 *
Manuel Pégourié-Gonnard56cc88a2015-05-11 18:40:45 +0200488 * \note In order to prevent timing attacks, this function
489 * executes the exact same sequence of (base field)
490 * operations for any valid m. It avoids any if-branch or
491 * array index depending on the value of m.
492 *
493 * \note If f_rng is not NULL, it is used to randomize intermediate
494 * results in order to prevent potential timing attacks
495 * targeting these results. It is recommended to always
496 * provide a non-NULL f_rng (the overhead is negligible).
497 *
Manuel Pégourié-Gonnard39d2adb2012-10-31 09:26:55 +0100498 * \param grp ECP group
499 * \param R Destination point
500 * \param m Integer by which to multiply
501 * \param P Point to multiply
Manuel Pégourié-Gonnarde09d2f82013-09-02 14:29:09 +0200502 * \param f_rng RNG function (see notes)
503 * \param p_rng RNG parameter
Manuel Pégourié-Gonnard39d2adb2012-10-31 09:26:55 +0100504 *
Manuel Pégourié-Gonnard7cfcea32012-11-05 10:06:12 +0100505 * \return 0 if successful,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200506 * MBEDTLS_ERR_ECP_INVALID_KEY if m is not a valid privkey
Manuel Pégourié-Gonnardff27b7c2013-11-21 09:28:03 +0100507 * or P is not a valid pubkey,
Manuel Pégourié-Gonnard6a8ca332015-05-28 09:33:39 +0200508 * MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed
Manuel Pégourié-Gonnard39d2adb2012-10-31 09:26:55 +0100509 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200510int mbedtls_ecp_mul( mbedtls_ecp_group *grp, mbedtls_ecp_point *R,
511 const mbedtls_mpi *m, const mbedtls_ecp_point *P,
Manuel Pégourié-Gonnard09ceaf42013-11-20 23:06:14 +0100512 int (*f_rng)(void *, unsigned char *, size_t), void *p_rng );
Manuel Pégourié-Gonnard39d2adb2012-10-31 09:26:55 +0100513
514/**
Manuel Pégourié-Gonnard56cc88a2015-05-11 18:40:45 +0200515 * \brief Multiplication and addition of two points by integers:
516 * R = m * P + n * Q
517 * (Not thread-safe to use same group in multiple threads)
518 *
Manuel Pégourié-Gonnard151dc772015-05-14 13:55:51 +0200519 * \note In contrast to mbedtls_ecp_mul(), this function does not guarantee
Manuel Pégourié-Gonnard56cc88a2015-05-11 18:40:45 +0200520 * a constant execution flow and timing.
521 *
522 * \param grp ECP group
523 * \param R Destination point
524 * \param m Integer by which to multiply P
525 * \param P Point to multiply by m
526 * \param n Integer by which to multiply Q
527 * \param Q Point to be multiplied by n
528 *
529 * \return 0 if successful,
530 * MBEDTLS_ERR_ECP_INVALID_KEY if m or n is not a valid privkey
531 * or P or Q is not a valid pubkey,
Manuel Pégourié-Gonnard6a8ca332015-05-28 09:33:39 +0200532 * MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed
Manuel Pégourié-Gonnard56cc88a2015-05-11 18:40:45 +0200533 */
534int mbedtls_ecp_muladd( mbedtls_ecp_group *grp, mbedtls_ecp_point *R,
535 const mbedtls_mpi *m, const mbedtls_ecp_point *P,
536 const mbedtls_mpi *n, const mbedtls_ecp_point *Q );
537
538/**
Manuel Pégourié-Gonnardc8dc2952013-07-01 14:06:13 +0200539 * \brief Check that a point is a valid public key on this curve
540 *
541 * \param grp Curve/group the point should belong to
542 * \param pt Point to check
543 *
544 * \return 0 if point is a valid public key,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200545 * MBEDTLS_ERR_ECP_INVALID_KEY otherwise.
Manuel Pégourié-Gonnardc8dc2952013-07-01 14:06:13 +0200546 *
547 * \note This function only checks the point is non-zero, has valid
548 * coordinates and lies on the curve, but not that it is
549 * indeed a multiple of G. This is additional check is more
550 * expensive, isn't required by standards, and shouldn't be
551 * necessary if the group used has a small cofactor. In
552 * particular, it is useless for the NIST groups which all
553 * have a cofactor of 1.
554 *
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200555 * \note Uses bare components rather than an mbedtls_ecp_keypair structure
Manuel Pégourié-Gonnardc8dc2952013-07-01 14:06:13 +0200556 * in order to ease use with other structures such as
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200557 * mbedtls_ecdh_context of mbedtls_ecdsa_context.
Manuel Pégourié-Gonnardc8dc2952013-07-01 14:06:13 +0200558 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200559int mbedtls_ecp_check_pubkey( const mbedtls_ecp_group *grp, const mbedtls_ecp_point *pt );
Manuel Pégourié-Gonnardc8dc2952013-07-01 14:06:13 +0200560
561/**
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200562 * \brief Check that an mbedtls_mpi is a valid private key for this curve
Manuel Pégourié-Gonnardc8dc2952013-07-01 14:06:13 +0200563 *
564 * \param grp Group used
565 * \param d Integer to check
566 *
567 * \return 0 if point is a valid private key,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200568 * MBEDTLS_ERR_ECP_INVALID_KEY otherwise.
Manuel Pégourié-Gonnardc8dc2952013-07-01 14:06:13 +0200569 *
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200570 * \note Uses bare components rather than an mbedtls_ecp_keypair structure
Manuel Pégourié-Gonnardc8dc2952013-07-01 14:06:13 +0200571 * in order to ease use with other structures such as
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200572 * mbedtls_ecdh_context of mbedtls_ecdsa_context.
Manuel Pégourié-Gonnardc8dc2952013-07-01 14:06:13 +0200573 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200574int mbedtls_ecp_check_privkey( const mbedtls_ecp_group *grp, const mbedtls_mpi *d );
Manuel Pégourié-Gonnardc8dc2952013-07-01 14:06:13 +0200575
576/**
Manuel Pégourié-Gonnard45a035a2013-01-26 14:42:45 +0100577 * \brief Generate a keypair
578 *
579 * \param grp ECP group
580 * \param d Destination MPI (secret part)
581 * \param Q Destination point (public part)
582 * \param f_rng RNG function
583 * \param p_rng RNG parameter
584 *
585 * \return 0 if successful,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200586 * or a MBEDTLS_ERR_ECP_XXX or MBEDTLS_MPI_XXX error code
Manuel Pégourié-Gonnardc8dc2952013-07-01 14:06:13 +0200587 *
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200588 * \note Uses bare components rather than an mbedtls_ecp_keypair structure
Manuel Pégourié-Gonnardc8dc2952013-07-01 14:06:13 +0200589 * in order to ease use with other structures such as
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200590 * mbedtls_ecdh_context of mbedtls_ecdsa_context.
Manuel Pégourié-Gonnard45a035a2013-01-26 14:42:45 +0100591 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200592int mbedtls_ecp_gen_keypair( mbedtls_ecp_group *grp, mbedtls_mpi *d, mbedtls_ecp_point *Q,
Manuel Pégourié-Gonnard45a035a2013-01-26 14:42:45 +0100593 int (*f_rng)(void *, unsigned char *, size_t),
594 void *p_rng );
595
596/**
Manuel Pégourié-Gonnard104ee1d2013-11-30 14:13:16 +0100597 * \brief Generate a keypair
598 *
599 * \param grp_id ECP group identifier
600 * \param key Destination keypair
601 * \param f_rng RNG function
602 * \param p_rng RNG parameter
603 *
604 * \return 0 if successful,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200605 * or a MBEDTLS_ERR_ECP_XXX or MBEDTLS_MPI_XXX error code
Manuel Pégourié-Gonnard104ee1d2013-11-30 14:13:16 +0100606 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200607int mbedtls_ecp_gen_key( mbedtls_ecp_group_id grp_id, mbedtls_ecp_keypair *key,
Manuel Pégourié-Gonnard104ee1d2013-11-30 14:13:16 +0100608 int (*f_rng)(void *, unsigned char *, size_t), void *p_rng );
609
Manuel Pégourié-Gonnard30668d62014-11-06 15:25:32 +0100610/**
611 * \brief Check a public-private key pair
612 *
613 * \param pub Keypair structure holding a public key
614 * \param prv Keypair structure holding a private (plus public) key
615 *
Manuel Pégourié-Gonnard862d5032015-04-15 11:30:46 +0200616 * \return 0 if successful (keys are valid and match), or
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200617 * MBEDTLS_ERR_ECP_BAD_INPUT_DATA, or
618 * a MBEDTLS_ERR_ECP_XXX or MBEDTLS_ERR_MPI_XXX code.
Manuel Pégourié-Gonnard30668d62014-11-06 15:25:32 +0100619 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200620int mbedtls_ecp_check_pub_priv( const mbedtls_ecp_keypair *pub, const mbedtls_ecp_keypair *prv );
Manuel Pégourié-Gonnard30668d62014-11-06 15:25:32 +0100621
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200622#if defined(MBEDTLS_SELF_TEST)
Manuel Pégourié-Gonnard104ee1d2013-11-30 14:13:16 +0100623/**
Manuel Pégourié-Gonnard39d2adb2012-10-31 09:26:55 +0100624 * \brief Checkup routine
625 *
Manuel Pégourié-Gonnard13a1ef82014-03-27 20:12:44 +0100626 * \return 0 if successful, or 1 if a test failed
Manuel Pégourié-Gonnard39d2adb2012-10-31 09:26:55 +0100627 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200628int mbedtls_ecp_self_test( int verbose );
Manuel Pégourié-Gonnard13a1ef82014-03-27 20:12:44 +0100629#endif
Manuel Pégourié-Gonnard39d2adb2012-10-31 09:26:55 +0100630
631#ifdef __cplusplus
632}
633#endif
634
Paul Bakker9af723c2014-05-01 13:03:14 +0200635#endif /* ecp.h */