PolarSSL v1.3.1
test_suite_ecdh.c
Go to the documentation of this file.
1 #include <polarssl/config.h>
2 
3 #ifdef POLARSSL_ECDH_C
4 
5 #include <polarssl/ecdh.h>
6 #endif /* POLARSSL_ECDH_C */
7 
8 
9 #if defined(POLARSSL_MEMORY_BUFFER_ALLOC_C)
10 #include "polarssl/memory.h"
11 #endif
12 
13 #ifdef _MSC_VER
14 #include <basetsd.h>
15 typedef UINT32 uint32_t;
16 #else
17 #include <inttypes.h>
18 #endif
19 
20 #include <assert.h>
21 #include <stdlib.h>
22 #include <string.h>
23 
24 /*
25  * 32-bit integer manipulation macros (big endian)
26  */
27 #ifndef GET_UINT32_BE
28 #define GET_UINT32_BE(n,b,i) \
29 { \
30  (n) = ( (uint32_t) (b)[(i) ] << 24 ) \
31  | ( (uint32_t) (b)[(i) + 1] << 16 ) \
32  | ( (uint32_t) (b)[(i) + 2] << 8 ) \
33  | ( (uint32_t) (b)[(i) + 3] ); \
34 }
35 #endif
36 
37 #ifndef PUT_UINT32_BE
38 #define PUT_UINT32_BE(n,b,i) \
39 { \
40  (b)[(i) ] = (unsigned char) ( (n) >> 24 ); \
41  (b)[(i) + 1] = (unsigned char) ( (n) >> 16 ); \
42  (b)[(i) + 2] = (unsigned char) ( (n) >> 8 ); \
43  (b)[(i) + 3] = (unsigned char) ( (n) ); \
44 }
45 #endif
46 
47 static int unhexify(unsigned char *obuf, const char *ibuf)
48 {
49  unsigned char c, c2;
50  int len = strlen(ibuf) / 2;
51  assert(!(strlen(ibuf) %1)); // must be even number of bytes
52 
53  while (*ibuf != 0)
54  {
55  c = *ibuf++;
56  if( c >= '0' && c <= '9' )
57  c -= '0';
58  else if( c >= 'a' && c <= 'f' )
59  c -= 'a' - 10;
60  else if( c >= 'A' && c <= 'F' )
61  c -= 'A' - 10;
62  else
63  assert( 0 );
64 
65  c2 = *ibuf++;
66  if( c2 >= '0' && c2 <= '9' )
67  c2 -= '0';
68  else if( c2 >= 'a' && c2 <= 'f' )
69  c2 -= 'a' - 10;
70  else if( c2 >= 'A' && c2 <= 'F' )
71  c2 -= 'A' - 10;
72  else
73  assert( 0 );
74 
75  *obuf++ = ( c << 4 ) | c2;
76  }
77 
78  return len;
79 }
80 
81 static void hexify(unsigned char *obuf, const unsigned char *ibuf, int len)
82 {
83  unsigned char l, h;
84 
85  while (len != 0)
86  {
87  h = (*ibuf) / 16;
88  l = (*ibuf) % 16;
89 
90  if( h < 10 )
91  *obuf++ = '0' + h;
92  else
93  *obuf++ = 'a' + h - 10;
94 
95  if( l < 10 )
96  *obuf++ = '0' + l;
97  else
98  *obuf++ = 'a' + l - 10;
99 
100  ++ibuf;
101  len--;
102  }
103 }
104 
114 static int rnd_std_rand( void *rng_state, unsigned char *output, size_t len )
115 {
116  size_t i;
117 
118  if( rng_state != NULL )
119  rng_state = NULL;
120 
121  for( i = 0; i < len; ++i )
122  output[i] = rand();
123 
124  return( 0 );
125 }
126 
132 static int rnd_zero_rand( void *rng_state, unsigned char *output, size_t len )
133 {
134  if( rng_state != NULL )
135  rng_state = NULL;
136 
137  memset( output, 0, len );
138 
139  return( 0 );
140 }
141 
142 typedef struct
143 {
144  unsigned char *buf;
145  size_t length;
146 } rnd_buf_info;
147 
159 static int rnd_buffer_rand( void *rng_state, unsigned char *output, size_t len )
160 {
161  rnd_buf_info *info = (rnd_buf_info *) rng_state;
162  size_t use_len;
163 
164  if( rng_state == NULL )
165  return( rnd_std_rand( NULL, output, len ) );
166 
167  use_len = len;
168  if( len > info->length )
169  use_len = info->length;
170 
171  if( use_len )
172  {
173  memcpy( output, info->buf, use_len );
174  info->buf += use_len;
175  info->length -= use_len;
176  }
177 
178  if( len - use_len > 0 )
179  return( rnd_std_rand( NULL, output + use_len, len - use_len ) );
180 
181  return( 0 );
182 }
183 
191 typedef struct
192 {
193  uint32_t key[16];
194  uint32_t v0, v1;
196 
205 static int rnd_pseudo_rand( void *rng_state, unsigned char *output, size_t len )
206 {
207  rnd_pseudo_info *info = (rnd_pseudo_info *) rng_state;
208  uint32_t i, *k, sum, delta=0x9E3779B9;
209  unsigned char result[4];
210 
211  if( rng_state == NULL )
212  return( rnd_std_rand( NULL, output, len ) );
213 
214  k = info->key;
215 
216  while( len > 0 )
217  {
218  size_t use_len = ( len > 4 ) ? 4 : len;
219  sum = 0;
220 
221  for( i = 0; i < 32; i++ )
222  {
223  info->v0 += (((info->v1 << 4) ^ (info->v1 >> 5)) + info->v1) ^ (sum + k[sum & 3]);
224  sum += delta;
225  info->v1 += (((info->v0 << 4) ^ (info->v0 >> 5)) + info->v0) ^ (sum + k[(sum>>11) & 3]);
226  }
227 
228  PUT_UINT32_BE( info->v0, result, 0 );
229  memcpy( output, result, use_len );
230  len -= use_len;
231  }
232 
233  return( 0 );
234 }
235 
245 static int not_rnd( void *in, unsigned char *out, size_t len )
246 {
247  unsigned char *obuf;
248  const char *ibuf = in;
249  unsigned char c, c2;
250  assert( len == strlen(ibuf) / 2 );
251  assert(!(strlen(ibuf) %1)); // must be even number of bytes
252 
253  obuf = out + (len - 1); // sic
254  while (*ibuf != 0)
255  {
256  c = *ibuf++;
257  if( c >= '0' && c <= '9' )
258  c -= '0';
259  else if( c >= 'a' && c <= 'f' )
260  c -= 'a' - 10;
261  else if( c >= 'A' && c <= 'F' )
262  c -= 'A' - 10;
263  else
264  assert( 0 );
265 
266  c2 = *ibuf++;
267  if( c2 >= '0' && c2 <= '9' )
268  c2 -= '0';
269  else if( c2 >= 'a' && c2 <= 'f' )
270  c2 -= 'a' - 10;
271  else if( c2 >= 'A' && c2 <= 'F' )
272  c2 -= 'A' - 10;
273  else
274  assert( 0 );
275 
276  *obuf-- = ( c << 4 ) | c2; // sic
277  }
278 
279  return( 0 );
280 }
281 
282 
283 #include <stdio.h>
284 #include <string.h>
285 
286 static int test_errors = 0;
287 
288 #ifdef POLARSSL_ECDH_C
289 
290 #define TEST_SUITE_ACTIVE
291 
292 static int test_assert( int correct, char *test )
293 {
294  if( correct )
295  return( 0 );
296 
297  test_errors++;
298  if( test_errors == 1 )
299  printf( "FAILED\n" );
300  printf( " %s\n", test );
301 
302  return( 1 );
303 }
304 
305 #define TEST_ASSERT( TEST ) \
306  do { test_assert( (TEST) ? 1 : 0, #TEST ); \
307  if( test_errors) return; \
308  } while (0)
309 
310 int verify_string( char **str )
311 {
312  if( (*str)[0] != '"' ||
313  (*str)[strlen( *str ) - 1] != '"' )
314  {
315  printf( "Expected string (with \"\") for parameter and got: %s\n", *str );
316  return( -1 );
317  }
318 
319  (*str)++;
320  (*str)[strlen( *str ) - 1] = '\0';
321 
322  return( 0 );
323 }
324 
325 int verify_int( char *str, int *value )
326 {
327  size_t i;
328  int minus = 0;
329  int digits = 1;
330  int hex = 0;
331 
332  for( i = 0; i < strlen( str ); i++ )
333  {
334  if( i == 0 && str[i] == '-' )
335  {
336  minus = 1;
337  continue;
338  }
339 
340  if( ( ( minus && i == 2 ) || ( !minus && i == 1 ) ) &&
341  str[i - 1] == '0' && str[i] == 'x' )
342  {
343  hex = 1;
344  continue;
345  }
346 
347  if( str[i] < '0' || str[i] > '9' )
348  {
349  digits = 0;
350  break;
351  }
352  }
353 
354  if( digits )
355  {
356  if( hex )
357  *value = strtol( str, NULL, 16 );
358  else
359  *value = strtol( str, NULL, 10 );
360 
361  return( 0 );
362  }
363 
364  if( strcmp( str, "POLARSSL_ECP_DP_SECP521R1" ) == 0 )
365  {
366  *value = ( POLARSSL_ECP_DP_SECP521R1 );
367  return( 0 );
368  }
369  if( strcmp( str, "POLARSSL_ECP_DP_SECP384R1" ) == 0 )
370  {
371  *value = ( POLARSSL_ECP_DP_SECP384R1 );
372  return( 0 );
373  }
374  if( strcmp( str, "POLARSSL_ECP_DP_SECP192R1" ) == 0 )
375  {
376  *value = ( POLARSSL_ECP_DP_SECP192R1 );
377  return( 0 );
378  }
379  if( strcmp( str, "POLARSSL_ECP_DP_SECP224R1" ) == 0 )
380  {
381  *value = ( POLARSSL_ECP_DP_SECP224R1 );
382  return( 0 );
383  }
384  if( strcmp( str, "POLARSSL_ECP_DP_SECP256R1" ) == 0 )
385  {
386  *value = ( POLARSSL_ECP_DP_SECP256R1 );
387  return( 0 );
388  }
389 
390 
391  printf( "Expected integer for parameter and got: %s\n", str );
392  return( -1 );
393 }
394 
395 void test_suite_ecdh_primitive_random( int id )
396 {
397  ecp_group grp;
398  ecp_point qA, qB;
399  mpi dA, dB, zA, zB;
400  rnd_pseudo_info rnd_info;
401 
402  ecp_group_init( &grp );
403  ecp_point_init( &qA ); ecp_point_init( &qB );
404  mpi_init( &dA ); mpi_init( &dB );
405  mpi_init( &zA ); mpi_init( &zB );
406  memset( &rnd_info, 0x00, sizeof( rnd_pseudo_info ) );
407 
408  TEST_ASSERT( ecp_use_known_dp( &grp, id ) == 0 );
409 
410  TEST_ASSERT( ecdh_gen_public( &grp, &dA, &qA, &rnd_pseudo_rand, &rnd_info )
411  == 0 );
412  TEST_ASSERT( ecdh_gen_public( &grp, &dB, &qB, &rnd_pseudo_rand, &rnd_info )
413  == 0 );
414  TEST_ASSERT( ecdh_compute_shared( &grp, &zA, &qB, &dA,
415  &rnd_pseudo_rand, &rnd_info ) == 0 );
416  TEST_ASSERT( ecdh_compute_shared( &grp, &zB, &qA, &dB,
417  NULL, NULL ) == 0 );
418 
419  TEST_ASSERT( mpi_cmp_mpi( &zA, &zB ) == 0 );
420 
421  ecp_group_free( &grp );
422  ecp_point_free( &qA ); ecp_point_free( &qB );
423  mpi_free( &dA ); mpi_free( &dB );
424  mpi_free( &zA ); mpi_free( &zB );
425 }
426 
427 void test_suite_ecdh_primitive_testvec( int id, char *dA_str, char *xA_str, char *yA_str,
428  char *dB_str, char *xB_str, char *yB_str,
429  char *z_str )
430 {
431  ecp_group grp;
432  ecp_point qA, qB;
433  mpi dA, dB, zA, zB, check;
434 
435  ecp_group_init( &grp );
436  ecp_point_init( &qA ); ecp_point_init( &qB );
437  mpi_init( &dA ); mpi_init( &dB );
438  mpi_init( &zA ); mpi_init( &zB ); mpi_init( &check );
439 
440  TEST_ASSERT( ecp_use_known_dp( &grp, id ) == 0 );
441 
442  TEST_ASSERT( ecdh_gen_public( &grp, &dA, &qA, &not_rnd, dA_str ) == 0 );
443  TEST_ASSERT( ! ecp_is_zero( &qA ) );
444  TEST_ASSERT( mpi_read_string( &check, 16, xA_str ) == 0 );
445  TEST_ASSERT( mpi_cmp_mpi( &qA.X, &check ) == 0 );
446  TEST_ASSERT( mpi_read_string( &check, 16, yA_str ) == 0 );
447  TEST_ASSERT( mpi_cmp_mpi( &qA.Y, &check ) == 0 );
448 
449  TEST_ASSERT( ecdh_gen_public( &grp, &dB, &qB, &not_rnd, dB_str ) == 0 );
450  TEST_ASSERT( ! ecp_is_zero( &qB ) );
451  TEST_ASSERT( mpi_read_string( &check, 16, xB_str ) == 0 );
452  TEST_ASSERT( mpi_cmp_mpi( &qB.X, &check ) == 0 );
453  TEST_ASSERT( mpi_read_string( &check, 16, yB_str ) == 0 );
454  TEST_ASSERT( mpi_cmp_mpi( &qB.Y, &check ) == 0 );
455 
456  TEST_ASSERT( mpi_read_string( &check, 16, z_str ) == 0 );
457  TEST_ASSERT( ecdh_compute_shared( &grp, &zA, &qB, &dA, NULL, NULL ) == 0 );
458  TEST_ASSERT( mpi_cmp_mpi( &zA, &check ) == 0 );
459  TEST_ASSERT( ecdh_compute_shared( &grp, &zB, &qA, &dB, NULL, NULL ) == 0 );
460  TEST_ASSERT( mpi_cmp_mpi( &zB, &check ) == 0 );
461 
462  ecp_group_free( &grp );
463  ecp_point_free( &qA ); ecp_point_free( &qB );
464  mpi_free( &dA ); mpi_free( &dB );
465  mpi_free( &zA ); mpi_free( &zB ); mpi_free( &check );
466 }
467 
468 void test_suite_ecdh_exchange( int id )
469 {
470  ecdh_context srv, cli;
471  unsigned char buf[1000];
472  const unsigned char *vbuf;
473  size_t len;
474  rnd_pseudo_info rnd_info;
475 
476  ecdh_init( &srv );
477  ecdh_init( &cli );
478  memset( &rnd_info, 0x00, sizeof( rnd_pseudo_info ) );
479 
480  TEST_ASSERT( ecp_use_known_dp( &srv.grp, id ) == 0 );
481 
482  memset( buf, 0x00, sizeof( buf ) ); vbuf = buf;
483  TEST_ASSERT( ecdh_make_params( &srv, &len, buf, 1000,
484  &rnd_pseudo_rand, &rnd_info ) == 0 );
485  TEST_ASSERT( ecdh_read_params( &cli, &vbuf, buf + len ) == 0 );
486 
487  memset( buf, 0x00, sizeof( buf ) );
488  TEST_ASSERT( ecdh_make_public( &cli, &len, buf, 1000,
489  &rnd_pseudo_rand, &rnd_info ) == 0 );
490  TEST_ASSERT( ecdh_read_public( &srv, buf, len ) == 0 );
491 
492  TEST_ASSERT( ecdh_calc_secret( &srv, &len, buf, 1000,
493  &rnd_pseudo_rand, &rnd_info ) == 0 );
494  TEST_ASSERT( ecdh_calc_secret( &cli, &len, buf, 1000, NULL, NULL ) == 0 );
495  TEST_ASSERT( mpi_cmp_mpi( &srv.z, &cli.z ) == 0 );
496 
497  ecdh_free( &srv );
498  ecdh_free( &cli );
499 }
500 
501 
502 #endif /* POLARSSL_ECDH_C */
503 
504 
505 int dep_check( char *str )
506 {
507  if( str == NULL )
508  return( 1 );
509 
510  if( strcmp( str, "POLARSSL_ECP_DP_SECP384R1_ENABLED" ) == 0 )
511  {
512 #if defined(POLARSSL_ECP_DP_SECP384R1_ENABLED)
513  return( 0 );
514 #else
515  return( 1 );
516 #endif
517  }
518  if( strcmp( str, "POLARSSL_ECP_DP_SECP192R1_ENABLED" ) == 0 )
519  {
520 #if defined(POLARSSL_ECP_DP_SECP192R1_ENABLED)
521  return( 0 );
522 #else
523  return( 1 );
524 #endif
525  }
526  if( strcmp( str, "POLARSSL_ECP_DP_SECP521R1_ENABLED" ) == 0 )
527  {
528 #if defined(POLARSSL_ECP_DP_SECP521R1_ENABLED)
529  return( 0 );
530 #else
531  return( 1 );
532 #endif
533  }
534  if( strcmp( str, "POLARSSL_ECP_DP_SECP224R1_ENABLED" ) == 0 )
535  {
536 #if defined(POLARSSL_ECP_DP_SECP224R1_ENABLED)
537  return( 0 );
538 #else
539  return( 1 );
540 #endif
541  }
542  if( strcmp( str, "POLARSSL_ECP_DP_SECP256R1_ENABLED" ) == 0 )
543  {
544 #if defined(POLARSSL_ECP_DP_SECP256R1_ENABLED)
545  return( 0 );
546 #else
547  return( 1 );
548 #endif
549  }
550 
551 
552  return( 1 );
553 }
554 
555 int dispatch_test(int cnt, char *params[50])
556 {
557  int ret;
558  ((void) cnt);
559  ((void) params);
560 
561 #if defined(TEST_SUITE_ACTIVE)
562  if( strcmp( params[0], "ecdh_primitive_random" ) == 0 )
563  {
564 
565  int param1;
566 
567  if( cnt != 2 )
568  {
569  fprintf( stderr, "\nIncorrect argument count (%d != %d)\n", cnt, 2 );
570  return( 2 );
571  }
572 
573  if( verify_int( params[1], &param1 ) != 0 ) return( 2 );
574 
575  test_suite_ecdh_primitive_random( param1 );
576  return ( 0 );
577 
578  return ( 3 );
579  }
580  else
581  if( strcmp( params[0], "ecdh_primitive_testvec" ) == 0 )
582  {
583 
584  int param1;
585  char *param2 = params[2];
586  char *param3 = params[3];
587  char *param4 = params[4];
588  char *param5 = params[5];
589  char *param6 = params[6];
590  char *param7 = params[7];
591  char *param8 = params[8];
592 
593  if( cnt != 9 )
594  {
595  fprintf( stderr, "\nIncorrect argument count (%d != %d)\n", cnt, 9 );
596  return( 2 );
597  }
598 
599  if( verify_int( params[1], &param1 ) != 0 ) return( 2 );
600  if( verify_string( &param2 ) != 0 ) return( 2 );
601  if( verify_string( &param3 ) != 0 ) return( 2 );
602  if( verify_string( &param4 ) != 0 ) return( 2 );
603  if( verify_string( &param5 ) != 0 ) return( 2 );
604  if( verify_string( &param6 ) != 0 ) return( 2 );
605  if( verify_string( &param7 ) != 0 ) return( 2 );
606  if( verify_string( &param8 ) != 0 ) return( 2 );
607 
608  test_suite_ecdh_primitive_testvec( param1, param2, param3, param4, param5, param6, param7, param8 );
609  return ( 0 );
610 
611  return ( 3 );
612  }
613  else
614  if( strcmp( params[0], "ecdh_exchange" ) == 0 )
615  {
616 
617  int param1;
618 
619  if( cnt != 2 )
620  {
621  fprintf( stderr, "\nIncorrect argument count (%d != %d)\n", cnt, 2 );
622  return( 2 );
623  }
624 
625  if( verify_int( params[1], &param1 ) != 0 ) return( 2 );
626 
627  test_suite_ecdh_exchange( param1 );
628  return ( 0 );
629 
630  return ( 3 );
631  }
632  else
633 
634  {
635  fprintf( stdout, "FAILED\nSkipping unknown test function '%s'\n", params[0] );
636  fflush( stdout );
637  return( 1 );
638  }
639 #else
640  return( 3 );
641 #endif
642  return( ret );
643 }
644 
645 int get_line( FILE *f, char *buf, size_t len )
646 {
647  char *ret;
648 
649  ret = fgets( buf, len, f );
650  if( ret == NULL )
651  return( -1 );
652 
653  if( strlen( buf ) && buf[strlen(buf) - 1] == '\n' )
654  buf[strlen(buf) - 1] = '\0';
655  if( strlen( buf ) && buf[strlen(buf) - 1] == '\r' )
656  buf[strlen(buf) - 1] = '\0';
657 
658  return( 0 );
659 }
660 
661 int parse_arguments( char *buf, size_t len, char *params[50] )
662 {
663  int cnt = 0, i;
664  char *cur = buf;
665  char *p = buf, *q;
666 
667  params[cnt++] = cur;
668 
669  while( *p != '\0' && p < buf + len )
670  {
671  if( *p == '\\' )
672  {
673  *p++;
674  *p++;
675  continue;
676  }
677  if( *p == ':' )
678  {
679  if( p + 1 < buf + len )
680  {
681  cur = p + 1;
682  params[cnt++] = cur;
683  }
684  *p = '\0';
685  }
686 
687  *p++;
688  }
689 
690  // Replace newlines, question marks and colons in strings
691  for( i = 0; i < cnt; i++ )
692  {
693  p = params[i];
694  q = params[i];
695 
696  while( *p != '\0' )
697  {
698  if( *p == '\\' && *(p + 1) == 'n' )
699  {
700  p += 2;
701  *(q++) = '\n';
702  }
703  else if( *p == '\\' && *(p + 1) == ':' )
704  {
705  p += 2;
706  *(q++) = ':';
707  }
708  else if( *p == '\\' && *(p + 1) == '?' )
709  {
710  p += 2;
711  *(q++) = '?';
712  }
713  else
714  *(q++) = *(p++);
715  }
716  *q = '\0';
717  }
718 
719  return( cnt );
720 }
721 
722 int main()
723 {
724  int ret, i, cnt, total_errors = 0, total_tests = 0, total_skipped = 0;
725  const char *filename = "/home/iurt/rpmbuild/BUILD/polarssl-1.3.1/tests/suites/test_suite_ecdh.data";
726  FILE *file;
727  char buf[5000];
728  char *params[50];
729 
730 #if defined(POLARSSL_MEMORY_BUFFER_ALLOC_C)
731  unsigned char alloc_buf[1000000];
732  memory_buffer_alloc_init( alloc_buf, sizeof(alloc_buf) );
733 #endif
734 
735  file = fopen( filename, "r" );
736  if( file == NULL )
737  {
738  fprintf( stderr, "Failed to open\n" );
739  return( 1 );
740  }
741 
742  while( !feof( file ) )
743  {
744  int skip = 0;
745 
746  if( ( ret = get_line( file, buf, sizeof(buf) ) ) != 0 )
747  break;
748  fprintf( stdout, "%s%.66s", test_errors ? "\n" : "", buf );
749  fprintf( stdout, " " );
750  for( i = strlen( buf ) + 1; i < 67; i++ )
751  fprintf( stdout, "." );
752  fprintf( stdout, " " );
753  fflush( stdout );
754 
755  total_tests++;
756 
757  if( ( ret = get_line( file, buf, sizeof(buf) ) ) != 0 )
758  break;
759  cnt = parse_arguments( buf, strlen(buf), params );
760 
761  if( strcmp( params[0], "depends_on" ) == 0 )
762  {
763  for( i = 1; i < cnt; i++ )
764  if( dep_check( params[i] ) != 0 )
765  skip = 1;
766 
767  if( ( ret = get_line( file, buf, sizeof(buf) ) ) != 0 )
768  break;
769  cnt = parse_arguments( buf, strlen(buf), params );
770  }
771 
772  if( skip == 0 )
773  {
774  test_errors = 0;
775  ret = dispatch_test( cnt, params );
776  }
777 
778  if( skip == 1 || ret == 3 )
779  {
780  total_skipped++;
781  fprintf( stdout, "----\n" );
782  fflush( stdout );
783  }
784  else if( ret == 0 && test_errors == 0 )
785  {
786  fprintf( stdout, "PASS\n" );
787  fflush( stdout );
788  }
789  else if( ret == 2 )
790  {
791  fprintf( stderr, "FAILED: FATAL PARSE ERROR\n" );
792  fclose(file);
793  exit( 2 );
794  }
795  else
796  total_errors++;
797 
798  if( ( ret = get_line( file, buf, sizeof(buf) ) ) != 0 )
799  break;
800  if( strlen(buf) != 0 )
801  {
802  fprintf( stderr, "Should be empty %d\n", (int) strlen(buf) );
803  return( 1 );
804  }
805  }
806  fclose(file);
807 
808  fprintf( stdout, "\n----------------------------------------------------------------------------\n\n");
809  if( total_errors == 0 )
810  fprintf( stdout, "PASSED" );
811  else
812  fprintf( stdout, "FAILED" );
813 
814  fprintf( stdout, " (%d / %d tests (%d skipped))\n",
815  total_tests - total_errors, total_tests, total_skipped );
816 
817 #if defined(POLARSSL_MEMORY_BUFFER_ALLOC_C)
818 #if defined(POLARSSL_MEMORY_DEBUG)
819  memory_buffer_alloc_status();
820 #endif
821  memory_buffer_alloc_free();
822 #endif
823 
824  return( total_errors != 0 );
825 }
826 
827