1 #if !defined(POLARSSL_CONFIG_FILE)
4 #include POLARSSL_CONFIG_FILE
14 #if defined(POLARSSL_MEMORY_BUFFER_ALLOC_C)
18 #if defined(POLARSSL_PLATFORM_C)
21 #define polarssl_malloc malloc
22 #define polarssl_free free
27 typedef UINT32 uint32_t;
40 #define GET_UINT32_BE(n,b,i) \
42 (n) = ( (uint32_t) (b)[(i) ] << 24 ) \
43 | ( (uint32_t) (b)[(i) + 1] << 16 ) \
44 | ( (uint32_t) (b)[(i) + 2] << 8 ) \
45 | ( (uint32_t) (b)[(i) + 3] ); \
50 #define PUT_UINT32_BE(n,b,i) \
52 (b)[(i) ] = (unsigned char) ( (n) >> 24 ); \
53 (b)[(i) + 1] = (unsigned char) ( (n) >> 16 ); \
54 (b)[(i) + 2] = (unsigned char) ( (n) >> 8 ); \
55 (b)[(i) + 3] = (unsigned char) ( (n) ); \
59 static int unhexify(
unsigned char *obuf,
const char *ibuf)
62 int len = strlen(ibuf) / 2;
63 assert(!(strlen(ibuf) %1));
68 if( c >=
'0' && c <=
'9' )
70 else if( c >=
'a' && c <=
'f' )
72 else if( c >=
'A' && c <=
'F' )
78 if( c2 >=
'0' && c2 <=
'9' )
80 else if( c2 >=
'a' && c2 <=
'f' )
82 else if( c2 >=
'A' && c2 <=
'F' )
87 *obuf++ = ( c << 4 ) | c2;
93 static void hexify(
unsigned char *obuf,
const unsigned char *ibuf,
int len)
105 *obuf++ =
'a' + h - 10;
110 *obuf++ =
'a' + l - 10;
127 size_t actual_len = len != 0 ? len : 1;
132 memset( p, 0x00, actual_len );
151 *olen = strlen(ibuf) / 2;
157 assert( obuf != NULL );
173 static int rnd_std_rand(
void *rng_state,
unsigned char *output,
size_t len )
175 #if !defined(__OpenBSD__)
178 if( rng_state != NULL )
181 for( i = 0; i < len; ++i )
184 if( rng_state != NULL )
187 arc4random_buf( output, len );
198 static int rnd_zero_rand(
void *rng_state,
unsigned char *output,
size_t len )
200 if( rng_state != NULL )
203 memset( output, 0, len );
230 if( rng_state == NULL )
239 memcpy( output, info->
buf, use_len );
240 info->
buf += use_len;
244 if( len - use_len > 0 )
245 return(
rnd_std_rand( NULL, output + use_len, len - use_len ) );
274 uint32_t i, *k, sum, delta=0x9E3779B9;
275 unsigned char result[4], *out = output;
277 if( rng_state == NULL )
284 size_t use_len = ( len > 4 ) ? 4 : len;
287 for( i = 0; i < 32; i++ )
289 info->
v0 += (((info->
v1 << 4) ^ (info->
v1 >> 5)) + info->
v1) ^ (sum + k[sum & 3]);
291 info->
v1 += (((info->
v0 << 4) ^ (info->
v0 >> 5)) + info->
v0) ^ (sum + k[(sum>>11) & 3]);
295 memcpy( out, result, use_len );
307 #if defined(POLARSSL_PLATFORM_C)
310 #define polarssl_printf printf
311 #define polarssl_malloc malloc
312 #define polarssl_free free
318 #define TEST_SUITE_ACTIVE
327 printf(
"FAILED\n" );
328 printf(
" %s\n", test );
333 #define TEST_ASSERT( TEST ) \
334 do { test_assert( (TEST) ? 1 : 0, #TEST ); \
335 if( test_errors) goto exit; \
340 if( (*str)[0] !=
'"' ||
341 (*str)[strlen( *str ) - 1] !=
'"' )
343 printf(
"Expected string (with \"\") for parameter and got: %s\n", *str );
348 (*str)[strlen( *str ) - 1] =
'\0';
360 for( i = 0; i < strlen( str ); i++ )
362 if( i == 0 && str[i] ==
'-' )
368 if( ( ( minus && i == 2 ) || ( !minus && i == 1 ) ) &&
369 str[i - 1] ==
'0' && str[i] ==
'x' )
375 if( ! ( ( str[i] >=
'0' && str[i] <=
'9' ) ||
376 ( hex && ( ( str[i] >=
'a' && str[i] <=
'f' ) ||
377 ( str[i] >=
'A' && str[i] <=
'F' ) ) ) ) )
387 *value = strtol( str, NULL, 16 );
389 *value = strtol( str, NULL, 10 );
396 printf(
"Expected integer for parameter and got: %s\n", str );
400 #ifdef POLARSSL_MD2_C
401 void test_suite_md2_text(
char *text_src_string,
char *hex_hash_string )
403 unsigned char src_str[100];
404 unsigned char hash_str[33];
405 unsigned char output[16];
407 memset( src_str, 0x00,
sizeof src_str );
408 memset( hash_str, 0x00,
sizeof hash_str );
409 memset( output, 0x00,
sizeof output );
411 strncpy( (
char *) src_str, text_src_string,
sizeof(src_str) - 1 );
413 md2( src_str, strlen( (
char *) src_str ), output );
414 hexify( hash_str, output,
sizeof output );
416 TEST_ASSERT( strcmp( (
char *) hash_str, hex_hash_string ) == 0 );
423 #ifdef POLARSSL_MD4_C
424 void test_suite_md4_text(
char *text_src_string,
char *hex_hash_string )
426 unsigned char src_str[100];
427 unsigned char hash_str[33];
428 unsigned char output[16];
430 memset( src_str, 0x00,
sizeof src_str );
431 memset( hash_str, 0x00,
sizeof hash_str );
432 memset( output, 0x00,
sizeof output );
434 strncpy( (
char *) src_str, text_src_string,
sizeof(src_str) - 1 );
436 md4( src_str, strlen( (
char *) src_str ), output );
437 hexify( hash_str, output,
sizeof output );
439 TEST_ASSERT( strcmp( (
char *) hash_str, hex_hash_string ) == 0 );
446 #ifdef POLARSSL_MD5_C
447 void test_suite_md5_text(
char *text_src_string,
char *hex_hash_string )
449 unsigned char src_str[100];
450 unsigned char hash_str[33];
451 unsigned char output[16];
453 memset( src_str, 0x00,
sizeof src_str );
454 memset( hash_str, 0x00,
sizeof hash_str );
455 memset( output, 0x00,
sizeof output );
457 strncpy( (
char *) src_str, text_src_string,
sizeof(src_str) - 1 );
459 md5( src_str, strlen( (
char *) src_str ), output );
460 hexify( hash_str, output,
sizeof output );
462 TEST_ASSERT( strcmp( (
char *) hash_str, hex_hash_string ) == 0 );
469 #ifdef POLARSSL_RIPEMD160_C
470 void test_suite_ripemd160_text(
char *text_src_string,
char *hex_hash_string )
472 unsigned char src_str[100];
473 unsigned char hash_str[41];
474 unsigned char output[20];
476 memset(src_str, 0x00,
sizeof src_str);
477 memset(hash_str, 0x00,
sizeof hash_str);
478 memset(output, 0x00,
sizeof output);
480 strncpy( (
char *) src_str, text_src_string,
sizeof(src_str) - 1 );
482 ripemd160( src_str, strlen( (
char *) src_str ), output );
483 hexify( hash_str, output,
sizeof output );
485 TEST_ASSERT( strcmp( (
char *) hash_str, hex_hash_string ) == 0 );
492 #ifdef POLARSSL_MD2_C
493 void test_suite_md2_hmac(
int trunc_size,
char *hex_key_string,
char *hex_src_string,
494 char *hex_hash_string )
496 unsigned char src_str[200];
497 unsigned char key_str[200];
498 unsigned char hash_str[33];
499 unsigned char output[16];
500 int key_len, src_len;
503 memset( src_str, 0x00,
sizeof src_str );
504 memset( key_str, 0x00,
sizeof key_str );
507 key_len =
unhexify( key_str, hex_key_string );
508 src_len =
unhexify( src_str, hex_src_string );
511 memset( hash_str, 0x00,
sizeof hash_str );
512 memset( output, 0x00,
sizeof output );
514 md2_hmac( key_str, key_len, src_str, src_len, output );
516 hexify( hash_str, output,
sizeof output );
517 TEST_ASSERT( strncmp( (
char *) hash_str, hex_hash_string, trunc_size * 2 ) == 0 );
520 memset( hash_str, 0x00,
sizeof hash_str );
521 memset( output, 0x00,
sizeof output );
522 memset( &ctx, 0x00,
sizeof ctx );
531 hexify( hash_str, output,
sizeof output );
532 TEST_ASSERT( strncmp( (
char *) hash_str, hex_hash_string, trunc_size * 2 ) == 0 );
535 memset( hash_str, 0x00,
sizeof hash_str );
536 memset( output, 0x00,
sizeof output );
543 hexify( hash_str, output,
sizeof output );
544 TEST_ASSERT( strncmp( (
char *) hash_str, hex_hash_string, trunc_size * 2 ) == 0 );
551 #ifdef POLARSSL_MD4_C
552 void test_suite_md4_hmac(
int trunc_size,
char *hex_key_string,
char *hex_src_string,
553 char *hex_hash_string )
555 unsigned char src_str[200];
556 unsigned char key_str[200];
557 unsigned char hash_str[33];
558 unsigned char output[16];
559 int key_len, src_len;
562 memset( src_str, 0x00,
sizeof src_str );
563 memset( key_str, 0x00,
sizeof key_str );
566 key_len =
unhexify( key_str, hex_key_string );
567 src_len =
unhexify( src_str, hex_src_string );
570 memset( hash_str, 0x00,
sizeof hash_str );
571 memset( output, 0x00,
sizeof output );
573 md4_hmac( key_str, key_len, src_str, src_len, output );
575 hexify( hash_str, output,
sizeof output );
576 TEST_ASSERT( strncmp( (
char *) hash_str, hex_hash_string, trunc_size * 2 ) == 0 );
579 memset( hash_str, 0x00,
sizeof hash_str );
580 memset( output, 0x00,
sizeof output );
581 memset( &ctx, 0x00,
sizeof ctx );
590 hexify( hash_str, output,
sizeof output );
591 TEST_ASSERT( strncmp( (
char *) hash_str, hex_hash_string, trunc_size * 2 ) == 0 );
594 memset( hash_str, 0x00,
sizeof hash_str );
595 memset( output, 0x00,
sizeof output );
602 hexify( hash_str, output,
sizeof output );
603 TEST_ASSERT( strncmp( (
char *) hash_str, hex_hash_string, trunc_size * 2 ) == 0 );
610 #ifdef POLARSSL_MD5_C
611 void test_suite_md5_hmac(
int trunc_size,
char *hex_key_string,
char *hex_src_string,
612 char *hex_hash_string )
614 unsigned char src_str[200];
615 unsigned char key_str[200];
616 unsigned char hash_str[33];
617 unsigned char output[16];
618 int key_len, src_len;
621 memset( src_str, 0x00,
sizeof src_str );
622 memset( key_str, 0x00,
sizeof key_str );
625 key_len =
unhexify( key_str, hex_key_string );
626 src_len =
unhexify( src_str, hex_src_string );
629 memset( hash_str, 0x00,
sizeof hash_str );
630 memset( output, 0x00,
sizeof output );
632 md5_hmac( key_str, key_len, src_str, src_len, output );
634 hexify( hash_str, output,
sizeof output );
635 TEST_ASSERT( strncmp( (
char *) hash_str, hex_hash_string, trunc_size * 2 ) == 0 );
638 memset( hash_str, 0x00,
sizeof hash_str );
639 memset( output, 0x00,
sizeof output );
640 memset( &ctx, 0x00,
sizeof ctx );
649 hexify( hash_str, output,
sizeof output );
650 TEST_ASSERT( strncmp( (
char *) hash_str, hex_hash_string, trunc_size * 2 ) == 0 );
653 memset( hash_str, 0x00,
sizeof hash_str );
654 memset( output, 0x00,
sizeof output );
661 hexify( hash_str, output,
sizeof output );
662 TEST_ASSERT( strncmp( (
char *) hash_str, hex_hash_string, trunc_size * 2 ) == 0 );
669 #ifdef POLARSSL_RIPEMD160_C
670 void test_suite_ripemd160_hmac(
int trunc_size,
char *hex_key_string,
char *hex_src_string,
671 char *hex_hash_string )
673 unsigned char src_str[200];
674 unsigned char key_str[200];
675 unsigned char hash_str[41];
676 unsigned char output[20];
677 int key_len, src_len;
680 memset( src_str, 0x00,
sizeof src_str );
681 memset( key_str, 0x00,
sizeof key_str );
684 key_len =
unhexify( key_str, hex_key_string );
685 src_len =
unhexify( src_str, hex_src_string );
688 memset( hash_str, 0x00,
sizeof hash_str );
689 memset( output, 0x00,
sizeof output );
693 hexify( hash_str, output,
sizeof output );
694 TEST_ASSERT( strncmp( (
char *) hash_str, hex_hash_string, trunc_size * 2 ) == 0 );
697 memset( hash_str, 0x00,
sizeof hash_str );
698 memset( output, 0x00,
sizeof output );
699 memset( &ctx, 0x00,
sizeof ctx );
708 hexify( hash_str, output,
sizeof output );
709 TEST_ASSERT( strncmp( (
char *) hash_str, hex_hash_string, trunc_size * 2 ) == 0 );
712 memset( hash_str, 0x00,
sizeof hash_str );
713 memset( output, 0x00,
sizeof output );
720 hexify( hash_str, output,
sizeof output );
721 TEST_ASSERT( strncmp( (
char *) hash_str, hex_hash_string, trunc_size * 2 ) == 0 );
728 #ifdef POLARSSL_MD2_C
729 #ifdef POLARSSL_FS_IO
730 void test_suite_md2_file(
char *filename,
char *hex_hash_string )
732 unsigned char hash_str[33];
733 unsigned char output[16];
735 memset( hash_str, 0x00,
sizeof hash_str );
736 memset( output, 0x00,
sizeof output );
739 hexify( hash_str, output,
sizeof output );
741 TEST_ASSERT( strcmp( (
char *) hash_str, hex_hash_string ) == 0 );
749 #ifdef POLARSSL_MD4_C
750 #ifdef POLARSSL_FS_IO
751 void test_suite_md4_file(
char *filename,
char *hex_hash_string )
753 unsigned char hash_str[33];
754 unsigned char output[16];
756 memset( hash_str, 0x00,
sizeof hash_str );
757 memset( output, 0x00,
sizeof output );
760 hexify( hash_str, output,
sizeof output );
762 TEST_ASSERT( strcmp( (
char *) hash_str, hex_hash_string ) == 0 );
770 #ifdef POLARSSL_MD5_C
771 #ifdef POLARSSL_FS_IO
772 void test_suite_md5_file(
char *filename,
char *hex_hash_string )
774 unsigned char hash_str[33];
775 unsigned char output[16];
777 memset( hash_str, 0x00,
sizeof hash_str );
778 memset( output, 0x00,
sizeof output );
781 hexify( hash_str, output,
sizeof output );
783 TEST_ASSERT( strcmp( (
char *) hash_str, hex_hash_string ) == 0 );
791 #ifdef POLARSSL_RIPEMD160_C
792 #ifdef POLARSSL_FS_IO
793 void test_suite_ripemd160_file(
char *filename,
char *hex_hash_string )
795 unsigned char hash_str[41];
796 unsigned char output[20];
798 memset(hash_str, 0x00,
sizeof hash_str );
799 memset(output, 0x00,
sizeof output );
802 hexify( hash_str, output,
sizeof output );
804 TEST_ASSERT( strcmp( (
char *) hash_str, hex_hash_string ) == 0 );
812 #ifdef POLARSSL_MD2_C
813 #ifdef POLARSSL_SELF_TEST
814 void test_suite_md2_selftest()
824 #ifdef POLARSSL_MD4_C
825 #ifdef POLARSSL_SELF_TEST
826 void test_suite_md4_selftest()
836 #ifdef POLARSSL_MD5_C
837 #ifdef POLARSSL_SELF_TEST
838 void test_suite_md5_selftest()
848 #ifdef POLARSSL_RIPEMD160_C
849 #ifdef POLARSSL_SELF_TEST
850 void test_suite_ripemd160_selftest()
879 #if defined(TEST_SUITE_ACTIVE)
880 if( strcmp( params[0],
"md2_text" ) == 0 )
882 #ifdef POLARSSL_MD2_C
884 char *param1 = params[1];
885 char *param2 = params[2];
889 fprintf( stderr,
"\nIncorrect argument count (%d != %d)\n", cnt, 3 );
896 test_suite_md2_text( param1, param2 );
903 if( strcmp( params[0],
"md4_text" ) == 0 )
905 #ifdef POLARSSL_MD4_C
907 char *param1 = params[1];
908 char *param2 = params[2];
912 fprintf( stderr,
"\nIncorrect argument count (%d != %d)\n", cnt, 3 );
919 test_suite_md4_text( param1, param2 );
926 if( strcmp( params[0],
"md5_text" ) == 0 )
928 #ifdef POLARSSL_MD5_C
930 char *param1 = params[1];
931 char *param2 = params[2];
935 fprintf( stderr,
"\nIncorrect argument count (%d != %d)\n", cnt, 3 );
942 test_suite_md5_text( param1, param2 );
949 if( strcmp( params[0],
"ripemd160_text" ) == 0 )
951 #ifdef POLARSSL_RIPEMD160_C
953 char *param1 = params[1];
954 char *param2 = params[2];
958 fprintf( stderr,
"\nIncorrect argument count (%d != %d)\n", cnt, 3 );
965 test_suite_ripemd160_text( param1, param2 );
972 if( strcmp( params[0],
"md2_hmac" ) == 0 )
974 #ifdef POLARSSL_MD2_C
977 char *param2 = params[2];
978 char *param3 = params[3];
979 char *param4 = params[4];
983 fprintf( stderr,
"\nIncorrect argument count (%d != %d)\n", cnt, 5 );
987 if(
verify_int( params[1], ¶m1 ) != 0 )
return( 2 );
992 test_suite_md2_hmac( param1, param2, param3, param4 );
999 if( strcmp( params[0],
"md4_hmac" ) == 0 )
1001 #ifdef POLARSSL_MD4_C
1004 char *param2 = params[2];
1005 char *param3 = params[3];
1006 char *param4 = params[4];
1010 fprintf( stderr,
"\nIncorrect argument count (%d != %d)\n", cnt, 5 );
1014 if(
verify_int( params[1], ¶m1 ) != 0 )
return( 2 );
1019 test_suite_md4_hmac( param1, param2, param3, param4 );
1026 if( strcmp( params[0],
"md5_hmac" ) == 0 )
1028 #ifdef POLARSSL_MD5_C
1031 char *param2 = params[2];
1032 char *param3 = params[3];
1033 char *param4 = params[4];
1037 fprintf( stderr,
"\nIncorrect argument count (%d != %d)\n", cnt, 5 );
1041 if(
verify_int( params[1], ¶m1 ) != 0 )
return( 2 );
1046 test_suite_md5_hmac( param1, param2, param3, param4 );
1053 if( strcmp( params[0],
"ripemd160_hmac" ) == 0 )
1055 #ifdef POLARSSL_RIPEMD160_C
1058 char *param2 = params[2];
1059 char *param3 = params[3];
1060 char *param4 = params[4];
1064 fprintf( stderr,
"\nIncorrect argument count (%d != %d)\n", cnt, 5 );
1068 if(
verify_int( params[1], ¶m1 ) != 0 )
return( 2 );
1073 test_suite_ripemd160_hmac( param1, param2, param3, param4 );
1080 if( strcmp( params[0],
"md2_file" ) == 0 )
1082 #ifdef POLARSSL_MD2_C
1083 #ifdef POLARSSL_FS_IO
1085 char *param1 = params[1];
1086 char *param2 = params[2];
1090 fprintf( stderr,
"\nIncorrect argument count (%d != %d)\n", cnt, 3 );
1097 test_suite_md2_file( param1, param2 );
1105 if( strcmp( params[0],
"md4_file" ) == 0 )
1107 #ifdef POLARSSL_MD4_C
1108 #ifdef POLARSSL_FS_IO
1110 char *param1 = params[1];
1111 char *param2 = params[2];
1115 fprintf( stderr,
"\nIncorrect argument count (%d != %d)\n", cnt, 3 );
1122 test_suite_md4_file( param1, param2 );
1130 if( strcmp( params[0],
"md5_file" ) == 0 )
1132 #ifdef POLARSSL_MD5_C
1133 #ifdef POLARSSL_FS_IO
1135 char *param1 = params[1];
1136 char *param2 = params[2];
1140 fprintf( stderr,
"\nIncorrect argument count (%d != %d)\n", cnt, 3 );
1147 test_suite_md5_file( param1, param2 );
1155 if( strcmp( params[0],
"ripemd160_file" ) == 0 )
1157 #ifdef POLARSSL_RIPEMD160_C
1158 #ifdef POLARSSL_FS_IO
1160 char *param1 = params[1];
1161 char *param2 = params[2];
1165 fprintf( stderr,
"\nIncorrect argument count (%d != %d)\n", cnt, 3 );
1172 test_suite_ripemd160_file( param1, param2 );
1180 if( strcmp( params[0],
"md2_selftest" ) == 0 )
1182 #ifdef POLARSSL_MD2_C
1183 #ifdef POLARSSL_SELF_TEST
1188 fprintf( stderr,
"\nIncorrect argument count (%d != %d)\n", cnt, 1 );
1193 test_suite_md2_selftest( );
1201 if( strcmp( params[0],
"md4_selftest" ) == 0 )
1203 #ifdef POLARSSL_MD4_C
1204 #ifdef POLARSSL_SELF_TEST
1209 fprintf( stderr,
"\nIncorrect argument count (%d != %d)\n", cnt, 1 );
1214 test_suite_md4_selftest( );
1222 if( strcmp( params[0],
"md5_selftest" ) == 0 )
1224 #ifdef POLARSSL_MD5_C
1225 #ifdef POLARSSL_SELF_TEST
1230 fprintf( stderr,
"\nIncorrect argument count (%d != %d)\n", cnt, 1 );
1235 test_suite_md5_selftest( );
1243 if( strcmp( params[0],
"ripemd160_selftest" ) == 0 )
1245 #ifdef POLARSSL_RIPEMD160_C
1246 #ifdef POLARSSL_SELF_TEST
1251 fprintf( stderr,
"\nIncorrect argument count (%d != %d)\n", cnt, 1 );
1256 test_suite_ripemd160_selftest( );
1266 fprintf( stdout,
"FAILED\nSkipping unknown test function '%s'\n", params[0] );
1280 ret = fgets( buf, len, f );
1284 if( strlen( buf ) && buf[strlen(buf) - 1] ==
'\n' )
1285 buf[strlen(buf) - 1] =
'\0';
1286 if( strlen( buf ) && buf[strlen(buf) - 1] ==
'\r' )
1287 buf[strlen(buf) - 1] =
'\0';
1298 params[cnt++] = cur;
1300 while( *p !=
'\0' && p < buf + len )
1310 if( p + 1 < buf + len )
1313 params[cnt++] = cur;
1322 for( i = 0; i < cnt; i++ )
1329 if( *p ==
'\\' && *(p + 1) ==
'n' )
1334 else if( *p ==
'\\' && *(p + 1) ==
':' )
1339 else if( *p ==
'\\' && *(p + 1) ==
'?' )
1355 int ret, i, cnt, total_errors = 0, total_tests = 0, total_skipped = 0;
1356 const char *filename =
"/root/rpmbuild/BUILD/polarssl-1.3.9/tests/suites/test_suite_mdx.data";
1361 #if defined(POLARSSL_MEMORY_BUFFER_ALLOC_C)
1362 unsigned char alloc_buf[1000000];
1366 file = fopen( filename,
"r" );
1369 fprintf( stderr,
"Failed to open\n" );
1373 while( !feof( file ) )
1377 if( ( ret =
get_line( file, buf,
sizeof(buf) ) ) != 0 )
1379 fprintf( stdout,
"%s%.66s",
test_errors ?
"\n" :
"", buf );
1380 fprintf( stdout,
" " );
1381 for( i = strlen( buf ) + 1; i < 67; i++ )
1382 fprintf( stdout,
"." );
1383 fprintf( stdout,
" " );
1388 if( ( ret =
get_line( file, buf,
sizeof(buf) ) ) != 0 )
1392 if( strcmp( params[0],
"depends_on" ) == 0 )
1394 for( i = 1; i < cnt; i++ )
1398 if( ( ret =
get_line( file, buf,
sizeof(buf) ) ) != 0 )
1409 if( skip == 1 || ret == 3 )
1412 fprintf( stdout,
"----\n" );
1417 fprintf( stdout,
"PASS\n" );
1422 fprintf( stderr,
"FAILED: FATAL PARSE ERROR\n" );
1429 if( ( ret =
get_line( file, buf,
sizeof(buf) ) ) != 0 )
1431 if( strlen(buf) != 0 )
1433 fprintf( stderr,
"Should be empty %d\n", (
int) strlen(buf) );
1439 fprintf( stdout,
"\n----------------------------------------------------------------------------\n\n");
1440 if( total_errors == 0 )
1441 fprintf( stdout,
"PASSED" );
1443 fprintf( stdout,
"FAILED" );
1445 fprintf( stdout,
" (%d / %d tests (%d skipped))\n",
1446 total_tests - total_errors, total_tests, total_skipped );
1448 #if defined(POLARSSL_MEMORY_BUFFER_ALLOC_C)
1449 #if defined(POLARSSL_MEMORY_DEBUG)
1450 memory_buffer_alloc_status();
1455 return( total_errors != 0 );
static int rnd_pseudo_rand(void *rng_state, unsigned char *output, size_t len)
This function returns random based on a pseudo random function.
Memory allocation layer (Deprecated to platform layer)
void ripemd160_hmac_finish(ripemd160_context *ctx, unsigned char output[20])
RIPEMD-160 HMAC final digest.
Info structure for the pseudo random function.
void md2_init(md2_context *ctx)
Initialize MD2 context.
void ripemd160_hmac_starts(ripemd160_context *ctx, const unsigned char *key, size_t keylen)
RIPEMD-160 HMAC context setup.
void md2_hmac_update(md2_context *ctx, const unsigned char *input, size_t ilen)
MD2 HMAC process buffer.
void ripemd160_hmac_reset(ripemd160_context *ctx)
RIPEMD-160 HMAC context reset.
void memory_buffer_alloc_free(void)
Free the mutex for thread-safety and clear remaining memory.
RIPEMD-160 context structure.
int md4_self_test(int verbose)
Checkup routine.
void md4_init(md4_context *ctx)
Initialize MD4 context.
int get_line(FILE *f, char *buf, size_t len)
void md4_hmac(const unsigned char *key, size_t keylen, const unsigned char *input, size_t ilen, unsigned char output[16])
Output = HMAC-MD4( hmac key, input buffer )
Configuration options (set of defines)
void md2(const unsigned char *input, size_t ilen, unsigned char output[16])
Output = MD2( input buffer )
void ripemd160(const unsigned char *input, size_t ilen, unsigned char output[20])
Output = RIPEMD-160( input buffer )
void md5_hmac(const unsigned char *key, size_t keylen, const unsigned char *input, size_t ilen, unsigned char output[16])
Output = HMAC-MD5( hmac key, input buffer )
void ripemd160_init(ripemd160_context *ctx)
Initialize RIPEMD-160 context.
int verify_int(char *str, int *value)
void md4(const unsigned char *input, size_t ilen, unsigned char output[16])
Output = MD4( input buffer )
void md5_free(md5_context *ctx)
Clear MD5 context.
RIPE MD-160 message digest.
int memory_buffer_alloc_init(unsigned char *buf, size_t len)
Initialize use of stack-based memory allocator.
void md2_hmac_finish(md2_context *ctx, unsigned char output[16])
MD2 HMAC final digest.
static int rnd_buffer_rand(void *rng_state, unsigned char *output, size_t len)
This function returns random based on a buffer it receives.
int dispatch_test(int cnt, char *params[50])
int md2_file(const char *path, unsigned char output[16])
Output = MD2( file contents )
int md5_self_test(int verbose)
Checkup routine.
void md2_free(md2_context *ctx)
Clear MD2 context.
int md5_file(const char *path, unsigned char output[16])
Output = MD5( file contents )
void md5_hmac_starts(md5_context *ctx, const unsigned char *key, size_t keylen)
MD5 HMAC context setup.
void md4_hmac_starts(md4_context *ctx, const unsigned char *key, size_t keylen)
MD4 HMAC context setup.
void md4_hmac_finish(md4_context *ctx, unsigned char output[16])
MD4 HMAC final digest.
void md5_hmac_reset(md5_context *ctx)
MD5 HMAC context reset.
int parse_arguments(char *buf, size_t len, char *params[50])
void ripemd160_hmac_update(ripemd160_context *ctx, const unsigned char *input, size_t ilen)
RIPEMD-160 HMAC process buffer.
void md5_hmac_finish(md5_context *ctx, unsigned char output[16])
MD5 HMAC final digest.
static unsigned char * zero_alloc(size_t len)
Allocate and zeroize a buffer.
static int unhexify(unsigned char *obuf, const char *ibuf)
static void hexify(unsigned char *obuf, const unsigned char *ibuf, int len)
int md2_self_test(int verbose)
Checkup routine.
void md5_init(md5_context *ctx)
Initialize MD5 context.
int verify_string(char **str)
void md2_hmac_starts(md2_context *ctx, const unsigned char *key, size_t keylen)
MD2 HMAC context setup.
static int rnd_std_rand(void *rng_state, unsigned char *output, size_t len)
This function just returns data from rand().
void ripemd160_free(ripemd160_context *ctx)
Clear RIPEMD-160 context.
void ripemd160_hmac(const unsigned char *key, size_t keylen, const unsigned char *input, size_t ilen, unsigned char output[20])
Output = HMAC-RIPEMD-160( hmac key, input buffer )
void md2_hmac(const unsigned char *key, size_t keylen, const unsigned char *input, size_t ilen, unsigned char output[16])
Output = HMAC-MD2( hmac key, input buffer )
#define TEST_ASSERT(TEST)
void md4_free(md4_context *ctx)
Clear MD4 context.
void md2_hmac_reset(md2_context *ctx)
MD2 HMAC context reset.
int ripemd160_self_test(int verbose)
Checkup routine.
static int test_assert(int correct, const char *test)
MD4 message digest algorithm (hash function)
void md5_hmac_update(md5_context *ctx, const unsigned char *input, size_t ilen)
MD5 HMAC process buffer.
int md4_file(const char *path, unsigned char output[16])
Output = MD4( file contents )
MD5 message digest algorithm (hash function)
void md5(const unsigned char *input, size_t ilen, unsigned char output[16])
Output = MD5( input buffer )
static int rnd_zero_rand(void *rng_state, unsigned char *output, size_t len)
This function only returns zeros.
#define PUT_UINT32_BE(n, b, i)
MD2 message digest algorithm (hash function)
void md4_hmac_reset(md4_context *ctx)
MD4 HMAC context reset.
void md4_hmac_update(md4_context *ctx, const unsigned char *input, size_t ilen)
MD4 HMAC process buffer.
int ripemd160_file(const char *path, unsigned char output[20])
Output = RIPEMD-160( file contents )
static unsigned char * unhexify_alloc(const char *ibuf, size_t *olen)
Allocate and fill a buffer from hex data.