1 #if !defined(POLARSSL_CONFIG_FILE)
4 #include POLARSSL_CONFIG_FILE
7 #ifdef POLARSSL_CIPHER_C
11 #if defined(POLARSSL_GCM_C)
17 #if defined(POLARSSL_MEMORY_BUFFER_ALLOC_C)
21 #if defined(POLARSSL_PLATFORM_C)
24 #define polarssl_malloc malloc
25 #define polarssl_free free
30 typedef UINT32 uint32_t;
43 #define GET_UINT32_BE(n,b,i) \
45 (n) = ( (uint32_t) (b)[(i) ] << 24 ) \
46 | ( (uint32_t) (b)[(i) + 1] << 16 ) \
47 | ( (uint32_t) (b)[(i) + 2] << 8 ) \
48 | ( (uint32_t) (b)[(i) + 3] ); \
53 #define PUT_UINT32_BE(n,b,i) \
55 (b)[(i) ] = (unsigned char) ( (n) >> 24 ); \
56 (b)[(i) + 1] = (unsigned char) ( (n) >> 16 ); \
57 (b)[(i) + 2] = (unsigned char) ( (n) >> 8 ); \
58 (b)[(i) + 3] = (unsigned char) ( (n) ); \
62 static int unhexify(
unsigned char *obuf,
const char *ibuf)
65 int len = strlen(ibuf) / 2;
66 assert(!(strlen(ibuf) %1));
71 if( c >=
'0' && c <=
'9' )
73 else if( c >=
'a' && c <=
'f' )
75 else if( c >=
'A' && c <=
'F' )
81 if( c2 >=
'0' && c2 <=
'9' )
83 else if( c2 >=
'a' && c2 <=
'f' )
85 else if( c2 >=
'A' && c2 <=
'F' )
90 *obuf++ = ( c << 4 ) | c2;
96 static void hexify(
unsigned char *obuf,
const unsigned char *ibuf,
int len)
108 *obuf++ =
'a' + h - 10;
113 *obuf++ =
'a' + l - 10;
130 size_t actual_len = len != 0 ? len : 1;
135 memset( p, 0x00, actual_len );
154 *olen = strlen(ibuf) / 2;
160 assert( obuf != NULL );
176 static int rnd_std_rand(
void *rng_state,
unsigned char *output,
size_t len )
178 #if !defined(__OpenBSD__)
181 if( rng_state != NULL )
184 for( i = 0; i < len; ++i )
187 if( rng_state != NULL )
190 arc4random_buf( output, len );
201 static int rnd_zero_rand(
void *rng_state,
unsigned char *output,
size_t len )
203 if( rng_state != NULL )
206 memset( output, 0, len );
233 if( rng_state == NULL )
242 memcpy( output, info->
buf, use_len );
243 info->
buf += use_len;
247 if( len - use_len > 0 )
248 return(
rnd_std_rand( NULL, output + use_len, len - use_len ) );
277 uint32_t i, *k, sum, delta=0x9E3779B9;
278 unsigned char result[4], *out = output;
280 if( rng_state == NULL )
287 size_t use_len = ( len > 4 ) ? 4 : len;
290 for( i = 0; i < 32; i++ )
292 info->
v0 += (((info->
v1 << 4) ^ (info->
v1 >> 5)) + info->
v1) ^ (sum + k[sum & 3]);
294 info->
v1 += (((info->
v0 << 4) ^ (info->
v0 >> 5)) + info->
v0) ^ (sum + k[(sum>>11) & 3]);
298 memcpy( out, result, use_len );
310 #if defined(POLARSSL_PLATFORM_C)
313 #define polarssl_printf printf
314 #define polarssl_malloc malloc
315 #define polarssl_free free
320 #ifdef POLARSSL_CIPHER_C
322 #define TEST_SUITE_ACTIVE
324 static int test_assert(
int correct,
const char *test )
331 printf(
"FAILED\n" );
332 printf(
" %s\n", test );
337 #define TEST_ASSERT( TEST ) \
338 do { test_assert( (TEST) ? 1 : 0, #TEST ); \
339 if( test_errors) goto exit; \
344 if( (*str)[0] !=
'"' ||
345 (*str)[strlen( *str ) - 1] !=
'"' )
347 printf(
"Expected string (with \"\") for parameter and got: %s\n", *str );
352 (*str)[strlen( *str ) - 1] =
'\0';
364 for( i = 0; i < strlen( str ); i++ )
366 if( i == 0 && str[i] ==
'-' )
372 if( ( ( minus && i == 2 ) || ( !minus && i == 1 ) ) &&
373 str[i - 1] ==
'0' && str[i] ==
'x' )
379 if( ! ( ( str[i] >=
'0' && str[i] <=
'9' ) ||
380 ( hex && ( ( str[i] >=
'a' && str[i] <=
'f' ) ||
381 ( str[i] >=
'A' && str[i] <=
'F' ) ) ) ) )
391 *value = strtol( str, NULL, 16 );
393 *value = strtol( str, NULL, 10 );
398 if( strcmp( str,
"POLARSSL_CIPHER_AES_128_CFB128" ) == 0 )
403 if( strcmp( str,
"POLARSSL_DECRYPT" ) == 0 )
408 if( strcmp( str,
"-1" ) == 0 )
413 if( strcmp( str,
"POLARSSL_CIPHER_AES_192_CFB128" ) == 0 )
418 if( strcmp( str,
"POLARSSL_CIPHER_AES_192_CBC" ) == 0 )
423 if( strcmp( str,
"POLARSSL_PADDING_NONE" ) == 0 )
428 if( strcmp( str,
"POLARSSL_PADDING_ZEROS" ) == 0 )
433 if( strcmp( str,
"POLARSSL_PADDING_ZEROS_AND_LEN" ) == 0 )
438 if( strcmp( str,
"POLARSSL_CIPHER_AES_128_CTR" ) == 0 )
443 if( strcmp( str,
"POLARSSL_PADDING_PKCS7" ) == 0 )
448 if( strcmp( str,
"POLARSSL_CIPHER_AES_128_CBC" ) == 0 )
453 if( strcmp( str,
"POLARSSL_CIPHER_AES_256_CFB128" ) == 0 )
458 if( strcmp( str,
"POLARSSL_ERR_CIPHER_INVALID_PADDING" ) == 0 )
463 if( strcmp( str,
"POLARSSL_CIPHER_AES_256_ECB" ) == 0 )
468 if( strcmp( str,
"POLARSSL_CIPHER_AES_128_ECB" ) == 0 )
473 if( strcmp( str,
"POLARSSL_ERR_CIPHER_FULL_BLOCK_EXPECTED" ) == 0 )
478 if( strcmp( str,
"POLARSSL_ENCRYPT" ) == 0 )
483 if( strcmp( str,
"POLARSSL_PADDING_ONE_AND_ZEROS" ) == 0 )
488 if( strcmp( str,
"POLARSSL_CIPHER_AES_256_CBC" ) == 0 )
493 if( strcmp( str,
"POLARSSL_CIPHER_AES_192_ECB" ) == 0 )
500 printf(
"Expected integer for parameter and got: %s\n", str );
504 void test_suite_cipher_list( )
506 const int *cipher_type;
508 for( cipher_type =
cipher_list(); *cipher_type != 0; cipher_type++ )
515 void test_suite_cipher_null_args( )
519 unsigned char buf[1] = { 0 };
553 #if defined(POLARSSL_GCM_C)
570 #if defined(POLARSSL_GCM_C)
586 void test_suite_enc_dec_buf(
int cipher_id,
char *cipher_string,
int key_len,
587 int length_val,
int pad_mode )
589 size_t length = length_val, outlen, total_len, i;
590 unsigned char key[32];
591 unsigned char iv[16];
592 unsigned char ad[13];
593 unsigned char tag[16];
594 unsigned char inbuf[64];
595 unsigned char encbuf[64];
596 unsigned char decbuf[64];
608 memset( key, 0x2a,
sizeof( key ) );
622 #if defined(POLARSSL_CIPHER_MODE_WITH_PADDING)
635 for( i = 0; i < 3; i++ )
637 memset( iv , 0x00 + i,
sizeof( iv ) );
638 memset( ad, 0x10 + i,
sizeof( ad ) );
639 memset( inbuf, 0x20 + i,
sizeof( inbuf ) );
641 memset( encbuf, 0,
sizeof( encbuf ) );
642 memset( decbuf, 0,
sizeof( decbuf ) );
643 memset( tag, 0,
sizeof( tag ) );
651 #if defined(POLARSSL_GCM_C)
662 total_len < length &&
668 #if defined(POLARSSL_GCM_C)
674 total_len > length &&
683 total_len < length &&
689 #if defined(POLARSSL_GCM_C)
706 void test_suite_enc_fail(
int cipher_id,
int pad_mode,
int key_len,
707 int length_val,
int ret )
709 size_t length = length_val;
710 unsigned char key[32];
711 unsigned char iv[16];
716 unsigned char inbuf[64];
717 unsigned char encbuf[64];
721 memset( key, 0, 32 );
722 memset( iv , 0, 16 );
726 memset( inbuf, 5, 64 );
727 memset( encbuf, 0, 64 );
736 #if defined(POLARSSL_CIPHER_MODE_WITH_PADDING)
743 #if defined(POLARSSL_GCM_C)
756 void test_suite_dec_empty_buf()
758 unsigned char key[32];
759 unsigned char iv[16];
764 unsigned char encbuf[64];
765 unsigned char decbuf[64];
769 memset( key, 0, 32 );
770 memset( iv , 0, 16 );
774 memset( encbuf, 0, 64 );
775 memset( decbuf, 0, 64 );
789 #if defined(POLARSSL_GCM_C)
797 &ctx_dec, decbuf + outlen, &outlen ) );
804 void test_suite_enc_dec_buf_multipart(
int cipher_id,
int key_len,
int first_length_val,
805 int second_length_val )
807 size_t first_length = first_length_val;
808 size_t second_length = second_length_val;
809 size_t length = first_length + second_length;
810 unsigned char key[32];
811 unsigned char iv[16];
817 unsigned char inbuf[64];
818 unsigned char encbuf[64];
819 unsigned char decbuf[64];
822 size_t totaloutlen = 0;
824 memset( key, 0, 32 );
825 memset( iv , 0, 16 );
830 memset( inbuf, 5, 64 );
831 memset( encbuf, 0, 64 );
832 memset( decbuf, 0, 64 );
850 #if defined(POLARSSL_GCM_C)
857 totaloutlen = outlen;
859 totaloutlen += outlen;
862 totaloutlen < length &&
866 totaloutlen += outlen;
869 totaloutlen > length &&
874 totaloutlen = outlen;
878 totaloutlen < length &&
882 totaloutlen += outlen;
893 void test_suite_decrypt_test_vec(
int cipher_id,
int pad_mode,
894 char *hex_key,
char *hex_iv,
895 char *hex_cipher,
char *hex_clear,
896 char *hex_ad,
char *hex_tag,
897 int finish_result,
int tag_result )
899 unsigned char key[50];
900 unsigned char iv[50];
901 unsigned char cipher[200];
902 unsigned char clear[200];
903 unsigned char ad[200];
904 unsigned char tag[20];
905 size_t key_len, iv_len, cipher_len, clear_len;
906 #if defined(POLARSSL_GCM_C)
907 size_t ad_len, tag_len;
910 unsigned char output[200];
911 size_t outlen, total_len;
915 memset( key, 0x00,
sizeof( key ) );
916 memset( iv, 0x00,
sizeof( iv ) );
917 memset( cipher, 0x00,
sizeof( cipher ) );
918 memset( clear, 0x00,
sizeof( clear ) );
919 memset( ad, 0x00,
sizeof( ad ) );
920 memset( tag, 0x00,
sizeof( tag ) );
921 memset( output, 0x00,
sizeof( output ) );
925 cipher_len =
unhexify( cipher, hex_cipher );
926 clear_len =
unhexify( clear, hex_clear );
927 #if defined(POLARSSL_GCM_C)
939 #if defined(POLARSSL_CIPHER_MODE_WITH_PADDING)
947 #if defined(POLARSSL_GCM_C)
958 #if defined(POLARSSL_GCM_C)
963 if( 0 == finish_result && 0 == tag_result )
966 TEST_ASSERT( 0 == memcmp( output, clear, clear_len ) );
973 #ifdef POLARSSL_CIPHER_MODE_AEAD
974 void test_suite_auth_crypt_tv(
int cipher_id,
char *hex_key,
char *hex_iv,
975 char *hex_ad,
char *hex_cipher,
976 char *hex_tag,
char *hex_clear )
979 unsigned char key[50];
980 unsigned char iv[50];
981 unsigned char cipher[200];
982 unsigned char clear[200];
983 unsigned char ad[200];
984 unsigned char tag[20];
985 unsigned char my_tag[20];
986 size_t key_len, iv_len, cipher_len, clear_len, ad_len, tag_len;
988 unsigned char output[200];
993 memset( key, 0x00,
sizeof( key ) );
994 memset( iv, 0x00,
sizeof( iv ) );
995 memset( cipher, 0x00,
sizeof( cipher ) );
996 memset( clear, 0x00,
sizeof( clear ) );
997 memset( ad, 0x00,
sizeof( ad ) );
998 memset( tag, 0x00,
sizeof( tag ) );
999 memset( my_tag, 0xFF,
sizeof( my_tag ) );
1000 memset( output, 0xFF,
sizeof( output ) );
1002 key_len =
unhexify( key, hex_key );
1004 cipher_len =
unhexify( cipher, hex_cipher );
1006 tag_len =
unhexify( tag, hex_tag );
1015 cipher, cipher_len, output, &outlen,
1023 if( strcmp( hex_clear,
"FAIL" ) == 0 )
1032 clear_len =
unhexify( clear, hex_clear );
1034 TEST_ASSERT( memcmp( output, clear, clear_len ) == 0 );
1037 memset( output, 0xFF,
sizeof( output ) );
1041 clear, clear_len, output, &outlen,
1046 TEST_ASSERT( memcmp( output, cipher, clear_len ) == 0 );
1047 TEST_ASSERT( memcmp( my_tag, tag, tag_len ) == 0 );
1061 void test_suite_test_vec_ecb(
int cipher_id,
int operation,
char *hex_key,
1062 char *hex_input,
char *hex_result,
1065 unsigned char key[50];
1066 unsigned char input[16];
1067 unsigned char result[16];
1070 unsigned char output[32];
1075 memset( key, 0x00,
sizeof( key ) );
1076 memset( input, 0x00,
sizeof( input ) );
1077 memset( result, 0x00,
sizeof( result ) );
1078 memset( output, 0x00,
sizeof( output ) );
1084 key_len =
unhexify( key, hex_key );
1094 output, &outlen ) );
1101 if( 0 == finish_result )
1109 #ifdef POLARSSL_CIPHER_MODE_WITH_PADDING
1110 void test_suite_set_padding(
int cipher_id,
int pad_mode,
int ret )
1128 #ifdef POLARSSL_CIPHER_MODE_CBC
1129 void test_suite_check_padding(
int pad_mode,
char *input_str,
int ret,
int dlen_check )
1133 unsigned char input[16];
1143 ilen =
unhexify( input, input_str );
1154 #ifdef POLARSSL_SELF_TEST
1155 void test_suite_cipher_selftest()
1173 if( strcmp( str,
"POLARSSL_CIPHER_PADDING_ZEROS" ) == 0 )
1175 #if defined(POLARSSL_CIPHER_PADDING_ZEROS)
1181 if( strcmp( str,
"POLARSSL_CIPHER_MODE_CBC" ) == 0 )
1183 #if defined(POLARSSL_CIPHER_MODE_CBC)
1189 if( strcmp( str,
"POLARSSL_CIPHER_PADDING_PKCS7" ) == 0 )
1191 #if defined(POLARSSL_CIPHER_PADDING_PKCS7)
1197 if( strcmp( str,
"POLARSSL_AES_C" ) == 0 )
1199 #if defined(POLARSSL_AES_C)
1205 if( strcmp( str,
"POLARSSL_CIPHER_MODE_CTR" ) == 0 )
1207 #if defined(POLARSSL_CIPHER_MODE_CTR)
1213 if( strcmp( str,
"POLARSSL_CIPHER_PADDING_ONE_AND_ZEROS" ) == 0 )
1215 #if defined(POLARSSL_CIPHER_PADDING_ONE_AND_ZEROS)
1221 if( strcmp( str,
"POLARSSL_CIPHER_MODE_CFB" ) == 0 )
1223 #if defined(POLARSSL_CIPHER_MODE_CFB)
1229 if( strcmp( str,
"POLARSSL_CIPHER_PADDING_ZEROS_AND_LEN" ) == 0 )
1231 #if defined(POLARSSL_CIPHER_PADDING_ZEROS_AND_LEN)
1248 #if defined(TEST_SUITE_ACTIVE)
1249 if( strcmp( params[0],
"cipher_list" ) == 0 )
1255 fprintf( stderr,
"\nIncorrect argument count (%d != %d)\n", cnt, 1 );
1260 test_suite_cipher_list( );
1266 if( strcmp( params[0],
"cipher_null_args" ) == 0 )
1272 fprintf( stderr,
"\nIncorrect argument count (%d != %d)\n", cnt, 1 );
1277 test_suite_cipher_null_args( );
1283 if( strcmp( params[0],
"enc_dec_buf" ) == 0 )
1287 char *param2 = params[2];
1294 fprintf( stderr,
"\nIncorrect argument count (%d != %d)\n", cnt, 6 );
1298 if(
verify_int( params[1], ¶m1 ) != 0 )
return( 2 );
1300 if(
verify_int( params[3], ¶m3 ) != 0 )
return( 2 );
1301 if(
verify_int( params[4], ¶m4 ) != 0 )
return( 2 );
1302 if(
verify_int( params[5], ¶m5 ) != 0 )
return( 2 );
1304 test_suite_enc_dec_buf( param1, param2, param3, param4, param5 );
1310 if( strcmp( params[0],
"enc_fail" ) == 0 )
1321 fprintf( stderr,
"\nIncorrect argument count (%d != %d)\n", cnt, 6 );
1325 if(
verify_int( params[1], ¶m1 ) != 0 )
return( 2 );
1326 if(
verify_int( params[2], ¶m2 ) != 0 )
return( 2 );
1327 if(
verify_int( params[3], ¶m3 ) != 0 )
return( 2 );
1328 if(
verify_int( params[4], ¶m4 ) != 0 )
return( 2 );
1329 if(
verify_int( params[5], ¶m5 ) != 0 )
return( 2 );
1331 test_suite_enc_fail( param1, param2, param3, param4, param5 );
1337 if( strcmp( params[0],
"dec_empty_buf" ) == 0 )
1343 fprintf( stderr,
"\nIncorrect argument count (%d != %d)\n", cnt, 1 );
1348 test_suite_dec_empty_buf( );
1354 if( strcmp( params[0],
"enc_dec_buf_multipart" ) == 0 )
1364 fprintf( stderr,
"\nIncorrect argument count (%d != %d)\n", cnt, 5 );
1368 if(
verify_int( params[1], ¶m1 ) != 0 )
return( 2 );
1369 if(
verify_int( params[2], ¶m2 ) != 0 )
return( 2 );
1370 if(
verify_int( params[3], ¶m3 ) != 0 )
return( 2 );
1371 if(
verify_int( params[4], ¶m4 ) != 0 )
return( 2 );
1373 test_suite_enc_dec_buf_multipart( param1, param2, param3, param4 );
1379 if( strcmp( params[0],
"decrypt_test_vec" ) == 0 )
1384 char *param3 = params[3];
1385 char *param4 = params[4];
1386 char *param5 = params[5];
1387 char *param6 = params[6];
1388 char *param7 = params[7];
1389 char *param8 = params[8];
1395 fprintf( stderr,
"\nIncorrect argument count (%d != %d)\n", cnt, 11 );
1399 if(
verify_int( params[1], ¶m1 ) != 0 )
return( 2 );
1400 if(
verify_int( params[2], ¶m2 ) != 0 )
return( 2 );
1407 if(
verify_int( params[9], ¶m9 ) != 0 )
return( 2 );
1408 if(
verify_int( params[10], ¶m10 ) != 0 )
return( 2 );
1410 test_suite_decrypt_test_vec( param1, param2, param3, param4, param5, param6, param7, param8, param9, param10 );
1416 if( strcmp( params[0],
"auth_crypt_tv" ) == 0 )
1418 #ifdef POLARSSL_CIPHER_MODE_AEAD
1421 char *param2 = params[2];
1422 char *param3 = params[3];
1423 char *param4 = params[4];
1424 char *param5 = params[5];
1425 char *param6 = params[6];
1426 char *param7 = params[7];
1430 fprintf( stderr,
"\nIncorrect argument count (%d != %d)\n", cnt, 8 );
1434 if(
verify_int( params[1], ¶m1 ) != 0 )
return( 2 );
1442 test_suite_auth_crypt_tv( param1, param2, param3, param4, param5, param6, param7 );
1449 if( strcmp( params[0],
"test_vec_ecb" ) == 0 )
1454 char *param3 = params[3];
1455 char *param4 = params[4];
1456 char *param5 = params[5];
1461 fprintf( stderr,
"\nIncorrect argument count (%d != %d)\n", cnt, 7 );
1465 if(
verify_int( params[1], ¶m1 ) != 0 )
return( 2 );
1466 if(
verify_int( params[2], ¶m2 ) != 0 )
return( 2 );
1470 if(
verify_int( params[6], ¶m6 ) != 0 )
return( 2 );
1472 test_suite_test_vec_ecb( param1, param2, param3, param4, param5, param6 );
1478 if( strcmp( params[0],
"set_padding" ) == 0 )
1480 #ifdef POLARSSL_CIPHER_MODE_WITH_PADDING
1488 fprintf( stderr,
"\nIncorrect argument count (%d != %d)\n", cnt, 4 );
1492 if(
verify_int( params[1], ¶m1 ) != 0 )
return( 2 );
1493 if(
verify_int( params[2], ¶m2 ) != 0 )
return( 2 );
1494 if(
verify_int( params[3], ¶m3 ) != 0 )
return( 2 );
1496 test_suite_set_padding( param1, param2, param3 );
1503 if( strcmp( params[0],
"check_padding" ) == 0 )
1505 #ifdef POLARSSL_CIPHER_MODE_CBC
1508 char *param2 = params[2];
1514 fprintf( stderr,
"\nIncorrect argument count (%d != %d)\n", cnt, 5 );
1518 if(
verify_int( params[1], ¶m1 ) != 0 )
return( 2 );
1520 if(
verify_int( params[3], ¶m3 ) != 0 )
return( 2 );
1521 if(
verify_int( params[4], ¶m4 ) != 0 )
return( 2 );
1523 test_suite_check_padding( param1, param2, param3, param4 );
1530 if( strcmp( params[0],
"cipher_selftest" ) == 0 )
1532 #ifdef POLARSSL_SELF_TEST
1537 fprintf( stderr,
"\nIncorrect argument count (%d != %d)\n", cnt, 1 );
1542 test_suite_cipher_selftest( );
1551 fprintf( stdout,
"FAILED\nSkipping unknown test function '%s'\n", params[0] );
1565 ret = fgets( buf, len, f );
1569 if( strlen( buf ) && buf[strlen(buf) - 1] ==
'\n' )
1570 buf[strlen(buf) - 1] =
'\0';
1571 if( strlen( buf ) && buf[strlen(buf) - 1] ==
'\r' )
1572 buf[strlen(buf) - 1] =
'\0';
1583 params[cnt++] = cur;
1585 while( *p !=
'\0' && p < buf + len )
1595 if( p + 1 < buf + len )
1598 params[cnt++] = cur;
1607 for( i = 0; i < cnt; i++ )
1614 if( *p ==
'\\' && *(p + 1) ==
'n' )
1619 else if( *p ==
'\\' && *(p + 1) ==
':' )
1624 else if( *p ==
'\\' && *(p + 1) ==
'?' )
1640 int ret, i, cnt, total_errors = 0, total_tests = 0, total_skipped = 0;
1641 const char *filename =
"/builddir/build/BUILD/polarssl-1.3.9/tests/suites/test_suite_cipher.aes.data";
1646 #if defined(POLARSSL_MEMORY_BUFFER_ALLOC_C)
1647 unsigned char alloc_buf[1000000];
1651 file = fopen( filename,
"r" );
1654 fprintf( stderr,
"Failed to open\n" );
1658 while( !feof( file ) )
1662 if( ( ret =
get_line( file, buf,
sizeof(buf) ) ) != 0 )
1664 fprintf( stdout,
"%s%.66s",
test_errors ?
"\n" :
"", buf );
1665 fprintf( stdout,
" " );
1666 for( i = strlen( buf ) + 1; i < 67; i++ )
1667 fprintf( stdout,
"." );
1668 fprintf( stdout,
" " );
1673 if( ( ret =
get_line( file, buf,
sizeof(buf) ) ) != 0 )
1677 if( strcmp( params[0],
"depends_on" ) == 0 )
1679 for( i = 1; i < cnt; i++ )
1683 if( ( ret =
get_line( file, buf,
sizeof(buf) ) ) != 0 )
1694 if( skip == 1 || ret == 3 )
1697 fprintf( stdout,
"----\n" );
1702 fprintf( stdout,
"PASS\n" );
1707 fprintf( stderr,
"FAILED: FATAL PARSE ERROR\n" );
1714 if( ( ret =
get_line( file, buf,
sizeof(buf) ) ) != 0 )
1716 if( strlen(buf) != 0 )
1718 fprintf( stderr,
"Should be empty %d\n", (
int) strlen(buf) );
1724 fprintf( stdout,
"\n----------------------------------------------------------------------------\n\n");
1725 if( total_errors == 0 )
1726 fprintf( stdout,
"PASSED" );
1728 fprintf( stdout,
"FAILED" );
1730 fprintf( stdout,
" (%d / %d tests (%d skipped))\n",
1731 total_tests - total_errors, total_tests, total_skipped );
1733 #if defined(POLARSSL_MEMORY_BUFFER_ALLOC_C)
1734 #if defined(POLARSSL_MEMORY_DEBUG)
1735 memory_buffer_alloc_status();
1740 return( total_errors != 0 );
static int rnd_zero_rand(void *rng_state, unsigned char *output, size_t len)
This function only returns zeros.
#define POLARSSL_ERR_CIPHER_BAD_INPUT_DATA
Bad input parameters to function.
int cipher_finish(cipher_context_t *ctx, unsigned char *output, size_t *olen)
Generic cipher finalisation function.
Memory allocation layer (Deprecated to platform layer)
static int cipher_get_iv_size(const cipher_context_t *ctx)
Returns the size of the cipher's IV/NONCE in bytes.
Info structure for the pseudo random function.
void cipher_init(cipher_context_t *ctx)
Initialize a cipher_context (as NONE)
void memory_buffer_alloc_free(void)
Free the mutex for thread-safety and clear remaining memory.
static cipher_mode_t cipher_get_cipher_mode(const cipher_context_t *ctx)
Returns the mode of operation for the cipher.
int cipher_write_tag(cipher_context_t *ctx, unsigned char *tag, size_t tag_len)
Write tag for AEAD ciphers.
zero padding (not reversible!)
const cipher_info_t * cipher_info_from_type(const cipher_type_t cipher_type)
Returns the cipher information structure associated with the given cipher type.
static unsigned int cipher_get_block_size(const cipher_context_t *ctx)
Returns the block size of the given cipher.
const cipher_info_t * cipher_info_from_string(const char *cipher_name)
Returns the cipher information structure associated with the given cipher name.
static unsigned char * unhexify_alloc(const char *ibuf, size_t *olen)
Allocate and fill a buffer from hex data.
int(* get_padding)(unsigned char *input, size_t ilen, size_t *data_len)
static int unhexify(unsigned char *obuf, const char *ibuf)
Configuration options (set of defines)
static unsigned char * zero_alloc(size_t len)
Allocate and zeroize a buffer.
#define POLARSSL_ERR_CIPHER_INVALID_PADDING
Input data contains invalid padding and is rejected.
static int test_assert(int correct, const char *test)
int parse_arguments(char *buf, size_t len, char *params[50])
int memory_buffer_alloc_init(unsigned char *buf, size_t len)
Initialize use of stack-based memory allocator.
const cipher_info_t * cipher_info
Information about the associated cipher.
#define TEST_ASSERT(TEST)
int cipher_update_ad(cipher_context_t *ctx, const unsigned char *ad, size_t ad_len)
Add additional data (for AEAD ciphers).
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 cipher_set_iv(cipher_context_t *ctx, const unsigned char *iv, size_t iv_len)
Set the initialization vector (IV) or nonce.
int cipher_auth_encrypt(cipher_context_t *ctx, const unsigned char *iv, size_t iv_len, const unsigned char *ad, size_t ad_len, const unsigned char *input, size_t ilen, unsigned char *output, size_t *olen, unsigned char *tag, size_t tag_len)
Generic autenticated encryption (AEAD ciphers).
int cipher_update(cipher_context_t *ctx, const unsigned char *input, size_t ilen, unsigned char *output, size_t *olen)
Generic cipher update function.
int cipher_auth_decrypt(cipher_context_t *ctx, const unsigned char *iv, size_t iv_len, const unsigned char *ad, size_t ad_len, const unsigned char *input, size_t ilen, unsigned char *output, size_t *olen, const unsigned char *tag, size_t tag_len)
Generic autenticated decryption (AEAD ciphers).
#define POLARSSL_ERR_CIPHER_FULL_BLOCK_EXPECTED
Decryption of block requires a full block.
static void hexify(unsigned char *obuf, const unsigned char *ibuf, int len)
int cipher_reset(cipher_context_t *ctx)
Finish preparation of the given context.
void cipher_free(cipher_context_t *ctx)
Free and clear the cipher-specific context of ctx.
int cipher_set_padding_mode(cipher_context_t *ctx, cipher_padding_t mode)
Set padding mode, for cipher modes that use padding.
cipher_mode_t mode
Cipher mode (e.g.
int cipher_init_ctx(cipher_context_t *ctx, const cipher_info_t *cipher_info)
Initialises and fills the cipher context structure with the appropriate values.
int cipher_setkey(cipher_context_t *ctx, const unsigned char *key, int key_length, const operation_t operation)
Set the key to use with the given context.
int verify_string(char **str)
static int rnd_std_rand(void *rng_state, unsigned char *output, size_t len)
This function just returns data from rand().
never pad (full blocks only)
int get_line(FILE *f, char *buf, size_t len)
Galois/Counter mode for 128-bit block ciphers.
const int * cipher_list(void)
Returns the list of ciphers supported by the generic cipher module.
#define PUT_UINT32_BE(n, b, i)
int verify_int(char *str, int *value)
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 cipher_self_test(int verbose)
Checkup routine.
int dispatch_test(int cnt, char *params[50])
int cipher_check_tag(cipher_context_t *ctx, const unsigned char *tag, size_t tag_len)
Check tag for AEAD ciphers.
#define POLARSSL_ERR_CIPHER_AUTH_FAILED
Authentication failed (for AEAD modes).