PolarSSL v1.3.9
test_suite_entropy.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_ENTROPY_C
8 
9 #include <polarssl/entropy.h>
10 
11 /*
12  * Number of calls made to entropy_dummy_source()
13  */
14 static size_t entropy_dummy_calls;
15 
16 /*
17  * Dummy entropy source
18  *
19  * If data is NULL, write exactly the requested length.
20  * Otherwise, write the length indicated by data or error if negative
21  */
22 static int entropy_dummy_source( void *data, unsigned char *output,
23  size_t len, size_t *olen )
24 {
25  entropy_dummy_calls++;
26 
27  if( data == NULL )
28  *olen = len;
29  else
30  {
31  int *d = (int *) data;
32 
33  if( *d < 0 )
35  else
36  *olen = *d;
37  }
38 
39  memset( output, 0x2a, *olen );
40 
41  return( 0 );
42 }
43 #endif /* POLARSSL_ENTROPY_C */
44 
45 
46 #if defined(POLARSSL_MEMORY_BUFFER_ALLOC_C)
47 #include "polarssl/memory.h"
48 #endif
49 
50 #if defined(POLARSSL_PLATFORM_C)
51 #include "polarssl/platform.h"
52 #else
53 #define polarssl_malloc malloc
54 #define polarssl_free free
55 #endif
56 
57 #ifdef _MSC_VER
58 #include <basetsd.h>
59 typedef UINT32 uint32_t;
60 #else
61 #include <inttypes.h>
62 #endif
63 
64 #include <assert.h>
65 #include <stdlib.h>
66 #include <string.h>
67 
68 /*
69  * 32-bit integer manipulation macros (big endian)
70  */
71 #ifndef GET_UINT32_BE
72 #define GET_UINT32_BE(n,b,i) \
73 { \
74  (n) = ( (uint32_t) (b)[(i) ] << 24 ) \
75  | ( (uint32_t) (b)[(i) + 1] << 16 ) \
76  | ( (uint32_t) (b)[(i) + 2] << 8 ) \
77  | ( (uint32_t) (b)[(i) + 3] ); \
78 }
79 #endif
80 
81 #ifndef PUT_UINT32_BE
82 #define PUT_UINT32_BE(n,b,i) \
83 { \
84  (b)[(i) ] = (unsigned char) ( (n) >> 24 ); \
85  (b)[(i) + 1] = (unsigned char) ( (n) >> 16 ); \
86  (b)[(i) + 2] = (unsigned char) ( (n) >> 8 ); \
87  (b)[(i) + 3] = (unsigned char) ( (n) ); \
88 }
89 #endif
90 
91 static int unhexify(unsigned char *obuf, const char *ibuf)
92 {
93  unsigned char c, c2;
94  int len = strlen(ibuf) / 2;
95  assert(!(strlen(ibuf) %1)); // must be even number of bytes
96 
97  while (*ibuf != 0)
98  {
99  c = *ibuf++;
100  if( c >= '0' && c <= '9' )
101  c -= '0';
102  else if( c >= 'a' && c <= 'f' )
103  c -= 'a' - 10;
104  else if( c >= 'A' && c <= 'F' )
105  c -= 'A' - 10;
106  else
107  assert( 0 );
108 
109  c2 = *ibuf++;
110  if( c2 >= '0' && c2 <= '9' )
111  c2 -= '0';
112  else if( c2 >= 'a' && c2 <= 'f' )
113  c2 -= 'a' - 10;
114  else if( c2 >= 'A' && c2 <= 'F' )
115  c2 -= 'A' - 10;
116  else
117  assert( 0 );
118 
119  *obuf++ = ( c << 4 ) | c2;
120  }
121 
122  return len;
123 }
124 
125 static void hexify(unsigned char *obuf, const unsigned char *ibuf, int len)
126 {
127  unsigned char l, h;
128 
129  while (len != 0)
130  {
131  h = (*ibuf) / 16;
132  l = (*ibuf) % 16;
133 
134  if( h < 10 )
135  *obuf++ = '0' + h;
136  else
137  *obuf++ = 'a' + h - 10;
138 
139  if( l < 10 )
140  *obuf++ = '0' + l;
141  else
142  *obuf++ = 'a' + l - 10;
143 
144  ++ibuf;
145  len--;
146  }
147 }
148 
156 static unsigned char *zero_alloc( size_t len )
157 {
158  void *p;
159  size_t actual_len = len != 0 ? len : 1;
160 
161  p = polarssl_malloc( actual_len );
162  assert( p != NULL );
163 
164  memset( p, 0x00, actual_len );
165 
166  return( p );
167 }
168 
179 static unsigned char *unhexify_alloc( const char *ibuf, size_t *olen )
180 {
181  unsigned char *obuf;
182 
183  *olen = strlen(ibuf) / 2;
184 
185  if( *olen == 0 )
186  return( zero_alloc( *olen ) );
187 
188  obuf = polarssl_malloc( *olen );
189  assert( obuf != NULL );
190 
191  (void) unhexify( obuf, ibuf );
192 
193  return( obuf );
194 }
195 
205 static int rnd_std_rand( void *rng_state, unsigned char *output, size_t len )
206 {
207 #if !defined(__OpenBSD__)
208  size_t i;
209 
210  if( rng_state != NULL )
211  rng_state = NULL;
212 
213  for( i = 0; i < len; ++i )
214  output[i] = rand();
215 #else
216  if( rng_state != NULL )
217  rng_state = NULL;
218 
219  arc4random_buf( output, len );
220 #endif /* !OpenBSD */
221 
222  return( 0 );
223 }
224 
230 static int rnd_zero_rand( void *rng_state, unsigned char *output, size_t len )
231 {
232  if( rng_state != NULL )
233  rng_state = NULL;
234 
235  memset( output, 0, len );
236 
237  return( 0 );
238 }
239 
240 typedef struct
241 {
242  unsigned char *buf;
243  size_t length;
244 } rnd_buf_info;
245 
257 static int rnd_buffer_rand( void *rng_state, unsigned char *output, size_t len )
258 {
259  rnd_buf_info *info = (rnd_buf_info *) rng_state;
260  size_t use_len;
261 
262  if( rng_state == NULL )
263  return( rnd_std_rand( NULL, output, len ) );
264 
265  use_len = len;
266  if( len > info->length )
267  use_len = info->length;
268 
269  if( use_len )
270  {
271  memcpy( output, info->buf, use_len );
272  info->buf += use_len;
273  info->length -= use_len;
274  }
275 
276  if( len - use_len > 0 )
277  return( rnd_std_rand( NULL, output + use_len, len - use_len ) );
278 
279  return( 0 );
280 }
281 
289 typedef struct
290 {
291  uint32_t key[16];
292  uint32_t v0, v1;
294 
303 static int rnd_pseudo_rand( void *rng_state, unsigned char *output, size_t len )
304 {
305  rnd_pseudo_info *info = (rnd_pseudo_info *) rng_state;
306  uint32_t i, *k, sum, delta=0x9E3779B9;
307  unsigned char result[4], *out = output;
308 
309  if( rng_state == NULL )
310  return( rnd_std_rand( NULL, output, len ) );
311 
312  k = info->key;
313 
314  while( len > 0 )
315  {
316  size_t use_len = ( len > 4 ) ? 4 : len;
317  sum = 0;
318 
319  for( i = 0; i < 32; i++ )
320  {
321  info->v0 += (((info->v1 << 4) ^ (info->v1 >> 5)) + info->v1) ^ (sum + k[sum & 3]);
322  sum += delta;
323  info->v1 += (((info->v0 << 4) ^ (info->v0 >> 5)) + info->v0) ^ (sum + k[(sum>>11) & 3]);
324  }
325 
326  PUT_UINT32_BE( info->v0, result, 0 );
327  memcpy( out, result, use_len );
328  len -= use_len;
329  out += 4;
330  }
331 
332  return( 0 );
333 }
334 
335 
336 #include <stdio.h>
337 #include <string.h>
338 
339 #if defined(POLARSSL_PLATFORM_C)
340 #include "polarssl/platform.h"
341 #else
342 #define polarssl_printf printf
343 #define polarssl_malloc malloc
344 #define polarssl_free free
345 #endif
346 
347 static int test_errors = 0;
348 
349 #ifdef POLARSSL_ENTROPY_C
350 
351 #define TEST_SUITE_ACTIVE
352 
353 static int test_assert( int correct, const char *test )
354 {
355  if( correct )
356  return( 0 );
357 
358  test_errors++;
359  if( test_errors == 1 )
360  printf( "FAILED\n" );
361  printf( " %s\n", test );
362 
363  return( 1 );
364 }
365 
366 #define TEST_ASSERT( TEST ) \
367  do { test_assert( (TEST) ? 1 : 0, #TEST ); \
368  if( test_errors) goto exit; \
369  } while (0)
370 
371 int verify_string( char **str )
372 {
373  if( (*str)[0] != '"' ||
374  (*str)[strlen( *str ) - 1] != '"' )
375  {
376  printf( "Expected string (with \"\") for parameter and got: %s\n", *str );
377  return( -1 );
378  }
379 
380  (*str)++;
381  (*str)[strlen( *str ) - 1] = '\0';
382 
383  return( 0 );
384 }
385 
386 int verify_int( char *str, int *value )
387 {
388  size_t i;
389  int minus = 0;
390  int digits = 1;
391  int hex = 0;
392 
393  for( i = 0; i < strlen( str ); i++ )
394  {
395  if( i == 0 && str[i] == '-' )
396  {
397  minus = 1;
398  continue;
399  }
400 
401  if( ( ( minus && i == 2 ) || ( !minus && i == 1 ) ) &&
402  str[i - 1] == '0' && str[i] == 'x' )
403  {
404  hex = 1;
405  continue;
406  }
407 
408  if( ! ( ( str[i] >= '0' && str[i] <= '9' ) ||
409  ( hex && ( ( str[i] >= 'a' && str[i] <= 'f' ) ||
410  ( str[i] >= 'A' && str[i] <= 'F' ) ) ) ) )
411  {
412  digits = 0;
413  break;
414  }
415  }
416 
417  if( digits )
418  {
419  if( hex )
420  *value = strtol( str, NULL, 16 );
421  else
422  *value = strtol( str, NULL, 10 );
423 
424  return( 0 );
425  }
426 
427  if( strcmp( str, "POLARSSL_ERR_ENTROPY_SOURCE_FAILED" ) == 0 )
428  {
430  return( 0 );
431  }
432 #ifdef POLARSSL_FS_IO
433  if( strcmp( str, "POLARSSL_ERR_ENTROPY_FILE_IO_ERROR" ) == 0 )
434  {
436  return( 0 );
437  }
438 #endif // POLARSSL_FS_IO
439 
440 
441  printf( "Expected integer for parameter and got: %s\n", str );
442  return( -1 );
443 }
444 
445 #ifdef POLARSSL_FS_IO
446 void test_suite_entropy_seed_file( char *path, int ret )
447 {
448  entropy_context ctx;
449 
450  entropy_init( &ctx );
451 
452  TEST_ASSERT( entropy_write_seed_file( &ctx, path ) == ret );
453  TEST_ASSERT( entropy_update_seed_file( &ctx, path ) == ret );
454 
455 exit:
456  entropy_free( &ctx );
457 }
458 #endif /* POLARSSL_FS_IO */
459 
460 void test_suite_entropy_too_many_sources( )
461 {
462  entropy_context ctx;
463  size_t i;
464 
465  entropy_init( &ctx );
466 
467  /*
468  * It's hard to tell precisely when the error will occur,
469  * since we don't know how many sources were automatically added.
470  */
471  for( i = 0; i < ENTROPY_MAX_SOURCES; i++ )
472  (void) entropy_add_source( &ctx, entropy_dummy_source, NULL, 16 );
473 
474  TEST_ASSERT( entropy_add_source( &ctx, entropy_dummy_source, NULL, 16 )
476 
477 exit:
478  entropy_free( &ctx );
479 }
480 
481 void test_suite_entropy_func_len( int len, int ret )
482 {
483  entropy_context ctx;
484  unsigned char buf[ENTROPY_BLOCK_SIZE + 10] = { 0 };
485  unsigned char acc[ENTROPY_BLOCK_SIZE + 10] = { 0 };
486  size_t i, j;
487 
488  entropy_init( &ctx );
489 
490  /*
491  * See comments in entropy_self_test()
492  */
493  for( i = 0; i < 8; i++ )
494  {
495  TEST_ASSERT( entropy_func( &ctx, buf, len ) == ret );
496  for( j = 0; j < sizeof( buf ); j++ )
497  acc[j] |= buf[j];
498  }
499 
500  if( ret == 0 )
501  for( j = 0; j < (size_t) len; j++ )
502  TEST_ASSERT( acc[j] != 0 );
503 
504  for( j = len; j < sizeof( buf ); j++ )
505  TEST_ASSERT( acc[j] == 0 );
506 
507 exit:
508  return;
509 }
510 
511 void test_suite_entropy_source_fail( char *path )
512 {
513  entropy_context ctx;
514  int fail = -1;
515  unsigned char buf[16];
516 
517  entropy_init( &ctx );
518 
519  TEST_ASSERT( entropy_add_source( &ctx, entropy_dummy_source, &fail, 16 )
520  == 0 );
521 
522  TEST_ASSERT( entropy_func( &ctx, buf, sizeof( buf ) )
524  TEST_ASSERT( entropy_gather( &ctx )
526 #if defined(POLARSSL_FS_IO)
527  TEST_ASSERT( entropy_write_seed_file( &ctx, path )
531 #else
532  ((void) path);
533 #endif
534 
535 exit:
536  entropy_free( &ctx );
537 }
538 
539 void test_suite_entropy_threshold( int threshold, int chunk_size, int result )
540 {
541  entropy_context ctx;
542  unsigned char buf[ENTROPY_BLOCK_SIZE] = { 0 };
543  int ret;
544 
545  entropy_init( &ctx );
546 
547  TEST_ASSERT( entropy_add_source( &ctx, entropy_dummy_source,
548  &chunk_size, threshold ) == 0 );
549 
550  entropy_dummy_calls = 0;
551  ret = entropy_func( &ctx, buf, sizeof( buf ) );
552 
553  if( result >= 0 )
554  {
555  TEST_ASSERT( ret == 0 );
556  TEST_ASSERT( entropy_dummy_calls == (size_t) result );
557  }
558  else
559  {
560  TEST_ASSERT( ret == result );
561  }
562 
563 exit:
564  entropy_free( &ctx );
565 }
566 
567 #ifdef POLARSSL_SELF_TEST
568 void test_suite_entropy_selftest( )
569 {
570  TEST_ASSERT( entropy_self_test( 0 ) == 0 );
571 
572 exit:
573  return;
574 }
575 #endif /* POLARSSL_SELF_TEST */
576 
577 
578 #endif /* POLARSSL_ENTROPY_C */
579 
580 
581 int dep_check( char *str )
582 {
583  if( str == NULL )
584  return( 1 );
585 
586 
587 
588  return( 1 );
589 }
590 
591 int dispatch_test(int cnt, char *params[50])
592 {
593  int ret;
594  ((void) cnt);
595  ((void) params);
596 
597 #if defined(TEST_SUITE_ACTIVE)
598  if( strcmp( params[0], "entropy_seed_file" ) == 0 )
599  {
600  #ifdef POLARSSL_FS_IO
601 
602  char *param1 = params[1];
603  int param2;
604 
605  if( cnt != 3 )
606  {
607  fprintf( stderr, "\nIncorrect argument count (%d != %d)\n", cnt, 3 );
608  return( 2 );
609  }
610 
611  if( verify_string( &param1 ) != 0 ) return( 2 );
612  if( verify_int( params[2], &param2 ) != 0 ) return( 2 );
613 
614  test_suite_entropy_seed_file( param1, param2 );
615  return ( 0 );
616  #endif /* POLARSSL_FS_IO */
617 
618  return ( 3 );
619  }
620  else
621  if( strcmp( params[0], "entropy_too_many_sources" ) == 0 )
622  {
623 
624 
625  if( cnt != 1 )
626  {
627  fprintf( stderr, "\nIncorrect argument count (%d != %d)\n", cnt, 1 );
628  return( 2 );
629  }
630 
631 
632  test_suite_entropy_too_many_sources( );
633  return ( 0 );
634 
635  return ( 3 );
636  }
637  else
638  if( strcmp( params[0], "entropy_func_len" ) == 0 )
639  {
640 
641  int param1;
642  int param2;
643 
644  if( cnt != 3 )
645  {
646  fprintf( stderr, "\nIncorrect argument count (%d != %d)\n", cnt, 3 );
647  return( 2 );
648  }
649 
650  if( verify_int( params[1], &param1 ) != 0 ) return( 2 );
651  if( verify_int( params[2], &param2 ) != 0 ) return( 2 );
652 
653  test_suite_entropy_func_len( param1, param2 );
654  return ( 0 );
655 
656  return ( 3 );
657  }
658  else
659  if( strcmp( params[0], "entropy_source_fail" ) == 0 )
660  {
661 
662  char *param1 = params[1];
663 
664  if( cnt != 2 )
665  {
666  fprintf( stderr, "\nIncorrect argument count (%d != %d)\n", cnt, 2 );
667  return( 2 );
668  }
669 
670  if( verify_string( &param1 ) != 0 ) return( 2 );
671 
672  test_suite_entropy_source_fail( param1 );
673  return ( 0 );
674 
675  return ( 3 );
676  }
677  else
678  if( strcmp( params[0], "entropy_threshold" ) == 0 )
679  {
680 
681  int param1;
682  int param2;
683  int param3;
684 
685  if( cnt != 4 )
686  {
687  fprintf( stderr, "\nIncorrect argument count (%d != %d)\n", cnt, 4 );
688  return( 2 );
689  }
690 
691  if( verify_int( params[1], &param1 ) != 0 ) return( 2 );
692  if( verify_int( params[2], &param2 ) != 0 ) return( 2 );
693  if( verify_int( params[3], &param3 ) != 0 ) return( 2 );
694 
695  test_suite_entropy_threshold( param1, param2, param3 );
696  return ( 0 );
697 
698  return ( 3 );
699  }
700  else
701  if( strcmp( params[0], "entropy_selftest" ) == 0 )
702  {
703  #ifdef POLARSSL_SELF_TEST
704 
705 
706  if( cnt != 1 )
707  {
708  fprintf( stderr, "\nIncorrect argument count (%d != %d)\n", cnt, 1 );
709  return( 2 );
710  }
711 
712 
713  test_suite_entropy_selftest( );
714  return ( 0 );
715  #endif /* POLARSSL_SELF_TEST */
716 
717  return ( 3 );
718  }
719  else
720 
721  {
722  fprintf( stdout, "FAILED\nSkipping unknown test function '%s'\n", params[0] );
723  fflush( stdout );
724  return( 1 );
725  }
726 #else
727  return( 3 );
728 #endif
729  return( ret );
730 }
731 
732 int get_line( FILE *f, char *buf, size_t len )
733 {
734  char *ret;
735 
736  ret = fgets( buf, len, f );
737  if( ret == NULL )
738  return( -1 );
739 
740  if( strlen( buf ) && buf[strlen(buf) - 1] == '\n' )
741  buf[strlen(buf) - 1] = '\0';
742  if( strlen( buf ) && buf[strlen(buf) - 1] == '\r' )
743  buf[strlen(buf) - 1] = '\0';
744 
745  return( 0 );
746 }
747 
748 int parse_arguments( char *buf, size_t len, char *params[50] )
749 {
750  int cnt = 0, i;
751  char *cur = buf;
752  char *p = buf, *q;
753 
754  params[cnt++] = cur;
755 
756  while( *p != '\0' && p < buf + len )
757  {
758  if( *p == '\\' )
759  {
760  p++;
761  p++;
762  continue;
763  }
764  if( *p == ':' )
765  {
766  if( p + 1 < buf + len )
767  {
768  cur = p + 1;
769  params[cnt++] = cur;
770  }
771  *p = '\0';
772  }
773 
774  p++;
775  }
776 
777  // Replace newlines, question marks and colons in strings
778  for( i = 0; i < cnt; i++ )
779  {
780  p = params[i];
781  q = params[i];
782 
783  while( *p != '\0' )
784  {
785  if( *p == '\\' && *(p + 1) == 'n' )
786  {
787  p += 2;
788  *(q++) = '\n';
789  }
790  else if( *p == '\\' && *(p + 1) == ':' )
791  {
792  p += 2;
793  *(q++) = ':';
794  }
795  else if( *p == '\\' && *(p + 1) == '?' )
796  {
797  p += 2;
798  *(q++) = '?';
799  }
800  else
801  *(q++) = *(p++);
802  }
803  *q = '\0';
804  }
805 
806  return( cnt );
807 }
808 
809 int main()
810 {
811  int ret, i, cnt, total_errors = 0, total_tests = 0, total_skipped = 0;
812  const char *filename = "/tmp/B.zrfcg4/BUILD/polarssl-1.3.9/tests/suites/test_suite_entropy.data";
813  FILE *file;
814  char buf[5000];
815  char *params[50];
816 
817 #if defined(POLARSSL_MEMORY_BUFFER_ALLOC_C)
818  unsigned char alloc_buf[1000000];
819  memory_buffer_alloc_init( alloc_buf, sizeof(alloc_buf) );
820 #endif
821 
822  file = fopen( filename, "r" );
823  if( file == NULL )
824  {
825  fprintf( stderr, "Failed to open\n" );
826  return( 1 );
827  }
828 
829  while( !feof( file ) )
830  {
831  int skip = 0;
832 
833  if( ( ret = get_line( file, buf, sizeof(buf) ) ) != 0 )
834  break;
835  fprintf( stdout, "%s%.66s", test_errors ? "\n" : "", buf );
836  fprintf( stdout, " " );
837  for( i = strlen( buf ) + 1; i < 67; i++ )
838  fprintf( stdout, "." );
839  fprintf( stdout, " " );
840  fflush( stdout );
841 
842  total_tests++;
843 
844  if( ( ret = get_line( file, buf, sizeof(buf) ) ) != 0 )
845  break;
846  cnt = parse_arguments( buf, strlen(buf), params );
847 
848  if( strcmp( params[0], "depends_on" ) == 0 )
849  {
850  for( i = 1; i < cnt; i++ )
851  if( dep_check( params[i] ) != 0 )
852  skip = 1;
853 
854  if( ( ret = get_line( file, buf, sizeof(buf) ) ) != 0 )
855  break;
856  cnt = parse_arguments( buf, strlen(buf), params );
857  }
858 
859  if( skip == 0 )
860  {
861  test_errors = 0;
862  ret = dispatch_test( cnt, params );
863  }
864 
865  if( skip == 1 || ret == 3 )
866  {
867  total_skipped++;
868  fprintf( stdout, "----\n" );
869  fflush( stdout );
870  }
871  else if( ret == 0 && test_errors == 0 )
872  {
873  fprintf( stdout, "PASS\n" );
874  fflush( stdout );
875  }
876  else if( ret == 2 )
877  {
878  fprintf( stderr, "FAILED: FATAL PARSE ERROR\n" );
879  fclose(file);
880  exit( 2 );
881  }
882  else
883  total_errors++;
884 
885  if( ( ret = get_line( file, buf, sizeof(buf) ) ) != 0 )
886  break;
887  if( strlen(buf) != 0 )
888  {
889  fprintf( stderr, "Should be empty %d\n", (int) strlen(buf) );
890  return( 1 );
891  }
892  }
893  fclose(file);
894 
895  fprintf( stdout, "\n----------------------------------------------------------------------------\n\n");
896  if( total_errors == 0 )
897  fprintf( stdout, "PASSED" );
898  else
899  fprintf( stdout, "FAILED" );
900 
901  fprintf( stdout, " (%d / %d tests (%d skipped))\n",
902  total_tests - total_errors, total_tests, total_skipped );
903 
904 #if defined(POLARSSL_MEMORY_BUFFER_ALLOC_C)
905 #if defined(POLARSSL_MEMORY_DEBUG)
906  memory_buffer_alloc_status();
907 #endif
909 #endif
910 
911  return( total_errors != 0 );
912 }
913 
914 
int get_line(FILE *f, char *buf, size_t len)
Memory allocation layer (Deprecated to platform layer)
int entropy_add_source(entropy_context *ctx, f_source_ptr f_source, void *p_source, size_t threshold)
Adds an entropy source to poll (Thread-safe if POLARSSL_THREADING_C is enabled)
static unsigned char * unhexify_alloc(const char *ibuf, size_t *olen)
Allocate and fill a buffer from hex data.
Info structure for the pseudo random function.
void memory_buffer_alloc_free(void)
Free the mutex for thread-safety and clear remaining memory.
static int rnd_zero_rand(void *rng_state, unsigned char *output, size_t len)
This function only returns zeros.
#define polarssl_malloc
static void hexify(unsigned char *obuf, const unsigned char *ibuf, int len)
#define POLARSSL_ERR_ENTROPY_MAX_SOURCES
No more sources can be added.
Definition: entropy.h:57
int dispatch_test(int cnt, char *params[50])
Configuration options (set of defines)
int entropy_gather(entropy_context *ctx)
Trigger an extra gather poll for the accumulator (Thread-safe if POLARSSL_THREADING_C is enabled) ...
Entropy context structure.
Definition: entropy.h:121
PolarSSL Platform abstraction layer.
static int test_assert(int correct, const char *test)
Entropy accumulator implementation.
#define PUT_UINT32_BE(n, b, i)
int memory_buffer_alloc_init(unsigned char *buf, size_t len)
Initialize use of stack-based memory allocator.
#define ENTROPY_BLOCK_SIZE
Block size of entropy accumulator (SHA-512)
Definition: entropy.h:80
#define TEST_ASSERT(TEST)
int entropy_write_seed_file(entropy_context *ctx, const char *path)
Write a seed file.
static int rnd_std_rand(void *rng_state, unsigned char *output, size_t len)
This function just returns data from rand().
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 unsigned char * zero_alloc(size_t len)
Allocate and zeroize a buffer.
int dep_check(char *str)
int entropy_self_test(int verbose)
Checkup routine.
int verify_string(char **str)
static int test_errors
unsigned char * buf
int entropy_update_seed_file(entropy_context *ctx, const char *path)
Read and update a seed file.
#define POLARSSL_ERR_ENTROPY_FILE_IO_ERROR
Read/write error in file.
Definition: entropy.h:59
static int unhexify(unsigned char *obuf, const char *ibuf)
#define ENTROPY_MAX_SOURCES
int main()
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 verify_int(char *str, int *value)
void entropy_init(entropy_context *ctx)
Initialize the context.
#define POLARSSL_ERR_ENTROPY_SOURCE_FAILED
Critical entropy source failure.
Definition: entropy.h:56
int parse_arguments(char *buf, size_t len, char *params[50])
int entropy_func(void *data, unsigned char *output, size_t len)
Retrieve entropy from the accumulator (Maximum length: ENTROPY_BLOCK_SIZE) (Thread-safe if POLARSSL_T...
void entropy_free(entropy_context *ctx)
Free the data in the context.