blob: 8debda44acfbbc9abea980cd625a675ca52c6bee [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 *
Paul Bakkercf4365f2013-01-16 17:00:43 +01006 * Copyright (C) 2006-2013, Brainspark B.V.
Manuel Pégourié-Gonnard39d2adb2012-10-31 09:26:55 +01007 *
8 * This file is part of PolarSSL (http://www.polarssl.org)
9 * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
10 *
11 * All rights reserved.
12 *
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
17 *
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
22 *
23 * You should have received a copy of the GNU General Public License along
24 * with this program; if not, write to the Free Software Foundation, Inc.,
25 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 */
27#ifndef POLARSSL_ECP_H
28#define POLARSSL_ECP_H
29
Manuel Pégourié-Gonnard0bad5c22013-01-26 15:30:46 +010030#include "polarssl/bignum.h"
Manuel Pégourié-Gonnard39d2adb2012-10-31 09:26:55 +010031
32/*
Manuel Pégourié-Gonnard7cfcea32012-11-05 10:06:12 +010033 * ECP error codes
Manuel Pégourié-Gonnard39d2adb2012-10-31 09:26:55 +010034 */
Paul Bakkercf4365f2013-01-16 17:00:43 +010035#define POLARSSL_ERR_ECP_BAD_INPUT_DATA -0x4F80 /**< Bad input parameters to function. */
Manuel Pégourié-Gonnard00794052013-02-09 19:00:07 +010036#define POLARSSL_ERR_ECP_BUFFER_TOO_SMALL -0x4F80 /**< The buffer is too small to write to. */
Paul Bakkercf4365f2013-01-16 17:00:43 +010037#define POLARSSL_ERR_ECP_GENERIC -0x4F00 /**< Generic ECP error */
Manuel Pégourié-Gonnard883f3132012-11-02 09:40:25 +010038
Manuel Pégourié-Gonnard39d2adb2012-10-31 09:26:55 +010039/**
Manuel Pégourié-Gonnard1c2782c2012-11-19 20:16:28 +010040 * \brief ECP point structure (jacobian coordinates)
Manuel Pégourié-Gonnardae180d02012-11-02 18:14:40 +010041 *
Manuel Pégourié-Gonnard1c2782c2012-11-19 20:16:28 +010042 * \note All functions expect and return points satisfying
43 * the following condition: Z == 0 or Z == 1. (Other
44 * values of Z are used by internal functions only.)
45 * The point is zero, or "at infinity", if Z == 0.
46 * Otherwise, X and Y are its standard (affine) coordinates.
Manuel Pégourié-Gonnard39d2adb2012-10-31 09:26:55 +010047 */
48typedef struct
49{
Manuel Pégourié-Gonnard5179e462012-10-31 19:37:54 +010050 mpi X; /*!< the point's X coordinate */
51 mpi Y; /*!< the point's Y coordinate */
Manuel Pégourié-Gonnard1c2782c2012-11-19 20:16:28 +010052 mpi Z; /*!< the point's Z coordinate */
Manuel Pégourié-Gonnard39d2adb2012-10-31 09:26:55 +010053}
54ecp_point;
55
Manuel Pégourié-Gonnardb3258872013-02-10 12:06:19 +010056/*
57 * RFC 4492 defines an enum NamedCurve with two-bytes values
58 */
59typedef uint16_t ecp_group_id;
60
Manuel Pégourié-Gonnard39d2adb2012-10-31 09:26:55 +010061/**
62 * \brief ECP group structure
63 *
Manuel Pégourié-Gonnard773ed542012-11-18 13:19:07 +010064 * The curves we consider are defined by y^2 = x^3 - 3x + B mod P,
65 * and a generator for a large subgroup of order N is fixed.
Manuel Pégourié-Gonnard62aad142012-11-10 00:27:12 +010066 *
Manuel Pégourié-Gonnard773ed542012-11-18 13:19:07 +010067 * pbits and nbits must be the size of P and N in bits.
Manuel Pégourié-Gonnard47123252012-11-10 14:44:24 +010068 *
Manuel Pégourié-Gonnard773ed542012-11-18 13:19:07 +010069 * If modp is NULL, reduction modulo P is done using a generic
70 * algorithm. Otherwise, it must point to a function that takes an mpi
71 * in the range 0..2^(2*pbits) and transforms it in-place in an integer
72 * of little more than pbits, so that the integer may be efficiently
73 * brought in the 0..P range by a few additions or substractions. It
74 * must return 0 on success and a POLARSSL_ERR_ECP_XXX error on failure.
Manuel Pégourié-Gonnard39d2adb2012-10-31 09:26:55 +010075 */
76typedef struct
77{
Manuel Pégourié-Gonnardb3258872013-02-10 12:06:19 +010078 ecp_group_id id; /*!< RFC 4492 group ID */
Manuel Pégourié-Gonnard39d2adb2012-10-31 09:26:55 +010079 mpi P; /*!< prime modulus of the base field */
80 mpi B; /*!< constant term in the equation */
81 ecp_point G; /*!< generator of the subgroup used */
82 mpi N; /*!< the order of G */
Manuel Pégourié-Gonnard773ed542012-11-18 13:19:07 +010083 size_t pbits; /*!< number of bits in P */
84 size_t nbits; /*!< number of bits in N */
Manuel Pégourié-Gonnard62aad142012-11-10 00:27:12 +010085 int (*modp)(mpi *); /*!< function for fast reduction mod P */
Manuel Pégourié-Gonnard39d2adb2012-10-31 09:26:55 +010086}
87ecp_group;
88
89/**
90 * RFC 5114 defines a number of standardized ECP groups for use with TLS.
91 *
92 * These also are the NIST-recommended ECP groups, are the random ECP groups
93 * recommended by SECG, and include the two groups used by NSA Suite B.
Manuel Pégourié-Gonnardd7e45702012-10-31 18:57:05 +010094 * There are known as secpLLLr1 with LLL = 192, 224, 256, 384, 521.
Manuel Pégourié-Gonnard39d2adb2012-10-31 09:26:55 +010095 *
96 * \warning This library does not support validation of arbitrary domain
97 * parameters. Therefore, only well-known domain parameters from trusted
Manuel Pégourié-Gonnard47123252012-11-10 14:44:24 +010098 * sources should be used. See ecp_use_known_dp().
Manuel Pégourié-Gonnard1a967282013-02-09 17:03:58 +010099 *
100 * \note The values are taken from RFC 4492's enum NamedCurve.
Manuel Pégourié-Gonnard39d2adb2012-10-31 09:26:55 +0100101 */
Manuel Pégourié-Gonnard1a967282013-02-09 17:03:58 +0100102#define POLARSSL_ECP_DP_SECP192R1 19
103#define POLARSSL_ECP_DP_SECP224R1 21
104#define POLARSSL_ECP_DP_SECP256R1 23
105#define POLARSSL_ECP_DP_SECP384R1 24
106#define POLARSSL_ECP_DP_SECP521R1 25
Manuel Pégourié-Gonnarda5402fe2012-11-07 20:24:05 +0100107
Manuel Pégourié-Gonnardb63f9e92012-11-21 13:00:58 +0100108/**
109 * Maximum bit size of the groups (that is, of N)
110 */
111#define POLARSSL_ECP_MAX_N_BITS 521
112
Manuel Pégourié-Gonnard85556072012-11-17 19:54:20 +0100113/*
Manuel Pégourié-Gonnardb63f9e92012-11-21 13:00:58 +0100114 * Maximum window size (actually, NAF width) used for point multipliation.
115 * Default: 7.
Manuel Pégourié-Gonnard85556072012-11-17 19:54:20 +0100116 * Minimum value: 2. Maximum value: 8.
117 *
Manuel Pégourié-Gonnardb63f9e92012-11-21 13:00:58 +0100118 * Result is an array of at most ( 1 << ( POLARSSL_ECP_WINDOW_SIZE - 1 ) )
Manuel Pégourié-Gonnard85556072012-11-17 19:54:20 +0100119 * points used for point multiplication, so at most 64 by default.
120 * In practice, most curves will use less precomputed points.
121 *
122 * Reduction in size may reduce speed for big curves.
123 */
Manuel Pégourié-Gonnardb63f9e92012-11-21 13:00:58 +0100124#define POLARSSL_ECP_WINDOW_SIZE 7 /**< Maximum NAF width used. */
Manuel Pégourié-Gonnard85556072012-11-17 19:54:20 +0100125
Manuel Pégourié-Gonnard37d218a2012-11-24 15:19:55 +0100126/*
Manuel Pégourié-Gonnard00794052013-02-09 19:00:07 +0100127 * Point formats, from RFC 4492's enum ECPointFormat
Manuel Pégourié-Gonnard37d218a2012-11-24 15:19:55 +0100128 */
129#define POLARSSL_ECP_PF_UNCOMPRESSED 0 /**< Uncompressed point format */
130#define POLARSSL_ECP_PF_COMPRESSED 1 /**< Compressed point format */
131
Manuel Pégourié-Gonnard1a967282013-02-09 17:03:58 +0100132/*
Manuel Pégourié-Gonnard00794052013-02-09 19:00:07 +0100133 * Some other constants from RFC 4492
Manuel Pégourié-Gonnard1a967282013-02-09 17:03:58 +0100134 */
Manuel Pégourié-Gonnard00794052013-02-09 19:00:07 +0100135#define POLARSSL_ECP_TLS_NAMED_CURVE 3 /**< ECCurveType's named_curve */
Manuel Pégourié-Gonnard1a967282013-02-09 17:03:58 +0100136
137
Manuel Pégourié-Gonnard39d2adb2012-10-31 09:26:55 +0100138#ifdef __cplusplus
139extern "C" {
140#endif
141
142/**
Manuel Pégourié-Gonnard847395a2012-11-05 13:13:44 +0100143 * \brief Initialize a point (as zero)
Manuel Pégourié-Gonnardae180d02012-11-02 18:14:40 +0100144 */
145void ecp_point_init( ecp_point *pt );
146
147/**
Manuel Pégourié-Gonnardb505c272012-11-05 17:27:54 +0100148 * \brief Initialize a group (to something meaningless)
149 */
150void ecp_group_init( ecp_group *grp );
151
152/**
Manuel Pégourié-Gonnard883f3132012-11-02 09:40:25 +0100153 * \brief Free the components of a point
154 */
155void ecp_point_free( ecp_point *pt );
156
157/**
158 * \brief Free the components of an ECP group
159 */
160void ecp_group_free( ecp_group *grp );
161
162/**
Manuel Pégourié-Gonnardae180d02012-11-02 18:14:40 +0100163 * \brief Set a point to zero
Manuel Pégourié-Gonnard1c2782c2012-11-19 20:16:28 +0100164 *
Manuel Pégourié-Gonnard6545ca72013-01-26 16:05:22 +0100165 * \param pt Destination point
166 *
Manuel Pégourié-Gonnard1c2782c2012-11-19 20:16:28 +0100167 * \return 0 if successful,
168 * POLARSSL_ERR_MPI_MALLOC_FAILED if memory allocation failed
Manuel Pégourié-Gonnardae180d02012-11-02 18:14:40 +0100169 */
Manuel Pégourié-Gonnard1c2782c2012-11-19 20:16:28 +0100170int ecp_set_zero( ecp_point *pt );
Manuel Pégourié-Gonnardae180d02012-11-02 18:14:40 +0100171
172/**
Manuel Pégourié-Gonnard6545ca72013-01-26 16:05:22 +0100173 * \brief Tell if a point is zero
174 *
175 * \param pt Point to test
176 *
177 * \return 1 if point is zero, 0 otherwise
178 */
179int ecp_is_zero( ecp_point *pt );
180
181/**
Manuel Pégourié-Gonnard883f3132012-11-02 09:40:25 +0100182 * \brief Copy the contents of point Q into P
183 *
184 * \param P Destination point
185 * \param Q Source point
186 *
Manuel Pégourié-Gonnard7cfcea32012-11-05 10:06:12 +0100187 * \return 0 if successful,
188 * POLARSSL_ERR_MPI_MALLOC_FAILED if memory allocation failed
Manuel Pégourié-Gonnard883f3132012-11-02 09:40:25 +0100189 */
190int ecp_copy( ecp_point *P, const ecp_point *Q );
191
192/**
Manuel Pégourié-Gonnard1c330572012-11-24 12:05:44 +0100193 * \brief Check that a point is a valid public key on this curve
194 *
195 * \param grp Curve/group the point should belong to
196 * \param pt Point to check
197 *
198 * \return 0 if point is a valid public key,
199 * POLARSSL_ERR_ECP_GENERIC otherwise.
200 *
201 * \note This function only checks the point is non-zero, has valid
202 * coordinates and lies on the curve, but not that it is
203 * indeed a multiple of G. This is additional check is more
204 * expensive, isn't required by standards, and shouldn't be
205 * necessary if the group used has a small cofactor. In
206 * particular, it is useless for the NIST groups which all
207 * have a cofactor of 1.
208 */
209int ecp_check_pubkey( const ecp_group *grp, const ecp_point *pt );
210
211/**
Manuel Pégourié-Gonnard847395a2012-11-05 13:13:44 +0100212 * \brief Import a non-zero point from two ASCII strings
213 *
214 * \param P Destination point
215 * \param radix Input numeric base
216 * \param x First affine coordinate as a null-terminated string
217 * \param y Second affine coordinate as a null-terminated string
218 *
219 * \return 0 if successful, or a POLARSSL_ERR_MPI_XXX error code
220 */
221int ecp_point_read_string( ecp_point *P, int radix,
222 const char *x, const char *y );
223
224/**
225 * \brief Import an ECP group from null-terminated ASCII strings
226 *
227 * \param grp Destination group
Manuel Pégourié-Gonnardb505c272012-11-05 17:27:54 +0100228 * \param radix Input numeric base
Manuel Pégourié-Gonnard847395a2012-11-05 13:13:44 +0100229 * \param p Prime modulus of the base field
230 * \param b Constant term in the equation
231 * \param gx The generator's X coordinate
232 * \param gy The generator's Y coordinate
233 * \param n The generator's order
234 *
235 * \return 0 if successful, or a POLARSSL_ERR_MPI_XXX error code
Manuel Pégourié-Gonnard773ed542012-11-18 13:19:07 +0100236 *
237 * \note Sets all fields except modp.
Manuel Pégourié-Gonnard847395a2012-11-05 13:13:44 +0100238 */
239int ecp_group_read_string( ecp_group *grp, int radix,
240 const char *p, const char *b,
241 const char *gx, const char *gy, const char *n);
242
243/**
Manuel Pégourié-Gonnard37d218a2012-11-24 15:19:55 +0100244 * \brief Export a point into unsigned binary data
Manuel Pégourié-Gonnarde19feb52012-11-24 14:10:14 +0100245 *
Manuel Pégourié-Gonnard5e402d82012-11-24 16:19:42 +0100246 * \param grp Group to which the point should belong
Manuel Pégourié-Gonnarde19feb52012-11-24 14:10:14 +0100247 * \param P Point to export
Manuel Pégourié-Gonnard37d218a2012-11-24 15:19:55 +0100248 * \param format Point format, should be a POLARSSL_ECP_PF_XXX macro
Manuel Pégourié-Gonnard00794052013-02-09 19:00:07 +0100249 * \param olen Length of the actual output
Manuel Pégourié-Gonnarde19feb52012-11-24 14:10:14 +0100250 * \param buf Output buffer
251 * \param buflen Length of the output buffer
252 *
Manuel Pégourié-Gonnard00794052013-02-09 19:00:07 +0100253 * \return 0 if successful,
254 * or POLARSSL_ERR_ECP_BAD_INPUT_DATA
255 * or POLARSSL_ERR_ECP_BUFFER_TOO_SMALL
Manuel Pégourié-Gonnarde19feb52012-11-24 14:10:14 +0100256 */
Manuel Pégourié-Gonnard7e860252013-02-10 10:58:48 +0100257int ecp_point_write_binary( const ecp_group *grp, const ecp_point *P,
Manuel Pégourié-Gonnard420f1eb2013-02-10 12:22:46 +0100258 int format, size_t *olen,
Manuel Pégourié-Gonnard7e860252013-02-10 10:58:48 +0100259 unsigned char *buf, size_t buflen );
Manuel Pégourié-Gonnarde19feb52012-11-24 14:10:14 +0100260
261/**
Manuel Pégourié-Gonnard5e402d82012-11-24 16:19:42 +0100262 * \brief Import a point from unsigned binary data
263 *
264 * \param grp Group to which the point should belong
265 * \param P Point to import
Manuel Pégourié-Gonnard5e402d82012-11-24 16:19:42 +0100266 * \param buf Input buffer
267 * \param ilen Actual length of input
268 *
269 * \return 0 if successful,
270 * POLARSSL_ERR_ECP_GENERIC if input is invalid
271 * POLARSSL_ERR_MPI_MALLOC_FAILED if memory allocation failed
272 *
273 * \note This function does NOT check that the point actually
274 * belongs to the given group, see ecp_check_pubkey() for
275 * that.
276 */
Manuel Pégourié-Gonnard7e860252013-02-10 10:58:48 +0100277int ecp_point_read_binary( const ecp_group *grp, ecp_point *P,
278 const unsigned char *buf, size_t ilen );
Manuel Pégourié-Gonnard1a967282013-02-09 17:03:58 +0100279
Manuel Pégourié-Gonnard5e402d82012-11-24 16:19:42 +0100280/**
Manuel Pégourié-Gonnarda5402fe2012-11-07 20:24:05 +0100281 * \brief Set a group using well-known domain parameters
282 *
283 * \param grp Destination group
284 * \param index Index in the list of well-known domain parameters
285 *
Manuel Pégourié-Gonnard47123252012-11-10 14:44:24 +0100286 * \return O if successful,
Manuel Pégourié-Gonnarda5402fe2012-11-07 20:24:05 +0100287 * POLARSSL_ERR_MPI_XXX if initialization failed
288 * POLARSSL_ERR_ECP_GENERIC if index is out of range
289 *
Manuel Pégourié-Gonnard1a967282013-02-09 17:03:58 +0100290 * \note Index should be a value of RFC 4492's enum NamdeCurve,
291 * possibly in the form of a POLARSSL_ECP_DP_XXX macro.
Manuel Pégourié-Gonnarda5402fe2012-11-07 20:24:05 +0100292 */
Manuel Pégourié-Gonnardb3258872013-02-10 12:06:19 +0100293int ecp_use_known_dp( ecp_group *grp, ecp_group_id id );
Manuel Pégourié-Gonnard1a967282013-02-09 17:03:58 +0100294
295/**
Manuel Pégourié-Gonnard00794052013-02-09 19:00:07 +0100296 * \brief Set a group from a TLS ECParameters record
Manuel Pégourié-Gonnard1a967282013-02-09 17:03:58 +0100297 *
298 * \param grp Destination group
Manuel Pégourié-Gonnard7c145c62013-02-10 13:20:52 +0100299 * \param buf &(Start of input buffer)
Manuel Pégourié-Gonnard1a967282013-02-09 17:03:58 +0100300 * \param len Buffer length
301 *
302 * \return O if successful,
303 * POLARSSL_ERR_MPI_XXX if initialization failed
304 * POLARSSL_ERR_ECP_BAD_INPUT_DATA if input is invalid
305 */
Manuel Pégourié-Gonnard7c145c62013-02-10 13:20:52 +0100306int ecp_tls_read_group( ecp_group *grp, const unsigned char **buf, size_t len );
Manuel Pégourié-Gonnarda5402fe2012-11-07 20:24:05 +0100307
308/**
Manuel Pégourié-Gonnardb3258872013-02-10 12:06:19 +0100309 * \brief Write the TLS ECParameters record for a group
310 *
311 * \param grp ECP group used
312 * \param olen Number of bytes actually written
313 * \param buf Buffer to write to
314 * \param blen Buffer length
315 *
316 * \return 0 if successful,
317 * or POLARSSL_ERR_ECP_BUFFER_TOO_SMALL
318 */
319int ecp_tls_write_group( const ecp_group *grp, size_t *olen,
320 unsigned char *buf, size_t blen );
321
322/**
Manuel Pégourié-Gonnard00794052013-02-09 19:00:07 +0100323 * \brief Import a point from a TLS ECPoint record
324 *
325 * \param grp ECP group used
326 * \param pt Destination point
Manuel Pégourié-Gonnard98f51812013-02-10 13:38:29 +0100327 * \param buf $(Start of input buffer)
Manuel Pégourié-Gonnard00794052013-02-09 19:00:07 +0100328 * \param len Buffer length
329 *
330 * \return O if successful,
331 * POLARSSL_ERR_MPI_XXX if initialization failed
332 * POLARSSL_ERR_ECP_BAD_INPUT_DATA if input is invalid
333 */
334int ecp_tls_read_point( const ecp_group *grp, ecp_point *pt,
Manuel Pégourié-Gonnard98f51812013-02-10 13:38:29 +0100335 const unsigned char **buf, size_t len );
Manuel Pégourié-Gonnard00794052013-02-09 19:00:07 +0100336
337/**
338 * \brief Export a point as a TLS ECPoint record
339 *
340 * \param grp ECP group used
341 * \param pt Point to export
342 * \param format Export format
343 * \param buf Buffer to write to
344 * \param len Buffer length
345 *
346 * \return 0 if successful,
347 * or POLARSSL_ERR_ECP_BAD_INPUT_DATA
348 * or POLARSSL_ERR_ECP_BUFFER_TOO_SMALL
349 */
350int ecp_tls_write_point( const ecp_group *grp, const ecp_point *pt,
Manuel Pégourié-Gonnard420f1eb2013-02-10 12:22:46 +0100351 int format, size_t *olen,
352 unsigned char *buf, size_t blen );
Manuel Pégourié-Gonnard00794052013-02-09 19:00:07 +0100353
354/**
Manuel Pégourié-Gonnard39d2adb2012-10-31 09:26:55 +0100355 * \brief Addition: R = P + Q
356 *
357 * \param grp ECP group
358 * \param R Destination point
359 * \param P Left-hand point
360 * \param Q Right-hand point
361 *
Manuel Pégourié-Gonnard7cfcea32012-11-05 10:06:12 +0100362 * \return 0 if successful,
Manuel Pégourié-Gonnard62aad142012-11-10 00:27:12 +0100363 * POLARSSL_ERR_MPI_MALLOC_FAILED if memory allocation failed
Manuel Pégourié-Gonnard39d2adb2012-10-31 09:26:55 +0100364 */
365int ecp_add( const ecp_group *grp, ecp_point *R,
366 const ecp_point *P, const ecp_point *Q );
367
368/**
Manuel Pégourié-Gonnard9674fd02012-11-19 21:23:27 +0100369 * \brief Subtraction: R = P - Q
370 *
371 * \param grp ECP group
372 * \param R Destination point
373 * \param P Left-hand point
374 * \param Q Right-hand point
375 *
376 * \return 0 if successful,
377 * POLARSSL_ERR_MPI_MALLOC_FAILED if memory allocation failed
378 */
379int ecp_sub( const ecp_group *grp, ecp_point *R,
380 const ecp_point *P, const ecp_point *Q );
381
382/**
Manuel Pégourié-Gonnard39d2adb2012-10-31 09:26:55 +0100383 * \brief Multiplication by an integer: R = m * P
384 *
385 * \param grp ECP group
386 * \param R Destination point
387 * \param m Integer by which to multiply
388 * \param P Point to multiply
389 *
Manuel Pégourié-Gonnard7cfcea32012-11-05 10:06:12 +0100390 * \return 0 if successful,
Manuel Pégourié-Gonnard62aad142012-11-10 00:27:12 +0100391 * POLARSSL_ERR_MPI_MALLOC_FAILED if memory allocation failed
Manuel Pégourié-Gonnardb63f9e92012-11-21 13:00:58 +0100392 * POLARSSL_ERR_ECP_GENERIC if m < 0 of m has greater bit
393 * length than N, the number of points in the group.
394 *
395 * \note This function executes a constant number of operations
396 * for random m in the allowed range.
Manuel Pégourié-Gonnard39d2adb2012-10-31 09:26:55 +0100397 */
Manuel Pégourié-Gonnard5179e462012-10-31 19:37:54 +0100398int ecp_mul( const ecp_group *grp, ecp_point *R,
399 const mpi *m, const ecp_point *P );
Manuel Pégourié-Gonnard39d2adb2012-10-31 09:26:55 +0100400
401/**
Manuel Pégourié-Gonnard45a035a2013-01-26 14:42:45 +0100402 * \brief Generate a keypair
403 *
404 * \param grp ECP group
405 * \param d Destination MPI (secret part)
406 * \param Q Destination point (public part)
407 * \param f_rng RNG function
408 * \param p_rng RNG parameter
409 *
410 * \return 0 if successful,
411 * or a POLARSSL_ERR_ECP_XXX or POLARSSL_MPI_XXX error code
412 */
413int ecp_gen_keypair( const ecp_group *grp, mpi *d, ecp_point *Q,
414 int (*f_rng)(void *, unsigned char *, size_t),
415 void *p_rng );
416
417/**
Manuel Pégourié-Gonnard39d2adb2012-10-31 09:26:55 +0100418 * \brief Checkup routine
419 *
420 * \return 0 if successful, or 1 if the test failed
421 */
422int ecp_self_test( int verbose );
423
424#ifdef __cplusplus
425}
426#endif
427
428#endif