xref: /illumos-gate/usr/src/common/crypto/ecc/ec2_test.c (revision 8119dad84d6416f13557b0ba8e2aaf9064cbcfd3)
1 /*
2  * ***** BEGIN LICENSE BLOCK *****
3  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4  *
5  * The contents of this file are subject to the Mozilla Public License Version
6  * 1.1 (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  * http://www.mozilla.org/MPL/
9  *
10  * Software distributed under the License is distributed on an "AS IS" basis,
11  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12  * for the specific language governing rights and limitations under the
13  * License.
14  *
15  * The Original Code is the elliptic curve math library for binary polynomial field curves.
16  *
17  * The Initial Developer of the Original Code is
18  * Sun Microsystems, Inc.
19  * Portions created by the Initial Developer are Copyright (C) 2003
20  * the Initial Developer. All Rights Reserved.
21  *
22  * Contributor(s):
23  *   Douglas Stebila <douglas@stebila.ca>, Sun Microsystems Laboratories
24  *
25  * Alternatively, the contents of this file may be used under the terms of
26  * either the GNU General Public License Version 2 or later (the "GPL"), or
27  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28  * in which case the provisions of the GPL or the LGPL are applicable instead
29  * of those above. If you wish to allow use of your version of this file only
30  * under the terms of either the GPL or the LGPL, and not to allow others to
31  * use your version of this file under the terms of the MPL, indicate your
32  * decision by deleting the provisions above and replace them with the notice
33  * and other provisions required by the GPL or the LGPL. If you do not delete
34  * the provisions above, a recipient may use your version of this file under
35  * the terms of any one of the MPL, the GPL or the LGPL.
36  *
37  * ***** END LICENSE BLOCK ***** */
38 /*
39  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
40  * Use is subject to license terms.
41  *
42  * Sun elects to use this software under the MPL license.
43  */
44 
45 #ifdef _KERNEL
46 #include <sys/types.h>
47 #include <sys/systm.h>
48 #include <sys/param.h>
49 #include <sys/modctl.h>
50 #include <sys/ddi.h>
51 #include <sys/crypto/spi.h>
52 #include <sys/sysmacros.h>
53 #include <sys/strsun.h>
54 #include <sys/md5.h>
55 #include <sys/sha1.h>
56 #include <sys/sha2.h>
57 #include <sys/random.h>
58 #include <sys/conf.h>
59 #include <sys/devops.h>
60 #include <sys/sunddi.h>
61 #include <sys/varargs.h>
62 #include <sys/kmem.h>
63 #include <sys/kstat.h>
64 #include <sys/crypto/common.h>
65 #else
66 #include <stdio.h>
67 #include <string.h>
68 #include <strings.h>
69 #include <assert.h>
70 #include <time.h>
71 #include <sys/time.h>
72 #include <sys/resource.h>
73 #endif /* _KERNEL */
74 
75 #include "mpi.h"
76 #include "mplogic.h"
77 #include "mpprime.h"
78 #include "mp_gf2m.h"
79 #include "ecl.h"
80 #include "ecl-curve.h"
81 #include "ec2.h"
82 #include "ecc_impl.h"
83 #include "ec.h"
84 
85 #ifndef KM_SLEEP
86 #define	KM_SLEEP	0
87 #endif
88 
89 #ifndef _KERNEL
90 /* Time k repetitions of operation op. */
91 #define M_TimeOperation(op, k) { \
92 	double dStart, dNow, dUserTime; \
93 	struct rusage ru; \
94 	int i; \
95 	getrusage(RUSAGE_SELF, &ru); \
96 	dStart = (double)ru.ru_utime.tv_sec+(double)ru.ru_utime.tv_usec*0.000001; \
97 	for (i = 0; i < k; i++) { \
98 		{ op; } \
99 	}; \
100 	getrusage(RUSAGE_SELF, &ru); \
101 	dNow = (double)ru.ru_utime.tv_sec+(double)ru.ru_utime.tv_usec*0.000001; \
102 	dUserTime = dNow-dStart; \
103 	if (dUserTime) printf("    %-45s k: %6i, t: %6.2f sec\n", #op, k, dUserTime); \
104 }
105 #else
106 #define	M_TimeOperation(op, k)
107 #endif
108 
109 /* Test curve using generic field arithmetic. */
110 #define ECTEST_GENERIC_GF2M(name_c, name) \
111 	printf("Testing %s using generic implementation...\n", name_c); \
112 	params = EC_GetNamedCurveParams(name, KM_SLEEP); \
113 	if (params == NULL) { \
114 			printf("  Error: could not construct params.\n"); \
115 			res = MP_NO; \
116 			goto CLEANUP; \
117 	} \
118 	ECGroup_free(group); \
119 	group = ECGroup_fromHex(params, KM_SLEEP); \
120 	if (group == NULL) { \
121 		printf("  Error: could not construct group.\n"); \
122 		res = MP_NO; \
123 		goto CLEANUP; \
124 	} \
125 	MP_CHECKOK( ectest_curve_GF2m(group, ectestPrint, ectestTime, 1, KM_SLEEP) ); \
126 	printf("... okay.\n");
127 
128 /* Test curve using specific field arithmetic. */
129 #define ECTEST_NAMED_GF2M(name_c, name) \
130 	printf("Testing %s using specific implementation...\n", name_c); \
131 	ECGroup_free(group); \
132 	group = ECGroup_fromName(name, KM_SLEEP); \
133 	if (group == NULL) { \
134 		printf("  Warning: could not construct group.\n"); \
135 		printf("... failed; continuing with remaining tests.\n"); \
136 	} else { \
137 		MP_CHECKOK( ectest_curve_GF2m(group, ectestPrint, ectestTime, 0, KM_SLEEP) ); \
138 		printf("... okay.\n"); \
139 	}
140 
141 /* Performs basic tests of elliptic curve cryptography over binary
142  * polynomial fields. If tests fail, then it prints an error message,
143  * aborts, and returns an error code. Otherwise, returns 0. */
144 int
145 ectest_curve_GF2m(ECGroup *group, int ectestPrint, int ectestTime,
146 				  int generic, int kmflag)
147 {
148 
149 	mp_int one, order_1, gx, gy, rx, ry, n;
150 	int size;
151 	mp_err res;
152 	char s[1000];
153 
154 	/* initialize values */
155 	MP_CHECKOK(mp_init(&one, kmflag));
156 	MP_CHECKOK(mp_init(&order_1, kmflag));
157 	MP_CHECKOK(mp_init(&gx, kmflag));
158 	MP_CHECKOK(mp_init(&gy, kmflag));
159 	MP_CHECKOK(mp_init(&rx, kmflag));
160 	MP_CHECKOK(mp_init(&ry, kmflag));
161 	MP_CHECKOK(mp_init(&n, kmflag));
162 
163 	MP_CHECKOK(mp_set_int(&one, 1));
164 	MP_CHECKOK(mp_sub(&group->order, &one, &order_1));
165 
166 	/* encode base point */
167 	if (group->meth->field_dec) {
168 		MP_CHECKOK(group->meth->field_dec(&group->genx, &gx, group->meth));
169 		MP_CHECKOK(group->meth->field_dec(&group->geny, &gy, group->meth));
170 	} else {
171 		MP_CHECKOK(mp_copy(&group->genx, &gx));
172 		MP_CHECKOK(mp_copy(&group->geny, &gy));
173 	}
174 
175 	if (ectestPrint) {
176 		/* output base point */
177 		printf("  base point P:\n");
178 		MP_CHECKOK(mp_toradix(&gx, s, 16));
179 		printf("    %s\n", s);
180 		MP_CHECKOK(mp_toradix(&gy, s, 16));
181 		printf("    %s\n", s);
182 		if (group->meth->field_enc) {
183 			printf("  base point P (encoded):\n");
184 			MP_CHECKOK(mp_toradix(&group->genx, s, 16));
185 			printf("    %s\n", s);
186 			MP_CHECKOK(mp_toradix(&group->geny, s, 16));
187 			printf("    %s\n", s);
188 		}
189 	}
190 
191 #ifdef ECL_ENABLE_GF2M_PT_MUL_AFF
192 	/* multiply base point by order - 1 and check for negative of base
193 	 * point */
194 	MP_CHECKOK(ec_GF2m_pt_mul_aff
195 			   (&order_1, &group->genx, &group->geny, &rx, &ry, group));
196 	if (ectestPrint) {
197 		printf("  (order-1)*P (affine):\n");
198 		MP_CHECKOK(mp_toradix(&rx, s, 16));
199 		printf("    %s\n", s);
200 		MP_CHECKOK(mp_toradix(&ry, s, 16));
201 		printf("    %s\n", s);
202 	}
203 	MP_CHECKOK(group->meth->field_add(&ry, &rx, &ry, group->meth));
204 	if ((mp_cmp(&rx, &group->genx) != 0)
205 		|| (mp_cmp(&ry, &group->geny) != 0)) {
206 		printf("  Error: invalid result (expected (- base point)).\n");
207 		res = MP_NO;
208 		goto CLEANUP;
209 	}
210 #endif
211 
212 	/* multiply base point by order - 1 and check for negative of base
213 	 * point */
214 	MP_CHECKOK(ec_GF2m_pt_mul_mont
215 			   (&order_1, &group->genx, &group->geny, &rx, &ry, group));
216 	if (ectestPrint) {
217 		printf("  (order-1)*P (montgomery):\n");
218 		MP_CHECKOK(mp_toradix(&rx, s, 16));
219 		printf("    %s\n", s);
220 		MP_CHECKOK(mp_toradix(&ry, s, 16));
221 		printf("    %s\n", s);
222 	}
223 	MP_CHECKOK(group->meth->field_add(&ry, &rx, &ry, group->meth));
224 	if ((mp_cmp(&rx, &group->genx) != 0)
225 		|| (mp_cmp(&ry, &group->geny) != 0)) {
226 		printf("  Error: invalid result (expected (- base point)).\n");
227 		res = MP_NO;
228 		goto CLEANUP;
229 	}
230 
231 #ifdef ECL_ENABLE_GF2M_PROJ
232 	/* multiply base point by order - 1 and check for negative of base
233 	 * point */
234 	MP_CHECKOK(ec_GF2m_pt_mul_proj
235 			   (&order_1, &group->genx, &group->geny, &rx, &ry, group));
236 	if (ectestPrint) {
237 		printf("  (order-1)*P (projective):\n");
238 		MP_CHECKOK(mp_toradix(&rx, s, 16));
239 		printf("    %s\n", s);
240 		MP_CHECKOK(mp_toradix(&ry, s, 16));
241 		printf("    %s\n", s);
242 	}
243 	MP_CHECKOK(group->meth->field_add(&ry, &rx, &ry, group->meth));
244 	if ((mp_cmp(&rx, &group->genx) != 0)
245 		|| (mp_cmp(&ry, &group->geny) != 0)) {
246 		printf("  Error: invalid result (expected (- base point)).\n");
247 		res = MP_NO;
248 		goto CLEANUP;
249 	}
250 #endif
251 
252 	/* multiply base point by order - 1 and check for negative of base
253 	 * point */
254 	MP_CHECKOK(ECPoint_mul(group, &order_1, NULL, NULL, &rx, &ry));
255 	if (ectestPrint) {
256 		printf("  (order-1)*P (ECPoint_mul):\n");
257 		MP_CHECKOK(mp_toradix(&rx, s, 16));
258 		printf("    %s\n", s);
259 		MP_CHECKOK(mp_toradix(&ry, s, 16));
260 		printf("    %s\n", s);
261 	}
262 	MP_CHECKOK(ec_GF2m_add(&ry, &rx, &ry, group->meth));
263 	if ((mp_cmp(&rx, &gx) != 0) || (mp_cmp(&ry, &gy) != 0)) {
264 		printf("  Error: invalid result (expected (- base point)).\n");
265 		res = MP_NO;
266 		goto CLEANUP;
267 	}
268 
269 	/* multiply base point by order - 1 and check for negative of base
270 	 * point */
271 	MP_CHECKOK(ECPoint_mul(group, &order_1, &gx, &gy, &rx, &ry));
272 	if (ectestPrint) {
273 		printf("  (order-1)*P (ECPoint_mul):\n");
274 		MP_CHECKOK(mp_toradix(&rx, s, 16));
275 		printf("    %s\n", s);
276 		MP_CHECKOK(mp_toradix(&ry, s, 16));
277 		printf("    %s\n", s);
278 	}
279 	MP_CHECKOK(ec_GF2m_add(&ry, &rx, &ry, group->meth));
280 	if ((mp_cmp(&rx, &gx) != 0) || (mp_cmp(&ry, &gy) != 0)) {
281 		printf("  Error: invalid result (expected (- base point)).\n");
282 		res = MP_NO;
283 		goto CLEANUP;
284 	}
285 
286 #ifdef ECL_ENABLE_GF2M_PT_MUL_AFF
287 	/* multiply base point by order and check for point at infinity */
288 	MP_CHECKOK(ec_GF2m_pt_mul_aff
289 			   (&group->order, &group->genx, &group->geny, &rx, &ry,
290 				group));
291 	if (ectestPrint) {
292 		printf("  (order)*P (affine):\n");
293 		MP_CHECKOK(mp_toradix(&rx, s, 16));
294 		printf("    %s\n", s);
295 		MP_CHECKOK(mp_toradix(&ry, s, 16));
296 		printf("    %s\n", s);
297 	}
298 	if (ec_GF2m_pt_is_inf_aff(&rx, &ry) != MP_YES) {
299 		printf("  Error: invalid result (expected point at infinity).\n");
300 		res = MP_NO;
301 		goto CLEANUP;
302 	}
303 #endif
304 
305 	/* multiply base point by order and check for point at infinity */
306 	MP_CHECKOK(ec_GF2m_pt_mul_mont
307 			   (&group->order, &group->genx, &group->geny, &rx, &ry,
308 				group));
309 	if (ectestPrint) {
310 		printf("  (order)*P (montgomery):\n");
311 		MP_CHECKOK(mp_toradix(&rx, s, 16));
312 		printf("    %s\n", s);
313 		MP_CHECKOK(mp_toradix(&ry, s, 16));
314 		printf("    %s\n", s);
315 	}
316 	if (ec_GF2m_pt_is_inf_aff(&rx, &ry) != MP_YES) {
317 		printf("  Error: invalid result (expected point at infinity).\n");
318 		res = MP_NO;
319 		goto CLEANUP;
320 	}
321 
322 #ifdef ECL_ENABLE_GF2M_PROJ
323 	/* multiply base point by order and check for point at infinity */
324 	MP_CHECKOK(ec_GF2m_pt_mul_proj
325 			   (&group->order, &group->genx, &group->geny, &rx, &ry,
326 				group));
327 	if (ectestPrint) {
328 		printf("  (order)*P (projective):\n");
329 		MP_CHECKOK(mp_toradix(&rx, s, 16));
330 		printf("    %s\n", s);
331 		MP_CHECKOK(mp_toradix(&ry, s, 16));
332 		printf("    %s\n", s);
333 	}
334 	if (ec_GF2m_pt_is_inf_aff(&rx, &ry) != MP_YES) {
335 		printf("  Error: invalid result (expected point at infinity).\n");
336 		res = MP_NO;
337 		goto CLEANUP;
338 	}
339 #endif
340 
341 	/* multiply base point by order and check for point at infinity */
342 	MP_CHECKOK(ECPoint_mul(group, &group->order, NULL, NULL, &rx, &ry));
343 	if (ectestPrint) {
344 		printf("  (order)*P (ECPoint_mul):\n");
345 		MP_CHECKOK(mp_toradix(&rx, s, 16));
346 		printf("    %s\n", s);
347 		MP_CHECKOK(mp_toradix(&ry, s, 16));
348 		printf("    %s\n", s);
349 	}
350 	if (ec_GF2m_pt_is_inf_aff(&rx, &ry) != MP_YES) {
351 		printf("  Error: invalid result (expected point at infinity).\n");
352 		res = MP_NO;
353 		goto CLEANUP;
354 	}
355 
356 	/* multiply base point by order and check for point at infinity */
357 	MP_CHECKOK(ECPoint_mul(group, &group->order, &gx, &gy, &rx, &ry));
358 	if (ectestPrint) {
359 		printf("  (order)*P (ECPoint_mul):\n");
360 		MP_CHECKOK(mp_toradix(&rx, s, 16));
361 		printf("    %s\n", s);
362 		MP_CHECKOK(mp_toradix(&ry, s, 16));
363 		printf("    %s\n", s);
364 	}
365 	if (ec_GF2m_pt_is_inf_aff(&rx, &ry) != MP_YES) {
366 		printf("  Error: invalid result (expected point at infinity).\n");
367 		res = MP_NO;
368 		goto CLEANUP;
369 	}
370 
371 	/* check that (order-1)P + (order-1)P + P == (order-1)P */
372 	MP_CHECKOK(ECPoints_mul
373 			   (group, &order_1, &order_1, &gx, &gy, &rx, &ry));
374 	MP_CHECKOK(ECPoints_mul(group, &one, &one, &rx, &ry, &rx, &ry));
375 	if (ectestPrint) {
376 		printf
377 			("  (order-1)*P + (order-1)*P + P == (order-1)*P (ECPoints_mul):\n");
378 		MP_CHECKOK(mp_toradix(&rx, s, 16));
379 		printf("    %s\n", s);
380 		MP_CHECKOK(mp_toradix(&ry, s, 16));
381 		printf("    %s\n", s);
382 	}
383 	MP_CHECKOK(ec_GF2m_add(&ry, &rx, &ry, group->meth));
384 	if ((mp_cmp(&rx, &gx) != 0) || (mp_cmp(&ry, &gy) != 0)) {
385 		printf("  Error: invalid result (expected (- base point)).\n");
386 		res = MP_NO;
387 		goto CLEANUP;
388 	}
389 
390 	/* test validate_point function */
391 	if (ECPoint_validate(group, &gx, &gy) != MP_YES) {
392 		printf("  Error: validate point on base point failed.\n");
393 		res = MP_NO;
394 		goto CLEANUP;
395 	}
396 	MP_CHECKOK(mp_add_d(&gy, 1, &ry));
397 	if (ECPoint_validate(group, &gx, &ry) != MP_NO) {
398 		printf("  Error: validate point on invalid point passed.\n");
399 		res = MP_NO;
400 		goto CLEANUP;
401 	}
402 
403 	if (ectestTime) {
404 		/* compute random scalar */
405 		size = mpl_significant_bits(&group->meth->irr);
406 		if (size < MP_OKAY) {
407 			goto CLEANUP;
408 		}
409 		MP_CHECKOK(mpp_random_size(&n, (size + ECL_BITS - 1) / ECL_BITS));
410 		MP_CHECKOK(group->meth->field_mod(&n, &n, group->meth));
411 		/* timed test */
412 		if (generic) {
413 #ifdef ECL_ENABLE_GF2M_PT_MUL_AFF
414 			M_TimeOperation(MP_CHECKOK
415 							(ec_GF2m_pt_mul_aff
416 							 (&n, &group->genx, &group->geny, &rx, &ry,
417 							  group)), 100);
418 #endif
419 			M_TimeOperation(MP_CHECKOK
420 							(ECPoint_mul(group, &n, NULL, NULL, &rx, &ry)),
421 							100);
422 			M_TimeOperation(MP_CHECKOK
423 							(ECPoints_mul
424 							 (group, &n, &n, &gx, &gy, &rx, &ry)), 100);
425 		} else {
426 			M_TimeOperation(MP_CHECKOK
427 							(ECPoint_mul(group, &n, NULL, NULL, &rx, &ry)),
428 							100);
429 			M_TimeOperation(MP_CHECKOK
430 							(ECPoint_mul(group, &n, &gx, &gy, &rx, &ry)),
431 							100);
432 			M_TimeOperation(MP_CHECKOK
433 							(ECPoints_mul
434 							 (group, &n, &n, &gx, &gy, &rx, &ry)), 100);
435 		}
436 	}
437 
438   CLEANUP:
439 	mp_clear(&one);
440 	mp_clear(&order_1);
441 	mp_clear(&gx);
442 	mp_clear(&gy);
443 	mp_clear(&rx);
444 	mp_clear(&ry);
445 	mp_clear(&n);
446 	if (res != MP_OKAY) {
447 #ifdef _KERNEL
448 		printf("  Error: exiting with error value 0x%x\n", res);
449 #else
450 		printf("  Error: exiting with error value %i\n", res);
451 #endif
452 	}
453 	return res;
454 }
455 
456 /* Performs tests of elliptic curve cryptography over binary polynomial
457  * fields. If tests fail, then it prints an error message, aborts, and
458  * returns an error code. Otherwise, returns 0. */
459 int
460 ec2_test()
461 {
462 	int ectestTime = 0;
463 	int ectestPrint = 0;
464 	int i;
465 	ECGroup *group = NULL;
466 	ECCurveParams *params = NULL;
467 	mp_err res;
468 
469 	/* generic arithmetic tests */
470 	ECTEST_GENERIC_GF2M("SECT-131R1", ECCurve_SECG_CHAR2_131R1);
471 
472 	/* specific arithmetic tests */
473 	ECTEST_NAMED_GF2M("NIST-K163", ECCurve_NIST_K163);
474 	ECTEST_NAMED_GF2M("NIST-B163", ECCurve_NIST_B163);
475 	ECTEST_NAMED_GF2M("NIST-K233", ECCurve_NIST_K233);
476 	ECTEST_NAMED_GF2M("NIST-B233", ECCurve_NIST_B233);
477 	ECTEST_NAMED_GF2M("NIST-K283", ECCurve_NIST_K283);
478 	ECTEST_NAMED_GF2M("NIST-B283", ECCurve_NIST_B283);
479 	ECTEST_NAMED_GF2M("NIST-K409", ECCurve_NIST_K409);
480 	ECTEST_NAMED_GF2M("NIST-B409", ECCurve_NIST_B409);
481 	ECTEST_NAMED_GF2M("NIST-K571", ECCurve_NIST_K571);
482 	ECTEST_NAMED_GF2M("NIST-B571", ECCurve_NIST_B571);
483 	ECTEST_NAMED_GF2M("ANSI X9.62 C2PNB163V1", ECCurve_X9_62_CHAR2_PNB163V1);
484 	ECTEST_NAMED_GF2M("ANSI X9.62 C2PNB163V2", ECCurve_X9_62_CHAR2_PNB163V2);
485 	ECTEST_NAMED_GF2M("ANSI X9.62 C2PNB163V3", ECCurve_X9_62_CHAR2_PNB163V3);
486 	ECTEST_NAMED_GF2M("ANSI X9.62 C2PNB176V1", ECCurve_X9_62_CHAR2_PNB176V1);
487 	ECTEST_NAMED_GF2M("ANSI X9.62 C2TNB191V1", ECCurve_X9_62_CHAR2_TNB191V1);
488 	ECTEST_NAMED_GF2M("ANSI X9.62 C2TNB191V2", ECCurve_X9_62_CHAR2_TNB191V2);
489 	ECTEST_NAMED_GF2M("ANSI X9.62 C2TNB191V3", ECCurve_X9_62_CHAR2_TNB191V3);
490 	ECTEST_NAMED_GF2M("ANSI X9.62 C2PNB208W1", ECCurve_X9_62_CHAR2_PNB208W1);
491 	ECTEST_NAMED_GF2M("ANSI X9.62 C2TNB239V1", ECCurve_X9_62_CHAR2_TNB239V1);
492 	ECTEST_NAMED_GF2M("ANSI X9.62 C2TNB239V2", ECCurve_X9_62_CHAR2_TNB239V2);
493 	ECTEST_NAMED_GF2M("ANSI X9.62 C2TNB239V3", ECCurve_X9_62_CHAR2_TNB239V3);
494 	ECTEST_NAMED_GF2M("ANSI X9.62 C2PNB272W1", ECCurve_X9_62_CHAR2_PNB272W1);
495 	ECTEST_NAMED_GF2M("ANSI X9.62 C2PNB304W1", ECCurve_X9_62_CHAR2_PNB304W1);
496 	ECTEST_NAMED_GF2M("ANSI X9.62 C2TNB359V1", ECCurve_X9_62_CHAR2_TNB359V1);
497 	ECTEST_NAMED_GF2M("ANSI X9.62 C2PNB368W1", ECCurve_X9_62_CHAR2_PNB368W1);
498 	ECTEST_NAMED_GF2M("ANSI X9.62 C2TNB431R1", ECCurve_X9_62_CHAR2_TNB431R1);
499 	ECTEST_NAMED_GF2M("SECT-113R1", ECCurve_SECG_CHAR2_113R1);
500 	ECTEST_NAMED_GF2M("SECT-113R2", ECCurve_SECG_CHAR2_113R2);
501 	ECTEST_NAMED_GF2M("SECT-131R1", ECCurve_SECG_CHAR2_131R1);
502 	ECTEST_NAMED_GF2M("SECT-131R2", ECCurve_SECG_CHAR2_131R2);
503 	ECTEST_NAMED_GF2M("SECT-163K1", ECCurve_SECG_CHAR2_163K1);
504 	ECTEST_NAMED_GF2M("SECT-163R1", ECCurve_SECG_CHAR2_163R1);
505 	ECTEST_NAMED_GF2M("SECT-163R2", ECCurve_SECG_CHAR2_163R2);
506 	ECTEST_NAMED_GF2M("SECT-193R1", ECCurve_SECG_CHAR2_193R1);
507 	ECTEST_NAMED_GF2M("SECT-193R2", ECCurve_SECG_CHAR2_193R2);
508 	ECTEST_NAMED_GF2M("SECT-233K1", ECCurve_SECG_CHAR2_233K1);
509 	ECTEST_NAMED_GF2M("SECT-233R1", ECCurve_SECG_CHAR2_233R1);
510 	ECTEST_NAMED_GF2M("SECT-239K1", ECCurve_SECG_CHAR2_239K1);
511 	ECTEST_NAMED_GF2M("SECT-283K1", ECCurve_SECG_CHAR2_283K1);
512 	ECTEST_NAMED_GF2M("SECT-283R1", ECCurve_SECG_CHAR2_283R1);
513 	ECTEST_NAMED_GF2M("SECT-409K1", ECCurve_SECG_CHAR2_409K1);
514 	ECTEST_NAMED_GF2M("SECT-409R1", ECCurve_SECG_CHAR2_409R1);
515 	ECTEST_NAMED_GF2M("SECT-571K1", ECCurve_SECG_CHAR2_571K1);
516 	ECTEST_NAMED_GF2M("SECT-571R1", ECCurve_SECG_CHAR2_571R1);
517 	ECTEST_NAMED_GF2M("WTLS-1 (113)", ECCurve_WTLS_1);
518 	ECTEST_NAMED_GF2M("WTLS-3 (163)", ECCurve_WTLS_3);
519 	ECTEST_NAMED_GF2M("WTLS-4 (113)", ECCurve_WTLS_4);
520 	ECTEST_NAMED_GF2M("WTLS-5 (163)", ECCurve_WTLS_5);
521 	ECTEST_NAMED_GF2M("WTLS-10 (233)", ECCurve_WTLS_10);
522 	ECTEST_NAMED_GF2M("WTLS-11 (233)", ECCurve_WTLS_11);
523 
524   CLEANUP:
525 	EC_FreeCurveParams(params);
526 	ECGroup_free(group);
527 	if (res != MP_OKAY) {
528 #ifdef _KERNEL
529 		printf("Error: exiting with error value 0x%x\n", res);
530 #else
531 		printf("Error: exiting with error value %i\n", res);
532 #endif
533 	}
534 	return res;
535 }
536