blob: 05f642343550cc45d67f8a2fcf26357f29f024a9 [file] [log] [blame]
Manuel Pégourié-Gonnard39d2adb2012-10-31 09:26:55 +01001/*
2 * Elliptic curves over GF(p)
3 *
4 * Copyright (C) 2012, Brainspark B.V.
5 *
6 * This file is part of PolarSSL (http://www.polarssl.org)
7 * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
8 *
9 * All rights reserved.
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License along
22 * with this program; if not, write to the Free Software Foundation, Inc.,
23 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 */
25
26/*
27 * References:
28 *
Manuel Pégourié-Gonnard883f3132012-11-02 09:40:25 +010029 * SEC1 http://www.secg.org/index.php?action=secg,docs_secg
Manuel Pégourié-Gonnardd070f512012-11-08 17:40:51 +010030 * GECC = Guide to Elliptic Curve Cryptography - Hankerson, Menezes, Vanstone
Manuel Pégourié-Gonnard62aad142012-11-10 00:27:12 +010031 * FIPS 186-3 http://csrc.nist.gov/publications/fips/fips186-3/fips_186-3.pdf
Manuel Pégourié-Gonnard39d2adb2012-10-31 09:26:55 +010032 */
33
34#include "polarssl/config.h"
35
36#if defined(POLARSSL_ECP_C)
37
38#include "polarssl/ecp.h"
Manuel Pégourié-Gonnard84338242012-11-11 20:45:18 +010039#include <limits.h>
Manuel Pégourié-Gonnard39d2adb2012-10-31 09:26:55 +010040
Manuel Pégourié-Gonnardb4a310b2012-11-13 20:57:00 +010041#if defined(POLARSSL_SELF_TEST)
42/*
43 * Counts of point addition and doubling operations.
44 * Used to test resistance of point multiplication to SPA/timing attacks.
45 */
46unsigned long add_count, dbl_count;
47#endif
48
Manuel Pégourié-Gonnard1e8c8ec2012-10-31 19:24:21 +010049/*
Manuel Pégourié-Gonnardb505c272012-11-05 17:27:54 +010050 * Initialize (the components of) a point
Manuel Pégourié-Gonnardae180d02012-11-02 18:14:40 +010051 */
52void ecp_point_init( ecp_point *pt )
53{
54 if( pt == NULL )
55 return;
56
Manuel Pégourié-Gonnardb505c272012-11-05 17:27:54 +010057 mpi_init( &pt->X );
58 mpi_init( &pt->Y );
Manuel Pégourié-Gonnard1c2782c2012-11-19 20:16:28 +010059 mpi_init( &pt->Z );
Manuel Pégourié-Gonnardb505c272012-11-05 17:27:54 +010060}
61
62/*
63 * Initialize (the components of) a group
64 */
65void ecp_group_init( ecp_group *grp )
66{
67 if( grp == NULL )
68 return;
69
70 mpi_init( &grp->P );
71 mpi_init( &grp->B );
72 ecp_point_init( &grp->G );
73 mpi_init( &grp->N );
Manuel Pégourié-Gonnard62aad142012-11-10 00:27:12 +010074
Manuel Pégourié-Gonnard62aad142012-11-10 00:27:12 +010075 grp->pbits = 0;
Manuel Pégourié-Gonnard773ed542012-11-18 13:19:07 +010076 grp->nbits = 0;
77
78 grp->modp = NULL;
Manuel Pégourié-Gonnardae180d02012-11-02 18:14:40 +010079}
80
81/*
Manuel Pégourié-Gonnard1e8c8ec2012-10-31 19:24:21 +010082 * Unallocate (the components of) a point
83 */
84void ecp_point_free( ecp_point *pt )
85{
86 if( pt == NULL )
87 return;
88
89 mpi_free( &( pt->X ) );
90 mpi_free( &( pt->Y ) );
Manuel Pégourié-Gonnard1c2782c2012-11-19 20:16:28 +010091 mpi_free( &( pt->Z ) );
Manuel Pégourié-Gonnard1e8c8ec2012-10-31 19:24:21 +010092}
93
94/*
95 * Unallocate (the components of) a group
96 */
97void ecp_group_free( ecp_group *grp )
98{
99 if( grp == NULL )
100 return;
101
Manuel Pégourié-Gonnard883f3132012-11-02 09:40:25 +0100102 mpi_free( &grp->P );
103 mpi_free( &grp->B );
104 ecp_point_free( &grp->G );
105 mpi_free( &grp->N );
Manuel Pégourié-Gonnard1e8c8ec2012-10-31 19:24:21 +0100106}
Manuel Pégourié-Gonnard39d2adb2012-10-31 09:26:55 +0100107
Manuel Pégourié-Gonnard883f3132012-11-02 09:40:25 +0100108/*
Manuel Pégourié-Gonnardae180d02012-11-02 18:14:40 +0100109 * Set point to zero
110 */
Manuel Pégourié-Gonnard1c2782c2012-11-19 20:16:28 +0100111int ecp_set_zero( ecp_point *pt )
Manuel Pégourié-Gonnardae180d02012-11-02 18:14:40 +0100112{
Manuel Pégourié-Gonnard1c2782c2012-11-19 20:16:28 +0100113 int ret;
114
115 MPI_CHK( mpi_lset( &pt->X , 1 ) );
116 MPI_CHK( mpi_lset( &pt->Y , 1 ) );
117 MPI_CHK( mpi_lset( &pt->Z , 0 ) );
118
119cleanup:
120 return( ret );
Manuel Pégourié-Gonnardae180d02012-11-02 18:14:40 +0100121}
122
123/*
Manuel Pégourié-Gonnard883f3132012-11-02 09:40:25 +0100124 * Copy the contents of Q into P
125 */
126int ecp_copy( ecp_point *P, const ecp_point *Q )
127{
Manuel Pégourié-Gonnard47123252012-11-10 14:44:24 +0100128 int ret;
Manuel Pégourié-Gonnard883f3132012-11-02 09:40:25 +0100129
Manuel Pégourié-Gonnard883f3132012-11-02 09:40:25 +0100130 MPI_CHK( mpi_copy( &P->X, &Q->X ) );
131 MPI_CHK( mpi_copy( &P->Y, &Q->Y ) );
Manuel Pégourié-Gonnard1c2782c2012-11-19 20:16:28 +0100132 MPI_CHK( mpi_copy( &P->Z, &Q->Z ) );
Manuel Pégourié-Gonnard883f3132012-11-02 09:40:25 +0100133
134cleanup:
135 return( ret );
136}
Manuel Pégourié-Gonnard5179e462012-10-31 19:37:54 +0100137
Manuel Pégourié-Gonnardae180d02012-11-02 18:14:40 +0100138/*
Manuel Pégourié-Gonnard847395a2012-11-05 13:13:44 +0100139 * Import a non-zero point from ASCII strings
140 */
141int ecp_point_read_string( ecp_point *P, int radix,
142 const char *x, const char *y )
143{
Manuel Pégourié-Gonnard47123252012-11-10 14:44:24 +0100144 int ret;
Manuel Pégourié-Gonnard847395a2012-11-05 13:13:44 +0100145
Manuel Pégourié-Gonnard847395a2012-11-05 13:13:44 +0100146 MPI_CHK( mpi_read_string( &P->X, radix, x ) );
147 MPI_CHK( mpi_read_string( &P->Y, radix, y ) );
Manuel Pégourié-Gonnard1c2782c2012-11-19 20:16:28 +0100148 MPI_CHK( mpi_lset( &P->Z, 1 ) );
Manuel Pégourié-Gonnard847395a2012-11-05 13:13:44 +0100149
150cleanup:
151 return( ret );
152}
153
154/*
155 * Import an ECP group from ASCII strings
156 */
157int ecp_group_read_string( ecp_group *grp, int radix,
158 const char *p, const char *b,
159 const char *gx, const char *gy, const char *n)
160{
Manuel Pégourié-Gonnard47123252012-11-10 14:44:24 +0100161 int ret;
Manuel Pégourié-Gonnard847395a2012-11-05 13:13:44 +0100162
163 MPI_CHK( mpi_read_string( &grp->P, radix, p ) );
164 MPI_CHK( mpi_read_string( &grp->B, radix, b ) );
165 MPI_CHK( ecp_point_read_string( &grp->G, radix, gx, gy ) );
166 MPI_CHK( mpi_read_string( &grp->N, radix, n ) );
167
Manuel Pégourié-Gonnard773ed542012-11-18 13:19:07 +0100168 grp->pbits = mpi_msb( &grp->P );
169 grp->nbits = mpi_msb( &grp->N );
170
Manuel Pégourié-Gonnard847395a2012-11-05 13:13:44 +0100171cleanup:
172 return( ret );
173}
174
Manuel Pégourié-Gonnarda5402fe2012-11-07 20:24:05 +0100175/*
Manuel Pégourié-Gonnard773ed542012-11-18 13:19:07 +0100176 * Wrapper around fast quasi-modp functions, with fall-back to mpi_mod_mpi.
177 * See the documentation of struct ecp_group.
Manuel Pégourié-Gonnard62aad142012-11-10 00:27:12 +0100178 */
179static int ecp_modp( mpi *N, const ecp_group *grp )
180{
Manuel Pégourié-Gonnard47123252012-11-10 14:44:24 +0100181 int ret;
Manuel Pégourié-Gonnard62aad142012-11-10 00:27:12 +0100182
183 if( grp->modp == NULL )
184 return( mpi_mod_mpi( N, N, &grp->P ) );
185
186 if( mpi_cmp_int( N, 0 ) < 0 || mpi_msb( N ) > 2 * grp->pbits )
187 return( POLARSSL_ERR_ECP_GENERIC );
188
189 MPI_CHK( grp->modp( N ) );
190
191 while( mpi_cmp_int( N, 0 ) < 0 )
192 MPI_CHK( mpi_add_mpi( N, N, &grp->P ) );
193
194 while( mpi_cmp_mpi( N, &grp->P ) >= 0 )
195 MPI_CHK( mpi_sub_mpi( N, N, &grp->P ) );
196
197cleanup:
198 return( ret );
199}
200
201/*
Manuel Pégourié-Gonnard84338242012-11-11 20:45:18 +0100202 * 192 bits in terms of t_uint
203 */
204#define P192_SIZE_INT ( 192 / CHAR_BIT / sizeof( t_uint ) )
205
206/*
207 * Table to get S1, S2, S3 of FIPS 186-3 D.2.1:
208 * -1 means let this chunk be 0
209 * a positive value i means A_i.
210 */
211#define P192_CHUNKS 3
212#define P192_CHUNK_CHAR ( 64 / CHAR_BIT )
213#define P192_CHUNK_INT ( P192_CHUNK_CHAR / sizeof( t_uint ) )
214
215const signed char p192_tbl[][P192_CHUNKS] = {
216 { -1, 3, 3 }, /* S1 */
217 { 4, 4, -1 }, /* S2 */
218 { 5, 5, 5 }, /* S3 */
219};
220
221/*
222 * Fast quasi-reduction modulo p192 (FIPS 186-3 D.2.1)
223 */
224static int ecp_mod_p192( mpi *N )
225{
226 int ret;
227 unsigned char i, j, offset;
228 signed char chunk;
229 mpi tmp, acc;
230 t_uint tmp_p[P192_SIZE_INT], acc_p[P192_SIZE_INT + 1];
231
232 tmp.s = 1;
233 tmp.n = sizeof( tmp_p ) / sizeof( tmp_p[0] );
234 tmp.p = tmp_p;
235
236 acc.s = 1;
237 acc.n = sizeof( acc_p ) / sizeof( acc_p[0] );
238 acc.p = acc_p;
239
240 MPI_CHK( mpi_grow( N, P192_SIZE_INT * 2 ) );
241
242 /*
243 * acc = T
244 */
245 memset( acc_p, 0, sizeof( acc_p ) );
246 memcpy( acc_p, N->p, P192_CHUNK_CHAR * P192_CHUNKS );
247
248 for( i = 0; i < sizeof( p192_tbl ) / sizeof( p192_tbl[0] ); i++)
249 {
250 /*
251 * tmp = S_i
252 */
253 memset( tmp_p, 0, sizeof( tmp_p ) );
254 for( j = 0, offset = P192_CHUNKS - 1; j < P192_CHUNKS; j++, offset-- )
255 {
256 chunk = p192_tbl[i][j];
257 if( chunk >= 0 )
258 memcpy( tmp_p + offset * P192_CHUNK_INT,
259 N->p + chunk * P192_CHUNK_INT,
260 P192_CHUNK_CHAR );
261 }
262
263 /*
264 * acc += tmp
265 */
266 MPI_CHK( mpi_add_abs( &acc, &acc, &tmp ) );
267 }
268
269 MPI_CHK( mpi_copy( N, &acc ) );
270
271cleanup:
272 return( ret );
273}
274
275/*
Manuel Pégourié-Gonnard62aad142012-11-10 00:27:12 +0100276 * Size of p521 in terms of t_uint
277 */
Manuel Pégourié-Gonnard84338242012-11-11 20:45:18 +0100278#define P521_SIZE_INT ( 521 / CHAR_BIT / sizeof( t_uint ) + 1 )
Manuel Pégourié-Gonnard62aad142012-11-10 00:27:12 +0100279
280/*
281 * Bits to keep in the most significant t_uint
282 */
283#if defined(POLARSS_HAVE_INT8)
284#define P521_MASK 0x01
285#else
286#define P521_MASK 0x01FF
287#endif
288
289/*
290 * Fast quasi-reduction modulo p521 (FIPS 186-3 D.2.5)
Manuel Pégourié-Gonnard62aad142012-11-10 00:27:12 +0100291 */
292static int ecp_mod_p521( mpi *N )
293{
Manuel Pégourié-Gonnard47123252012-11-10 14:44:24 +0100294 int ret;
Manuel Pégourié-Gonnard62aad142012-11-10 00:27:12 +0100295 t_uint Mp[P521_SIZE_INT];
296 mpi M;
297
298 if( N->n < P521_SIZE_INT )
299 return( 0 );
300
301 memset( Mp, 0, P521_SIZE_INT * sizeof( t_uint ) );
302 memcpy( Mp, N->p, P521_SIZE_INT * sizeof( t_uint ) );
303 Mp[P521_SIZE_INT - 1] &= P521_MASK;
304
305 M.s = 1;
306 M.n = P521_SIZE_INT;
307 M.p = Mp;
308
309 MPI_CHK( mpi_shift_r( N, 521 ) );
310
311 MPI_CHK( mpi_add_abs( N, N, &M ) );
312
313cleanup:
314 return( ret );
315}
316
317/*
Manuel Pégourié-Gonnarddada4da2012-11-10 14:23:17 +0100318 * Domain parameters for secp192r1
319 */
320#define SECP192R1_P \
321 "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFFFFFFFFFF"
322#define SECP192R1_B \
323 "64210519E59C80E70FA7E9AB72243049FEB8DEECC146B9B1"
324#define SECP192R1_GX \
325 "188DA80EB03090F67CBF20EB43A18800F4FF0AFD82FF1012"
326#define SECP192R1_GY \
327 "07192B95FFC8DA78631011ED6B24CDD573F977A11E794811"
328#define SECP192R1_N \
329 "FFFFFFFFFFFFFFFFFFFFFFFF99DEF836146BC9B1B4D22831"
330
331/*
332 * Domain parameters for secp224r1
333 */
334#define SECP224R1_P \
335 "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF000000000000000000000001"
336#define SECP224R1_B \
337 "B4050A850C04B3ABF54132565044B0B7D7BFD8BA270B39432355FFB4"
338#define SECP224R1_GX \
339 "B70E0CBD6BB4BF7F321390B94A03C1D356C21122343280D6115C1D21"
340#define SECP224R1_GY \
341 "BD376388B5F723FB4C22DFE6CD4375A05A07476444D5819985007E34"
342#define SECP224R1_N \
343 "FFFFFFFFFFFFFFFFFFFFFFFFFFFF16A2E0B8F03E13DD29455C5C2A3D"
344
345/*
346 * Domain parameters for secp256r1
347 */
348#define SECP256R1_P \
349 "FFFFFFFF00000001000000000000000000000000FFFFFFFFFFFFFFFFFFFFFFFF"
350#define SECP256R1_B \
351 "5AC635D8AA3A93E7B3EBBD55769886BC651D06B0CC53B0F63BCE3C3E27D2604B"
352#define SECP256R1_GX \
353 "6B17D1F2E12C4247F8BCE6E563A440F277037D812DEB33A0F4A13945D898C296"
354#define SECP256R1_GY \
355 "4FE342E2FE1A7F9B8EE7EB4A7C0F9E162BCE33576B315ECECBB6406837BF51F5"
356#define SECP256R1_N \
357 "FFFFFFFF00000000FFFFFFFFFFFFFFFFBCE6FAADA7179E84F3B9CAC2FC632551"
358
359/*
360 * Domain parameters for secp384r1
361 */
362#define SECP384R1_P \
363 "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF" \
364 "FFFFFFFFFFFFFFFEFFFFFFFF0000000000000000FFFFFFFF"
365#define SECP384R1_B \
366 "B3312FA7E23EE7E4988E056BE3F82D19181D9C6EFE814112" \
367 "0314088F5013875AC656398D8A2ED19D2A85C8EDD3EC2AEF"
368#define SECP384R1_GX \
369 "AA87CA22BE8B05378EB1C71EF320AD746E1D3B628BA79B98" \
370 "59F741E082542A385502F25DBF55296C3A545E3872760AB7"
371#define SECP384R1_GY \
372 "3617DE4A96262C6F5D9E98BF9292DC29F8F41DBD289A147C" \
373 "E9DA3113B5F0B8C00A60B1CE1D7E819D7A431D7C90EA0E5F"
374#define SECP384R1_N \
375 "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF" \
376 "C7634D81F4372DDF581A0DB248B0A77AECEC196ACCC52973"
377
378/*
379 * Domain parameters for secp521r1
380 */
381#define SECP521R1_P \
382 "000001FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF" \
383 "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF" \
384 "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"
385#define SECP521R1_B \
386 "00000051953EB9618E1C9A1F929A21A0B68540EEA2DA725B" \
387 "99B315F3B8B489918EF109E156193951EC7E937B1652C0BD" \
388 "3BB1BF073573DF883D2C34F1EF451FD46B503F00"
389#define SECP521R1_GX \
390 "000000C6858E06B70404E9CD9E3ECB662395B4429C648139" \
391 "053FB521F828AF606B4D3DBAA14B5E77EFE75928FE1DC127" \
392 "A2FFA8DE3348B3C1856A429BF97E7E31C2E5BD66"
393#define SECP521R1_GY \
394 "0000011839296A789A3BC0045C8A5FB42C7D1BD998F54449" \
395 "579B446817AFBD17273E662C97EE72995EF42640C550B901" \
396 "3FAD0761353C7086A272C24088BE94769FD16650"
397#define SECP521R1_N \
398 "000001FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF" \
399 "FFFFFFFFFFFFFFFFFFFFFFFA51868783BF2F966B7FCC0148" \
400 "F709A5D03BB5C9B8899C47AEBB6FB71E91386409"
401
402/*
Manuel Pégourié-Gonnarda5402fe2012-11-07 20:24:05 +0100403 * Set a group using well-known domain parameters
404 */
405int ecp_use_known_dp( ecp_group *grp, size_t index )
406{
407 switch( index )
408 {
409 case POLARSSL_ECP_DP_SECP192R1:
Manuel Pégourié-Gonnard84338242012-11-11 20:45:18 +0100410 grp->modp = ecp_mod_p192;
Manuel Pégourié-Gonnarda5402fe2012-11-07 20:24:05 +0100411 return( ecp_group_read_string( grp, 16,
Manuel Pégourié-Gonnarddada4da2012-11-10 14:23:17 +0100412 SECP192R1_P, SECP192R1_B,
413 SECP192R1_GX, SECP192R1_GY, SECP192R1_N ) );
414
Manuel Pégourié-Gonnarda5402fe2012-11-07 20:24:05 +0100415 case POLARSSL_ECP_DP_SECP224R1:
416 return( ecp_group_read_string( grp, 16,
Manuel Pégourié-Gonnarddada4da2012-11-10 14:23:17 +0100417 SECP224R1_P, SECP224R1_B,
418 SECP224R1_GX, SECP224R1_GY, SECP224R1_N ) );
419
Manuel Pégourié-Gonnarda5402fe2012-11-07 20:24:05 +0100420 case POLARSSL_ECP_DP_SECP256R1:
421 return( ecp_group_read_string( grp, 16,
Manuel Pégourié-Gonnarddada4da2012-11-10 14:23:17 +0100422 SECP256R1_P, SECP256R1_B,
423 SECP256R1_GX, SECP256R1_GY, SECP256R1_N ) );
424
Manuel Pégourié-Gonnarda5402fe2012-11-07 20:24:05 +0100425 case POLARSSL_ECP_DP_SECP384R1:
426 return( ecp_group_read_string( grp, 16,
Manuel Pégourié-Gonnarddada4da2012-11-10 14:23:17 +0100427 SECP384R1_P, SECP384R1_B,
428 SECP384R1_GX, SECP384R1_GY, SECP384R1_N ) );
429
Manuel Pégourié-Gonnarda5402fe2012-11-07 20:24:05 +0100430 case POLARSSL_ECP_DP_SECP521R1:
Manuel Pégourié-Gonnard62aad142012-11-10 00:27:12 +0100431 grp->modp = ecp_mod_p521;
Manuel Pégourié-Gonnarda5402fe2012-11-07 20:24:05 +0100432 return( ecp_group_read_string( grp, 16,
Manuel Pégourié-Gonnarddada4da2012-11-10 14:23:17 +0100433 SECP521R1_P, SECP521R1_B,
434 SECP521R1_GX, SECP521R1_GY, SECP521R1_N ) );
Manuel Pégourié-Gonnarda5402fe2012-11-07 20:24:05 +0100435 }
436
437 return( POLARSSL_ERR_ECP_GENERIC );
438}
Manuel Pégourié-Gonnardab38b702012-11-05 17:34:55 +0100439
Manuel Pégourié-Gonnard847395a2012-11-05 13:13:44 +0100440/*
Manuel Pégourié-Gonnard47123252012-11-10 14:44:24 +0100441 * Fast mod-p functions expect their argument to be in the 0..p^2 range.
Manuel Pégourié-Gonnarddada4da2012-11-10 14:23:17 +0100442 *
Manuel Pégourié-Gonnard47123252012-11-10 14:44:24 +0100443 * In order to guarantee that, we need to ensure that operands of
444 * mpi_mul_mpi are in the 0..p range. So, after each operation we will
Manuel Pégourié-Gonnarddada4da2012-11-10 14:23:17 +0100445 * bring the result back to this range.
446 *
Manuel Pégourié-Gonnard47123252012-11-10 14:44:24 +0100447 * The following macros are shortcuts for doing that.
Manuel Pégourié-Gonnarddada4da2012-11-10 14:23:17 +0100448 */
449
450/*
Manuel Pégourié-Gonnard84d1aea2012-11-09 02:09:38 +0100451 * Reduce a mpi mod p in-place, general case, to use after mpi_mul_mpi
452 */
Manuel Pégourié-Gonnard62aad142012-11-10 00:27:12 +0100453#define MOD_MUL( N ) MPI_CHK( ecp_modp( &N, grp ) )
Manuel Pégourié-Gonnard84d1aea2012-11-09 02:09:38 +0100454
455/*
456 * Reduce a mpi mod p in-place, to use after mpi_sub_mpi
457 */
458#define MOD_SUB( N ) \
459 while( mpi_cmp_int( &N, 0 ) < 0 ) \
460 MPI_CHK( mpi_add_mpi( &N, &N, &grp->P ) )
461
462/*
463 * Reduce a mpi mod p in-place, to use after mpi_add_mpi and mpi_mul_int
464 */
465#define MOD_ADD( N ) \
466 while( mpi_cmp_mpi( &N, &grp->P ) >= 0 ) \
467 MPI_CHK( mpi_sub_mpi( &N, &N, &grp->P ) )
468
469/*
Manuel Pégourié-Gonnard1c2782c2012-11-19 20:16:28 +0100470 * Normalize jacobian coordinates so that Z == 0 || Z == 1 (GECC 3.2.1)
Manuel Pégourié-Gonnardd070f512012-11-08 17:40:51 +0100471 */
Manuel Pégourié-Gonnard1c2782c2012-11-19 20:16:28 +0100472static int ecp_normalize( const ecp_group *grp, ecp_point *pt )
Manuel Pégourié-Gonnardd070f512012-11-08 17:40:51 +0100473{
Manuel Pégourié-Gonnard47123252012-11-10 14:44:24 +0100474 int ret;
Manuel Pégourié-Gonnardd070f512012-11-08 17:40:51 +0100475 mpi Zi, ZZi, T;
476
Manuel Pégourié-Gonnard1c2782c2012-11-19 20:16:28 +0100477 if( mpi_cmp_int( &pt->Z, 0 ) == 0 )
Manuel Pégourié-Gonnardd070f512012-11-08 17:40:51 +0100478 return( 0 );
Manuel Pégourié-Gonnardd070f512012-11-08 17:40:51 +0100479
480 mpi_init( &Zi ); mpi_init( &ZZi ); mpi_init( &T );
481
Manuel Pégourié-Gonnard1c2782c2012-11-19 20:16:28 +0100482 /*
483 * X = X / Z^2 mod p
484 */
485 MPI_CHK( mpi_inv_mod( &Zi, &pt->Z, &grp->P ) );
486 MPI_CHK( mpi_mul_mpi( &ZZi, &Zi, &Zi ) ); MOD_MUL( ZZi );
487 MPI_CHK( mpi_mul_mpi( &pt->X, &pt->X, &ZZi ) ); MOD_MUL( pt->X );
Manuel Pégourié-Gonnardd070f512012-11-08 17:40:51 +0100488
489 /*
Manuel Pégourié-Gonnard1c2782c2012-11-19 20:16:28 +0100490 * Y = Y / Z^3 mod p
Manuel Pégourié-Gonnardd070f512012-11-08 17:40:51 +0100491 */
Manuel Pégourié-Gonnard1c2782c2012-11-19 20:16:28 +0100492 MPI_CHK( mpi_mul_mpi( &pt->Y, &pt->Y, &ZZi ) ); MOD_MUL( pt->Y );
493 MPI_CHK( mpi_mul_mpi( &pt->Y, &pt->Y, &Zi ) ); MOD_MUL( pt->Y );
Manuel Pégourié-Gonnardd070f512012-11-08 17:40:51 +0100494
495 /*
Manuel Pégourié-Gonnard1c2782c2012-11-19 20:16:28 +0100496 * Z = 1
Manuel Pégourié-Gonnardd070f512012-11-08 17:40:51 +0100497 */
Manuel Pégourié-Gonnard1c2782c2012-11-19 20:16:28 +0100498 MPI_CHK( mpi_lset( &pt->Z, 1 ) );
Manuel Pégourié-Gonnardd070f512012-11-08 17:40:51 +0100499
500cleanup:
501
502 mpi_free( &Zi ); mpi_free( &ZZi ); mpi_free( &T );
503
504 return( ret );
505}
506
507/*
Manuel Pégourié-Gonnard989c32b2012-11-08 22:02:42 +0100508 * Point doubling R = 2 P, Jacobian coordinates (GECC 3.21)
509 */
Manuel Pégourié-Gonnard1c2782c2012-11-19 20:16:28 +0100510static int ecp_double_jac( const ecp_group *grp, ecp_point *R,
511 const ecp_point *P )
Manuel Pégourié-Gonnard989c32b2012-11-08 22:02:42 +0100512{
Manuel Pégourié-Gonnard47123252012-11-10 14:44:24 +0100513 int ret;
Manuel Pégourié-Gonnard989c32b2012-11-08 22:02:42 +0100514 mpi T1, T2, T3, X, Y, Z;
515
Manuel Pégourié-Gonnardb4a310b2012-11-13 20:57:00 +0100516#if defined(POLARSSL_SELF_TEST)
517 dbl_count++;
518#endif
519
Manuel Pégourié-Gonnard7e0adfb2012-11-08 23:21:46 +0100520 if( mpi_cmp_int( &P->Z, 0 ) == 0 )
Manuel Pégourié-Gonnard1c2782c2012-11-19 20:16:28 +0100521 return( ecp_set_zero( R ) );
Manuel Pégourié-Gonnard7e0adfb2012-11-08 23:21:46 +0100522
Manuel Pégourié-Gonnard989c32b2012-11-08 22:02:42 +0100523 mpi_init( &T1 ); mpi_init( &T2 ); mpi_init( &T3 );
524 mpi_init( &X ); mpi_init( &Y ); mpi_init( &Z );
525
Manuel Pégourié-Gonnard47123252012-11-10 14:44:24 +0100526 MPI_CHK( mpi_mul_mpi( &T1, &P->Z, &P->Z ) ); MOD_MUL( T1 );
527 MPI_CHK( mpi_sub_mpi( &T2, &P->X, &T1 ) ); MOD_SUB( T2 );
528 MPI_CHK( mpi_add_mpi( &T1, &P->X, &T1 ) ); MOD_ADD( T1 );
529 MPI_CHK( mpi_mul_mpi( &T2, &T2, &T1 ) ); MOD_MUL( T2 );
530 MPI_CHK( mpi_mul_int( &T2, &T2, 3 ) ); MOD_ADD( T2 );
531 MPI_CHK( mpi_mul_int( &Y, &P->Y, 2 ) ); MOD_ADD( Y );
532 MPI_CHK( mpi_mul_mpi( &Z, &Y, &P->Z ) ); MOD_MUL( Z );
533 MPI_CHK( mpi_mul_mpi( &Y, &Y, &Y ) ); MOD_MUL( Y );
534 MPI_CHK( mpi_mul_mpi( &T3, &Y, &P->X ) ); MOD_MUL( T3 );
535 MPI_CHK( mpi_mul_mpi( &Y, &Y, &Y ) ); MOD_MUL( Y );
Manuel Pégourié-Gonnard989c32b2012-11-08 22:02:42 +0100536
Manuel Pégourié-Gonnard84d1aea2012-11-09 02:09:38 +0100537 /*
538 * For Y = Y / 2 mod p, we must make sure that Y is even before
539 * using right-shift. No need to reduce mod p afterwards.
540 */
541 if( mpi_get_bit( &Y, 0 ) == 1 )
542 MPI_CHK( mpi_add_mpi( &Y, &Y, &grp->P ) );
543 MPI_CHK( mpi_shift_r( &Y, 1 ) );
544
Manuel Pégourié-Gonnard47123252012-11-10 14:44:24 +0100545 MPI_CHK( mpi_mul_mpi( &X, &T2, &T2 ) ); MOD_MUL( X );
546 MPI_CHK( mpi_mul_int( &T1, &T3, 2 ) ); MOD_ADD( T1 );
547 MPI_CHK( mpi_sub_mpi( &X, &X, &T1 ) ); MOD_SUB( X );
548 MPI_CHK( mpi_sub_mpi( &T1, &T3, &X ) ); MOD_SUB( T1 );
549 MPI_CHK( mpi_mul_mpi( &T1, &T1, &T2 ) ); MOD_MUL( T1 );
550 MPI_CHK( mpi_sub_mpi( &Y, &T1, &Y ) ); MOD_SUB( Y );
Manuel Pégourié-Gonnard84d1aea2012-11-09 02:09:38 +0100551
552 MPI_CHK( mpi_copy( &R->X, &X ) );
553 MPI_CHK( mpi_copy( &R->Y, &Y ) );
554 MPI_CHK( mpi_copy( &R->Z, &Z ) );
Manuel Pégourié-Gonnard989c32b2012-11-08 22:02:42 +0100555
556cleanup:
557
558 mpi_free( &T1 ); mpi_free( &T2 ); mpi_free( &T3 );
559 mpi_free( &X ); mpi_free( &Y ); mpi_free( &Z );
560
561 return( ret );
562}
563
564/*
Manuel Pégourié-Gonnard9674fd02012-11-19 21:23:27 +0100565 * Addition or subtraction: R = P + Q or R = P + Q,
566 * mixed affine-Jacobian coordinates (GECC 3.22)
567 *
568 * The coordinates of Q must be normalized (= affine),
569 * but those of P don't need to. R is not normalized.
570 *
571 * If sign >= 0, perform addition, otherwise perform subtraction,
572 * taking advantage of the fact that, for Q != 0, we have
573 * -Q = (Q.X, -Q.Y, Q.Z)
Manuel Pégourié-Gonnardae180d02012-11-02 18:14:40 +0100574 */
Manuel Pégourié-Gonnard1c2782c2012-11-19 20:16:28 +0100575static int ecp_add_mixed( const ecp_group *grp, ecp_point *R,
Manuel Pégourié-Gonnard9674fd02012-11-19 21:23:27 +0100576 const ecp_point *P, const ecp_point *Q,
577 signed char sign )
Manuel Pégourié-Gonnardae180d02012-11-02 18:14:40 +0100578{
Manuel Pégourié-Gonnard47123252012-11-10 14:44:24 +0100579 int ret;
Manuel Pégourié-Gonnard7e0adfb2012-11-08 23:21:46 +0100580 mpi T1, T2, T3, T4, X, Y, Z;
Manuel Pégourié-Gonnardae180d02012-11-02 18:14:40 +0100581
Manuel Pégourié-Gonnardb4a310b2012-11-13 20:57:00 +0100582#if defined(POLARSSL_SELF_TEST)
583 add_count++;
584#endif
585
Manuel Pégourié-Gonnardae180d02012-11-02 18:14:40 +0100586 /*
Manuel Pégourié-Gonnard7e0adfb2012-11-08 23:21:46 +0100587 * Trivial cases: P == 0 or Q == 0
Manuel Pégourié-Gonnard9674fd02012-11-19 21:23:27 +0100588 * (Check Q first, so that we know Q != 0 when we compute -Q.)
Manuel Pégourié-Gonnardae180d02012-11-02 18:14:40 +0100589 */
Manuel Pégourié-Gonnard1c2782c2012-11-19 20:16:28 +0100590 if( mpi_cmp_int( &Q->Z, 0 ) == 0 )
591 return( ecp_copy( R, P ) );
592
Manuel Pégourié-Gonnard9674fd02012-11-19 21:23:27 +0100593 if( mpi_cmp_int( &P->Z, 0 ) == 0 )
594 {
595 ret = ecp_copy( R, Q );
596
597 /*
598 * -R.Y mod P = P - R.Y unless R.Y == 0
599 */
600 if( ret == 0 && sign < 0)
601 if( mpi_cmp_int( &R->Y, 0 ) != 0 )
602 ret = mpi_sub_mpi( &R->Y, &grp->P, &R->Y );
603
604 return( ret );
605 }
606
Manuel Pégourié-Gonnard1c2782c2012-11-19 20:16:28 +0100607 /*
608 * Make sure Q coordinates are normalized
609 */
610 if( mpi_cmp_int( &Q->Z, 1 ) != 0 )
611 return( POLARSSL_ERR_ECP_GENERIC );
Manuel Pégourié-Gonnardae180d02012-11-02 18:14:40 +0100612
Manuel Pégourié-Gonnard7e0adfb2012-11-08 23:21:46 +0100613 mpi_init( &T1 ); mpi_init( &T2 ); mpi_init( &T3 ); mpi_init( &T4 );
614 mpi_init( &X ); mpi_init( &Y ); mpi_init( &Z );
Manuel Pégourié-Gonnardab38b702012-11-05 17:34:55 +0100615
Manuel Pégourié-Gonnard47123252012-11-10 14:44:24 +0100616 MPI_CHK( mpi_mul_mpi( &T1, &P->Z, &P->Z ) ); MOD_MUL( T1 );
617 MPI_CHK( mpi_mul_mpi( &T2, &T1, &P->Z ) ); MOD_MUL( T2 );
618 MPI_CHK( mpi_mul_mpi( &T1, &T1, &Q->X ) ); MOD_MUL( T1 );
619 MPI_CHK( mpi_mul_mpi( &T2, &T2, &Q->Y ) ); MOD_MUL( T2 );
Manuel Pégourié-Gonnard9674fd02012-11-19 21:23:27 +0100620
621 /*
622 * For subtraction, -Q.Y should have been used instead of Q.Y,
623 * so we replace T2 by -T2, which is P - T2 mod P
624 */
625 if( sign < 0 )
626 {
627 MPI_CHK( mpi_sub_mpi( &T2, &grp->P, &T2 ) );
628 MOD_SUB( T2 );
629 }
630
Manuel Pégourié-Gonnard47123252012-11-10 14:44:24 +0100631 MPI_CHK( mpi_sub_mpi( &T1, &T1, &P->X ) ); MOD_SUB( T1 );
632 MPI_CHK( mpi_sub_mpi( &T2, &T2, &P->Y ) ); MOD_SUB( T2 );
Manuel Pégourié-Gonnardae180d02012-11-02 18:14:40 +0100633
Manuel Pégourié-Gonnard7e0adfb2012-11-08 23:21:46 +0100634 if( mpi_cmp_int( &T1, 0 ) == 0 )
635 {
636 if( mpi_cmp_int( &T2, 0 ) == 0 )
637 {
638 ret = ecp_double_jac( grp, R, P );
639 goto cleanup;
640 }
641 else
642 {
Manuel Pégourié-Gonnard1c2782c2012-11-19 20:16:28 +0100643 ret = ecp_set_zero( R );
Manuel Pégourié-Gonnard7e0adfb2012-11-08 23:21:46 +0100644 goto cleanup;
645 }
646 }
647
Manuel Pégourié-Gonnard47123252012-11-10 14:44:24 +0100648 MPI_CHK( mpi_mul_mpi( &Z, &P->Z, &T1 ) ); MOD_MUL( Z );
649 MPI_CHK( mpi_mul_mpi( &T3, &T1, &T1 ) ); MOD_MUL( T3 );
650 MPI_CHK( mpi_mul_mpi( &T4, &T3, &T1 ) ); MOD_MUL( T4 );
651 MPI_CHK( mpi_mul_mpi( &T3, &T3, &P->X ) ); MOD_MUL( T3 );
652 MPI_CHK( mpi_mul_int( &T1, &T3, 2 ) ); MOD_ADD( T1 );
653 MPI_CHK( mpi_mul_mpi( &X, &T2, &T2 ) ); MOD_MUL( X );
654 MPI_CHK( mpi_sub_mpi( &X, &X, &T1 ) ); MOD_SUB( X );
655 MPI_CHK( mpi_sub_mpi( &X, &X, &T4 ) ); MOD_SUB( X );
656 MPI_CHK( mpi_sub_mpi( &T3, &T3, &X ) ); MOD_SUB( T3 );
657 MPI_CHK( mpi_mul_mpi( &T3, &T3, &T2 ) ); MOD_MUL( T3 );
658 MPI_CHK( mpi_mul_mpi( &T4, &T4, &P->Y ) ); MOD_MUL( T4 );
659 MPI_CHK( mpi_sub_mpi( &Y, &T3, &T4 ) ); MOD_SUB( Y );
Manuel Pégourié-Gonnard7e0adfb2012-11-08 23:21:46 +0100660
Manuel Pégourié-Gonnard84d1aea2012-11-09 02:09:38 +0100661 MPI_CHK( mpi_copy( &R->X, &X ) );
662 MPI_CHK( mpi_copy( &R->Y, &Y ) );
663 MPI_CHK( mpi_copy( &R->Z, &Z ) );
Manuel Pégourié-Gonnardae180d02012-11-02 18:14:40 +0100664
665cleanup:
666
Manuel Pégourié-Gonnard7e0adfb2012-11-08 23:21:46 +0100667 mpi_free( &T1 ); mpi_free( &T2 ); mpi_free( &T3 ); mpi_free( &T4 );
668 mpi_free( &X ); mpi_free( &Y ); mpi_free( &Z );
Manuel Pégourié-Gonnardae180d02012-11-02 18:14:40 +0100669
670 return( ret );
671}
672
673/*
Manuel Pégourié-Gonnard1c2782c2012-11-19 20:16:28 +0100674 * Addition: R = P + Q, result's coordinates normalized
Manuel Pégourié-Gonnardae180d02012-11-02 18:14:40 +0100675 */
676int ecp_add( const ecp_group *grp, ecp_point *R,
677 const ecp_point *P, const ecp_point *Q )
678{
Manuel Pégourié-Gonnard47123252012-11-10 14:44:24 +0100679 int ret;
Manuel Pégourié-Gonnard989c32b2012-11-08 22:02:42 +0100680
Manuel Pégourié-Gonnard9674fd02012-11-19 21:23:27 +0100681 MPI_CHK( ecp_add_mixed( grp, R, P, Q , 1 ) );
682 MPI_CHK( ecp_normalize( grp, R ) );
683
684cleanup:
685 return( ret );
686}
687
688/*
689 * Subtraction: R = P - Q, result's coordinates normalized
690 */
691int ecp_sub( const ecp_group *grp, ecp_point *R,
692 const ecp_point *P, const ecp_point *Q )
693{
694 int ret;
695
696 MPI_CHK( ecp_add_mixed( grp, R, P, Q, -1 ) );
Manuel Pégourié-Gonnard1c2782c2012-11-19 20:16:28 +0100697 MPI_CHK( ecp_normalize( grp, R ) );
Manuel Pégourié-Gonnardae180d02012-11-02 18:14:40 +0100698
Manuel Pégourié-Gonnard989c32b2012-11-08 22:02:42 +0100699cleanup:
Manuel Pégourié-Gonnard7e0adfb2012-11-08 23:21:46 +0100700 return( ret );
Manuel Pégourié-Gonnardae180d02012-11-02 18:14:40 +0100701}
702
Manuel Pégourié-Gonnardefaa31e2012-11-06 21:34:35 +0100703/*
Manuel Pégourié-Gonnard4bdd47d2012-11-11 14:33:59 +0100704 * Integer multiplication: R = m * P (GECC 5.7, SPA-resistant)
Manuel Pégourié-Gonnardefaa31e2012-11-06 21:34:35 +0100705 */
706int ecp_mul( const ecp_group *grp, ecp_point *R,
707 const mpi *m, const ecp_point *P )
708{
Manuel Pégourié-Gonnard4bdd47d2012-11-11 14:33:59 +0100709 int ret, cmp;
Manuel Pégourié-Gonnardefaa31e2012-11-06 21:34:35 +0100710 size_t pos;
Manuel Pégourié-Gonnard1c2782c2012-11-19 20:16:28 +0100711 ecp_point Q[2];
Manuel Pégourié-Gonnardefaa31e2012-11-06 21:34:35 +0100712
Manuel Pégourié-Gonnard4bdd47d2012-11-11 14:33:59 +0100713 cmp = mpi_cmp_int( m, 0 );
714
715 if( cmp < 0 )
716 return( POLARSSL_ERR_ECP_GENERIC );
717
Manuel Pégourié-Gonnardefaa31e2012-11-06 21:34:35 +0100718 /*
Manuel Pégourié-Gonnard4bdd47d2012-11-11 14:33:59 +0100719 * The general method works only for m != 0
Manuel Pégourié-Gonnardefaa31e2012-11-06 21:34:35 +0100720 */
Manuel Pégourié-Gonnard4bdd47d2012-11-11 14:33:59 +0100721 if( cmp == 0 ) {
Manuel Pégourié-Gonnard1c2782c2012-11-19 20:16:28 +0100722 return( ecp_set_zero( R ) );
Manuel Pégourié-Gonnardefaa31e2012-11-06 21:34:35 +0100723 }
724
Manuel Pégourié-Gonnard1c2782c2012-11-19 20:16:28 +0100725 ecp_point_init( &Q[0] ); ecp_point_init( &Q[1] );
Manuel Pégourié-Gonnard47123252012-11-10 14:44:24 +0100726
Manuel Pégourié-Gonnard1c2782c2012-11-19 20:16:28 +0100727 MPI_CHK( ecp_set_zero( &Q[0] ) );
Manuel Pégourié-Gonnardefaa31e2012-11-06 21:34:35 +0100728
Manuel Pégourié-Gonnard989c32b2012-11-08 22:02:42 +0100729 for( pos = mpi_msb( m ) - 1 ; ; pos-- )
Manuel Pégourié-Gonnardefaa31e2012-11-06 21:34:35 +0100730 {
Manuel Pégourié-Gonnarde0c16922012-11-08 23:27:28 +0100731 MPI_CHK( ecp_double_jac( grp, &Q[0], &Q[0] ) );
Manuel Pégourié-Gonnard9674fd02012-11-19 21:23:27 +0100732 MPI_CHK( ecp_add_mixed( grp, &Q[1], &Q[0], P, 1 ) );
Manuel Pégourié-Gonnard1c2782c2012-11-19 20:16:28 +0100733 MPI_CHK( ecp_copy( &Q[0], &Q[ mpi_get_bit( m, pos ) ] ) );
Manuel Pégourié-Gonnardefaa31e2012-11-06 21:34:35 +0100734
735 if( pos == 0 )
736 break;
737 }
738
Manuel Pégourié-Gonnard1c2782c2012-11-19 20:16:28 +0100739 MPI_CHK( ecp_copy( R, &Q[0] ) );
740 MPI_CHK( ecp_normalize( grp, R ) );
Manuel Pégourié-Gonnardefaa31e2012-11-06 21:34:35 +0100741
742cleanup:
743
Manuel Pégourié-Gonnard1c2782c2012-11-19 20:16:28 +0100744 ecp_point_free( &Q[0] ); ecp_point_free( &Q[1] );
Manuel Pégourié-Gonnardefaa31e2012-11-06 21:34:35 +0100745
746 return( ret );
747}
748
749
Manuel Pégourié-Gonnard39d2adb2012-10-31 09:26:55 +0100750#if defined(POLARSSL_SELF_TEST)
751
Manuel Pégourié-Gonnardb505c272012-11-05 17:27:54 +0100752/*
Manuel Pégourié-Gonnard39d2adb2012-10-31 09:26:55 +0100753 * Checkup routine
754 */
755int ecp_self_test( int verbose )
756{
Manuel Pégourié-Gonnardb4a310b2012-11-13 20:57:00 +0100757 int ret;
758 size_t i;
759 ecp_group grp;
760 ecp_point R;
761 mpi m;
762 unsigned long add_c_prev, dbl_c_prev;
763 char *exponents[] =
764 {
765 "400000000000000000000000000000000000000000000000",
766 "7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF",
767 "555555555555555555555555555555555555555555555555",
768 "5EA6F389A38B8BC81E767753B15AA5569E1782E30ABE7D25",
769 "000000000000000000000000000000000000000000000010",
770 };
771
772 ecp_group_init( &grp );
773 ecp_point_init( &R );
774 mpi_init( &m );
775
776 MPI_CHK( ecp_use_known_dp( &grp, POLARSSL_ECP_DP_SECP192R1 ) );
777
778 if( verbose != 0 )
779 printf( " ECP test #1 (SPA resistance): " );
780
781 add_count = 0;
782 dbl_count = 0;
783 MPI_CHK( mpi_read_string( &m, 16, exponents[0] ) );
784 MPI_CHK( ecp_mul( &grp, &R, &m, &grp.G ) );
785
786 for( i = 1; i < sizeof( exponents ) / sizeof( exponents[0] ); i++ )
787 {
788 add_c_prev = add_count;
789 dbl_c_prev = dbl_count;
790 add_count = 0;
791 dbl_count = 0;
792
793 MPI_CHK( mpi_read_string( &m, 16, exponents[i] ) );
794 MPI_CHK( ecp_mul( &grp, &R, &m, &grp.G ) );
795
796 if( add_count != add_c_prev || dbl_count != dbl_c_prev )
797 {
798 if( verbose != 0 )
799 printf( "failed (%zu)\n", i );
800
801 ret = 1;
802 goto cleanup;
803 }
804 }
805
806 if( verbose != 0 )
807 printf( "passed\n" );
808
809cleanup:
810
811 if( ret < 0 && verbose != 0 )
812 printf( "Unexpected error, return code = %08X\n", ret );
813
814 ecp_group_free( &grp );
815 ecp_point_free( &R );
816 mpi_free( &m );
817
818 if( verbose != 0 )
819 printf( "\n" );
820
821 return( ret );
Manuel Pégourié-Gonnard39d2adb2012-10-31 09:26:55 +0100822}
823
824#endif
825
826#endif