8 typedef UINT32 uint32_t;
17 #define GET_UINT32_BE(n,b,i) \
19 (n) = ( (uint32_t) (b)[(i) ] << 24 ) \
20 | ( (uint32_t) (b)[(i) + 1] << 16 ) \
21 | ( (uint32_t) (b)[(i) + 2] << 8 ) \
22 | ( (uint32_t) (b)[(i) + 3] ); \
27 #define PUT_UINT32_BE(n,b,i) \
29 (b)[(i) ] = (unsigned char) ( (n) >> 24 ); \
30 (b)[(i) + 1] = (unsigned char) ( (n) >> 16 ); \
31 (b)[(i) + 2] = (unsigned char) ( (n) >> 8 ); \
32 (b)[(i) + 3] = (unsigned char) ( (n) ); \
36 int unhexify(
unsigned char *obuf,
const char *ibuf)
39 int len = strlen(ibuf) / 2;
40 assert(!(strlen(ibuf) %1));
45 if( c >=
'0' && c <=
'9' )
47 else if( c >=
'a' && c <=
'f' )
49 else if( c >=
'A' && c <=
'F' )
55 if( c2 >=
'0' && c2 <=
'9' )
57 else if( c2 >=
'a' && c2 <=
'f' )
59 else if( c2 >=
'A' && c2 <=
'F' )
64 *obuf++ = ( c << 4 ) | c2;
70 void hexify(
unsigned char *obuf,
const unsigned char *ibuf,
int len)
82 *obuf++ =
'a' + h - 10;
87 *obuf++ =
'a' + l - 10;
103 static int rnd_std_rand(
void *rng_state,
unsigned char *output,
size_t len )
107 if( rng_state != NULL )
110 for( i = 0; i < len; ++i )
121 static int rnd_zero_rand(
void *rng_state,
unsigned char *output,
size_t len )
123 if( rng_state != NULL )
126 memset( output, 0, len );
153 if( rng_state == NULL )
162 memcpy( output, info->
buf, use_len );
163 info->
buf += use_len;
167 if( len - use_len > 0 )
168 return(
rnd_std_rand( NULL, output + use_len, len - use_len ) );
197 uint32_t i, *k, sum, delta=0x9E3779B9;
198 unsigned char result[4];
200 if( rng_state == NULL )
207 size_t use_len = ( len > 4 ) ? 4 : len;
210 for( i = 0; i < 32; i++ )
212 info->
v0 += (((info->
v1 << 4) ^ (info->
v1 >> 5)) + info->
v1) ^ (sum + k[sum & 3]);
214 info->
v1 += (((info->
v0 << 4) ^ (info->
v0 >> 5)) + info->
v0) ^ (sum + k[(sum>>11) & 3]);
218 memcpy( output, result, use_len );
228 #ifdef POLARSSL_CIPHER_C
231 FCT_SUITE_BGN(test_suite_cipher)
233 #ifdef POLARSSL_SELF_TEST
235 FCT_TEST_BGN(cipher_selftest)
243 FCT_TEST_BGN(decrypt_empty_buffer)
244 unsigned char key[32];
245 unsigned char iv[16];
250 unsigned char encbuf[64];
251 unsigned char decbuf[64];
255 memset( key, 0, 32 );
256 memset( iv , 0, 16 );
258 memset( &ctx_dec, 0,
sizeof( ctx_dec ) );
260 memset( encbuf, 0, 64 );
261 memset( decbuf, 0, 64 );
265 fct_chk( NULL != cipher_info);
274 fct_chk( 0 ==
cipher_update( &ctx_dec, encbuf, 0, decbuf, &outlen ) );
275 fct_chk( 0 == outlen );
277 fct_chk( 0 == outlen );
282 #ifdef POLARSSL_CIPHER_NULL_CIPHER
284 FCT_TEST_BGN(null_encrypt_and_decrypt_0_bytes)
286 unsigned char key[32];
287 unsigned char iv[16];
293 unsigned char inbuf[64];
294 unsigned char encbuf[64];
295 unsigned char decbuf[64];
300 memset( key, 0, 32 );
301 memset( iv , 0, 16 );
303 memset( &ctx_dec, 0,
sizeof( ctx_dec ) );
304 memset( &ctx_enc, 0,
sizeof( ctx_enc ) );
306 memset( inbuf, 5, 64 );
307 memset( encbuf, 0, 64 );
308 memset( decbuf, 0, 64 );
312 fct_chk( NULL != cipher_info );
336 fct_chk( 0 ==
cipher_update( &ctx_enc, inbuf, length, encbuf, &outlen ) );
343 fct_chk( outlen == enclen );
346 fct_chk( 0 ==
cipher_finish( &ctx_enc, encbuf + outlen, &outlen ) );
353 fct_chk( outlen == 0 );
358 fct_chk( 0 ==
cipher_update( &ctx_dec, encbuf, enclen, decbuf, &outlen ) );
365 fct_chk( enclen == outlen );
368 fct_chk( 0 ==
cipher_finish( &ctx_dec, decbuf + outlen, &outlen ) );
375 fct_chk( outlen == 0 );
379 fct_chk( 0 == memcmp(inbuf, decbuf, length) );
386 #ifdef POLARSSL_CIPHER_NULL_CIPHER
388 FCT_TEST_BGN(null_encrypt_and_decrypt_1_bytes)
390 unsigned char key[32];
391 unsigned char iv[16];
397 unsigned char inbuf[64];
398 unsigned char encbuf[64];
399 unsigned char decbuf[64];
404 memset( key, 0, 32 );
405 memset( iv , 0, 16 );
407 memset( &ctx_dec, 0,
sizeof( ctx_dec ) );
408 memset( &ctx_enc, 0,
sizeof( ctx_enc ) );
410 memset( inbuf, 5, 64 );
411 memset( encbuf, 0, 64 );
412 memset( decbuf, 0, 64 );
416 fct_chk( NULL != cipher_info );
440 fct_chk( 0 ==
cipher_update( &ctx_enc, inbuf, length, encbuf, &outlen ) );
447 fct_chk( outlen == enclen );
450 fct_chk( 0 ==
cipher_finish( &ctx_enc, encbuf + outlen, &outlen ) );
457 fct_chk( outlen == 0 );
462 fct_chk( 0 ==
cipher_update( &ctx_dec, encbuf, enclen, decbuf, &outlen ) );
469 fct_chk( enclen == outlen );
472 fct_chk( 0 ==
cipher_finish( &ctx_dec, decbuf + outlen, &outlen ) );
479 fct_chk( outlen == 0 );
483 fct_chk( 0 == memcmp(inbuf, decbuf, length) );
490 #ifdef POLARSSL_CIPHER_NULL_CIPHER
492 FCT_TEST_BGN(null_encrypt_and_decrypt_2_bytes)
494 unsigned char key[32];
495 unsigned char iv[16];
501 unsigned char inbuf[64];
502 unsigned char encbuf[64];
503 unsigned char decbuf[64];
508 memset( key, 0, 32 );
509 memset( iv , 0, 16 );
511 memset( &ctx_dec, 0,
sizeof( ctx_dec ) );
512 memset( &ctx_enc, 0,
sizeof( ctx_enc ) );
514 memset( inbuf, 5, 64 );
515 memset( encbuf, 0, 64 );
516 memset( decbuf, 0, 64 );
520 fct_chk( NULL != cipher_info );
544 fct_chk( 0 ==
cipher_update( &ctx_enc, inbuf, length, encbuf, &outlen ) );
551 fct_chk( outlen == enclen );
554 fct_chk( 0 ==
cipher_finish( &ctx_enc, encbuf + outlen, &outlen ) );
561 fct_chk( outlen == 0 );
566 fct_chk( 0 ==
cipher_update( &ctx_dec, encbuf, enclen, decbuf, &outlen ) );
573 fct_chk( enclen == outlen );
576 fct_chk( 0 ==
cipher_finish( &ctx_dec, decbuf + outlen, &outlen ) );
583 fct_chk( outlen == 0 );
587 fct_chk( 0 == memcmp(inbuf, decbuf, length) );
594 #ifdef POLARSSL_CIPHER_NULL_CIPHER
596 FCT_TEST_BGN(null_encrypt_and_decrypt_7_bytes)
598 unsigned char key[32];
599 unsigned char iv[16];
605 unsigned char inbuf[64];
606 unsigned char encbuf[64];
607 unsigned char decbuf[64];
612 memset( key, 0, 32 );
613 memset( iv , 0, 16 );
615 memset( &ctx_dec, 0,
sizeof( ctx_dec ) );
616 memset( &ctx_enc, 0,
sizeof( ctx_enc ) );
618 memset( inbuf, 5, 64 );
619 memset( encbuf, 0, 64 );
620 memset( decbuf, 0, 64 );
624 fct_chk( NULL != cipher_info );
648 fct_chk( 0 ==
cipher_update( &ctx_enc, inbuf, length, encbuf, &outlen ) );
655 fct_chk( outlen == enclen );
658 fct_chk( 0 ==
cipher_finish( &ctx_enc, encbuf + outlen, &outlen ) );
665 fct_chk( outlen == 0 );
670 fct_chk( 0 ==
cipher_update( &ctx_dec, encbuf, enclen, decbuf, &outlen ) );
677 fct_chk( enclen == outlen );
680 fct_chk( 0 ==
cipher_finish( &ctx_dec, decbuf + outlen, &outlen ) );
687 fct_chk( outlen == 0 );
691 fct_chk( 0 == memcmp(inbuf, decbuf, length) );
698 #ifdef POLARSSL_CIPHER_NULL_CIPHER
700 FCT_TEST_BGN(null_encrypt_and_decrypt_8_bytes)
702 unsigned char key[32];
703 unsigned char iv[16];
709 unsigned char inbuf[64];
710 unsigned char encbuf[64];
711 unsigned char decbuf[64];
716 memset( key, 0, 32 );
717 memset( iv , 0, 16 );
719 memset( &ctx_dec, 0,
sizeof( ctx_dec ) );
720 memset( &ctx_enc, 0,
sizeof( ctx_enc ) );
722 memset( inbuf, 5, 64 );
723 memset( encbuf, 0, 64 );
724 memset( decbuf, 0, 64 );
728 fct_chk( NULL != cipher_info );
752 fct_chk( 0 ==
cipher_update( &ctx_enc, inbuf, length, encbuf, &outlen ) );
759 fct_chk( outlen == enclen );
762 fct_chk( 0 ==
cipher_finish( &ctx_enc, encbuf + outlen, &outlen ) );
769 fct_chk( outlen == 0 );
774 fct_chk( 0 ==
cipher_update( &ctx_dec, encbuf, enclen, decbuf, &outlen ) );
781 fct_chk( enclen == outlen );
784 fct_chk( 0 ==
cipher_finish( &ctx_dec, decbuf + outlen, &outlen ) );
791 fct_chk( outlen == 0 );
795 fct_chk( 0 == memcmp(inbuf, decbuf, length) );
802 #ifdef POLARSSL_CIPHER_NULL_CIPHER
804 FCT_TEST_BGN(null_encrypt_and_decrypt_9_bytes)
806 unsigned char key[32];
807 unsigned char iv[16];
813 unsigned char inbuf[64];
814 unsigned char encbuf[64];
815 unsigned char decbuf[64];
820 memset( key, 0, 32 );
821 memset( iv , 0, 16 );
823 memset( &ctx_dec, 0,
sizeof( ctx_dec ) );
824 memset( &ctx_enc, 0,
sizeof( ctx_enc ) );
826 memset( inbuf, 5, 64 );
827 memset( encbuf, 0, 64 );
828 memset( decbuf, 0, 64 );
832 fct_chk( NULL != cipher_info );
856 fct_chk( 0 ==
cipher_update( &ctx_enc, inbuf, length, encbuf, &outlen ) );
863 fct_chk( outlen == enclen );
866 fct_chk( 0 ==
cipher_finish( &ctx_enc, encbuf + outlen, &outlen ) );
873 fct_chk( outlen == 0 );
878 fct_chk( 0 ==
cipher_update( &ctx_dec, encbuf, enclen, decbuf, &outlen ) );
885 fct_chk( enclen == outlen );
888 fct_chk( 0 ==
cipher_finish( &ctx_dec, decbuf + outlen, &outlen ) );
895 fct_chk( outlen == 0 );
899 fct_chk( 0 == memcmp(inbuf, decbuf, length) );
906 #ifdef POLARSSL_CIPHER_NULL_CIPHER
908 FCT_TEST_BGN(null_encrypt_and_decrypt_15_bytes)
910 unsigned char key[32];
911 unsigned char iv[16];
917 unsigned char inbuf[64];
918 unsigned char encbuf[64];
919 unsigned char decbuf[64];
924 memset( key, 0, 32 );
925 memset( iv , 0, 16 );
927 memset( &ctx_dec, 0,
sizeof( ctx_dec ) );
928 memset( &ctx_enc, 0,
sizeof( ctx_enc ) );
930 memset( inbuf, 5, 64 );
931 memset( encbuf, 0, 64 );
932 memset( decbuf, 0, 64 );
936 fct_chk( NULL != cipher_info );
960 fct_chk( 0 ==
cipher_update( &ctx_enc, inbuf, length, encbuf, &outlen ) );
967 fct_chk( outlen == enclen );
970 fct_chk( 0 ==
cipher_finish( &ctx_enc, encbuf + outlen, &outlen ) );
977 fct_chk( outlen == 0 );
982 fct_chk( 0 ==
cipher_update( &ctx_dec, encbuf, enclen, decbuf, &outlen ) );
989 fct_chk( enclen == outlen );
992 fct_chk( 0 ==
cipher_finish( &ctx_dec, decbuf + outlen, &outlen ) );
999 fct_chk( outlen == 0 );
1003 fct_chk( 0 == memcmp(inbuf, decbuf, length) );
1010 #ifdef POLARSSL_CIPHER_NULL_CIPHER
1012 FCT_TEST_BGN(null_encrypt_and_decrypt_16_bytes)
1014 unsigned char key[32];
1015 unsigned char iv[16];
1021 unsigned char inbuf[64];
1022 unsigned char encbuf[64];
1023 unsigned char decbuf[64];
1028 memset( key, 0, 32 );
1029 memset( iv , 0, 16 );
1031 memset( &ctx_dec, 0,
sizeof( ctx_dec ) );
1032 memset( &ctx_enc, 0,
sizeof( ctx_enc ) );
1034 memset( inbuf, 5, 64 );
1035 memset( encbuf, 0, 64 );
1036 memset( decbuf, 0, 64 );
1040 fct_chk( NULL != cipher_info );
1064 fct_chk( 0 ==
cipher_update( &ctx_enc, inbuf, length, encbuf, &outlen ) );
1071 fct_chk( outlen == enclen );
1074 fct_chk( 0 ==
cipher_finish( &ctx_enc, encbuf + outlen, &outlen ) );
1081 fct_chk( outlen == 0 );
1086 fct_chk( 0 ==
cipher_update( &ctx_dec, encbuf, enclen, decbuf, &outlen ) );
1093 fct_chk( enclen == outlen );
1096 fct_chk( 0 ==
cipher_finish( &ctx_dec, decbuf + outlen, &outlen ) );
1103 fct_chk( outlen == 0 );
1107 fct_chk( 0 == memcmp(inbuf, decbuf, length) );
1114 #ifdef POLARSSL_CIPHER_NULL_CIPHER
1116 FCT_TEST_BGN(null_encrypt_and_decrypt_31_bytes)
1118 unsigned char key[32];
1119 unsigned char iv[16];
1125 unsigned char inbuf[64];
1126 unsigned char encbuf[64];
1127 unsigned char decbuf[64];
1132 memset( key, 0, 32 );
1133 memset( iv , 0, 16 );
1135 memset( &ctx_dec, 0,
sizeof( ctx_dec ) );
1136 memset( &ctx_enc, 0,
sizeof( ctx_enc ) );
1138 memset( inbuf, 5, 64 );
1139 memset( encbuf, 0, 64 );
1140 memset( decbuf, 0, 64 );
1144 fct_chk( NULL != cipher_info );
1168 fct_chk( 0 ==
cipher_update( &ctx_enc, inbuf, length, encbuf, &outlen ) );
1175 fct_chk( outlen == enclen );
1178 fct_chk( 0 ==
cipher_finish( &ctx_enc, encbuf + outlen, &outlen ) );
1185 fct_chk( outlen == 0 );
1190 fct_chk( 0 ==
cipher_update( &ctx_dec, encbuf, enclen, decbuf, &outlen ) );
1197 fct_chk( enclen == outlen );
1200 fct_chk( 0 ==
cipher_finish( &ctx_dec, decbuf + outlen, &outlen ) );
1207 fct_chk( outlen == 0 );
1211 fct_chk( 0 == memcmp(inbuf, decbuf, length) );
1218 #ifdef POLARSSL_CIPHER_NULL_CIPHER
1220 FCT_TEST_BGN(null_encrypt_and_decrypt_32_bytes)
1222 unsigned char key[32];
1223 unsigned char iv[16];
1229 unsigned char inbuf[64];
1230 unsigned char encbuf[64];
1231 unsigned char decbuf[64];
1236 memset( key, 0, 32 );
1237 memset( iv , 0, 16 );
1239 memset( &ctx_dec, 0,
sizeof( ctx_dec ) );
1240 memset( &ctx_enc, 0,
sizeof( ctx_enc ) );
1242 memset( inbuf, 5, 64 );
1243 memset( encbuf, 0, 64 );
1244 memset( decbuf, 0, 64 );
1248 fct_chk( NULL != cipher_info );
1272 fct_chk( 0 ==
cipher_update( &ctx_enc, inbuf, length, encbuf, &outlen ) );
1279 fct_chk( outlen == enclen );
1282 fct_chk( 0 ==
cipher_finish( &ctx_enc, encbuf + outlen, &outlen ) );
1289 fct_chk( outlen == 0 );
1294 fct_chk( 0 ==
cipher_update( &ctx_dec, encbuf, enclen, decbuf, &outlen ) );
1301 fct_chk( enclen == outlen );
1304 fct_chk( 0 ==
cipher_finish( &ctx_dec, decbuf + outlen, &outlen ) );
1311 fct_chk( outlen == 0 );
1315 fct_chk( 0 == memcmp(inbuf, decbuf, length) );
1322 #ifdef POLARSSL_CIPHER_NULL_CIPHER
1324 FCT_TEST_BGN(null_encrypt_and_decrypt_33_bytes)
1326 unsigned char key[32];
1327 unsigned char iv[16];
1333 unsigned char inbuf[64];
1334 unsigned char encbuf[64];
1335 unsigned char decbuf[64];
1340 memset( key, 0, 32 );
1341 memset( iv , 0, 16 );
1343 memset( &ctx_dec, 0,
sizeof( ctx_dec ) );
1344 memset( &ctx_enc, 0,
sizeof( ctx_enc ) );
1346 memset( inbuf, 5, 64 );
1347 memset( encbuf, 0, 64 );
1348 memset( decbuf, 0, 64 );
1352 fct_chk( NULL != cipher_info );
1376 fct_chk( 0 ==
cipher_update( &ctx_enc, inbuf, length, encbuf, &outlen ) );
1383 fct_chk( outlen == enclen );
1386 fct_chk( 0 ==
cipher_finish( &ctx_enc, encbuf + outlen, &outlen ) );
1393 fct_chk( outlen == 0 );
1398 fct_chk( 0 ==
cipher_update( &ctx_dec, encbuf, enclen, decbuf, &outlen ) );
1405 fct_chk( enclen == outlen );
1408 fct_chk( 0 ==
cipher_finish( &ctx_dec, decbuf + outlen, &outlen ) );
1415 fct_chk( outlen == 0 );
1419 fct_chk( 0 == memcmp(inbuf, decbuf, length) );
1426 #ifdef POLARSSL_CIPHER_NULL_CIPHER
1428 FCT_TEST_BGN(null_encrypt_and_decrypt_47_bytes)
1430 unsigned char key[32];
1431 unsigned char iv[16];
1437 unsigned char inbuf[64];
1438 unsigned char encbuf[64];
1439 unsigned char decbuf[64];
1444 memset( key, 0, 32 );
1445 memset( iv , 0, 16 );
1447 memset( &ctx_dec, 0,
sizeof( ctx_dec ) );
1448 memset( &ctx_enc, 0,
sizeof( ctx_enc ) );
1450 memset( inbuf, 5, 64 );
1451 memset( encbuf, 0, 64 );
1452 memset( decbuf, 0, 64 );
1456 fct_chk( NULL != cipher_info );
1480 fct_chk( 0 ==
cipher_update( &ctx_enc, inbuf, length, encbuf, &outlen ) );
1487 fct_chk( outlen == enclen );
1490 fct_chk( 0 ==
cipher_finish( &ctx_enc, encbuf + outlen, &outlen ) );
1497 fct_chk( outlen == 0 );
1502 fct_chk( 0 ==
cipher_update( &ctx_dec, encbuf, enclen, decbuf, &outlen ) );
1509 fct_chk( enclen == outlen );
1512 fct_chk( 0 ==
cipher_finish( &ctx_dec, decbuf + outlen, &outlen ) );
1519 fct_chk( outlen == 0 );
1523 fct_chk( 0 == memcmp(inbuf, decbuf, length) );
1530 #ifdef POLARSSL_CIPHER_NULL_CIPHER
1532 FCT_TEST_BGN(null_encrypt_and_decrypt_48_bytes)
1534 unsigned char key[32];
1535 unsigned char iv[16];
1541 unsigned char inbuf[64];
1542 unsigned char encbuf[64];
1543 unsigned char decbuf[64];
1548 memset( key, 0, 32 );
1549 memset( iv , 0, 16 );
1551 memset( &ctx_dec, 0,
sizeof( ctx_dec ) );
1552 memset( &ctx_enc, 0,
sizeof( ctx_enc ) );
1554 memset( inbuf, 5, 64 );
1555 memset( encbuf, 0, 64 );
1556 memset( decbuf, 0, 64 );
1560 fct_chk( NULL != cipher_info );
1584 fct_chk( 0 ==
cipher_update( &ctx_enc, inbuf, length, encbuf, &outlen ) );
1591 fct_chk( outlen == enclen );
1594 fct_chk( 0 ==
cipher_finish( &ctx_enc, encbuf + outlen, &outlen ) );
1601 fct_chk( outlen == 0 );
1606 fct_chk( 0 ==
cipher_update( &ctx_dec, encbuf, enclen, decbuf, &outlen ) );
1613 fct_chk( enclen == outlen );
1616 fct_chk( 0 ==
cipher_finish( &ctx_dec, decbuf + outlen, &outlen ) );
1623 fct_chk( outlen == 0 );
1627 fct_chk( 0 == memcmp(inbuf, decbuf, length) );
1634 #ifdef POLARSSL_CIPHER_NULL_CIPHER
1636 FCT_TEST_BGN(null_encrypt_and_decrypt_49_bytes)
1638 unsigned char key[32];
1639 unsigned char iv[16];
1645 unsigned char inbuf[64];
1646 unsigned char encbuf[64];
1647 unsigned char decbuf[64];
1652 memset( key, 0, 32 );
1653 memset( iv , 0, 16 );
1655 memset( &ctx_dec, 0,
sizeof( ctx_dec ) );
1656 memset( &ctx_enc, 0,
sizeof( ctx_enc ) );
1658 memset( inbuf, 5, 64 );
1659 memset( encbuf, 0, 64 );
1660 memset( decbuf, 0, 64 );
1664 fct_chk( NULL != cipher_info );
1688 fct_chk( 0 ==
cipher_update( &ctx_enc, inbuf, length, encbuf, &outlen ) );
1695 fct_chk( outlen == enclen );
1698 fct_chk( 0 ==
cipher_finish( &ctx_enc, encbuf + outlen, &outlen ) );
1705 fct_chk( outlen == 0 );
1710 fct_chk( 0 ==
cipher_update( &ctx_dec, encbuf, enclen, decbuf, &outlen ) );
1717 fct_chk( enclen == outlen );
1720 fct_chk( 0 ==
cipher_finish( &ctx_dec, decbuf + outlen, &outlen ) );
1727 fct_chk( outlen == 0 );
1731 fct_chk( 0 == memcmp(inbuf, decbuf, length) );
1738 #ifdef POLARSSL_CIPHER_NULL_CIPHER
1740 FCT_TEST_BGN(null_encrypt_and_decrypt_1_bytes_in_multiple_parts_1)
1741 size_t first_length = 1;
1742 size_t second_length = 0;
1743 size_t length = first_length + second_length;
1744 unsigned char key[32];
1745 unsigned char iv[16];
1751 unsigned char inbuf[64];
1752 unsigned char encbuf[64];
1753 unsigned char decbuf[64];
1756 size_t totaloutlen = 0;
1759 memset( key, 0, 32 );
1760 memset( iv , 0, 16 );
1762 memset( &ctx_dec, 0,
sizeof( ctx_dec ) );
1763 memset( &ctx_enc, 0,
sizeof( ctx_enc ) );
1765 memset( inbuf, 5, 64 );
1766 memset( encbuf, 0, 64 );
1767 memset( decbuf, 0, 64 );
1771 fct_chk( NULL != cipher_info);
1793 fct_chk( 0 ==
cipher_update( &ctx_enc, inbuf, first_length, encbuf, &outlen ) );
1794 totaloutlen = outlen;
1795 fct_chk( 0 ==
cipher_update( &ctx_enc, inbuf + first_length, second_length, encbuf + totaloutlen, &outlen ) );
1796 totaloutlen += outlen;
1803 fct_chk( totaloutlen == enclen );
1805 fct_chk( 0 ==
cipher_finish( &ctx_enc, encbuf + totaloutlen, &outlen ) );
1806 totaloutlen += outlen;
1813 fct_chk( outlen == 0 );
1817 fct_chk( 0 ==
cipher_update( &ctx_dec, encbuf, enclen, decbuf, &outlen ) );
1824 fct_chk( enclen == outlen );
1826 fct_chk( 0 ==
cipher_finish( &ctx_dec, decbuf + outlen, &outlen ) );
1833 fct_chk( outlen == 0 );
1837 fct_chk( 0 == memcmp(inbuf, decbuf, length) );
1844 #ifdef POLARSSL_CIPHER_NULL_CIPHER
1846 FCT_TEST_BGN(null_encrypt_and_decrypt_1_bytes_in_multiple_parts_2)
1847 size_t first_length = 0;
1848 size_t second_length = 1;
1849 size_t length = first_length + second_length;
1850 unsigned char key[32];
1851 unsigned char iv[16];
1857 unsigned char inbuf[64];
1858 unsigned char encbuf[64];
1859 unsigned char decbuf[64];
1862 size_t totaloutlen = 0;
1865 memset( key, 0, 32 );
1866 memset( iv , 0, 16 );
1868 memset( &ctx_dec, 0,
sizeof( ctx_dec ) );
1869 memset( &ctx_enc, 0,
sizeof( ctx_enc ) );
1871 memset( inbuf, 5, 64 );
1872 memset( encbuf, 0, 64 );
1873 memset( decbuf, 0, 64 );
1877 fct_chk( NULL != cipher_info);
1899 fct_chk( 0 ==
cipher_update( &ctx_enc, inbuf, first_length, encbuf, &outlen ) );
1900 totaloutlen = outlen;
1901 fct_chk( 0 ==
cipher_update( &ctx_enc, inbuf + first_length, second_length, encbuf + totaloutlen, &outlen ) );
1902 totaloutlen += outlen;
1909 fct_chk( totaloutlen == enclen );
1911 fct_chk( 0 ==
cipher_finish( &ctx_enc, encbuf + totaloutlen, &outlen ) );
1912 totaloutlen += outlen;
1919 fct_chk( outlen == 0 );
1923 fct_chk( 0 ==
cipher_update( &ctx_dec, encbuf, enclen, decbuf, &outlen ) );
1930 fct_chk( enclen == outlen );
1932 fct_chk( 0 ==
cipher_finish( &ctx_dec, decbuf + outlen, &outlen ) );
1939 fct_chk( outlen == 0 );
1943 fct_chk( 0 == memcmp(inbuf, decbuf, length) );
1950 #ifdef POLARSSL_CIPHER_NULL_CIPHER
1952 FCT_TEST_BGN(null_encrypt_and_decrypt_16_bytes_in_multiple_parts_1)
1953 size_t first_length = 16;
1954 size_t second_length = 0;
1955 size_t length = first_length + second_length;
1956 unsigned char key[32];
1957 unsigned char iv[16];
1963 unsigned char inbuf[64];
1964 unsigned char encbuf[64];
1965 unsigned char decbuf[64];
1968 size_t totaloutlen = 0;
1971 memset( key, 0, 32 );
1972 memset( iv , 0, 16 );
1974 memset( &ctx_dec, 0,
sizeof( ctx_dec ) );
1975 memset( &ctx_enc, 0,
sizeof( ctx_enc ) );
1977 memset( inbuf, 5, 64 );
1978 memset( encbuf, 0, 64 );
1979 memset( decbuf, 0, 64 );
1983 fct_chk( NULL != cipher_info);
2005 fct_chk( 0 ==
cipher_update( &ctx_enc, inbuf, first_length, encbuf, &outlen ) );
2006 totaloutlen = outlen;
2007 fct_chk( 0 ==
cipher_update( &ctx_enc, inbuf + first_length, second_length, encbuf + totaloutlen, &outlen ) );
2008 totaloutlen += outlen;
2015 fct_chk( totaloutlen == enclen );
2017 fct_chk( 0 ==
cipher_finish( &ctx_enc, encbuf + totaloutlen, &outlen ) );
2018 totaloutlen += outlen;
2025 fct_chk( outlen == 0 );
2029 fct_chk( 0 ==
cipher_update( &ctx_dec, encbuf, enclen, decbuf, &outlen ) );
2036 fct_chk( enclen == outlen );
2038 fct_chk( 0 ==
cipher_finish( &ctx_dec, decbuf + outlen, &outlen ) );
2045 fct_chk( outlen == 0 );
2049 fct_chk( 0 == memcmp(inbuf, decbuf, length) );
2056 #ifdef POLARSSL_CIPHER_NULL_CIPHER
2058 FCT_TEST_BGN(null_encrypt_and_decrypt_16_bytes_in_multiple_parts_2)
2059 size_t first_length = 0;
2060 size_t second_length = 16;
2061 size_t length = first_length + second_length;
2062 unsigned char key[32];
2063 unsigned char iv[16];
2069 unsigned char inbuf[64];
2070 unsigned char encbuf[64];
2071 unsigned char decbuf[64];
2074 size_t totaloutlen = 0;
2077 memset( key, 0, 32 );
2078 memset( iv , 0, 16 );
2080 memset( &ctx_dec, 0,
sizeof( ctx_dec ) );
2081 memset( &ctx_enc, 0,
sizeof( ctx_enc ) );
2083 memset( inbuf, 5, 64 );
2084 memset( encbuf, 0, 64 );
2085 memset( decbuf, 0, 64 );
2089 fct_chk( NULL != cipher_info);
2111 fct_chk( 0 ==
cipher_update( &ctx_enc, inbuf, first_length, encbuf, &outlen ) );
2112 totaloutlen = outlen;
2113 fct_chk( 0 ==
cipher_update( &ctx_enc, inbuf + first_length, second_length, encbuf + totaloutlen, &outlen ) );
2114 totaloutlen += outlen;
2121 fct_chk( totaloutlen == enclen );
2123 fct_chk( 0 ==
cipher_finish( &ctx_enc, encbuf + totaloutlen, &outlen ) );
2124 totaloutlen += outlen;
2131 fct_chk( outlen == 0 );
2135 fct_chk( 0 ==
cipher_update( &ctx_dec, encbuf, enclen, decbuf, &outlen ) );
2142 fct_chk( enclen == outlen );
2144 fct_chk( 0 ==
cipher_finish( &ctx_dec, decbuf + outlen, &outlen ) );
2151 fct_chk( outlen == 0 );
2155 fct_chk( 0 == memcmp(inbuf, decbuf, length) );
2162 #ifdef POLARSSL_CIPHER_NULL_CIPHER
2164 FCT_TEST_BGN(null_encrypt_and_decrypt_16_bytes_in_multiple_parts_3)
2165 size_t first_length = 1;
2166 size_t second_length = 15;
2167 size_t length = first_length + second_length;
2168 unsigned char key[32];
2169 unsigned char iv[16];
2175 unsigned char inbuf[64];
2176 unsigned char encbuf[64];
2177 unsigned char decbuf[64];
2180 size_t totaloutlen = 0;
2183 memset( key, 0, 32 );
2184 memset( iv , 0, 16 );
2186 memset( &ctx_dec, 0,
sizeof( ctx_dec ) );
2187 memset( &ctx_enc, 0,
sizeof( ctx_enc ) );
2189 memset( inbuf, 5, 64 );
2190 memset( encbuf, 0, 64 );
2191 memset( decbuf, 0, 64 );
2195 fct_chk( NULL != cipher_info);
2217 fct_chk( 0 ==
cipher_update( &ctx_enc, inbuf, first_length, encbuf, &outlen ) );
2218 totaloutlen = outlen;
2219 fct_chk( 0 ==
cipher_update( &ctx_enc, inbuf + first_length, second_length, encbuf + totaloutlen, &outlen ) );
2220 totaloutlen += outlen;
2227 fct_chk( totaloutlen == enclen );
2229 fct_chk( 0 ==
cipher_finish( &ctx_enc, encbuf + totaloutlen, &outlen ) );
2230 totaloutlen += outlen;
2237 fct_chk( outlen == 0 );
2241 fct_chk( 0 ==
cipher_update( &ctx_dec, encbuf, enclen, decbuf, &outlen ) );
2248 fct_chk( enclen == outlen );
2250 fct_chk( 0 ==
cipher_finish( &ctx_dec, decbuf + outlen, &outlen ) );
2257 fct_chk( outlen == 0 );
2261 fct_chk( 0 == memcmp(inbuf, decbuf, length) );
2268 #ifdef POLARSSL_CIPHER_NULL_CIPHER
2270 FCT_TEST_BGN(null_encrypt_and_decrypt_16_bytes_in_multiple_parts_4)
2271 size_t first_length = 15;
2272 size_t second_length = 1;
2273 size_t length = first_length + second_length;
2274 unsigned char key[32];
2275 unsigned char iv[16];
2281 unsigned char inbuf[64];
2282 unsigned char encbuf[64];
2283 unsigned char decbuf[64];
2286 size_t totaloutlen = 0;
2289 memset( key, 0, 32 );
2290 memset( iv , 0, 16 );
2292 memset( &ctx_dec, 0,
sizeof( ctx_dec ) );
2293 memset( &ctx_enc, 0,
sizeof( ctx_enc ) );
2295 memset( inbuf, 5, 64 );
2296 memset( encbuf, 0, 64 );
2297 memset( decbuf, 0, 64 );
2301 fct_chk( NULL != cipher_info);
2323 fct_chk( 0 ==
cipher_update( &ctx_enc, inbuf, first_length, encbuf, &outlen ) );
2324 totaloutlen = outlen;
2325 fct_chk( 0 ==
cipher_update( &ctx_enc, inbuf + first_length, second_length, encbuf + totaloutlen, &outlen ) );
2326 totaloutlen += outlen;
2333 fct_chk( totaloutlen == enclen );
2335 fct_chk( 0 ==
cipher_finish( &ctx_enc, encbuf + totaloutlen, &outlen ) );
2336 totaloutlen += outlen;
2343 fct_chk( outlen == 0 );
2347 fct_chk( 0 ==
cipher_update( &ctx_dec, encbuf, enclen, decbuf, &outlen ) );
2354 fct_chk( enclen == outlen );
2356 fct_chk( 0 ==
cipher_finish( &ctx_dec, decbuf + outlen, &outlen ) );
2363 fct_chk( outlen == 0 );
2367 fct_chk( 0 == memcmp(inbuf, decbuf, length) );
2374 #ifdef POLARSSL_CIPHER_NULL_CIPHER
2376 FCT_TEST_BGN(null_encrypt_and_decrypt_22_bytes_in_multiple_parts_1)
2377 size_t first_length = 15;
2378 size_t second_length = 7;
2379 size_t length = first_length + second_length;
2380 unsigned char key[32];
2381 unsigned char iv[16];
2387 unsigned char inbuf[64];
2388 unsigned char encbuf[64];
2389 unsigned char decbuf[64];
2392 size_t totaloutlen = 0;
2395 memset( key, 0, 32 );
2396 memset( iv , 0, 16 );
2398 memset( &ctx_dec, 0,
sizeof( ctx_dec ) );
2399 memset( &ctx_enc, 0,
sizeof( ctx_enc ) );
2401 memset( inbuf, 5, 64 );
2402 memset( encbuf, 0, 64 );
2403 memset( decbuf, 0, 64 );
2407 fct_chk( NULL != cipher_info);
2429 fct_chk( 0 ==
cipher_update( &ctx_enc, inbuf, first_length, encbuf, &outlen ) );
2430 totaloutlen = outlen;
2431 fct_chk( 0 ==
cipher_update( &ctx_enc, inbuf + first_length, second_length, encbuf + totaloutlen, &outlen ) );
2432 totaloutlen += outlen;
2439 fct_chk( totaloutlen == enclen );
2441 fct_chk( 0 ==
cipher_finish( &ctx_enc, encbuf + totaloutlen, &outlen ) );
2442 totaloutlen += outlen;
2449 fct_chk( outlen == 0 );
2453 fct_chk( 0 ==
cipher_update( &ctx_dec, encbuf, enclen, decbuf, &outlen ) );
2460 fct_chk( enclen == outlen );
2462 fct_chk( 0 ==
cipher_finish( &ctx_dec, decbuf + outlen, &outlen ) );
2469 fct_chk( outlen == 0 );
2473 fct_chk( 0 == memcmp(inbuf, decbuf, length) );
2480 #ifdef POLARSSL_CIPHER_NULL_CIPHER
2482 FCT_TEST_BGN(null_encrypt_and_decrypt_22_bytes_in_multiple_parts_1)
2483 size_t first_length = 16;
2484 size_t second_length = 6;
2485 size_t length = first_length + second_length;
2486 unsigned char key[32];
2487 unsigned char iv[16];
2493 unsigned char inbuf[64];
2494 unsigned char encbuf[64];
2495 unsigned char decbuf[64];
2498 size_t totaloutlen = 0;
2501 memset( key, 0, 32 );
2502 memset( iv , 0, 16 );
2504 memset( &ctx_dec, 0,
sizeof( ctx_dec ) );
2505 memset( &ctx_enc, 0,
sizeof( ctx_enc ) );
2507 memset( inbuf, 5, 64 );
2508 memset( encbuf, 0, 64 );
2509 memset( decbuf, 0, 64 );
2513 fct_chk( NULL != cipher_info);
2535 fct_chk( 0 ==
cipher_update( &ctx_enc, inbuf, first_length, encbuf, &outlen ) );
2536 totaloutlen = outlen;
2537 fct_chk( 0 ==
cipher_update( &ctx_enc, inbuf + first_length, second_length, encbuf + totaloutlen, &outlen ) );
2538 totaloutlen += outlen;
2545 fct_chk( totaloutlen == enclen );
2547 fct_chk( 0 ==
cipher_finish( &ctx_enc, encbuf + totaloutlen, &outlen ) );
2548 totaloutlen += outlen;
2555 fct_chk( outlen == 0 );
2559 fct_chk( 0 ==
cipher_update( &ctx_dec, encbuf, enclen, decbuf, &outlen ) );
2566 fct_chk( enclen == outlen );
2568 fct_chk( 0 ==
cipher_finish( &ctx_dec, decbuf + outlen, &outlen ) );
2575 fct_chk( outlen == 0 );
2579 fct_chk( 0 == memcmp(inbuf, decbuf, length) );
2586 #ifdef POLARSSL_CIPHER_NULL_CIPHER
2588 FCT_TEST_BGN(null_encrypt_and_decrypt_22_bytes_in_multiple_parts_1)
2589 size_t first_length = 17;
2590 size_t second_length = 6;
2591 size_t length = first_length + second_length;
2592 unsigned char key[32];
2593 unsigned char iv[16];
2599 unsigned char inbuf[64];
2600 unsigned char encbuf[64];
2601 unsigned char decbuf[64];
2604 size_t totaloutlen = 0;
2607 memset( key, 0, 32 );
2608 memset( iv , 0, 16 );
2610 memset( &ctx_dec, 0,
sizeof( ctx_dec ) );
2611 memset( &ctx_enc, 0,
sizeof( ctx_enc ) );
2613 memset( inbuf, 5, 64 );
2614 memset( encbuf, 0, 64 );
2615 memset( decbuf, 0, 64 );
2619 fct_chk( NULL != cipher_info);
2641 fct_chk( 0 ==
cipher_update( &ctx_enc, inbuf, first_length, encbuf, &outlen ) );
2642 totaloutlen = outlen;
2643 fct_chk( 0 ==
cipher_update( &ctx_enc, inbuf + first_length, second_length, encbuf + totaloutlen, &outlen ) );
2644 totaloutlen += outlen;
2651 fct_chk( totaloutlen == enclen );
2653 fct_chk( 0 ==
cipher_finish( &ctx_enc, encbuf + totaloutlen, &outlen ) );
2654 totaloutlen += outlen;
2661 fct_chk( outlen == 0 );
2665 fct_chk( 0 ==
cipher_update( &ctx_dec, encbuf, enclen, decbuf, &outlen ) );
2672 fct_chk( enclen == outlen );
2674 fct_chk( 0 ==
cipher_finish( &ctx_dec, decbuf + outlen, &outlen ) );
2681 fct_chk( outlen == 0 );
2685 fct_chk( 0 == memcmp(inbuf, decbuf, length) );
2692 #ifdef POLARSSL_CIPHER_NULL_CIPHER
2694 FCT_TEST_BGN(null_encrypt_and_decrypt_32_bytes_in_multiple_parts_1)
2695 size_t first_length = 16;
2696 size_t second_length = 16;
2697 size_t length = first_length + second_length;
2698 unsigned char key[32];
2699 unsigned char iv[16];
2705 unsigned char inbuf[64];
2706 unsigned char encbuf[64];
2707 unsigned char decbuf[64];
2710 size_t totaloutlen = 0;
2713 memset( key, 0, 32 );
2714 memset( iv , 0, 16 );
2716 memset( &ctx_dec, 0,
sizeof( ctx_dec ) );
2717 memset( &ctx_enc, 0,
sizeof( ctx_enc ) );
2719 memset( inbuf, 5, 64 );
2720 memset( encbuf, 0, 64 );
2721 memset( decbuf, 0, 64 );
2725 fct_chk( NULL != cipher_info);
2747 fct_chk( 0 ==
cipher_update( &ctx_enc, inbuf, first_length, encbuf, &outlen ) );
2748 totaloutlen = outlen;
2749 fct_chk( 0 ==
cipher_update( &ctx_enc, inbuf + first_length, second_length, encbuf + totaloutlen, &outlen ) );
2750 totaloutlen += outlen;
2757 fct_chk( totaloutlen == enclen );
2759 fct_chk( 0 ==
cipher_finish( &ctx_enc, encbuf + totaloutlen, &outlen ) );
2760 totaloutlen += outlen;
2767 fct_chk( outlen == 0 );
2771 fct_chk( 0 ==
cipher_update( &ctx_dec, encbuf, enclen, decbuf, &outlen ) );
2778 fct_chk( enclen == outlen );
2780 fct_chk( 0 ==
cipher_finish( &ctx_dec, decbuf + outlen, &outlen ) );
2787 fct_chk( outlen == 0 );
2791 fct_chk( 0 == memcmp(inbuf, decbuf, length) );