PolarSSL v1.3.9
test_suite_ecp.c
Go to the documentation of this file.
1#if !defined(POLARSSL_CONFIG_FILE)
2#include <polarssl/config.h>
3#else
4#include POLARSSL_CONFIG_FILE
5#endif
6
7#ifdef POLARSSL_ECP_C
8
9#include <polarssl/ecp.h>
10
11#define POLARSSL_ECP_PF_UNKNOWN -1
12#endif /* POLARSSL_ECP_C */
13
14
15#if defined(POLARSSL_MEMORY_BUFFER_ALLOC_C)
16#include "polarssl/memory.h"
17#endif
18
19#if defined(POLARSSL_PLATFORM_C)
20#include "polarssl/platform.h"
21#else
22#define polarssl_malloc malloc
23#define polarssl_free free
24#endif
25
26#ifdef _MSC_VER
27#include <basetsd.h>
28typedef UINT32 uint32_t;
29#else
30#include <inttypes.h>
31#endif
32
33#include <assert.h>
34#include <stdlib.h>
35#include <string.h>
36
37/*
38 * 32-bit integer manipulation macros (big endian)
39 */
40#ifndef GET_UINT32_BE
41#define GET_UINT32_BE(n,b,i) \
42{ \
43 (n) = ( (uint32_t) (b)[(i) ] << 24 ) \
44 | ( (uint32_t) (b)[(i) + 1] << 16 ) \
45 | ( (uint32_t) (b)[(i) + 2] << 8 ) \
46 | ( (uint32_t) (b)[(i) + 3] ); \
47}
48#endif
49
50#ifndef PUT_UINT32_BE
51#define PUT_UINT32_BE(n,b,i) \
52{ \
53 (b)[(i) ] = (unsigned char) ( (n) >> 24 ); \
54 (b)[(i) + 1] = (unsigned char) ( (n) >> 16 ); \
55 (b)[(i) + 2] = (unsigned char) ( (n) >> 8 ); \
56 (b)[(i) + 3] = (unsigned char) ( (n) ); \
57}
58#endif
59
60static int unhexify(unsigned char *obuf, const char *ibuf)
61{
62 unsigned char c, c2;
63 int len = strlen(ibuf) / 2;
64 assert(!(strlen(ibuf) %1)); // must be even number of bytes
65
66 while (*ibuf != 0)
67 {
68 c = *ibuf++;
69 if( c >= '0' && c <= '9' )
70 c -= '0';
71 else if( c >= 'a' && c <= 'f' )
72 c -= 'a' - 10;
73 else if( c >= 'A' && c <= 'F' )
74 c -= 'A' - 10;
75 else
76 assert( 0 );
77
78 c2 = *ibuf++;
79 if( c2 >= '0' && c2 <= '9' )
80 c2 -= '0';
81 else if( c2 >= 'a' && c2 <= 'f' )
82 c2 -= 'a' - 10;
83 else if( c2 >= 'A' && c2 <= 'F' )
84 c2 -= 'A' - 10;
85 else
86 assert( 0 );
87
88 *obuf++ = ( c << 4 ) | c2;
89 }
90
91 return len;
92}
93
94static void hexify(unsigned char *obuf, const unsigned char *ibuf, int len)
95{
96 unsigned char l, h;
97
98 while (len != 0)
99 {
100 h = (*ibuf) / 16;
101 l = (*ibuf) % 16;
102
103 if( h < 10 )
104 *obuf++ = '0' + h;
105 else
106 *obuf++ = 'a' + h - 10;
107
108 if( l < 10 )
109 *obuf++ = '0' + l;
110 else
111 *obuf++ = 'a' + l - 10;
112
113 ++ibuf;
114 len--;
115 }
116}
117
125static unsigned char *zero_alloc( size_t len )
126{
127 void *p;
128 size_t actual_len = len != 0 ? len : 1;
129
130 p = polarssl_malloc( actual_len );
131 assert( p != NULL );
132
133 memset( p, 0x00, actual_len );
134
135 return( p );
136}
137
148static unsigned char *unhexify_alloc( const char *ibuf, size_t *olen )
149{
150 unsigned char *obuf;
151
152 *olen = strlen(ibuf) / 2;
153
154 if( *olen == 0 )
155 return( zero_alloc( *olen ) );
156
157 obuf = polarssl_malloc( *olen );
158 assert( obuf != NULL );
159
160 (void) unhexify( obuf, ibuf );
161
162 return( obuf );
163}
164
174static int rnd_std_rand( void *rng_state, unsigned char *output, size_t len )
175{
176#if !defined(__OpenBSD__)
177 size_t i;
178
179 if( rng_state != NULL )
180 rng_state = NULL;
181
182 for( i = 0; i < len; ++i )
183 output[i] = rand();
184#else
185 if( rng_state != NULL )
186 rng_state = NULL;
187
188 arc4random_buf( output, len );
189#endif /* !OpenBSD */
190
191 return( 0 );
192}
193
199static int rnd_zero_rand( void *rng_state, unsigned char *output, size_t len )
200{
201 if( rng_state != NULL )
202 rng_state = NULL;
203
204 memset( output, 0, len );
205
206 return( 0 );
207}
208
209typedef struct
210{
211 unsigned char *buf;
212 size_t length;
214
226static int rnd_buffer_rand( void *rng_state, unsigned char *output, size_t len )
227{
228 rnd_buf_info *info = (rnd_buf_info *) rng_state;
229 size_t use_len;
230
231 if( rng_state == NULL )
232 return( rnd_std_rand( NULL, output, len ) );
233
234 use_len = len;
235 if( len > info->length )
236 use_len = info->length;
237
238 if( use_len )
239 {
240 memcpy( output, info->buf, use_len );
241 info->buf += use_len;
242 info->length -= use_len;
243 }
244
245 if( len - use_len > 0 )
246 return( rnd_std_rand( NULL, output + use_len, len - use_len ) );
247
248 return( 0 );
249}
250
258typedef struct
259{
260 uint32_t key[16];
261 uint32_t v0, v1;
263
272static int rnd_pseudo_rand( void *rng_state, unsigned char *output, size_t len )
273{
274 rnd_pseudo_info *info = (rnd_pseudo_info *) rng_state;
275 uint32_t i, *k, sum, delta=0x9E3779B9;
276 unsigned char result[4], *out = output;
277
278 if( rng_state == NULL )
279 return( rnd_std_rand( NULL, output, len ) );
280
281 k = info->key;
282
283 while( len > 0 )
284 {
285 size_t use_len = ( len > 4 ) ? 4 : len;
286 sum = 0;
287
288 for( i = 0; i < 32; i++ )
289 {
290 info->v0 += (((info->v1 << 4) ^ (info->v1 >> 5)) + info->v1) ^ (sum + k[sum & 3]);
291 sum += delta;
292 info->v1 += (((info->v0 << 4) ^ (info->v0 >> 5)) + info->v0) ^ (sum + k[(sum>>11) & 3]);
293 }
294
295 PUT_UINT32_BE( info->v0, result, 0 );
296 memcpy( out, result, use_len );
297 len -= use_len;
298 out += 4;
299 }
300
301 return( 0 );
302}
303
304
305#include <stdio.h>
306#include <string.h>
307
308#if defined(POLARSSL_PLATFORM_C)
309#include "polarssl/platform.h"
310#else
311#define polarssl_printf printf
312#define polarssl_malloc malloc
313#define polarssl_free free
314#endif
315
316static int test_errors = 0;
317
318#ifdef POLARSSL_ECP_C
319
320#define TEST_SUITE_ACTIVE
321
322static int test_assert( int correct, const char *test )
323{
324 if( correct )
325 return( 0 );
326
327 test_errors++;
328 if( test_errors == 1 )
329 printf( "FAILED\n" );
330 printf( " %s\n", test );
331
332 return( 1 );
333}
334
335#define TEST_ASSERT( TEST ) \
336 do { test_assert( (TEST) ? 1 : 0, #TEST ); \
337 if( test_errors) goto exit; \
338 } while (0)
339
340int verify_string( char **str )
341{
342 if( (*str)[0] != '"' ||
343 (*str)[strlen( *str ) - 1] != '"' )
344 {
345 printf( "Expected string (with \"\") for parameter and got: %s\n", *str );
346 return( -1 );
347 }
348
349 (*str)++;
350 (*str)[strlen( *str ) - 1] = '\0';
351
352 return( 0 );
353}
354
355int verify_int( char *str, int *value )
356{
357 size_t i;
358 int minus = 0;
359 int digits = 1;
360 int hex = 0;
361
362 for( i = 0; i < strlen( str ); i++ )
363 {
364 if( i == 0 && str[i] == '-' )
365 {
366 minus = 1;
367 continue;
368 }
369
370 if( ( ( minus && i == 2 ) || ( !minus && i == 1 ) ) &&
371 str[i - 1] == '0' && str[i] == 'x' )
372 {
373 hex = 1;
374 continue;
375 }
376
377 if( ! ( ( str[i] >= '0' && str[i] <= '9' ) ||
378 ( hex && ( ( str[i] >= 'a' && str[i] <= 'f' ) ||
379 ( str[i] >= 'A' && str[i] <= 'F' ) ) ) ) )
380 {
381 digits = 0;
382 break;
383 }
384 }
385
386 if( digits )
387 {
388 if( hex )
389 *value = strtol( str, NULL, 16 );
390 else
391 *value = strtol( str, NULL, 10 );
392
393 return( 0 );
394 }
395
396 if( strcmp( str, "POLARSSL_ECP_DP_SECP521R1" ) == 0 )
397 {
398 *value = ( POLARSSL_ECP_DP_SECP521R1 );
399 return( 0 );
400 }
401 if( strcmp( str, "POLARSSL_ECP_DP_M255" ) == 0 )
402 {
403 *value = ( POLARSSL_ECP_DP_M255 );
404 return( 0 );
405 }
406 if( strcmp( str, "POLARSSL_ECP_DP_BP256R1" ) == 0 )
407 {
408 *value = ( POLARSSL_ECP_DP_BP256R1 );
409 return( 0 );
410 }
411 if( strcmp( str, "POLARSSL_ECP_DP_SECP384R1" ) == 0 )
412 {
413 *value = ( POLARSSL_ECP_DP_SECP384R1 );
414 return( 0 );
415 }
416 if( strcmp( str, "POLARSSL_ECP_DP_SECP224R1" ) == 0 )
417 {
418 *value = ( POLARSSL_ECP_DP_SECP224R1 );
419 return( 0 );
420 }
421 if( strcmp( str, "POLARSSL_ECP_DP_SECP256K1" ) == 0 )
422 {
423 *value = ( POLARSSL_ECP_DP_SECP256K1 );
424 return( 0 );
425 }
426 if( strcmp( str, "POLARSSL_ECP_PF_UNKNOWN" ) == 0 )
427 {
428 *value = ( POLARSSL_ECP_PF_UNKNOWN );
429 return( 0 );
430 }
431 if( strcmp( str, "POLARSSL_ECP_PF_COMPRESSED" ) == 0 )
432 {
433 *value = ( POLARSSL_ECP_PF_COMPRESSED );
434 return( 0 );
435 }
436 if( strcmp( str, "POLARSSL_ECP_DP_BP384R1" ) == 0 )
437 {
438 *value = ( POLARSSL_ECP_DP_BP384R1 );
439 return( 0 );
440 }
441 if( strcmp( str, "POLARSSL_ECP_DP_SECP224K1" ) == 0 )
442 {
443 *value = ( POLARSSL_ECP_DP_SECP224K1 );
444 return( 0 );
445 }
446 if( strcmp( str, "POLARSSL_ECP_DP_SECP192R1" ) == 0 )
447 {
448 *value = ( POLARSSL_ECP_DP_SECP192R1 );
449 return( 0 );
450 }
451 if( strcmp( str, "POLARSSL_ERR_ECP_BAD_INPUT_DATA" ) == 0 )
452 {
454 return( 0 );
455 }
456 if( strcmp( str, "POLARSSL_ECP_DP_BP512R1" ) == 0 )
457 {
458 *value = ( POLARSSL_ECP_DP_BP512R1 );
459 return( 0 );
460 }
461 if( strcmp( str, "POLARSSL_ECP_DP_SECP192K1" ) == 0 )
462 {
463 *value = ( POLARSSL_ECP_DP_SECP192K1 );
464 return( 0 );
465 }
466 if( strcmp( str, "POLARSSL_ECP_PF_UNCOMPRESSED" ) == 0 )
467 {
468 *value = ( POLARSSL_ECP_PF_UNCOMPRESSED );
469 return( 0 );
470 }
471 if( strcmp( str, "POLARSSL_ERR_ECP_INVALID_KEY" ) == 0 )
472 {
473 *value = ( POLARSSL_ERR_ECP_INVALID_KEY );
474 return( 0 );
475 }
476 if( strcmp( str, "POLARSSL_ERR_ECP_BUFFER_TOO_SMALL" ) == 0 )
477 {
479 return( 0 );
480 }
481 if( strcmp( str, "-1" ) == 0 )
482 {
483 *value = ( -1 );
484 return( 0 );
485 }
486 if( strcmp( str, "POLARSSL_ECP_DP_SECP256R1" ) == 0 )
487 {
488 *value = ( POLARSSL_ECP_DP_SECP256R1 );
489 return( 0 );
490 }
491 if( strcmp( str, "POLARSSL_ERR_ECP_FEATURE_UNAVAILABLE" ) == 0 )
492 {
494 return( 0 );
495 }
496
497
498 printf( "Expected integer for parameter and got: %s\n", str );
499 return( -1 );
500}
501
502void test_suite_ecp_curve_info( int id, int tls_id, int size, char *name )
503{
504 const ecp_curve_info *by_id, *by_tls, *by_name;
505
506 by_id = ecp_curve_info_from_grp_id( id );
507 by_tls = ecp_curve_info_from_tls_id( tls_id );
508 by_name = ecp_curve_info_from_name( name );
509 TEST_ASSERT( by_id != NULL );
510 TEST_ASSERT( by_tls != NULL );
511 TEST_ASSERT( by_name != NULL );
512
513 TEST_ASSERT( by_id == by_tls );
514 TEST_ASSERT( by_id == by_name );
515
516 TEST_ASSERT( by_id->size == size );
517
518exit:
519 return;
520}
521
522void test_suite_ecp_small_add( int a_zero, char *x_a, char *y_a, int b_zero, char *x_b,
523 char *y_b, int c_zero, int x_c, int y_c )
524{
525 ecp_group grp;
526 ecp_point A, B, C;
527
528 ecp_group_init( &grp );
529 ecp_point_init( &A ); ecp_point_init( &B ); ecp_point_init( &C );
530
532 "47", "4", "17", "42", "13" ) == 0 );
533
534 if( a_zero )
535 ecp_set_zero( &A );
536 else
537 TEST_ASSERT( ecp_point_read_string( &A, 10, x_a, y_a ) == 0 );
538
539 if( b_zero )
540 ecp_set_zero( &B );
541 else
542 TEST_ASSERT( ecp_point_read_string( &B, 10, x_b, y_b ) == 0 );
543
544 TEST_ASSERT( ecp_add( &grp, &C, &A, &B ) == 0 );
545
546 if( c_zero )
547 TEST_ASSERT( mpi_cmp_int( &C.Z, 0 ) == 0 );
548 else
549 {
550 TEST_ASSERT( mpi_cmp_int( &C.X, x_c ) == 0 );
551 TEST_ASSERT( mpi_cmp_int( &C.Y, y_c ) == 0 );
552 }
553
554 TEST_ASSERT( ecp_add( &grp, &C, &B, &A ) == 0 );
555
556 if( c_zero )
557 TEST_ASSERT( mpi_cmp_int( &C.Z, 0 ) == 0 );
558 else
559 {
560 TEST_ASSERT( mpi_cmp_int( &C.X, x_c ) == 0 );
561 TEST_ASSERT( mpi_cmp_int( &C.Y, y_c ) == 0 );
562 }
563
564exit:
565 ecp_group_free( &grp );
566 ecp_point_free( &A ); ecp_point_free( &B ); ecp_point_free( &C );
567}
568
569void test_suite_ecp_small_sub( int a_zero, char *x_a, char *y_a, int b_zero, char *x_b,
570 char *y_b, int c_zero, int x_c, int y_c )
571{
572 ecp_group grp;
573 ecp_point A, B, C;
574
575 ecp_group_init( &grp );
576 ecp_point_init( &A ); ecp_point_init( &B ); ecp_point_init( &C );
577
579 "47", "4", "17", "42", "13" ) == 0 );
580
581 if( a_zero )
582 ecp_set_zero( &A );
583 else
584 TEST_ASSERT( ecp_point_read_string( &A, 10, x_a, y_a ) == 0 );
585
586 if( b_zero )
587 ecp_set_zero( &B );
588 else
589 TEST_ASSERT( ecp_point_read_string( &B, 10, x_b, y_b ) == 0 );
590
591 TEST_ASSERT( ecp_sub( &grp, &C, &A, &B ) == 0 );
592
593 if( c_zero )
594 TEST_ASSERT( mpi_cmp_int( &C.Z, 0 ) == 0 );
595 else
596 {
597 TEST_ASSERT( mpi_cmp_int( &C.X, x_c ) == 0 );
598 TEST_ASSERT( mpi_cmp_int( &C.Y, y_c ) == 0 );
599 }
600
601exit:
602 ecp_group_free( &grp );
603 ecp_point_free( &A ); ecp_point_free( &B ); ecp_point_free( &C );
604}
605
606void test_suite_ecp_small_mul( int m_str, int r_zero, int x_r, int y_r, int ret )
607{
608 ecp_group grp;
609 ecp_point R;
610 mpi m;
611 rnd_pseudo_info rnd_info;
612
613 ecp_group_init( &grp );
614 ecp_point_init( &R );
615 mpi_init( &m );
616 memset( &rnd_info, 0x00, sizeof( rnd_pseudo_info ) );
617
619 "47", "4", "17", "42", "13" ) == 0 );
620
621 TEST_ASSERT( mpi_lset( &m, m_str ) == 0 );
622
623 TEST_ASSERT( ecp_mul( &grp, &R, &m, &grp.G, NULL, NULL ) == ret );
624
625 if( ret == 0 )
626 {
627 if( r_zero )
628 TEST_ASSERT( mpi_cmp_int( &R.Z, 0 ) == 0 );
629 else
630 {
631 TEST_ASSERT( mpi_cmp_int( &R.X, x_r ) == 0 );
632 TEST_ASSERT( mpi_cmp_int( &R.Y, y_r ) == 0 );
633 }
634 }
635
636 /* try again with randomization */
637 ecp_point_free( &R );
638
639 TEST_ASSERT( ecp_mul( &grp, &R, &m, &grp.G,
640 &rnd_pseudo_rand, &rnd_info ) == ret );
641
642 if( ret == 0 )
643 {
644 if( r_zero )
645 TEST_ASSERT( mpi_cmp_int( &R.Z, 0 ) == 0 );
646 else
647 {
648 TEST_ASSERT( mpi_cmp_int( &R.X, x_r ) == 0 );
649 TEST_ASSERT( mpi_cmp_int( &R.Y, y_r ) == 0 );
650 }
651 }
652
653exit:
654 ecp_group_free( &grp );
655 ecp_point_free( &R );
656 mpi_free( &m );
657}
658
659void test_suite_ecp_small_check_pub( int x, int y, int z, int ret )
660{
661 ecp_group grp;
662 ecp_point P;
663
664 ecp_group_init( &grp );
665 ecp_point_init( &P );
666
668 "47", "4", "17", "42", "13" ) == 0 );
669
670 TEST_ASSERT( mpi_lset( &P.X, x ) == 0 );
671 TEST_ASSERT( mpi_lset( &P.Y, y ) == 0 );
672 TEST_ASSERT( mpi_lset( &P.Z, z ) == 0 );
673
674 TEST_ASSERT( ecp_check_pubkey( &grp, &P ) == ret );
675
676exit:
677 ecp_group_free( &grp );
678 ecp_point_free( &P );
679}
680
681void test_suite_ecp_check_pub_mx( int grp_id, char *key_hex, int ret )
682{
683 ecp_group grp;
684 ecp_point P;
685
686 ecp_group_init( &grp );
687 ecp_point_init( &P );
688
689 TEST_ASSERT( ecp_use_known_dp( &grp, grp_id ) == 0 );
690
691 TEST_ASSERT( mpi_read_string( &P.X, 16, key_hex ) == 0 );
692 TEST_ASSERT( mpi_lset( &P.Z, 1 ) == 0 );
693
694 TEST_ASSERT( ecp_check_pubkey( &grp, &P ) == ret );
695
696exit:
697 ecp_group_free( &grp );
698 ecp_point_free( &P );
699}
700
701void test_suite_ecp_test_vect( int id, char *dA_str, char *xA_str, char *yA_str,
702 char *dB_str, char *xB_str, char *yB_str, char *xZ_str,
703 char *yZ_str )
704{
705 ecp_group grp;
706 ecp_point R;
707 mpi dA, xA, yA, dB, xB, yB, xZ, yZ;
708 rnd_pseudo_info rnd_info;
709
710 ecp_group_init( &grp ); ecp_point_init( &R );
711 mpi_init( &dA ); mpi_init( &xA ); mpi_init( &yA ); mpi_init( &dB );
712 mpi_init( &xB ); mpi_init( &yB ); mpi_init( &xZ ); mpi_init( &yZ );
713 memset( &rnd_info, 0x00, sizeof( rnd_pseudo_info ) );
714
715 TEST_ASSERT( ecp_use_known_dp( &grp, id ) == 0 );
716
717 TEST_ASSERT( ecp_check_pubkey( &grp, &grp.G ) == 0 );
718
719 TEST_ASSERT( mpi_read_string( &dA, 16, dA_str ) == 0 );
720 TEST_ASSERT( mpi_read_string( &xA, 16, xA_str ) == 0 );
721 TEST_ASSERT( mpi_read_string( &yA, 16, yA_str ) == 0 );
722 TEST_ASSERT( mpi_read_string( &dB, 16, dB_str ) == 0 );
723 TEST_ASSERT( mpi_read_string( &xB, 16, xB_str ) == 0 );
724 TEST_ASSERT( mpi_read_string( &yB, 16, yB_str ) == 0 );
725 TEST_ASSERT( mpi_read_string( &xZ, 16, xZ_str ) == 0 );
726 TEST_ASSERT( mpi_read_string( &yZ, 16, yZ_str ) == 0 );
727
728 TEST_ASSERT( ecp_mul( &grp, &R, &dA, &grp.G,
729 &rnd_pseudo_rand, &rnd_info ) == 0 );
730 TEST_ASSERT( mpi_cmp_mpi( &R.X, &xA ) == 0 );
731 TEST_ASSERT( mpi_cmp_mpi( &R.Y, &yA ) == 0 );
732 TEST_ASSERT( ecp_check_pubkey( &grp, &R ) == 0 );
733 TEST_ASSERT( ecp_mul( &grp, &R, &dB, &R, NULL, NULL ) == 0 );
734 TEST_ASSERT( mpi_cmp_mpi( &R.X, &xZ ) == 0 );
735 TEST_ASSERT( mpi_cmp_mpi( &R.Y, &yZ ) == 0 );
736 TEST_ASSERT( ecp_check_pubkey( &grp, &R ) == 0 );
737
738 TEST_ASSERT( ecp_mul( &grp, &R, &dB, &grp.G, NULL, NULL ) == 0 );
739 TEST_ASSERT( mpi_cmp_mpi( &R.X, &xB ) == 0 );
740 TEST_ASSERT( mpi_cmp_mpi( &R.Y, &yB ) == 0 );
741 TEST_ASSERT( ecp_check_pubkey( &grp, &R ) == 0 );
742 TEST_ASSERT( ecp_mul( &grp, &R, &dA, &R,
743 &rnd_pseudo_rand, &rnd_info ) == 0 );
744 TEST_ASSERT( mpi_cmp_mpi( &R.X, &xZ ) == 0 );
745 TEST_ASSERT( mpi_cmp_mpi( &R.Y, &yZ ) == 0 );
746 TEST_ASSERT( ecp_check_pubkey( &grp, &R ) == 0 );
747
748exit:
749 ecp_group_free( &grp ); ecp_point_free( &R );
750 mpi_free( &dA ); mpi_free( &xA ); mpi_free( &yA ); mpi_free( &dB );
751 mpi_free( &xB ); mpi_free( &yB ); mpi_free( &xZ ); mpi_free( &yZ );
752}
753
754void test_suite_ecp_test_vec_x( int id, char *dA_hex, char *xA_hex,
755 char *dB_hex, char *xB_hex, char *xS_hex )
756{
757 ecp_group grp;
758 ecp_point R;
759 mpi dA, xA, dB, xB, xS;
760 rnd_pseudo_info rnd_info;
761
762 ecp_group_init( &grp ); ecp_point_init( &R );
763 mpi_init( &dA ); mpi_init( &xA );
764 mpi_init( &dB ); mpi_init( &xB );
765 mpi_init( &xS );
766 memset( &rnd_info, 0x00, sizeof( rnd_pseudo_info ) );
767
768 TEST_ASSERT( ecp_use_known_dp( &grp, id ) == 0 );
769
770 TEST_ASSERT( ecp_check_pubkey( &grp, &grp.G ) == 0 );
771
772 TEST_ASSERT( mpi_read_string( &dA, 16, dA_hex ) == 0 );
773 TEST_ASSERT( mpi_read_string( &dB, 16, dB_hex ) == 0 );
774 TEST_ASSERT( mpi_read_string( &xA, 16, xA_hex ) == 0 );
775 TEST_ASSERT( mpi_read_string( &xB, 16, xB_hex ) == 0 );
776 TEST_ASSERT( mpi_read_string( &xS, 16, xS_hex ) == 0 );
777
778 TEST_ASSERT( ecp_mul( &grp, &R, &dA, &grp.G,
779 &rnd_pseudo_rand, &rnd_info ) == 0 );
780 TEST_ASSERT( ecp_check_pubkey( &grp, &R ) == 0 );
781 TEST_ASSERT( mpi_cmp_mpi( &R.X, &xA ) == 0 );
782
783 TEST_ASSERT( ecp_mul( &grp, &R, &dB, &R,
784 &rnd_pseudo_rand, &rnd_info ) == 0 );
785 TEST_ASSERT( ecp_check_pubkey( &grp, &R ) == 0 );
786 TEST_ASSERT( mpi_cmp_mpi( &R.X, &xS ) == 0 );
787
788 TEST_ASSERT( ecp_mul( &grp, &R, &dB, &grp.G, NULL, NULL ) == 0 );
789 TEST_ASSERT( ecp_check_pubkey( &grp, &R ) == 0 );
790 TEST_ASSERT( mpi_cmp_mpi( &R.X, &xB ) == 0 );
791
792 TEST_ASSERT( ecp_mul( &grp, &R, &dA, &R, NULL, NULL ) == 0 );
793 TEST_ASSERT( ecp_check_pubkey( &grp, &R ) == 0 );
794 TEST_ASSERT( mpi_cmp_mpi( &R.X, &xS ) == 0 );
795
796exit:
797 ecp_group_free( &grp ); ecp_point_free( &R );
798 mpi_free( &dA ); mpi_free( &xA );
799 mpi_free( &dB ); mpi_free( &xB );
800 mpi_free( &xS );
801}
802
803void test_suite_ecp_fast_mod( int id, char *N_str )
804{
805 ecp_group grp;
806 mpi N, R;
807
808 mpi_init( &N ); mpi_init( &R );
809 ecp_group_init( &grp );
810
811 TEST_ASSERT( mpi_read_string( &N, 16, N_str ) == 0 );
812 TEST_ASSERT( ecp_use_known_dp( &grp, id ) == 0 );
813 TEST_ASSERT( grp.modp != NULL );
814
815 /*
816 * Store correct result before we touch N
817 */
818 TEST_ASSERT( mpi_mod_mpi( &R, &N, &grp.P ) == 0 );
819
820 TEST_ASSERT( grp.modp( &N ) == 0 );
821 TEST_ASSERT( mpi_msb( &N ) <= grp.pbits + 3 );
822
823 /*
824 * Use mod rather than addition/subtraction in case previous test fails
825 */
826 TEST_ASSERT( mpi_mod_mpi( &N, &N, &grp.P ) == 0 );
827 TEST_ASSERT( mpi_cmp_mpi( &N, &R ) == 0 );
828
829exit:
830 mpi_free( &N ); mpi_free( &R );
831 ecp_group_free( &grp );
832}
833
834void test_suite_ecp_write_binary( int id, char *x, char *y, char *z, int format,
835 char *out, int blen, int ret )
836{
837 ecp_group grp;
838 ecp_point P;
839 unsigned char buf[256], str[512];
840 size_t olen;
841
842 memset( buf, 0, sizeof( buf ) );
843 memset( str, 0, sizeof( str ) );
844
845 ecp_group_init( &grp ); ecp_point_init( &P );
846
847 TEST_ASSERT( ecp_use_known_dp( &grp, id ) == 0 );
848
849 TEST_ASSERT( mpi_read_string( &P.X, 16, x ) == 0 );
850 TEST_ASSERT( mpi_read_string( &P.Y, 16, y ) == 0 );
851 TEST_ASSERT( mpi_read_string( &P.Z, 16, z ) == 0 );
852
853 TEST_ASSERT( ecp_point_write_binary( &grp, &P, format,
854 &olen, buf, blen ) == ret );
855
856 if( ret == 0 )
857 {
858 hexify( str, buf, olen );
859 TEST_ASSERT( strcasecmp( (char *) str, out ) == 0 );
860 }
861
862exit:
863 ecp_group_free( &grp ); ecp_point_free( &P );
864}
865
866void test_suite_ecp_read_binary( int id, char *input, char *x, char *y, char *z,
867 int ret )
868{
869 ecp_group grp;
870 ecp_point P;
871 mpi X, Y, Z;
872 int ilen;
873 unsigned char buf[256];
874
875 memset( buf, 0, sizeof( buf ) );
876
877 ecp_group_init( &grp ); ecp_point_init( &P );
878 mpi_init( &X ); mpi_init( &Y ); mpi_init( &Z );
879
880 TEST_ASSERT( ecp_use_known_dp( &grp, id ) == 0 );
881
882 TEST_ASSERT( mpi_read_string( &X, 16, x ) == 0 );
883 TEST_ASSERT( mpi_read_string( &Y, 16, y ) == 0 );
884 TEST_ASSERT( mpi_read_string( &Z, 16, z ) == 0 );
885
886 ilen = unhexify( buf, input );
887
888 TEST_ASSERT( ecp_point_read_binary( &grp, &P, buf, ilen ) == ret );
889
890 if( ret == 0 )
891 {
892 TEST_ASSERT( mpi_cmp_mpi( &P.X, &X ) == 0 );
893 TEST_ASSERT( mpi_cmp_mpi( &P.Y, &Y ) == 0 );
894 TEST_ASSERT( mpi_cmp_mpi( &P.Z, &Z ) == 0 );
895 }
896
897exit:
898 ecp_group_free( &grp ); ecp_point_free( &P );
899 mpi_free( &X ); mpi_free( &Y ); mpi_free( &Z );
900}
901
902void test_suite_ecp_tls_read_point( int id, char *input, char *x, char *y, char *z,
903 int ret )
904{
905 ecp_group grp;
906 ecp_point P;
907 mpi X, Y, Z;
908 size_t ilen;
909 unsigned char buf[256];
910 const unsigned char *vbuf = buf;
911
912 memset( buf, 0, sizeof( buf ) );
913
914 ecp_group_init( &grp ); ecp_point_init( &P );
915 mpi_init( &X ); mpi_init( &Y ); mpi_init( &Z );
916
917 TEST_ASSERT( ecp_use_known_dp( &grp, id ) == 0 );
918
919 TEST_ASSERT( mpi_read_string( &X, 16, x ) == 0 );
920 TEST_ASSERT( mpi_read_string( &Y, 16, y ) == 0 );
921 TEST_ASSERT( mpi_read_string( &Z, 16, z ) == 0 );
922
923 ilen = unhexify( buf, input );
924
925 TEST_ASSERT( ecp_tls_read_point( &grp, &P, &vbuf, ilen ) == ret );
926
927 if( ret == 0 )
928 {
929 TEST_ASSERT( mpi_cmp_mpi( &P.X, &X ) == 0 );
930 TEST_ASSERT( mpi_cmp_mpi( &P.Y, &Y ) == 0 );
931 TEST_ASSERT( mpi_cmp_mpi( &P.Z, &Z ) == 0 );
932 TEST_ASSERT( *vbuf == 0x00 );
933 }
934
935exit:
936 ecp_group_free( &grp ); ecp_point_free( &P );
937 mpi_free( &X ); mpi_free( &Y ); mpi_free( &Z );
938}
939
940void test_suite_ecp_tls_write_read_point( int id )
941{
942 ecp_group grp;
943 ecp_point pt;
944 unsigned char buf[256];
945 const unsigned char *vbuf;
946 size_t olen;
947
948 ecp_group_init( &grp );
949 ecp_point_init( &pt );
950
951 TEST_ASSERT( ecp_use_known_dp( &grp, id ) == 0 );
952
953 memset( buf, 0x00, sizeof( buf ) ); vbuf = buf;
954 TEST_ASSERT( ecp_tls_write_point( &grp, &grp.G,
955 POLARSSL_ECP_PF_COMPRESSED, &olen, buf, 256 ) == 0 );
956 TEST_ASSERT( ecp_tls_read_point( &grp, &pt, &vbuf, olen )
958 TEST_ASSERT( vbuf == buf + olen );
959
960 memset( buf, 0x00, sizeof( buf ) ); vbuf = buf;
961 TEST_ASSERT( ecp_tls_write_point( &grp, &grp.G,
962 POLARSSL_ECP_PF_UNCOMPRESSED, &olen, buf, 256 ) == 0 );
963 TEST_ASSERT( ecp_tls_read_point( &grp, &pt, &vbuf, olen ) == 0 );
964 TEST_ASSERT( mpi_cmp_mpi( &grp.G.X, &pt.X ) == 0 );
965 TEST_ASSERT( mpi_cmp_mpi( &grp.G.Y, &pt.Y ) == 0 );
966 TEST_ASSERT( mpi_cmp_mpi( &grp.G.Z, &pt.Z ) == 0 );
967 TEST_ASSERT( vbuf == buf + olen );
968
969 memset( buf, 0x00, sizeof( buf ) ); vbuf = buf;
970 TEST_ASSERT( ecp_set_zero( &pt ) == 0 );
972 POLARSSL_ECP_PF_COMPRESSED, &olen, buf, 256 ) == 0 );
973 TEST_ASSERT( ecp_tls_read_point( &grp, &pt, &vbuf, olen ) == 0 );
974 TEST_ASSERT( ecp_is_zero( &pt ) );
975 TEST_ASSERT( vbuf == buf + olen );
976
977 memset( buf, 0x00, sizeof( buf ) ); vbuf = buf;
978 TEST_ASSERT( ecp_set_zero( &pt ) == 0 );
980 POLARSSL_ECP_PF_UNCOMPRESSED, &olen, buf, 256 ) == 0 );
981 TEST_ASSERT( ecp_tls_read_point( &grp, &pt, &vbuf, olen ) == 0 );
982 TEST_ASSERT( ecp_is_zero( &pt ) );
983 TEST_ASSERT( vbuf == buf + olen );
984
985exit:
986 ecp_group_free( &grp );
987 ecp_point_free( &pt );
988}
989
990void test_suite_ecp_tls_read_group( char *record, int result, int bits )
991{
992 ecp_group grp;
993 unsigned char buf[10];
994 const unsigned char *vbuf = buf;
995 int len, ret;
996
997 ecp_group_init( &grp );
998 memset( buf, 0x00, sizeof( buf ) );
999
1000 len = unhexify( buf, record );
1001
1002 ret = ecp_tls_read_group( &grp, &vbuf, len );
1003
1004 TEST_ASSERT( ret == result );
1005 if( ret == 0)
1006 {
1007 TEST_ASSERT( mpi_msb( &grp.P ) == (size_t) bits );
1008 TEST_ASSERT( *vbuf == 0x00 );
1009 }
1010
1011exit:
1012 ecp_group_free( &grp );
1013}
1014
1015void test_suite_ecp_tls_write_read_group( int id )
1016{
1017 ecp_group grp1, grp2;
1018 unsigned char buf[10];
1019 const unsigned char *vbuf = buf;
1020 size_t len;
1021 int ret;
1022
1023 ecp_group_init( &grp1 );
1024 ecp_group_init( &grp2 );
1025 memset( buf, 0x00, sizeof( buf ) );
1026
1027 TEST_ASSERT( ecp_use_known_dp( &grp1, id ) == 0 );
1028
1029 TEST_ASSERT( ecp_tls_write_group( &grp1, &len, buf, 10 ) == 0 );
1030 ret = ecp_tls_read_group( &grp2, &vbuf, len );
1031 TEST_ASSERT( ret == 0 );
1032
1033 if( ret == 0 )
1034 {
1035 TEST_ASSERT( mpi_cmp_mpi( &grp1.N, &grp2.N ) == 0 );
1036 TEST_ASSERT( grp1.id == grp2.id );
1037 }
1038
1039exit:
1040 ecp_group_free( &grp1 );
1041 ecp_group_free( &grp2 );
1042}
1043
1044void test_suite_ecp_check_privkey( int id, char *key_hex, int ret )
1045{
1046 ecp_group grp;
1047 mpi d;
1048
1049 ecp_group_init( &grp );
1050 mpi_init( &d );
1051
1052 TEST_ASSERT( ecp_use_known_dp( &grp, id ) == 0 );
1053 TEST_ASSERT( mpi_read_string( &d, 16, key_hex ) == 0 );
1054
1055 TEST_ASSERT( ecp_check_privkey( &grp, &d ) == ret );
1056
1057exit:
1058 ecp_group_free( &grp );
1059 mpi_free( &d );
1060}
1061
1062void test_suite_ecp_gen_keypair( int id )
1063{
1064 ecp_group grp;
1065 ecp_point Q;
1066 mpi d;
1067 rnd_pseudo_info rnd_info;
1068
1069 ecp_group_init( &grp );
1070 ecp_point_init( &Q );
1071 mpi_init( &d );
1072 memset( &rnd_info, 0x00, sizeof( rnd_pseudo_info ) );
1073
1074 TEST_ASSERT( ecp_use_known_dp( &grp, id ) == 0 );
1075
1076 TEST_ASSERT( ecp_gen_keypair( &grp, &d, &Q, &rnd_pseudo_rand, &rnd_info )
1077 == 0 );
1078
1079 TEST_ASSERT( ecp_check_pubkey( &grp, &Q ) == 0 );
1080 TEST_ASSERT( ecp_check_privkey( &grp, &d ) == 0 );
1081
1082exit:
1083 ecp_group_free( &grp );
1084 ecp_point_free( &Q );
1085 mpi_free( &d );
1086}
1087
1088void test_suite_ecp_gen_key( int id )
1089{
1090 ecp_keypair key;
1091 rnd_pseudo_info rnd_info;
1092
1093 ecp_keypair_init( &key );
1094 memset( &rnd_info, 0x00, sizeof( rnd_pseudo_info ) );
1095
1096 TEST_ASSERT( ecp_gen_key( id, &key, &rnd_pseudo_rand, &rnd_info ) == 0 );
1097
1098 TEST_ASSERT( ecp_check_pubkey( &key.grp, &key.Q ) == 0 );
1099 TEST_ASSERT( ecp_check_privkey( &key.grp, &key.d ) == 0 );
1100
1101exit:
1102 ecp_keypair_free( &key );
1103}
1104
1105#ifdef POLARSSL_SELF_TEST
1106void test_suite_ecp_selftest()
1107{
1108 TEST_ASSERT( ecp_self_test( 0 ) == 0 );
1109
1110exit:
1111 return;
1112}
1113#endif /* POLARSSL_SELF_TEST */
1114
1115
1116#endif /* POLARSSL_ECP_C */
1117
1118
1119int dep_check( char *str )
1120{
1121 if( str == NULL )
1122 return( 1 );
1123
1124 if( strcmp( str, "POLARSSL_ECP_DP_BP512R1_ENABLED" ) == 0 )
1125 {
1126#if defined(POLARSSL_ECP_DP_BP512R1_ENABLED)
1127 return( 0 );
1128#else
1129 return( 1 );
1130#endif
1131 }
1132 if( strcmp( str, "POLARSSL_ECP_DP_BP384R1_ENABLED" ) == 0 )
1133 {
1134#if defined(POLARSSL_ECP_DP_BP384R1_ENABLED)
1135 return( 0 );
1136#else
1137 return( 1 );
1138#endif
1139 }
1140 if( strcmp( str, "POLARSSL_ECP_DP_SECP256R1_ENABLED" ) == 0 )
1141 {
1142#if defined(POLARSSL_ECP_DP_SECP256R1_ENABLED)
1143 return( 0 );
1144#else
1145 return( 1 );
1146#endif
1147 }
1148 if( strcmp( str, "POLARSSL_ECP_DP_M255_ENABLED" ) == 0 )
1149 {
1150#if defined(POLARSSL_ECP_DP_M255_ENABLED)
1151 return( 0 );
1152#else
1153 return( 1 );
1154#endif
1155 }
1156 if( strcmp( str, "POLARSSL_ECP_DP_SECP224K1_ENABLED" ) == 0 )
1157 {
1158#if defined(POLARSSL_ECP_DP_SECP224K1_ENABLED)
1159 return( 0 );
1160#else
1161 return( 1 );
1162#endif
1163 }
1164 if( strcmp( str, "POLARSSL_ECP_DP_SECP256K1_ENABLED" ) == 0 )
1165 {
1166#if defined(POLARSSL_ECP_DP_SECP256K1_ENABLED)
1167 return( 0 );
1168#else
1169 return( 1 );
1170#endif
1171 }
1172 if( strcmp( str, "POLARSSL_ECP_DP_BP256R1_ENABLED" ) == 0 )
1173 {
1174#if defined(POLARSSL_ECP_DP_BP256R1_ENABLED)
1175 return( 0 );
1176#else
1177 return( 1 );
1178#endif
1179 }
1180 if( strcmp( str, "POLARSSL_ECP_DP_SECP192K1_ENABLED" ) == 0 )
1181 {
1182#if defined(POLARSSL_ECP_DP_SECP192K1_ENABLED)
1183 return( 0 );
1184#else
1185 return( 1 );
1186#endif
1187 }
1188 if( strcmp( str, "POLARSSL_ECP_DP_SECP521R1_ENABLED" ) == 0 )
1189 {
1190#if defined(POLARSSL_ECP_DP_SECP521R1_ENABLED)
1191 return( 0 );
1192#else
1193 return( 1 );
1194#endif
1195 }
1196 if( strcmp( str, "POLARSSL_ECP_DP_SECP384R1_ENABLED" ) == 0 )
1197 {
1198#if defined(POLARSSL_ECP_DP_SECP384R1_ENABLED)
1199 return( 0 );
1200#else
1201 return( 1 );
1202#endif
1203 }
1204 if( strcmp( str, "POLARSSL_ECP_DP_SECP192R1_ENABLED" ) == 0 )
1205 {
1206#if defined(POLARSSL_ECP_DP_SECP192R1_ENABLED)
1207 return( 0 );
1208#else
1209 return( 1 );
1210#endif
1211 }
1212 if( strcmp( str, "POLARSSL_ECP_DP_SECP224R1_ENABLED" ) == 0 )
1213 {
1214#if defined(POLARSSL_ECP_DP_SECP224R1_ENABLED)
1215 return( 0 );
1216#else
1217 return( 1 );
1218#endif
1219 }
1220
1221
1222 return( 1 );
1223}
1224
1225int dispatch_test(int cnt, char *params[50])
1226{
1227 int ret;
1228 ((void) cnt);
1229 ((void) params);
1230
1231#if defined(TEST_SUITE_ACTIVE)
1232 if( strcmp( params[0], "ecp_curve_info" ) == 0 )
1233 {
1234
1235 int param1;
1236 int param2;
1237 int param3;
1238 char *param4 = params[4];
1239
1240 if( cnt != 5 )
1241 {
1242 fprintf( stderr, "\nIncorrect argument count (%d != %d)\n", cnt, 5 );
1243 return( 2 );
1244 }
1245
1246 if( verify_int( params[1], &param1 ) != 0 ) return( 2 );
1247 if( verify_int( params[2], &param2 ) != 0 ) return( 2 );
1248 if( verify_int( params[3], &param3 ) != 0 ) return( 2 );
1249 if( verify_string( &param4 ) != 0 ) return( 2 );
1250
1251 test_suite_ecp_curve_info( param1, param2, param3, param4 );
1252 return ( 0 );
1253
1254 return ( 3 );
1255 }
1256 else
1257 if( strcmp( params[0], "ecp_small_add" ) == 0 )
1258 {
1259
1260 int param1;
1261 char *param2 = params[2];
1262 char *param3 = params[3];
1263 int param4;
1264 char *param5 = params[5];
1265 char *param6 = params[6];
1266 int param7;
1267 int param8;
1268 int param9;
1269
1270 if( cnt != 10 )
1271 {
1272 fprintf( stderr, "\nIncorrect argument count (%d != %d)\n", cnt, 10 );
1273 return( 2 );
1274 }
1275
1276 if( verify_int( params[1], &param1 ) != 0 ) return( 2 );
1277 if( verify_string( &param2 ) != 0 ) return( 2 );
1278 if( verify_string( &param3 ) != 0 ) return( 2 );
1279 if( verify_int( params[4], &param4 ) != 0 ) return( 2 );
1280 if( verify_string( &param5 ) != 0 ) return( 2 );
1281 if( verify_string( &param6 ) != 0 ) return( 2 );
1282 if( verify_int( params[7], &param7 ) != 0 ) return( 2 );
1283 if( verify_int( params[8], &param8 ) != 0 ) return( 2 );
1284 if( verify_int( params[9], &param9 ) != 0 ) return( 2 );
1285
1286 test_suite_ecp_small_add( param1, param2, param3, param4, param5, param6, param7, param8, param9 );
1287 return ( 0 );
1288
1289 return ( 3 );
1290 }
1291 else
1292 if( strcmp( params[0], "ecp_small_sub" ) == 0 )
1293 {
1294
1295 int param1;
1296 char *param2 = params[2];
1297 char *param3 = params[3];
1298 int param4;
1299 char *param5 = params[5];
1300 char *param6 = params[6];
1301 int param7;
1302 int param8;
1303 int param9;
1304
1305 if( cnt != 10 )
1306 {
1307 fprintf( stderr, "\nIncorrect argument count (%d != %d)\n", cnt, 10 );
1308 return( 2 );
1309 }
1310
1311 if( verify_int( params[1], &param1 ) != 0 ) return( 2 );
1312 if( verify_string( &param2 ) != 0 ) return( 2 );
1313 if( verify_string( &param3 ) != 0 ) return( 2 );
1314 if( verify_int( params[4], &param4 ) != 0 ) return( 2 );
1315 if( verify_string( &param5 ) != 0 ) return( 2 );
1316 if( verify_string( &param6 ) != 0 ) return( 2 );
1317 if( verify_int( params[7], &param7 ) != 0 ) return( 2 );
1318 if( verify_int( params[8], &param8 ) != 0 ) return( 2 );
1319 if( verify_int( params[9], &param9 ) != 0 ) return( 2 );
1320
1321 test_suite_ecp_small_sub( param1, param2, param3, param4, param5, param6, param7, param8, param9 );
1322 return ( 0 );
1323
1324 return ( 3 );
1325 }
1326 else
1327 if( strcmp( params[0], "ecp_small_mul" ) == 0 )
1328 {
1329
1330 int param1;
1331 int param2;
1332 int param3;
1333 int param4;
1334 int param5;
1335
1336 if( cnt != 6 )
1337 {
1338 fprintf( stderr, "\nIncorrect argument count (%d != %d)\n", cnt, 6 );
1339 return( 2 );
1340 }
1341
1342 if( verify_int( params[1], &param1 ) != 0 ) return( 2 );
1343 if( verify_int( params[2], &param2 ) != 0 ) return( 2 );
1344 if( verify_int( params[3], &param3 ) != 0 ) return( 2 );
1345 if( verify_int( params[4], &param4 ) != 0 ) return( 2 );
1346 if( verify_int( params[5], &param5 ) != 0 ) return( 2 );
1347
1348 test_suite_ecp_small_mul( param1, param2, param3, param4, param5 );
1349 return ( 0 );
1350
1351 return ( 3 );
1352 }
1353 else
1354 if( strcmp( params[0], "ecp_small_check_pub" ) == 0 )
1355 {
1356
1357 int param1;
1358 int param2;
1359 int param3;
1360 int param4;
1361
1362 if( cnt != 5 )
1363 {
1364 fprintf( stderr, "\nIncorrect argument count (%d != %d)\n", cnt, 5 );
1365 return( 2 );
1366 }
1367
1368 if( verify_int( params[1], &param1 ) != 0 ) return( 2 );
1369 if( verify_int( params[2], &param2 ) != 0 ) return( 2 );
1370 if( verify_int( params[3], &param3 ) != 0 ) return( 2 );
1371 if( verify_int( params[4], &param4 ) != 0 ) return( 2 );
1372
1373 test_suite_ecp_small_check_pub( param1, param2, param3, param4 );
1374 return ( 0 );
1375
1376 return ( 3 );
1377 }
1378 else
1379 if( strcmp( params[0], "ecp_check_pub_mx" ) == 0 )
1380 {
1381
1382 int param1;
1383 char *param2 = params[2];
1384 int param3;
1385
1386 if( cnt != 4 )
1387 {
1388 fprintf( stderr, "\nIncorrect argument count (%d != %d)\n", cnt, 4 );
1389 return( 2 );
1390 }
1391
1392 if( verify_int( params[1], &param1 ) != 0 ) return( 2 );
1393 if( verify_string( &param2 ) != 0 ) return( 2 );
1394 if( verify_int( params[3], &param3 ) != 0 ) return( 2 );
1395
1396 test_suite_ecp_check_pub_mx( param1, param2, param3 );
1397 return ( 0 );
1398
1399 return ( 3 );
1400 }
1401 else
1402 if( strcmp( params[0], "ecp_test_vect" ) == 0 )
1403 {
1404
1405 int param1;
1406 char *param2 = params[2];
1407 char *param3 = params[3];
1408 char *param4 = params[4];
1409 char *param5 = params[5];
1410 char *param6 = params[6];
1411 char *param7 = params[7];
1412 char *param8 = params[8];
1413 char *param9 = params[9];
1414
1415 if( cnt != 10 )
1416 {
1417 fprintf( stderr, "\nIncorrect argument count (%d != %d)\n", cnt, 10 );
1418 return( 2 );
1419 }
1420
1421 if( verify_int( params[1], &param1 ) != 0 ) return( 2 );
1422 if( verify_string( &param2 ) != 0 ) return( 2 );
1423 if( verify_string( &param3 ) != 0 ) return( 2 );
1424 if( verify_string( &param4 ) != 0 ) return( 2 );
1425 if( verify_string( &param5 ) != 0 ) return( 2 );
1426 if( verify_string( &param6 ) != 0 ) return( 2 );
1427 if( verify_string( &param7 ) != 0 ) return( 2 );
1428 if( verify_string( &param8 ) != 0 ) return( 2 );
1429 if( verify_string( &param9 ) != 0 ) return( 2 );
1430
1431 test_suite_ecp_test_vect( param1, param2, param3, param4, param5, param6, param7, param8, param9 );
1432 return ( 0 );
1433
1434 return ( 3 );
1435 }
1436 else
1437 if( strcmp( params[0], "ecp_test_vec_x" ) == 0 )
1438 {
1439
1440 int param1;
1441 char *param2 = params[2];
1442 char *param3 = params[3];
1443 char *param4 = params[4];
1444 char *param5 = params[5];
1445 char *param6 = params[6];
1446
1447 if( cnt != 7 )
1448 {
1449 fprintf( stderr, "\nIncorrect argument count (%d != %d)\n", cnt, 7 );
1450 return( 2 );
1451 }
1452
1453 if( verify_int( params[1], &param1 ) != 0 ) return( 2 );
1454 if( verify_string( &param2 ) != 0 ) return( 2 );
1455 if( verify_string( &param3 ) != 0 ) return( 2 );
1456 if( verify_string( &param4 ) != 0 ) return( 2 );
1457 if( verify_string( &param5 ) != 0 ) return( 2 );
1458 if( verify_string( &param6 ) != 0 ) return( 2 );
1459
1460 test_suite_ecp_test_vec_x( param1, param2, param3, param4, param5, param6 );
1461 return ( 0 );
1462
1463 return ( 3 );
1464 }
1465 else
1466 if( strcmp( params[0], "ecp_fast_mod" ) == 0 )
1467 {
1468
1469 int param1;
1470 char *param2 = params[2];
1471
1472 if( cnt != 3 )
1473 {
1474 fprintf( stderr, "\nIncorrect argument count (%d != %d)\n", cnt, 3 );
1475 return( 2 );
1476 }
1477
1478 if( verify_int( params[1], &param1 ) != 0 ) return( 2 );
1479 if( verify_string( &param2 ) != 0 ) return( 2 );
1480
1481 test_suite_ecp_fast_mod( param1, param2 );
1482 return ( 0 );
1483
1484 return ( 3 );
1485 }
1486 else
1487 if( strcmp( params[0], "ecp_write_binary" ) == 0 )
1488 {
1489
1490 int param1;
1491 char *param2 = params[2];
1492 char *param3 = params[3];
1493 char *param4 = params[4];
1494 int param5;
1495 char *param6 = params[6];
1496 int param7;
1497 int param8;
1498
1499 if( cnt != 9 )
1500 {
1501 fprintf( stderr, "\nIncorrect argument count (%d != %d)\n", cnt, 9 );
1502 return( 2 );
1503 }
1504
1505 if( verify_int( params[1], &param1 ) != 0 ) return( 2 );
1506 if( verify_string( &param2 ) != 0 ) return( 2 );
1507 if( verify_string( &param3 ) != 0 ) return( 2 );
1508 if( verify_string( &param4 ) != 0 ) return( 2 );
1509 if( verify_int( params[5], &param5 ) != 0 ) return( 2 );
1510 if( verify_string( &param6 ) != 0 ) return( 2 );
1511 if( verify_int( params[7], &param7 ) != 0 ) return( 2 );
1512 if( verify_int( params[8], &param8 ) != 0 ) return( 2 );
1513
1514 test_suite_ecp_write_binary( param1, param2, param3, param4, param5, param6, param7, param8 );
1515 return ( 0 );
1516
1517 return ( 3 );
1518 }
1519 else
1520 if( strcmp( params[0], "ecp_read_binary" ) == 0 )
1521 {
1522
1523 int param1;
1524 char *param2 = params[2];
1525 char *param3 = params[3];
1526 char *param4 = params[4];
1527 char *param5 = params[5];
1528 int param6;
1529
1530 if( cnt != 7 )
1531 {
1532 fprintf( stderr, "\nIncorrect argument count (%d != %d)\n", cnt, 7 );
1533 return( 2 );
1534 }
1535
1536 if( verify_int( params[1], &param1 ) != 0 ) return( 2 );
1537 if( verify_string( &param2 ) != 0 ) return( 2 );
1538 if( verify_string( &param3 ) != 0 ) return( 2 );
1539 if( verify_string( &param4 ) != 0 ) return( 2 );
1540 if( verify_string( &param5 ) != 0 ) return( 2 );
1541 if( verify_int( params[6], &param6 ) != 0 ) return( 2 );
1542
1543 test_suite_ecp_read_binary( param1, param2, param3, param4, param5, param6 );
1544 return ( 0 );
1545
1546 return ( 3 );
1547 }
1548 else
1549 if( strcmp( params[0], "ecp_tls_read_point" ) == 0 )
1550 {
1551
1552 int param1;
1553 char *param2 = params[2];
1554 char *param3 = params[3];
1555 char *param4 = params[4];
1556 char *param5 = params[5];
1557 int param6;
1558
1559 if( cnt != 7 )
1560 {
1561 fprintf( stderr, "\nIncorrect argument count (%d != %d)\n", cnt, 7 );
1562 return( 2 );
1563 }
1564
1565 if( verify_int( params[1], &param1 ) != 0 ) return( 2 );
1566 if( verify_string( &param2 ) != 0 ) return( 2 );
1567 if( verify_string( &param3 ) != 0 ) return( 2 );
1568 if( verify_string( &param4 ) != 0 ) return( 2 );
1569 if( verify_string( &param5 ) != 0 ) return( 2 );
1570 if( verify_int( params[6], &param6 ) != 0 ) return( 2 );
1571
1572 test_suite_ecp_tls_read_point( param1, param2, param3, param4, param5, param6 );
1573 return ( 0 );
1574
1575 return ( 3 );
1576 }
1577 else
1578 if( strcmp( params[0], "ecp_tls_write_read_point" ) == 0 )
1579 {
1580
1581 int param1;
1582
1583 if( cnt != 2 )
1584 {
1585 fprintf( stderr, "\nIncorrect argument count (%d != %d)\n", cnt, 2 );
1586 return( 2 );
1587 }
1588
1589 if( verify_int( params[1], &param1 ) != 0 ) return( 2 );
1590
1591 test_suite_ecp_tls_write_read_point( param1 );
1592 return ( 0 );
1593
1594 return ( 3 );
1595 }
1596 else
1597 if( strcmp( params[0], "ecp_tls_read_group" ) == 0 )
1598 {
1599
1600 char *param1 = params[1];
1601 int param2;
1602 int param3;
1603
1604 if( cnt != 4 )
1605 {
1606 fprintf( stderr, "\nIncorrect argument count (%d != %d)\n", cnt, 4 );
1607 return( 2 );
1608 }
1609
1610 if( verify_string( &param1 ) != 0 ) return( 2 );
1611 if( verify_int( params[2], &param2 ) != 0 ) return( 2 );
1612 if( verify_int( params[3], &param3 ) != 0 ) return( 2 );
1613
1614 test_suite_ecp_tls_read_group( param1, param2, param3 );
1615 return ( 0 );
1616
1617 return ( 3 );
1618 }
1619 else
1620 if( strcmp( params[0], "ecp_tls_write_read_group" ) == 0 )
1621 {
1622
1623 int param1;
1624
1625 if( cnt != 2 )
1626 {
1627 fprintf( stderr, "\nIncorrect argument count (%d != %d)\n", cnt, 2 );
1628 return( 2 );
1629 }
1630
1631 if( verify_int( params[1], &param1 ) != 0 ) return( 2 );
1632
1633 test_suite_ecp_tls_write_read_group( param1 );
1634 return ( 0 );
1635
1636 return ( 3 );
1637 }
1638 else
1639 if( strcmp( params[0], "ecp_check_privkey" ) == 0 )
1640 {
1641
1642 int param1;
1643 char *param2 = params[2];
1644 int param3;
1645
1646 if( cnt != 4 )
1647 {
1648 fprintf( stderr, "\nIncorrect argument count (%d != %d)\n", cnt, 4 );
1649 return( 2 );
1650 }
1651
1652 if( verify_int( params[1], &param1 ) != 0 ) return( 2 );
1653 if( verify_string( &param2 ) != 0 ) return( 2 );
1654 if( verify_int( params[3], &param3 ) != 0 ) return( 2 );
1655
1656 test_suite_ecp_check_privkey( param1, param2, param3 );
1657 return ( 0 );
1658
1659 return ( 3 );
1660 }
1661 else
1662 if( strcmp( params[0], "ecp_gen_keypair" ) == 0 )
1663 {
1664
1665 int param1;
1666
1667 if( cnt != 2 )
1668 {
1669 fprintf( stderr, "\nIncorrect argument count (%d != %d)\n", cnt, 2 );
1670 return( 2 );
1671 }
1672
1673 if( verify_int( params[1], &param1 ) != 0 ) return( 2 );
1674
1675 test_suite_ecp_gen_keypair( param1 );
1676 return ( 0 );
1677
1678 return ( 3 );
1679 }
1680 else
1681 if( strcmp( params[0], "ecp_gen_key" ) == 0 )
1682 {
1683
1684 int param1;
1685
1686 if( cnt != 2 )
1687 {
1688 fprintf( stderr, "\nIncorrect argument count (%d != %d)\n", cnt, 2 );
1689 return( 2 );
1690 }
1691
1692 if( verify_int( params[1], &param1 ) != 0 ) return( 2 );
1693
1694 test_suite_ecp_gen_key( param1 );
1695 return ( 0 );
1696
1697 return ( 3 );
1698 }
1699 else
1700 if( strcmp( params[0], "ecp_selftest" ) == 0 )
1701 {
1702 #ifdef POLARSSL_SELF_TEST
1703
1704
1705 if( cnt != 1 )
1706 {
1707 fprintf( stderr, "\nIncorrect argument count (%d != %d)\n", cnt, 1 );
1708 return( 2 );
1709 }
1710
1711
1712 test_suite_ecp_selftest( );
1713 return ( 0 );
1714 #endif /* POLARSSL_SELF_TEST */
1715
1716 return ( 3 );
1717 }
1718 else
1719
1720 {
1721 fprintf( stdout, "FAILED\nSkipping unknown test function '%s'\n", params[0] );
1722 fflush( stdout );
1723 return( 1 );
1724 }
1725#else
1726 return( 3 );
1727#endif
1728 return( ret );
1729}
1730
1731int get_line( FILE *f, char *buf, size_t len )
1732{
1733 char *ret;
1734
1735 ret = fgets( buf, len, f );
1736 if( ret == NULL )
1737 return( -1 );
1738
1739 if( strlen( buf ) && buf[strlen(buf) - 1] == '\n' )
1740 buf[strlen(buf) - 1] = '\0';
1741 if( strlen( buf ) && buf[strlen(buf) - 1] == '\r' )
1742 buf[strlen(buf) - 1] = '\0';
1743
1744 return( 0 );
1745}
1746
1747int parse_arguments( char *buf, size_t len, char *params[50] )
1748{
1749 int cnt = 0, i;
1750 char *cur = buf;
1751 char *p = buf, *q;
1752
1753 params[cnt++] = cur;
1754
1755 while( *p != '\0' && p < buf + len )
1756 {
1757 if( *p == '\\' )
1758 {
1759 p++;
1760 p++;
1761 continue;
1762 }
1763 if( *p == ':' )
1764 {
1765 if( p + 1 < buf + len )
1766 {
1767 cur = p + 1;
1768 params[cnt++] = cur;
1769 }
1770 *p = '\0';
1771 }
1772
1773 p++;
1774 }
1775
1776 // Replace newlines, question marks and colons in strings
1777 for( i = 0; i < cnt; i++ )
1778 {
1779 p = params[i];
1780 q = params[i];
1781
1782 while( *p != '\0' )
1783 {
1784 if( *p == '\\' && *(p + 1) == 'n' )
1785 {
1786 p += 2;
1787 *(q++) = '\n';
1788 }
1789 else if( *p == '\\' && *(p + 1) == ':' )
1790 {
1791 p += 2;
1792 *(q++) = ':';
1793 }
1794 else if( *p == '\\' && *(p + 1) == '?' )
1795 {
1796 p += 2;
1797 *(q++) = '?';
1798 }
1799 else
1800 *(q++) = *(p++);
1801 }
1802 *q = '\0';
1803 }
1804
1805 return( cnt );
1806}
1807
1808int main()
1809{
1810 int ret, i, cnt, total_errors = 0, total_tests = 0, total_skipped = 0;
1811 const char *filename = "/builddir/build/BUILD/polarssl-1.3.9/tests/suites/test_suite_ecp.data";
1812 FILE *file;
1813 char buf[5000];
1814 char *params[50];
1815
1816#if defined(POLARSSL_MEMORY_BUFFER_ALLOC_C)
1817 unsigned char alloc_buf[1000000];
1818 memory_buffer_alloc_init( alloc_buf, sizeof(alloc_buf) );
1819#endif
1820
1821 file = fopen( filename, "r" );
1822 if( file == NULL )
1823 {
1824 fprintf( stderr, "Failed to open\n" );
1825 return( 1 );
1826 }
1827
1828 while( !feof( file ) )
1829 {
1830 int skip = 0;
1831
1832 if( ( ret = get_line( file, buf, sizeof(buf) ) ) != 0 )
1833 break;
1834 fprintf( stdout, "%s%.66s", test_errors ? "\n" : "", buf );
1835 fprintf( stdout, " " );
1836 for( i = strlen( buf ) + 1; i < 67; i++ )
1837 fprintf( stdout, "." );
1838 fprintf( stdout, " " );
1839 fflush( stdout );
1840
1841 total_tests++;
1842
1843 if( ( ret = get_line( file, buf, sizeof(buf) ) ) != 0 )
1844 break;
1845 cnt = parse_arguments( buf, strlen(buf), params );
1846
1847 if( strcmp( params[0], "depends_on" ) == 0 )
1848 {
1849 for( i = 1; i < cnt; i++ )
1850 if( dep_check( params[i] ) != 0 )
1851 skip = 1;
1852
1853 if( ( ret = get_line( file, buf, sizeof(buf) ) ) != 0 )
1854 break;
1855 cnt = parse_arguments( buf, strlen(buf), params );
1856 }
1857
1858 if( skip == 0 )
1859 {
1860 test_errors = 0;
1861 ret = dispatch_test( cnt, params );
1862 }
1863
1864 if( skip == 1 || ret == 3 )
1865 {
1866 total_skipped++;
1867 fprintf( stdout, "----\n" );
1868 fflush( stdout );
1869 }
1870 else if( ret == 0 && test_errors == 0 )
1871 {
1872 fprintf( stdout, "PASS\n" );
1873 fflush( stdout );
1874 }
1875 else if( ret == 2 )
1876 {
1877 fprintf( stderr, "FAILED: FATAL PARSE ERROR\n" );
1878 fclose(file);
1879 exit( 2 );
1880 }
1881 else
1882 total_errors++;
1883
1884 if( ( ret = get_line( file, buf, sizeof(buf) ) ) != 0 )
1885 break;
1886 if( strlen(buf) != 0 )
1887 {
1888 fprintf( stderr, "Should be empty %d\n", (int) strlen(buf) );
1889 return( 1 );
1890 }
1891 }
1892 fclose(file);
1893
1894 fprintf( stdout, "\n----------------------------------------------------------------------------\n\n");
1895 if( total_errors == 0 )
1896 fprintf( stdout, "PASSED" );
1897 else
1898 fprintf( stdout, "FAILED" );
1899
1900 fprintf( stdout, " (%d / %d tests (%d skipped))\n",
1901 total_tests - total_errors, total_tests, total_skipped );
1902
1903#if defined(POLARSSL_MEMORY_BUFFER_ALLOC_C)
1904#if defined(POLARSSL_MEMORY_DEBUG)
1905 memory_buffer_alloc_status();
1906#endif
1908#endif
1909
1910 return( total_errors != 0 );
1911}
1912
1913
int mpi_lset(mpi *X, t_sint z)
Set value from integer.
int mpi_mod_mpi(mpi *R, const mpi *A, const mpi *B)
Modulo: R = A mod B.
void mpi_init(mpi *X)
Initialize one MPI.
size_t mpi_msb(const mpi *X)
Return the number of bits up to and including the most significant '1' bit'.
int mpi_read_string(mpi *X, int radix, const char *s)
Import from an ASCII string.
void mpi_free(mpi *X)
Unallocate one MPI.
int mpi_cmp_mpi(const mpi *X, const mpi *Y)
Compare signed values.
int mpi_cmp_int(const mpi *X, t_sint z)
Compare signed values.
Configuration options (set of defines)
Elliptic curves over GF(p)
int ecp_sub(const ecp_group *grp, ecp_point *R, const ecp_point *P, const ecp_point *Q)
Subtraction: R = P - Q.
const ecp_curve_info * ecp_curve_info_from_grp_id(ecp_group_id grp_id)
Get curve information from an internal group identifier.
#define POLARSSL_ERR_ECP_INVALID_KEY
Invalid private or public key.
Definition: ecp.h:41
int ecp_tls_read_group(ecp_group *grp, const unsigned char **buf, size_t len)
Set a group from a TLS ECParameters record.
int ecp_check_pubkey(const ecp_group *grp, const ecp_point *pt)
Check that a point is a valid public key on this curve.
int ecp_self_test(int verbose)
Checkup routine.
int ecp_mul(ecp_group *grp, ecp_point *R, const mpi *m, const ecp_point *P, int(*f_rng)(void *, unsigned char *, size_t), void *p_rng)
Multiplication by an integer: R = m * P (Not thread-safe to use same group in multiple threads)
int ecp_set_zero(ecp_point *pt)
Set a point to zero.
int ecp_point_read_binary(const ecp_group *grp, ecp_point *P, const unsigned char *buf, size_t ilen)
Import a point from unsigned binary data.
int ecp_point_read_string(ecp_point *P, int radix, const char *x, const char *y)
Import a non-zero point from two ASCII strings.
int ecp_add(const ecp_group *grp, ecp_point *R, const ecp_point *P, const ecp_point *Q)
Addition: R = P + Q.
#define POLARSSL_ERR_ECP_BAD_INPUT_DATA
Bad input parameters to function.
Definition: ecp.h:35
#define POLARSSL_ERR_ECP_BUFFER_TOO_SMALL
The buffer is too small to write to.
Definition: ecp.h:36
int ecp_tls_read_point(const ecp_group *grp, ecp_point *pt, const unsigned char **buf, size_t len)
Import a point from a TLS ECPoint record.
void ecp_point_free(ecp_point *pt)
Free the components of a point.
@ POLARSSL_ECP_DP_SECP192K1
Definition: ecp.h:72
@ POLARSSL_ECP_DP_SECP521R1
Definition: ecp.h:64
@ POLARSSL_ECP_DP_SECP256R1
Definition: ecp.h:62
@ POLARSSL_ECP_DP_BP384R1
Definition: ecp.h:66
@ POLARSSL_ECP_DP_M255
Definition: ecp.h:69
@ POLARSSL_ECP_DP_SECP224K1
Definition: ecp.h:73
@ POLARSSL_ECP_DP_SECP384R1
Definition: ecp.h:63
@ POLARSSL_ECP_DP_SECP256K1
Definition: ecp.h:74
@ POLARSSL_ECP_DP_SECP224R1
Definition: ecp.h:61
@ POLARSSL_ECP_DP_SECP192R1
Definition: ecp.h:60
@ POLARSSL_ECP_DP_BP256R1
Definition: ecp.h:65
@ POLARSSL_ECP_DP_BP512R1
Definition: ecp.h:67
const ecp_curve_info * ecp_curve_info_from_tls_id(uint16_t tls_id)
Get curve information from a TLS NamedCurve value.
void ecp_point_init(ecp_point *pt)
Initialize a point (as zero)
#define POLARSSL_ERR_ECP_FEATURE_UNAVAILABLE
Requested curve not available.
Definition: ecp.h:37
void ecp_keypair_free(ecp_keypair *key)
Free the components of a key pair.
int ecp_check_privkey(const ecp_group *grp, const mpi *d)
Check that an mpi is a valid private key for this curve.
void ecp_group_init(ecp_group *grp)
Initialize a group (to something meaningless)
int ecp_tls_write_group(const ecp_group *grp, size_t *olen, unsigned char *buf, size_t blen)
Write the TLS ECParameters record for a group.
int ecp_group_read_string(ecp_group *grp, int radix, const char *p, const char *b, const char *gx, const char *gy, const char *n)
Import an ECP group from null-terminated ASCII strings.
int ecp_gen_keypair(ecp_group *grp, mpi *d, ecp_point *Q, int(*f_rng)(void *, unsigned char *, size_t), void *p_rng)
Generate a keypair.
int ecp_is_zero(ecp_point *pt)
Tell if a point is zero.
#define POLARSSL_ECP_PF_UNCOMPRESSED
Uncompressed point format.
Definition: ecp.h:233
const ecp_curve_info * ecp_curve_info_from_name(const char *name)
Get curve information from a human-readable name.
void ecp_group_free(ecp_group *grp)
Free the components of an ECP group.
int ecp_gen_key(ecp_group_id grp_id, ecp_keypair *key, int(*f_rng)(void *, unsigned char *, size_t), void *p_rng)
Generate a keypair.
void ecp_keypair_init(ecp_keypair *key)
Initialize a key pair (as an invalid one)
#define POLARSSL_ECP_PF_COMPRESSED
Compressed point format.
Definition: ecp.h:234
int ecp_tls_write_point(const ecp_group *grp, const ecp_point *pt, int format, size_t *olen, unsigned char *buf, size_t blen)
Export a point as a TLS ECPoint record.
int ecp_use_known_dp(ecp_group *grp, ecp_group_id index)
Set a group using well-known domain parameters.
int ecp_point_write_binary(const ecp_group *grp, const ecp_point *P, int format, size_t *olen, unsigned char *buf, size_t buflen)
Export a point into unsigned binary data.
Memory allocation layer (Deprecated to platform layer)
void memory_buffer_alloc_free(void)
Free the mutex for thread-safety and clear remaining memory.
int memory_buffer_alloc_init(unsigned char *buf, size_t len)
Initialize use of stack-based memory allocator.
PolarSSL Platform abstraction layer.
Curve information for use by other modules.
Definition: ecp.h:88
uint16_t size
Definition: ecp.h:91
ECP group structure.
Definition: ecp.h:137
size_t pbits
Definition: ecp.h:144
int(* modp)(mpi *)
Definition: ecp.h:147
mpi N
Definition: ecp.h:143
ecp_group_id id
Definition: ecp.h:138
mpi P
Definition: ecp.h:139
ecp_point G
Definition: ecp.h:142
ECP key pair structure.
Definition: ecp.h:164
ecp_point Q
Definition: ecp.h:167
mpi d
Definition: ecp.h:166
ecp_group grp
Definition: ecp.h:165
ECP point structure (jacobian coordinates)
Definition: ecp.h:105
mpi Y
Definition: ecp.h:107
mpi Z
Definition: ecp.h:108
mpi X
Definition: ecp.h:106
MPI structure.
Definition: bignum.h:183
unsigned char * buf
Info structure for the pseudo random function.
static unsigned char * unhexify_alloc(const char *ibuf, size_t *olen)
Allocate and fill a buffer from hex data.
int dep_check(char *str)
int dispatch_test(int cnt, char *params[50])
#define polarssl_malloc
static void hexify(unsigned char *obuf, const unsigned char *ibuf, int len)
int parse_arguments(char *buf, size_t len, char *params[50])
#define PUT_UINT32_BE(n, b, i)
static int rnd_pseudo_rand(void *rng_state, unsigned char *output, size_t len)
This function returns random based on a pseudo random function.
int get_line(FILE *f, char *buf, size_t len)
static int test_errors
static int rnd_buffer_rand(void *rng_state, unsigned char *output, size_t len)
This function returns random based on a buffer it receives.
static int unhexify(unsigned char *obuf, const char *ibuf)
static unsigned char * zero_alloc(size_t len)
Allocate and zeroize a buffer.
static int rnd_std_rand(void *rng_state, unsigned char *output, size_t len)
This function just returns data from rand().
int main()
static int rnd_zero_rand(void *rng_state, unsigned char *output, size_t len)
This function only returns zeros.
int verify_int(char *str, int *value)
static int test_assert(int correct, const char *test)
int verify_string(char **str)
#define TEST_ASSERT(TEST)