00001 #include <polarssl/config.h>
00002
00003 #ifdef POLARSSL_ECDH_C
00004
00005 #include <polarssl/ecdh.h>
00006 #define WANT_NOT_RND_MPI
00007 #endif
00008
00009
00010 #if defined(POLARSSL_MEMORY_BUFFER_ALLOC_C)
00011 #include "polarssl/memory.h"
00012 #endif
00013
00014 #if defined(WANT_NOT_RND_MPI)
00015 #if defined(POLARSSL_BIGNUM_C)
00016 #include "polarssl/bignum.h"
00017 #else
00018 #error "not_rnd_mpi() need bignum.c"
00019 #endif
00020 #endif
00021
00022 #ifdef _MSC_VER
00023 #include <basetsd.h>
00024 typedef UINT32 uint32_t;
00025 #else
00026 #include <inttypes.h>
00027 #endif
00028
00029 #include <assert.h>
00030 #include <stdlib.h>
00031 #include <string.h>
00032
00033
00034
00035
00036 #ifndef GET_UINT32_BE
00037 #define GET_UINT32_BE(n,b,i) \
00038 { \
00039 (n) = ( (uint32_t) (b)[(i) ] << 24 ) \
00040 | ( (uint32_t) (b)[(i) + 1] << 16 ) \
00041 | ( (uint32_t) (b)[(i) + 2] << 8 ) \
00042 | ( (uint32_t) (b)[(i) + 3] ); \
00043 }
00044 #endif
00045
00046 #ifndef PUT_UINT32_BE
00047 #define PUT_UINT32_BE(n,b,i) \
00048 { \
00049 (b)[(i) ] = (unsigned char) ( (n) >> 24 ); \
00050 (b)[(i) + 1] = (unsigned char) ( (n) >> 16 ); \
00051 (b)[(i) + 2] = (unsigned char) ( (n) >> 8 ); \
00052 (b)[(i) + 3] = (unsigned char) ( (n) ); \
00053 }
00054 #endif
00055
00056 static int unhexify(unsigned char *obuf, const char *ibuf)
00057 {
00058 unsigned char c, c2;
00059 int len = strlen(ibuf) / 2;
00060 assert(!(strlen(ibuf) %1));
00061
00062 while (*ibuf != 0)
00063 {
00064 c = *ibuf++;
00065 if( c >= '0' && c <= '9' )
00066 c -= '0';
00067 else if( c >= 'a' && c <= 'f' )
00068 c -= 'a' - 10;
00069 else if( c >= 'A' && c <= 'F' )
00070 c -= 'A' - 10;
00071 else
00072 assert( 0 );
00073
00074 c2 = *ibuf++;
00075 if( c2 >= '0' && c2 <= '9' )
00076 c2 -= '0';
00077 else if( c2 >= 'a' && c2 <= 'f' )
00078 c2 -= 'a' - 10;
00079 else if( c2 >= 'A' && c2 <= 'F' )
00080 c2 -= 'A' - 10;
00081 else
00082 assert( 0 );
00083
00084 *obuf++ = ( c << 4 ) | c2;
00085 }
00086
00087 return len;
00088 }
00089
00090 static void hexify(unsigned char *obuf, const unsigned char *ibuf, int len)
00091 {
00092 unsigned char l, h;
00093
00094 while (len != 0)
00095 {
00096 h = (*ibuf) / 16;
00097 l = (*ibuf) % 16;
00098
00099 if( h < 10 )
00100 *obuf++ = '0' + h;
00101 else
00102 *obuf++ = 'a' + h - 10;
00103
00104 if( l < 10 )
00105 *obuf++ = '0' + l;
00106 else
00107 *obuf++ = 'a' + l - 10;
00108
00109 ++ibuf;
00110 len--;
00111 }
00112 }
00113
00123 static int rnd_std_rand( void *rng_state, unsigned char *output, size_t len )
00124 {
00125 size_t i;
00126
00127 if( rng_state != NULL )
00128 rng_state = NULL;
00129
00130 for( i = 0; i < len; ++i )
00131 output[i] = rand();
00132
00133 return( 0 );
00134 }
00135
00141 static int rnd_zero_rand( void *rng_state, unsigned char *output, size_t len )
00142 {
00143 if( rng_state != NULL )
00144 rng_state = NULL;
00145
00146 memset( output, 0, len );
00147
00148 return( 0 );
00149 }
00150
00151 typedef struct
00152 {
00153 unsigned char *buf;
00154 size_t length;
00155 } rnd_buf_info;
00156
00168 static int rnd_buffer_rand( void *rng_state, unsigned char *output, size_t len )
00169 {
00170 rnd_buf_info *info = (rnd_buf_info *) rng_state;
00171 size_t use_len;
00172
00173 if( rng_state == NULL )
00174 return( rnd_std_rand( NULL, output, len ) );
00175
00176 use_len = len;
00177 if( len > info->length )
00178 use_len = info->length;
00179
00180 if( use_len )
00181 {
00182 memcpy( output, info->buf, use_len );
00183 info->buf += use_len;
00184 info->length -= use_len;
00185 }
00186
00187 if( len - use_len > 0 )
00188 return( rnd_std_rand( NULL, output + use_len, len - use_len ) );
00189
00190 return( 0 );
00191 }
00192
00200 typedef struct
00201 {
00202 uint32_t key[16];
00203 uint32_t v0, v1;
00204 } rnd_pseudo_info;
00205
00214 static int rnd_pseudo_rand( void *rng_state, unsigned char *output, size_t len )
00215 {
00216 rnd_pseudo_info *info = (rnd_pseudo_info *) rng_state;
00217 uint32_t i, *k, sum, delta=0x9E3779B9;
00218 unsigned char result[4];
00219
00220 if( rng_state == NULL )
00221 return( rnd_std_rand( NULL, output, len ) );
00222
00223 k = info->key;
00224
00225 while( len > 0 )
00226 {
00227 size_t use_len = ( len > 4 ) ? 4 : len;
00228 sum = 0;
00229
00230 for( i = 0; i < 32; i++ )
00231 {
00232 info->v0 += (((info->v1 << 4) ^ (info->v1 >> 5)) + info->v1) ^ (sum + k[sum & 3]);
00233 sum += delta;
00234 info->v1 += (((info->v0 << 4) ^ (info->v0 >> 5)) + info->v0) ^ (sum + k[(sum>>11) & 3]);
00235 }
00236
00237 PUT_UINT32_BE( info->v0, result, 0 );
00238 memcpy( output, result, use_len );
00239 len -= use_len;
00240 }
00241
00242 return( 0 );
00243 }
00244
00245 #if defined(WANT_NOT_RND_MPI)
00246
00254 #define ciL (sizeof(t_uint))
00255 #define CHARS_TO_LIMBS(i) (((i) + ciL - 1) / ciL)
00256 static int not_rnd_mpi( void *in, unsigned char *out, size_t len )
00257 {
00258 char *str = (char *) in;
00259 mpi X;
00260
00261
00262
00263
00264
00265 X.s = 1;
00266 X.p = (t_uint *) out;
00267 X.n = CHARS_TO_LIMBS( len );
00268
00269
00270
00271
00272
00273 assert( strlen( str ) / 2 == len );
00274
00275 return( mpi_read_string( &X, 16, str ) );
00276 }
00277 #endif
00278
00279
00280 #include <stdio.h>
00281 #include <string.h>
00282
00283 static int test_errors = 0;
00284
00285 #ifdef POLARSSL_ECDH_C
00286
00287 #define TEST_SUITE_ACTIVE
00288
00289 static int test_assert( int correct, char *test )
00290 {
00291 if( correct )
00292 return( 0 );
00293
00294 test_errors++;
00295 if( test_errors == 1 )
00296 printf( "FAILED\n" );
00297 printf( " %s\n", test );
00298
00299 return( 1 );
00300 }
00301
00302 #define TEST_ASSERT( TEST ) \
00303 do { test_assert( (TEST) ? 1 : 0, #TEST ); \
00304 if( test_errors) return; \
00305 } while (0)
00306
00307 int verify_string( char **str )
00308 {
00309 if( (*str)[0] != '"' ||
00310 (*str)[strlen( *str ) - 1] != '"' )
00311 {
00312 printf( "Expected string (with \"\") for parameter and got: %s\n", *str );
00313 return( -1 );
00314 }
00315
00316 (*str)++;
00317 (*str)[strlen( *str ) - 1] = '\0';
00318
00319 return( 0 );
00320 }
00321
00322 int verify_int( char *str, int *value )
00323 {
00324 size_t i;
00325 int minus = 0;
00326 int digits = 1;
00327 int hex = 0;
00328
00329 for( i = 0; i < strlen( str ); i++ )
00330 {
00331 if( i == 0 && str[i] == '-' )
00332 {
00333 minus = 1;
00334 continue;
00335 }
00336
00337 if( ( ( minus && i == 2 ) || ( !minus && i == 1 ) ) &&
00338 str[i - 1] == '0' && str[i] == 'x' )
00339 {
00340 hex = 1;
00341 continue;
00342 }
00343
00344 if( str[i] < '0' || str[i] > '9' )
00345 {
00346 digits = 0;
00347 break;
00348 }
00349 }
00350
00351 if( digits )
00352 {
00353 if( hex )
00354 *value = strtol( str, NULL, 16 );
00355 else
00356 *value = strtol( str, NULL, 10 );
00357
00358 return( 0 );
00359 }
00360
00361 if( strcmp( str, "POLARSSL_ECP_DP_SECP521R1" ) == 0 )
00362 {
00363 *value = ( POLARSSL_ECP_DP_SECP521R1 );
00364 return( 0 );
00365 }
00366 if( strcmp( str, "POLARSSL_ECP_DP_SECP384R1" ) == 0 )
00367 {
00368 *value = ( POLARSSL_ECP_DP_SECP384R1 );
00369 return( 0 );
00370 }
00371 if( strcmp( str, "POLARSSL_ECP_DP_SECP192R1" ) == 0 )
00372 {
00373 *value = ( POLARSSL_ECP_DP_SECP192R1 );
00374 return( 0 );
00375 }
00376 if( strcmp( str, "POLARSSL_ECP_DP_SECP224R1" ) == 0 )
00377 {
00378 *value = ( POLARSSL_ECP_DP_SECP224R1 );
00379 return( 0 );
00380 }
00381 if( strcmp( str, "POLARSSL_ECP_DP_SECP256R1" ) == 0 )
00382 {
00383 *value = ( POLARSSL_ECP_DP_SECP256R1 );
00384 return( 0 );
00385 }
00386
00387
00388 printf( "Expected integer for parameter and got: %s\n", str );
00389 return( -1 );
00390 }
00391
00392 void test_suite_ecdh_primitive_random( int id )
00393 {
00394 ecp_group grp;
00395 ecp_point qA, qB;
00396 mpi dA, dB, zA, zB;
00397 rnd_pseudo_info rnd_info;
00398
00399 ecp_group_init( &grp );
00400 ecp_point_init( &qA ); ecp_point_init( &qB );
00401 mpi_init( &dA ); mpi_init( &dB );
00402 mpi_init( &zA ); mpi_init( &zB );
00403 memset( &rnd_info, 0x00, sizeof( rnd_pseudo_info ) );
00404
00405 TEST_ASSERT( ecp_use_known_dp( &grp, id ) == 0 );
00406
00407 TEST_ASSERT( ecdh_gen_public( &grp, &dA, &qA, &rnd_pseudo_rand, &rnd_info )
00408 == 0 );
00409 TEST_ASSERT( ecdh_gen_public( &grp, &dB, &qB, &rnd_pseudo_rand, &rnd_info )
00410 == 0 );
00411 TEST_ASSERT( ecdh_compute_shared( &grp, &zA, &qB, &dA,
00412 &rnd_pseudo_rand, &rnd_info ) == 0 );
00413 TEST_ASSERT( ecdh_compute_shared( &grp, &zB, &qA, &dB,
00414 NULL, NULL ) == 0 );
00415
00416 TEST_ASSERT( mpi_cmp_mpi( &zA, &zB ) == 0 );
00417
00418 ecp_group_free( &grp );
00419 ecp_point_free( &qA ); ecp_point_free( &qB );
00420 mpi_free( &dA ); mpi_free( &dB );
00421 mpi_free( &zA ); mpi_free( &zB );
00422 }
00423
00424 void test_suite_ecdh_primitive_testvec( int id, char *dA_str, char *xA_str, char *yA_str,
00425 char *dB_str, char *xB_str, char *yB_str,
00426 char *z_str )
00427 {
00428 ecp_group grp;
00429 ecp_point qA, qB;
00430 mpi dA, dB, zA, zB, check;
00431
00432 ecp_group_init( &grp );
00433 ecp_point_init( &qA ); ecp_point_init( &qB );
00434 mpi_init( &dA ); mpi_init( &dB );
00435 mpi_init( &zA ); mpi_init( &zB ); mpi_init( &check );
00436
00437 TEST_ASSERT( ecp_use_known_dp( &grp, id ) == 0 );
00438
00439 TEST_ASSERT( ecdh_gen_public( &grp, &dA, &qA, ¬_rnd_mpi, dA_str ) == 0 );
00440 TEST_ASSERT( ! ecp_is_zero( &qA ) );
00441 TEST_ASSERT( mpi_read_string( &check, 16, xA_str ) == 0 );
00442 TEST_ASSERT( mpi_cmp_mpi( &qA.X, &check ) == 0 );
00443 TEST_ASSERT( mpi_read_string( &check, 16, yA_str ) == 0 );
00444 TEST_ASSERT( mpi_cmp_mpi( &qA.Y, &check ) == 0 );
00445
00446 TEST_ASSERT( ecdh_gen_public( &grp, &dB, &qB, ¬_rnd_mpi, dB_str ) == 0 );
00447 TEST_ASSERT( ! ecp_is_zero( &qB ) );
00448 TEST_ASSERT( mpi_read_string( &check, 16, xB_str ) == 0 );
00449 TEST_ASSERT( mpi_cmp_mpi( &qB.X, &check ) == 0 );
00450 TEST_ASSERT( mpi_read_string( &check, 16, yB_str ) == 0 );
00451 TEST_ASSERT( mpi_cmp_mpi( &qB.Y, &check ) == 0 );
00452
00453 TEST_ASSERT( mpi_read_string( &check, 16, z_str ) == 0 );
00454 TEST_ASSERT( ecdh_compute_shared( &grp, &zA, &qB, &dA, NULL, NULL ) == 0 );
00455 TEST_ASSERT( mpi_cmp_mpi( &zA, &check ) == 0 );
00456 TEST_ASSERT( ecdh_compute_shared( &grp, &zB, &qA, &dB, NULL, NULL ) == 0 );
00457 TEST_ASSERT( mpi_cmp_mpi( &zB, &check ) == 0 );
00458
00459 ecp_group_free( &grp );
00460 ecp_point_free( &qA ); ecp_point_free( &qB );
00461 mpi_free( &dA ); mpi_free( &dB );
00462 mpi_free( &zA ); mpi_free( &zB ); mpi_free( &check );
00463 }
00464
00465 void test_suite_ecdh_exchange( int id )
00466 {
00467 ecdh_context srv, cli;
00468 unsigned char buf[1000];
00469 const unsigned char *vbuf;
00470 size_t len;
00471 rnd_pseudo_info rnd_info;
00472
00473 ecdh_init( &srv );
00474 ecdh_init( &cli );
00475 memset( &rnd_info, 0x00, sizeof( rnd_pseudo_info ) );
00476
00477 TEST_ASSERT( ecp_use_known_dp( &srv.grp, id ) == 0 );
00478
00479 memset( buf, 0x00, sizeof( buf ) ); vbuf = buf;
00480 TEST_ASSERT( ecdh_make_params( &srv, &len, buf, 1000,
00481 &rnd_pseudo_rand, &rnd_info ) == 0 );
00482 TEST_ASSERT( ecdh_read_params( &cli, &vbuf, buf + len ) == 0 );
00483
00484 memset( buf, 0x00, sizeof( buf ) );
00485 TEST_ASSERT( ecdh_make_public( &cli, &len, buf, 1000,
00486 &rnd_pseudo_rand, &rnd_info ) == 0 );
00487 TEST_ASSERT( ecdh_read_public( &srv, buf, len ) == 0 );
00488
00489 TEST_ASSERT( ecdh_calc_secret( &srv, &len, buf, 1000,
00490 &rnd_pseudo_rand, &rnd_info ) == 0 );
00491 TEST_ASSERT( ecdh_calc_secret( &cli, &len, buf, 1000, NULL, NULL ) == 0 );
00492 TEST_ASSERT( mpi_cmp_mpi( &srv.z, &cli.z ) == 0 );
00493
00494 ecdh_free( &srv );
00495 ecdh_free( &cli );
00496 }
00497
00498
00499 #endif
00500
00501
00502 int dep_check( char *str )
00503 {
00504 if( str == NULL )
00505 return( 1 );
00506
00507 if( strcmp( str, "POLARSSL_ECP_DP_SECP384R1_ENABLED" ) == 0 )
00508 {
00509 #if defined(POLARSSL_ECP_DP_SECP384R1_ENABLED)
00510 return( 0 );
00511 #else
00512 return( 1 );
00513 #endif
00514 }
00515 if( strcmp( str, "POLARSSL_ECP_DP_SECP192R1_ENABLED" ) == 0 )
00516 {
00517 #if defined(POLARSSL_ECP_DP_SECP192R1_ENABLED)
00518 return( 0 );
00519 #else
00520 return( 1 );
00521 #endif
00522 }
00523 if( strcmp( str, "POLARSSL_ECP_DP_SECP521R1_ENABLED" ) == 0 )
00524 {
00525 #if defined(POLARSSL_ECP_DP_SECP521R1_ENABLED)
00526 return( 0 );
00527 #else
00528 return( 1 );
00529 #endif
00530 }
00531 if( strcmp( str, "POLARSSL_ECP_DP_SECP224R1_ENABLED" ) == 0 )
00532 {
00533 #if defined(POLARSSL_ECP_DP_SECP224R1_ENABLED)
00534 return( 0 );
00535 #else
00536 return( 1 );
00537 #endif
00538 }
00539 if( strcmp( str, "POLARSSL_ECP_DP_SECP256R1_ENABLED" ) == 0 )
00540 {
00541 #if defined(POLARSSL_ECP_DP_SECP256R1_ENABLED)
00542 return( 0 );
00543 #else
00544 return( 1 );
00545 #endif
00546 }
00547
00548
00549 return( 1 );
00550 }
00551
00552 int dispatch_test(int cnt, char *params[50])
00553 {
00554 int ret;
00555 ((void) cnt);
00556 ((void) params);
00557
00558 #if defined(TEST_SUITE_ACTIVE)
00559 if( strcmp( params[0], "ecdh_primitive_random" ) == 0 )
00560 {
00561
00562 int param1;
00563
00564 if( cnt != 2 )
00565 {
00566 fprintf( stderr, "\nIncorrect argument count (%d != %d)\n", cnt, 2 );
00567 return( 2 );
00568 }
00569
00570 if( verify_int( params[1], ¶m1 ) != 0 ) return( 2 );
00571
00572 test_suite_ecdh_primitive_random( param1 );
00573 return ( 0 );
00574
00575 return ( 3 );
00576 }
00577 else
00578 if( strcmp( params[0], "ecdh_primitive_testvec" ) == 0 )
00579 {
00580
00581 int param1;
00582 char *param2 = params[2];
00583 char *param3 = params[3];
00584 char *param4 = params[4];
00585 char *param5 = params[5];
00586 char *param6 = params[6];
00587 char *param7 = params[7];
00588 char *param8 = params[8];
00589
00590 if( cnt != 9 )
00591 {
00592 fprintf( stderr, "\nIncorrect argument count (%d != %d)\n", cnt, 9 );
00593 return( 2 );
00594 }
00595
00596 if( verify_int( params[1], ¶m1 ) != 0 ) return( 2 );
00597 if( verify_string( ¶m2 ) != 0 ) return( 2 );
00598 if( verify_string( ¶m3 ) != 0 ) return( 2 );
00599 if( verify_string( ¶m4 ) != 0 ) return( 2 );
00600 if( verify_string( ¶m5 ) != 0 ) return( 2 );
00601 if( verify_string( ¶m6 ) != 0 ) return( 2 );
00602 if( verify_string( ¶m7 ) != 0 ) return( 2 );
00603 if( verify_string( ¶m8 ) != 0 ) return( 2 );
00604
00605 test_suite_ecdh_primitive_testvec( param1, param2, param3, param4, param5, param6, param7, param8 );
00606 return ( 0 );
00607
00608 return ( 3 );
00609 }
00610 else
00611 if( strcmp( params[0], "ecdh_exchange" ) == 0 )
00612 {
00613
00614 int param1;
00615
00616 if( cnt != 2 )
00617 {
00618 fprintf( stderr, "\nIncorrect argument count (%d != %d)\n", cnt, 2 );
00619 return( 2 );
00620 }
00621
00622 if( verify_int( params[1], ¶m1 ) != 0 ) return( 2 );
00623
00624 test_suite_ecdh_exchange( param1 );
00625 return ( 0 );
00626
00627 return ( 3 );
00628 }
00629 else
00630
00631 {
00632 fprintf( stdout, "FAILED\nSkipping unknown test function '%s'\n", params[0] );
00633 fflush( stdout );
00634 return( 1 );
00635 }
00636 #else
00637 return( 3 );
00638 #endif
00639 return( ret );
00640 }
00641
00642 int get_line( FILE *f, char *buf, size_t len )
00643 {
00644 char *ret;
00645
00646 ret = fgets( buf, len, f );
00647 if( ret == NULL )
00648 return( -1 );
00649
00650 if( strlen( buf ) && buf[strlen(buf) - 1] == '\n' )
00651 buf[strlen(buf) - 1] = '\0';
00652 if( strlen( buf ) && buf[strlen(buf) - 1] == '\r' )
00653 buf[strlen(buf) - 1] = '\0';
00654
00655 return( 0 );
00656 }
00657
00658 int parse_arguments( char *buf, size_t len, char *params[50] )
00659 {
00660 int cnt = 0, i;
00661 char *cur = buf;
00662 char *p = buf, *q;
00663
00664 params[cnt++] = cur;
00665
00666 while( *p != '\0' && p < buf + len )
00667 {
00668 if( *p == '\\' )
00669 {
00670 *p++;
00671 *p++;
00672 continue;
00673 }
00674 if( *p == ':' )
00675 {
00676 if( p + 1 < buf + len )
00677 {
00678 cur = p + 1;
00679 params[cnt++] = cur;
00680 }
00681 *p = '\0';
00682 }
00683
00684 *p++;
00685 }
00686
00687
00688 for( i = 0; i < cnt; i++ )
00689 {
00690 p = params[i];
00691 q = params[i];
00692
00693 while( *p != '\0' )
00694 {
00695 if( *p == '\\' && *(p + 1) == 'n' )
00696 {
00697 p += 2;
00698 *(q++) = '\n';
00699 }
00700 else if( *p == '\\' && *(p + 1) == ':' )
00701 {
00702 p += 2;
00703 *(q++) = ':';
00704 }
00705 else if( *p == '\\' && *(p + 1) == '?' )
00706 {
00707 p += 2;
00708 *(q++) = '?';
00709 }
00710 else
00711 *(q++) = *(p++);
00712 }
00713 *q = '\0';
00714 }
00715
00716 return( cnt );
00717 }
00718
00719 int main()
00720 {
00721 int ret, i, cnt, total_errors = 0, total_tests = 0, total_skipped = 0;
00722 const char *filename = "/home/abuild/rpmbuild/BUILD/polarssl-1.3.2/tests/suites/test_suite_ecdh.data";
00723 FILE *file;
00724 char buf[5000];
00725 char *params[50];
00726
00727 #if defined(POLARSSL_MEMORY_BUFFER_ALLOC_C)
00728 unsigned char alloc_buf[1000000];
00729 memory_buffer_alloc_init( alloc_buf, sizeof(alloc_buf) );
00730 #endif
00731
00732 file = fopen( filename, "r" );
00733 if( file == NULL )
00734 {
00735 fprintf( stderr, "Failed to open\n" );
00736 return( 1 );
00737 }
00738
00739 while( !feof( file ) )
00740 {
00741 int skip = 0;
00742
00743 if( ( ret = get_line( file, buf, sizeof(buf) ) ) != 0 )
00744 break;
00745 fprintf( stdout, "%s%.66s", test_errors ? "\n" : "", buf );
00746 fprintf( stdout, " " );
00747 for( i = strlen( buf ) + 1; i < 67; i++ )
00748 fprintf( stdout, "." );
00749 fprintf( stdout, " " );
00750 fflush( stdout );
00751
00752 total_tests++;
00753
00754 if( ( ret = get_line( file, buf, sizeof(buf) ) ) != 0 )
00755 break;
00756 cnt = parse_arguments( buf, strlen(buf), params );
00757
00758 if( strcmp( params[0], "depends_on" ) == 0 )
00759 {
00760 for( i = 1; i < cnt; i++ )
00761 if( dep_check( params[i] ) != 0 )
00762 skip = 1;
00763
00764 if( ( ret = get_line( file, buf, sizeof(buf) ) ) != 0 )
00765 break;
00766 cnt = parse_arguments( buf, strlen(buf), params );
00767 }
00768
00769 if( skip == 0 )
00770 {
00771 test_errors = 0;
00772 ret = dispatch_test( cnt, params );
00773 }
00774
00775 if( skip == 1 || ret == 3 )
00776 {
00777 total_skipped++;
00778 fprintf( stdout, "----\n" );
00779 fflush( stdout );
00780 }
00781 else if( ret == 0 && test_errors == 0 )
00782 {
00783 fprintf( stdout, "PASS\n" );
00784 fflush( stdout );
00785 }
00786 else if( ret == 2 )
00787 {
00788 fprintf( stderr, "FAILED: FATAL PARSE ERROR\n" );
00789 fclose(file);
00790 exit( 2 );
00791 }
00792 else
00793 total_errors++;
00794
00795 if( ( ret = get_line( file, buf, sizeof(buf) ) ) != 0 )
00796 break;
00797 if( strlen(buf) != 0 )
00798 {
00799 fprintf( stderr, "Should be empty %d\n", (int) strlen(buf) );
00800 return( 1 );
00801 }
00802 }
00803 fclose(file);
00804
00805 fprintf( stdout, "\n----------------------------------------------------------------------------\n\n");
00806 if( total_errors == 0 )
00807 fprintf( stdout, "PASSED" );
00808 else
00809 fprintf( stdout, "FAILED" );
00810
00811 fprintf( stdout, " (%d / %d tests (%d skipped))\n",
00812 total_tests - total_errors, total_tests, total_skipped );
00813
00814 #if defined(POLARSSL_MEMORY_BUFFER_ALLOC_C)
00815 #if defined(POLARSSL_MEMORY_DEBUG)
00816 memory_buffer_alloc_status();
00817 #endif
00818 memory_buffer_alloc_free();
00819 #endif
00820
00821 return( total_errors != 0 );
00822 }
00823
00824