9 typedef UINT32 uint32_t;
18 #define GET_UINT32_BE(n,b,i) \
20 (n) = ( (uint32_t) (b)[(i) ] << 24 ) \
21 | ( (uint32_t) (b)[(i) + 1] << 16 ) \
22 | ( (uint32_t) (b)[(i) + 2] << 8 ) \
23 | ( (uint32_t) (b)[(i) + 3] ); \
28 #define PUT_UINT32_BE(n,b,i) \
30 (b)[(i) ] = (unsigned char) ( (n) >> 24 ); \
31 (b)[(i) + 1] = (unsigned char) ( (n) >> 16 ); \
32 (b)[(i) + 2] = (unsigned char) ( (n) >> 8 ); \
33 (b)[(i) + 3] = (unsigned char) ( (n) ); \
37 int unhexify(
unsigned char *obuf,
const char *ibuf)
40 int len = strlen(ibuf) / 2;
41 assert(!(strlen(ibuf) %1));
46 if( c >=
'0' && c <=
'9' )
48 else if( c >=
'a' && c <=
'f' )
50 else if( c >=
'A' && c <=
'F' )
56 if( c2 >=
'0' && c2 <=
'9' )
58 else if( c2 >=
'a' && c2 <=
'f' )
60 else if( c2 >=
'A' && c2 <=
'F' )
65 *obuf++ = ( c << 4 ) | c2;
71 void hexify(
unsigned char *obuf,
const unsigned char *ibuf,
int len)
83 *obuf++ =
'a' + h - 10;
88 *obuf++ =
'a' + l - 10;
104 static int rnd_std_rand(
void *rng_state,
unsigned char *output,
size_t len )
108 if( rng_state != NULL )
111 for( i = 0; i < len; ++i )
122 static int rnd_zero_rand(
void *rng_state,
unsigned char *output,
size_t len )
124 if( rng_state != NULL )
127 memset( output, 0, len );
154 if( rng_state == NULL )
163 memcpy( output, info->
buf, use_len );
164 info->
buf += use_len;
168 if( len - use_len > 0 )
169 return(
rnd_std_rand( NULL, output + use_len, len - use_len ) );
198 uint32_t i, *k, sum, delta=0x9E3779B9;
199 unsigned char result[4];
201 if( rng_state == NULL )
208 size_t use_len = ( len > 4 ) ? 4 : len;
211 for( i = 0; i < 32; i++ )
213 info->
v0 += (((info->
v1 << 4) ^ (info->
v1 >> 5)) + info->
v1) ^ (sum + k[sum & 3]);
215 info->
v1 += (((info->
v0 << 4) ^ (info->
v0 >> 5)) + info->
v0) ^ (sum + k[(sum>>11) & 3]);
219 memcpy( output, result, use_len );
229 #ifdef POLARSSL_CIPHER_C
232 FCT_SUITE_BGN(test_suite_cipher)
234 #ifdef POLARSSL_SELF_TEST
236 FCT_TEST_BGN(cipher_selftest)
244 FCT_TEST_BGN(decrypt_empty_buffer)
245 unsigned char key[32];
246 unsigned char iv[16];
251 unsigned char encbuf[64];
252 unsigned char decbuf[64];
256 memset( key, 0, 32 );
257 memset( iv , 0, 16 );
259 memset( &ctx_dec, 0,
sizeof( ctx_dec ) );
261 memset( encbuf, 0, 64 );
262 memset( decbuf, 0, 64 );
266 fct_chk( NULL != cipher_info);
275 fct_chk( 0 ==
cipher_update( &ctx_dec, encbuf, 0, decbuf, &outlen ) );
276 fct_chk( 0 == outlen );
278 fct_chk( 0 == outlen );
283 #ifdef POLARSSL_CIPHER_NULL_CIPHER
285 FCT_TEST_BGN(null_encrypt_and_decrypt_0_bytes)
287 unsigned char key[32];
288 unsigned char iv[16];
294 unsigned char inbuf[64];
295 unsigned char encbuf[64];
296 unsigned char decbuf[64];
301 memset( key, 0, 32 );
302 memset( iv , 0, 16 );
304 memset( &ctx_dec, 0,
sizeof( ctx_dec ) );
305 memset( &ctx_enc, 0,
sizeof( ctx_enc ) );
307 memset( inbuf, 5, 64 );
308 memset( encbuf, 0, 64 );
309 memset( decbuf, 0, 64 );
313 fct_chk( NULL != cipher_info );
337 fct_chk( 0 ==
cipher_update( &ctx_enc, inbuf, length, encbuf, &outlen ) );
344 fct_chk( outlen == enclen );
347 fct_chk( 0 ==
cipher_finish( &ctx_enc, encbuf + outlen, &outlen ) );
354 fct_chk( outlen == 0 );
359 fct_chk( 0 ==
cipher_update( &ctx_dec, encbuf, enclen, decbuf, &outlen ) );
366 fct_chk( enclen == outlen );
369 fct_chk( 0 ==
cipher_finish( &ctx_dec, decbuf + outlen, &outlen ) );
376 fct_chk( outlen == 0 );
380 fct_chk( 0 == memcmp(inbuf, decbuf, length) );
387 #ifdef POLARSSL_CIPHER_NULL_CIPHER
389 FCT_TEST_BGN(null_encrypt_and_decrypt_1_bytes)
391 unsigned char key[32];
392 unsigned char iv[16];
398 unsigned char inbuf[64];
399 unsigned char encbuf[64];
400 unsigned char decbuf[64];
405 memset( key, 0, 32 );
406 memset( iv , 0, 16 );
408 memset( &ctx_dec, 0,
sizeof( ctx_dec ) );
409 memset( &ctx_enc, 0,
sizeof( ctx_enc ) );
411 memset( inbuf, 5, 64 );
412 memset( encbuf, 0, 64 );
413 memset( decbuf, 0, 64 );
417 fct_chk( NULL != cipher_info );
441 fct_chk( 0 ==
cipher_update( &ctx_enc, inbuf, length, encbuf, &outlen ) );
448 fct_chk( outlen == enclen );
451 fct_chk( 0 ==
cipher_finish( &ctx_enc, encbuf + outlen, &outlen ) );
458 fct_chk( outlen == 0 );
463 fct_chk( 0 ==
cipher_update( &ctx_dec, encbuf, enclen, decbuf, &outlen ) );
470 fct_chk( enclen == outlen );
473 fct_chk( 0 ==
cipher_finish( &ctx_dec, decbuf + outlen, &outlen ) );
480 fct_chk( outlen == 0 );
484 fct_chk( 0 == memcmp(inbuf, decbuf, length) );
491 #ifdef POLARSSL_CIPHER_NULL_CIPHER
493 FCT_TEST_BGN(null_encrypt_and_decrypt_2_bytes)
495 unsigned char key[32];
496 unsigned char iv[16];
502 unsigned char inbuf[64];
503 unsigned char encbuf[64];
504 unsigned char decbuf[64];
509 memset( key, 0, 32 );
510 memset( iv , 0, 16 );
512 memset( &ctx_dec, 0,
sizeof( ctx_dec ) );
513 memset( &ctx_enc, 0,
sizeof( ctx_enc ) );
515 memset( inbuf, 5, 64 );
516 memset( encbuf, 0, 64 );
517 memset( decbuf, 0, 64 );
521 fct_chk( NULL != cipher_info );
545 fct_chk( 0 ==
cipher_update( &ctx_enc, inbuf, length, encbuf, &outlen ) );
552 fct_chk( outlen == enclen );
555 fct_chk( 0 ==
cipher_finish( &ctx_enc, encbuf + outlen, &outlen ) );
562 fct_chk( outlen == 0 );
567 fct_chk( 0 ==
cipher_update( &ctx_dec, encbuf, enclen, decbuf, &outlen ) );
574 fct_chk( enclen == outlen );
577 fct_chk( 0 ==
cipher_finish( &ctx_dec, decbuf + outlen, &outlen ) );
584 fct_chk( outlen == 0 );
588 fct_chk( 0 == memcmp(inbuf, decbuf, length) );
595 #ifdef POLARSSL_CIPHER_NULL_CIPHER
597 FCT_TEST_BGN(null_encrypt_and_decrypt_7_bytes)
599 unsigned char key[32];
600 unsigned char iv[16];
606 unsigned char inbuf[64];
607 unsigned char encbuf[64];
608 unsigned char decbuf[64];
613 memset( key, 0, 32 );
614 memset( iv , 0, 16 );
616 memset( &ctx_dec, 0,
sizeof( ctx_dec ) );
617 memset( &ctx_enc, 0,
sizeof( ctx_enc ) );
619 memset( inbuf, 5, 64 );
620 memset( encbuf, 0, 64 );
621 memset( decbuf, 0, 64 );
625 fct_chk( NULL != cipher_info );
649 fct_chk( 0 ==
cipher_update( &ctx_enc, inbuf, length, encbuf, &outlen ) );
656 fct_chk( outlen == enclen );
659 fct_chk( 0 ==
cipher_finish( &ctx_enc, encbuf + outlen, &outlen ) );
666 fct_chk( outlen == 0 );
671 fct_chk( 0 ==
cipher_update( &ctx_dec, encbuf, enclen, decbuf, &outlen ) );
678 fct_chk( enclen == outlen );
681 fct_chk( 0 ==
cipher_finish( &ctx_dec, decbuf + outlen, &outlen ) );
688 fct_chk( outlen == 0 );
692 fct_chk( 0 == memcmp(inbuf, decbuf, length) );
699 #ifdef POLARSSL_CIPHER_NULL_CIPHER
701 FCT_TEST_BGN(null_encrypt_and_decrypt_8_bytes)
703 unsigned char key[32];
704 unsigned char iv[16];
710 unsigned char inbuf[64];
711 unsigned char encbuf[64];
712 unsigned char decbuf[64];
717 memset( key, 0, 32 );
718 memset( iv , 0, 16 );
720 memset( &ctx_dec, 0,
sizeof( ctx_dec ) );
721 memset( &ctx_enc, 0,
sizeof( ctx_enc ) );
723 memset( inbuf, 5, 64 );
724 memset( encbuf, 0, 64 );
725 memset( decbuf, 0, 64 );
729 fct_chk( NULL != cipher_info );
753 fct_chk( 0 ==
cipher_update( &ctx_enc, inbuf, length, encbuf, &outlen ) );
760 fct_chk( outlen == enclen );
763 fct_chk( 0 ==
cipher_finish( &ctx_enc, encbuf + outlen, &outlen ) );
770 fct_chk( outlen == 0 );
775 fct_chk( 0 ==
cipher_update( &ctx_dec, encbuf, enclen, decbuf, &outlen ) );
782 fct_chk( enclen == outlen );
785 fct_chk( 0 ==
cipher_finish( &ctx_dec, decbuf + outlen, &outlen ) );
792 fct_chk( outlen == 0 );
796 fct_chk( 0 == memcmp(inbuf, decbuf, length) );
803 #ifdef POLARSSL_CIPHER_NULL_CIPHER
805 FCT_TEST_BGN(null_encrypt_and_decrypt_9_bytes)
807 unsigned char key[32];
808 unsigned char iv[16];
814 unsigned char inbuf[64];
815 unsigned char encbuf[64];
816 unsigned char decbuf[64];
821 memset( key, 0, 32 );
822 memset( iv , 0, 16 );
824 memset( &ctx_dec, 0,
sizeof( ctx_dec ) );
825 memset( &ctx_enc, 0,
sizeof( ctx_enc ) );
827 memset( inbuf, 5, 64 );
828 memset( encbuf, 0, 64 );
829 memset( decbuf, 0, 64 );
833 fct_chk( NULL != cipher_info );
857 fct_chk( 0 ==
cipher_update( &ctx_enc, inbuf, length, encbuf, &outlen ) );
864 fct_chk( outlen == enclen );
867 fct_chk( 0 ==
cipher_finish( &ctx_enc, encbuf + outlen, &outlen ) );
874 fct_chk( outlen == 0 );
879 fct_chk( 0 ==
cipher_update( &ctx_dec, encbuf, enclen, decbuf, &outlen ) );
886 fct_chk( enclen == outlen );
889 fct_chk( 0 ==
cipher_finish( &ctx_dec, decbuf + outlen, &outlen ) );
896 fct_chk( outlen == 0 );
900 fct_chk( 0 == memcmp(inbuf, decbuf, length) );
907 #ifdef POLARSSL_CIPHER_NULL_CIPHER
909 FCT_TEST_BGN(null_encrypt_and_decrypt_15_bytes)
911 unsigned char key[32];
912 unsigned char iv[16];
918 unsigned char inbuf[64];
919 unsigned char encbuf[64];
920 unsigned char decbuf[64];
925 memset( key, 0, 32 );
926 memset( iv , 0, 16 );
928 memset( &ctx_dec, 0,
sizeof( ctx_dec ) );
929 memset( &ctx_enc, 0,
sizeof( ctx_enc ) );
931 memset( inbuf, 5, 64 );
932 memset( encbuf, 0, 64 );
933 memset( decbuf, 0, 64 );
937 fct_chk( NULL != cipher_info );
961 fct_chk( 0 ==
cipher_update( &ctx_enc, inbuf, length, encbuf, &outlen ) );
968 fct_chk( outlen == enclen );
971 fct_chk( 0 ==
cipher_finish( &ctx_enc, encbuf + outlen, &outlen ) );
978 fct_chk( outlen == 0 );
983 fct_chk( 0 ==
cipher_update( &ctx_dec, encbuf, enclen, decbuf, &outlen ) );
990 fct_chk( enclen == outlen );
993 fct_chk( 0 ==
cipher_finish( &ctx_dec, decbuf + outlen, &outlen ) );
1000 fct_chk( outlen == 0 );
1004 fct_chk( 0 == memcmp(inbuf, decbuf, length) );
1011 #ifdef POLARSSL_CIPHER_NULL_CIPHER
1013 FCT_TEST_BGN(null_encrypt_and_decrypt_16_bytes)
1015 unsigned char key[32];
1016 unsigned char iv[16];
1022 unsigned char inbuf[64];
1023 unsigned char encbuf[64];
1024 unsigned char decbuf[64];
1029 memset( key, 0, 32 );
1030 memset( iv , 0, 16 );
1032 memset( &ctx_dec, 0,
sizeof( ctx_dec ) );
1033 memset( &ctx_enc, 0,
sizeof( ctx_enc ) );
1035 memset( inbuf, 5, 64 );
1036 memset( encbuf, 0, 64 );
1037 memset( decbuf, 0, 64 );
1041 fct_chk( NULL != cipher_info );
1065 fct_chk( 0 ==
cipher_update( &ctx_enc, inbuf, length, encbuf, &outlen ) );
1072 fct_chk( outlen == enclen );
1075 fct_chk( 0 ==
cipher_finish( &ctx_enc, encbuf + outlen, &outlen ) );
1082 fct_chk( outlen == 0 );
1087 fct_chk( 0 ==
cipher_update( &ctx_dec, encbuf, enclen, decbuf, &outlen ) );
1094 fct_chk( enclen == outlen );
1097 fct_chk( 0 ==
cipher_finish( &ctx_dec, decbuf + outlen, &outlen ) );
1104 fct_chk( outlen == 0 );
1108 fct_chk( 0 == memcmp(inbuf, decbuf, length) );
1115 #ifdef POLARSSL_CIPHER_NULL_CIPHER
1117 FCT_TEST_BGN(null_encrypt_and_decrypt_31_bytes)
1119 unsigned char key[32];
1120 unsigned char iv[16];
1126 unsigned char inbuf[64];
1127 unsigned char encbuf[64];
1128 unsigned char decbuf[64];
1133 memset( key, 0, 32 );
1134 memset( iv , 0, 16 );
1136 memset( &ctx_dec, 0,
sizeof( ctx_dec ) );
1137 memset( &ctx_enc, 0,
sizeof( ctx_enc ) );
1139 memset( inbuf, 5, 64 );
1140 memset( encbuf, 0, 64 );
1141 memset( decbuf, 0, 64 );
1145 fct_chk( NULL != cipher_info );
1169 fct_chk( 0 ==
cipher_update( &ctx_enc, inbuf, length, encbuf, &outlen ) );
1176 fct_chk( outlen == enclen );
1179 fct_chk( 0 ==
cipher_finish( &ctx_enc, encbuf + outlen, &outlen ) );
1186 fct_chk( outlen == 0 );
1191 fct_chk( 0 ==
cipher_update( &ctx_dec, encbuf, enclen, decbuf, &outlen ) );
1198 fct_chk( enclen == outlen );
1201 fct_chk( 0 ==
cipher_finish( &ctx_dec, decbuf + outlen, &outlen ) );
1208 fct_chk( outlen == 0 );
1212 fct_chk( 0 == memcmp(inbuf, decbuf, length) );
1219 #ifdef POLARSSL_CIPHER_NULL_CIPHER
1221 FCT_TEST_BGN(null_encrypt_and_decrypt_32_bytes)
1223 unsigned char key[32];
1224 unsigned char iv[16];
1230 unsigned char inbuf[64];
1231 unsigned char encbuf[64];
1232 unsigned char decbuf[64];
1237 memset( key, 0, 32 );
1238 memset( iv , 0, 16 );
1240 memset( &ctx_dec, 0,
sizeof( ctx_dec ) );
1241 memset( &ctx_enc, 0,
sizeof( ctx_enc ) );
1243 memset( inbuf, 5, 64 );
1244 memset( encbuf, 0, 64 );
1245 memset( decbuf, 0, 64 );
1249 fct_chk( NULL != cipher_info );
1273 fct_chk( 0 ==
cipher_update( &ctx_enc, inbuf, length, encbuf, &outlen ) );
1280 fct_chk( outlen == enclen );
1283 fct_chk( 0 ==
cipher_finish( &ctx_enc, encbuf + outlen, &outlen ) );
1290 fct_chk( outlen == 0 );
1295 fct_chk( 0 ==
cipher_update( &ctx_dec, encbuf, enclen, decbuf, &outlen ) );
1302 fct_chk( enclen == outlen );
1305 fct_chk( 0 ==
cipher_finish( &ctx_dec, decbuf + outlen, &outlen ) );
1312 fct_chk( outlen == 0 );
1316 fct_chk( 0 == memcmp(inbuf, decbuf, length) );
1323 #ifdef POLARSSL_CIPHER_NULL_CIPHER
1325 FCT_TEST_BGN(null_encrypt_and_decrypt_33_bytes)
1327 unsigned char key[32];
1328 unsigned char iv[16];
1334 unsigned char inbuf[64];
1335 unsigned char encbuf[64];
1336 unsigned char decbuf[64];
1341 memset( key, 0, 32 );
1342 memset( iv , 0, 16 );
1344 memset( &ctx_dec, 0,
sizeof( ctx_dec ) );
1345 memset( &ctx_enc, 0,
sizeof( ctx_enc ) );
1347 memset( inbuf, 5, 64 );
1348 memset( encbuf, 0, 64 );
1349 memset( decbuf, 0, 64 );
1353 fct_chk( NULL != cipher_info );
1377 fct_chk( 0 ==
cipher_update( &ctx_enc, inbuf, length, encbuf, &outlen ) );
1384 fct_chk( outlen == enclen );
1387 fct_chk( 0 ==
cipher_finish( &ctx_enc, encbuf + outlen, &outlen ) );
1394 fct_chk( outlen == 0 );
1399 fct_chk( 0 ==
cipher_update( &ctx_dec, encbuf, enclen, decbuf, &outlen ) );
1406 fct_chk( enclen == outlen );
1409 fct_chk( 0 ==
cipher_finish( &ctx_dec, decbuf + outlen, &outlen ) );
1416 fct_chk( outlen == 0 );
1420 fct_chk( 0 == memcmp(inbuf, decbuf, length) );
1427 #ifdef POLARSSL_CIPHER_NULL_CIPHER
1429 FCT_TEST_BGN(null_encrypt_and_decrypt_47_bytes)
1431 unsigned char key[32];
1432 unsigned char iv[16];
1438 unsigned char inbuf[64];
1439 unsigned char encbuf[64];
1440 unsigned char decbuf[64];
1445 memset( key, 0, 32 );
1446 memset( iv , 0, 16 );
1448 memset( &ctx_dec, 0,
sizeof( ctx_dec ) );
1449 memset( &ctx_enc, 0,
sizeof( ctx_enc ) );
1451 memset( inbuf, 5, 64 );
1452 memset( encbuf, 0, 64 );
1453 memset( decbuf, 0, 64 );
1457 fct_chk( NULL != cipher_info );
1481 fct_chk( 0 ==
cipher_update( &ctx_enc, inbuf, length, encbuf, &outlen ) );
1488 fct_chk( outlen == enclen );
1491 fct_chk( 0 ==
cipher_finish( &ctx_enc, encbuf + outlen, &outlen ) );
1498 fct_chk( outlen == 0 );
1503 fct_chk( 0 ==
cipher_update( &ctx_dec, encbuf, enclen, decbuf, &outlen ) );
1510 fct_chk( enclen == outlen );
1513 fct_chk( 0 ==
cipher_finish( &ctx_dec, decbuf + outlen, &outlen ) );
1520 fct_chk( outlen == 0 );
1524 fct_chk( 0 == memcmp(inbuf, decbuf, length) );
1531 #ifdef POLARSSL_CIPHER_NULL_CIPHER
1533 FCT_TEST_BGN(null_encrypt_and_decrypt_48_bytes)
1535 unsigned char key[32];
1536 unsigned char iv[16];
1542 unsigned char inbuf[64];
1543 unsigned char encbuf[64];
1544 unsigned char decbuf[64];
1549 memset( key, 0, 32 );
1550 memset( iv , 0, 16 );
1552 memset( &ctx_dec, 0,
sizeof( ctx_dec ) );
1553 memset( &ctx_enc, 0,
sizeof( ctx_enc ) );
1555 memset( inbuf, 5, 64 );
1556 memset( encbuf, 0, 64 );
1557 memset( decbuf, 0, 64 );
1561 fct_chk( NULL != cipher_info );
1585 fct_chk( 0 ==
cipher_update( &ctx_enc, inbuf, length, encbuf, &outlen ) );
1592 fct_chk( outlen == enclen );
1595 fct_chk( 0 ==
cipher_finish( &ctx_enc, encbuf + outlen, &outlen ) );
1602 fct_chk( outlen == 0 );
1607 fct_chk( 0 ==
cipher_update( &ctx_dec, encbuf, enclen, decbuf, &outlen ) );
1614 fct_chk( enclen == outlen );
1617 fct_chk( 0 ==
cipher_finish( &ctx_dec, decbuf + outlen, &outlen ) );
1624 fct_chk( outlen == 0 );
1628 fct_chk( 0 == memcmp(inbuf, decbuf, length) );
1635 #ifdef POLARSSL_CIPHER_NULL_CIPHER
1637 FCT_TEST_BGN(null_encrypt_and_decrypt_49_bytes)
1639 unsigned char key[32];
1640 unsigned char iv[16];
1646 unsigned char inbuf[64];
1647 unsigned char encbuf[64];
1648 unsigned char decbuf[64];
1653 memset( key, 0, 32 );
1654 memset( iv , 0, 16 );
1656 memset( &ctx_dec, 0,
sizeof( ctx_dec ) );
1657 memset( &ctx_enc, 0,
sizeof( ctx_enc ) );
1659 memset( inbuf, 5, 64 );
1660 memset( encbuf, 0, 64 );
1661 memset( decbuf, 0, 64 );
1665 fct_chk( NULL != cipher_info );
1689 fct_chk( 0 ==
cipher_update( &ctx_enc, inbuf, length, encbuf, &outlen ) );
1696 fct_chk( outlen == enclen );
1699 fct_chk( 0 ==
cipher_finish( &ctx_enc, encbuf + outlen, &outlen ) );
1706 fct_chk( outlen == 0 );
1711 fct_chk( 0 ==
cipher_update( &ctx_dec, encbuf, enclen, decbuf, &outlen ) );
1718 fct_chk( enclen == outlen );
1721 fct_chk( 0 ==
cipher_finish( &ctx_dec, decbuf + outlen, &outlen ) );
1728 fct_chk( outlen == 0 );
1732 fct_chk( 0 == memcmp(inbuf, decbuf, length) );
1739 #ifdef POLARSSL_CIPHER_NULL_CIPHER
1741 FCT_TEST_BGN(null_encrypt_and_decrypt_1_bytes_in_multiple_parts_1)
1742 size_t first_length = 1;
1743 size_t second_length = 0;
1744 size_t length = first_length + second_length;
1745 unsigned char key[32];
1746 unsigned char iv[16];
1752 unsigned char inbuf[64];
1753 unsigned char encbuf[64];
1754 unsigned char decbuf[64];
1757 size_t totaloutlen = 0;
1760 memset( key, 0, 32 );
1761 memset( iv , 0, 16 );
1763 memset( &ctx_dec, 0,
sizeof( ctx_dec ) );
1764 memset( &ctx_enc, 0,
sizeof( ctx_enc ) );
1766 memset( inbuf, 5, 64 );
1767 memset( encbuf, 0, 64 );
1768 memset( decbuf, 0, 64 );
1772 fct_chk( NULL != cipher_info);
1794 fct_chk( 0 ==
cipher_update( &ctx_enc, inbuf, first_length, encbuf, &outlen ) );
1795 totaloutlen = outlen;
1796 fct_chk( 0 ==
cipher_update( &ctx_enc, inbuf + first_length, second_length, encbuf + totaloutlen, &outlen ) );
1797 totaloutlen += outlen;
1804 fct_chk( totaloutlen == enclen );
1806 fct_chk( 0 ==
cipher_finish( &ctx_enc, encbuf + totaloutlen, &outlen ) );
1807 totaloutlen += outlen;
1814 fct_chk( outlen == 0 );
1818 fct_chk( 0 ==
cipher_update( &ctx_dec, encbuf, enclen, decbuf, &outlen ) );
1825 fct_chk( enclen == outlen );
1827 fct_chk( 0 ==
cipher_finish( &ctx_dec, decbuf + outlen, &outlen ) );
1834 fct_chk( outlen == 0 );
1838 fct_chk( 0 == memcmp(inbuf, decbuf, length) );
1845 #ifdef POLARSSL_CIPHER_NULL_CIPHER
1847 FCT_TEST_BGN(null_encrypt_and_decrypt_1_bytes_in_multiple_parts_2)
1848 size_t first_length = 0;
1849 size_t second_length = 1;
1850 size_t length = first_length + second_length;
1851 unsigned char key[32];
1852 unsigned char iv[16];
1858 unsigned char inbuf[64];
1859 unsigned char encbuf[64];
1860 unsigned char decbuf[64];
1863 size_t totaloutlen = 0;
1866 memset( key, 0, 32 );
1867 memset( iv , 0, 16 );
1869 memset( &ctx_dec, 0,
sizeof( ctx_dec ) );
1870 memset( &ctx_enc, 0,
sizeof( ctx_enc ) );
1872 memset( inbuf, 5, 64 );
1873 memset( encbuf, 0, 64 );
1874 memset( decbuf, 0, 64 );
1878 fct_chk( NULL != cipher_info);
1900 fct_chk( 0 ==
cipher_update( &ctx_enc, inbuf, first_length, encbuf, &outlen ) );
1901 totaloutlen = outlen;
1902 fct_chk( 0 ==
cipher_update( &ctx_enc, inbuf + first_length, second_length, encbuf + totaloutlen, &outlen ) );
1903 totaloutlen += outlen;
1910 fct_chk( totaloutlen == enclen );
1912 fct_chk( 0 ==
cipher_finish( &ctx_enc, encbuf + totaloutlen, &outlen ) );
1913 totaloutlen += outlen;
1920 fct_chk( outlen == 0 );
1924 fct_chk( 0 ==
cipher_update( &ctx_dec, encbuf, enclen, decbuf, &outlen ) );
1931 fct_chk( enclen == outlen );
1933 fct_chk( 0 ==
cipher_finish( &ctx_dec, decbuf + outlen, &outlen ) );
1940 fct_chk( outlen == 0 );
1944 fct_chk( 0 == memcmp(inbuf, decbuf, length) );
1951 #ifdef POLARSSL_CIPHER_NULL_CIPHER
1953 FCT_TEST_BGN(null_encrypt_and_decrypt_16_bytes_in_multiple_parts_1)
1954 size_t first_length = 16;
1955 size_t second_length = 0;
1956 size_t length = first_length + second_length;
1957 unsigned char key[32];
1958 unsigned char iv[16];
1964 unsigned char inbuf[64];
1965 unsigned char encbuf[64];
1966 unsigned char decbuf[64];
1969 size_t totaloutlen = 0;
1972 memset( key, 0, 32 );
1973 memset( iv , 0, 16 );
1975 memset( &ctx_dec, 0,
sizeof( ctx_dec ) );
1976 memset( &ctx_enc, 0,
sizeof( ctx_enc ) );
1978 memset( inbuf, 5, 64 );
1979 memset( encbuf, 0, 64 );
1980 memset( decbuf, 0, 64 );
1984 fct_chk( NULL != cipher_info);
2006 fct_chk( 0 ==
cipher_update( &ctx_enc, inbuf, first_length, encbuf, &outlen ) );
2007 totaloutlen = outlen;
2008 fct_chk( 0 ==
cipher_update( &ctx_enc, inbuf + first_length, second_length, encbuf + totaloutlen, &outlen ) );
2009 totaloutlen += outlen;
2016 fct_chk( totaloutlen == enclen );
2018 fct_chk( 0 ==
cipher_finish( &ctx_enc, encbuf + totaloutlen, &outlen ) );
2019 totaloutlen += outlen;
2026 fct_chk( outlen == 0 );
2030 fct_chk( 0 ==
cipher_update( &ctx_dec, encbuf, enclen, decbuf, &outlen ) );
2037 fct_chk( enclen == outlen );
2039 fct_chk( 0 ==
cipher_finish( &ctx_dec, decbuf + outlen, &outlen ) );
2046 fct_chk( outlen == 0 );
2050 fct_chk( 0 == memcmp(inbuf, decbuf, length) );
2057 #ifdef POLARSSL_CIPHER_NULL_CIPHER
2059 FCT_TEST_BGN(null_encrypt_and_decrypt_16_bytes_in_multiple_parts_2)
2060 size_t first_length = 0;
2061 size_t second_length = 16;
2062 size_t length = first_length + second_length;
2063 unsigned char key[32];
2064 unsigned char iv[16];
2070 unsigned char inbuf[64];
2071 unsigned char encbuf[64];
2072 unsigned char decbuf[64];
2075 size_t totaloutlen = 0;
2078 memset( key, 0, 32 );
2079 memset( iv , 0, 16 );
2081 memset( &ctx_dec, 0,
sizeof( ctx_dec ) );
2082 memset( &ctx_enc, 0,
sizeof( ctx_enc ) );
2084 memset( inbuf, 5, 64 );
2085 memset( encbuf, 0, 64 );
2086 memset( decbuf, 0, 64 );
2090 fct_chk( NULL != cipher_info);
2112 fct_chk( 0 ==
cipher_update( &ctx_enc, inbuf, first_length, encbuf, &outlen ) );
2113 totaloutlen = outlen;
2114 fct_chk( 0 ==
cipher_update( &ctx_enc, inbuf + first_length, second_length, encbuf + totaloutlen, &outlen ) );
2115 totaloutlen += outlen;
2122 fct_chk( totaloutlen == enclen );
2124 fct_chk( 0 ==
cipher_finish( &ctx_enc, encbuf + totaloutlen, &outlen ) );
2125 totaloutlen += outlen;
2132 fct_chk( outlen == 0 );
2136 fct_chk( 0 ==
cipher_update( &ctx_dec, encbuf, enclen, decbuf, &outlen ) );
2143 fct_chk( enclen == outlen );
2145 fct_chk( 0 ==
cipher_finish( &ctx_dec, decbuf + outlen, &outlen ) );
2152 fct_chk( outlen == 0 );
2156 fct_chk( 0 == memcmp(inbuf, decbuf, length) );
2163 #ifdef POLARSSL_CIPHER_NULL_CIPHER
2165 FCT_TEST_BGN(null_encrypt_and_decrypt_16_bytes_in_multiple_parts_3)
2166 size_t first_length = 1;
2167 size_t second_length = 15;
2168 size_t length = first_length + second_length;
2169 unsigned char key[32];
2170 unsigned char iv[16];
2176 unsigned char inbuf[64];
2177 unsigned char encbuf[64];
2178 unsigned char decbuf[64];
2181 size_t totaloutlen = 0;
2184 memset( key, 0, 32 );
2185 memset( iv , 0, 16 );
2187 memset( &ctx_dec, 0,
sizeof( ctx_dec ) );
2188 memset( &ctx_enc, 0,
sizeof( ctx_enc ) );
2190 memset( inbuf, 5, 64 );
2191 memset( encbuf, 0, 64 );
2192 memset( decbuf, 0, 64 );
2196 fct_chk( NULL != cipher_info);
2218 fct_chk( 0 ==
cipher_update( &ctx_enc, inbuf, first_length, encbuf, &outlen ) );
2219 totaloutlen = outlen;
2220 fct_chk( 0 ==
cipher_update( &ctx_enc, inbuf + first_length, second_length, encbuf + totaloutlen, &outlen ) );
2221 totaloutlen += outlen;
2228 fct_chk( totaloutlen == enclen );
2230 fct_chk( 0 ==
cipher_finish( &ctx_enc, encbuf + totaloutlen, &outlen ) );
2231 totaloutlen += outlen;
2238 fct_chk( outlen == 0 );
2242 fct_chk( 0 ==
cipher_update( &ctx_dec, encbuf, enclen, decbuf, &outlen ) );
2249 fct_chk( enclen == outlen );
2251 fct_chk( 0 ==
cipher_finish( &ctx_dec, decbuf + outlen, &outlen ) );
2258 fct_chk( outlen == 0 );
2262 fct_chk( 0 == memcmp(inbuf, decbuf, length) );
2269 #ifdef POLARSSL_CIPHER_NULL_CIPHER
2271 FCT_TEST_BGN(null_encrypt_and_decrypt_16_bytes_in_multiple_parts_4)
2272 size_t first_length = 15;
2273 size_t second_length = 1;
2274 size_t length = first_length + second_length;
2275 unsigned char key[32];
2276 unsigned char iv[16];
2282 unsigned char inbuf[64];
2283 unsigned char encbuf[64];
2284 unsigned char decbuf[64];
2287 size_t totaloutlen = 0;
2290 memset( key, 0, 32 );
2291 memset( iv , 0, 16 );
2293 memset( &ctx_dec, 0,
sizeof( ctx_dec ) );
2294 memset( &ctx_enc, 0,
sizeof( ctx_enc ) );
2296 memset( inbuf, 5, 64 );
2297 memset( encbuf, 0, 64 );
2298 memset( decbuf, 0, 64 );
2302 fct_chk( NULL != cipher_info);
2324 fct_chk( 0 ==
cipher_update( &ctx_enc, inbuf, first_length, encbuf, &outlen ) );
2325 totaloutlen = outlen;
2326 fct_chk( 0 ==
cipher_update( &ctx_enc, inbuf + first_length, second_length, encbuf + totaloutlen, &outlen ) );
2327 totaloutlen += outlen;
2334 fct_chk( totaloutlen == enclen );
2336 fct_chk( 0 ==
cipher_finish( &ctx_enc, encbuf + totaloutlen, &outlen ) );
2337 totaloutlen += outlen;
2344 fct_chk( outlen == 0 );
2348 fct_chk( 0 ==
cipher_update( &ctx_dec, encbuf, enclen, decbuf, &outlen ) );
2355 fct_chk( enclen == outlen );
2357 fct_chk( 0 ==
cipher_finish( &ctx_dec, decbuf + outlen, &outlen ) );
2364 fct_chk( outlen == 0 );
2368 fct_chk( 0 == memcmp(inbuf, decbuf, length) );
2375 #ifdef POLARSSL_CIPHER_NULL_CIPHER
2377 FCT_TEST_BGN(null_encrypt_and_decrypt_22_bytes_in_multiple_parts_1)
2378 size_t first_length = 15;
2379 size_t second_length = 7;
2380 size_t length = first_length + second_length;
2381 unsigned char key[32];
2382 unsigned char iv[16];
2388 unsigned char inbuf[64];
2389 unsigned char encbuf[64];
2390 unsigned char decbuf[64];
2393 size_t totaloutlen = 0;
2396 memset( key, 0, 32 );
2397 memset( iv , 0, 16 );
2399 memset( &ctx_dec, 0,
sizeof( ctx_dec ) );
2400 memset( &ctx_enc, 0,
sizeof( ctx_enc ) );
2402 memset( inbuf, 5, 64 );
2403 memset( encbuf, 0, 64 );
2404 memset( decbuf, 0, 64 );
2408 fct_chk( NULL != cipher_info);
2430 fct_chk( 0 ==
cipher_update( &ctx_enc, inbuf, first_length, encbuf, &outlen ) );
2431 totaloutlen = outlen;
2432 fct_chk( 0 ==
cipher_update( &ctx_enc, inbuf + first_length, second_length, encbuf + totaloutlen, &outlen ) );
2433 totaloutlen += outlen;
2440 fct_chk( totaloutlen == enclen );
2442 fct_chk( 0 ==
cipher_finish( &ctx_enc, encbuf + totaloutlen, &outlen ) );
2443 totaloutlen += outlen;
2450 fct_chk( outlen == 0 );
2454 fct_chk( 0 ==
cipher_update( &ctx_dec, encbuf, enclen, decbuf, &outlen ) );
2461 fct_chk( enclen == outlen );
2463 fct_chk( 0 ==
cipher_finish( &ctx_dec, decbuf + outlen, &outlen ) );
2470 fct_chk( outlen == 0 );
2474 fct_chk( 0 == memcmp(inbuf, decbuf, length) );
2481 #ifdef POLARSSL_CIPHER_NULL_CIPHER
2483 FCT_TEST_BGN(null_encrypt_and_decrypt_22_bytes_in_multiple_parts_1)
2484 size_t first_length = 16;
2485 size_t second_length = 6;
2486 size_t length = first_length + second_length;
2487 unsigned char key[32];
2488 unsigned char iv[16];
2494 unsigned char inbuf[64];
2495 unsigned char encbuf[64];
2496 unsigned char decbuf[64];
2499 size_t totaloutlen = 0;
2502 memset( key, 0, 32 );
2503 memset( iv , 0, 16 );
2505 memset( &ctx_dec, 0,
sizeof( ctx_dec ) );
2506 memset( &ctx_enc, 0,
sizeof( ctx_enc ) );
2508 memset( inbuf, 5, 64 );
2509 memset( encbuf, 0, 64 );
2510 memset( decbuf, 0, 64 );
2514 fct_chk( NULL != cipher_info);
2536 fct_chk( 0 ==
cipher_update( &ctx_enc, inbuf, first_length, encbuf, &outlen ) );
2537 totaloutlen = outlen;
2538 fct_chk( 0 ==
cipher_update( &ctx_enc, inbuf + first_length, second_length, encbuf + totaloutlen, &outlen ) );
2539 totaloutlen += outlen;
2546 fct_chk( totaloutlen == enclen );
2548 fct_chk( 0 ==
cipher_finish( &ctx_enc, encbuf + totaloutlen, &outlen ) );
2549 totaloutlen += outlen;
2556 fct_chk( outlen == 0 );
2560 fct_chk( 0 ==
cipher_update( &ctx_dec, encbuf, enclen, decbuf, &outlen ) );
2567 fct_chk( enclen == outlen );
2569 fct_chk( 0 ==
cipher_finish( &ctx_dec, decbuf + outlen, &outlen ) );
2576 fct_chk( outlen == 0 );
2580 fct_chk( 0 == memcmp(inbuf, decbuf, length) );
2587 #ifdef POLARSSL_CIPHER_NULL_CIPHER
2589 FCT_TEST_BGN(null_encrypt_and_decrypt_22_bytes_in_multiple_parts_1)
2590 size_t first_length = 17;
2591 size_t second_length = 6;
2592 size_t length = first_length + second_length;
2593 unsigned char key[32];
2594 unsigned char iv[16];
2600 unsigned char inbuf[64];
2601 unsigned char encbuf[64];
2602 unsigned char decbuf[64];
2605 size_t totaloutlen = 0;
2608 memset( key, 0, 32 );
2609 memset( iv , 0, 16 );
2611 memset( &ctx_dec, 0,
sizeof( ctx_dec ) );
2612 memset( &ctx_enc, 0,
sizeof( ctx_enc ) );
2614 memset( inbuf, 5, 64 );
2615 memset( encbuf, 0, 64 );
2616 memset( decbuf, 0, 64 );
2620 fct_chk( NULL != cipher_info);
2642 fct_chk( 0 ==
cipher_update( &ctx_enc, inbuf, first_length, encbuf, &outlen ) );
2643 totaloutlen = outlen;
2644 fct_chk( 0 ==
cipher_update( &ctx_enc, inbuf + first_length, second_length, encbuf + totaloutlen, &outlen ) );
2645 totaloutlen += outlen;
2652 fct_chk( totaloutlen == enclen );
2654 fct_chk( 0 ==
cipher_finish( &ctx_enc, encbuf + totaloutlen, &outlen ) );
2655 totaloutlen += outlen;
2662 fct_chk( outlen == 0 );
2666 fct_chk( 0 ==
cipher_update( &ctx_dec, encbuf, enclen, decbuf, &outlen ) );
2673 fct_chk( enclen == outlen );
2675 fct_chk( 0 ==
cipher_finish( &ctx_dec, decbuf + outlen, &outlen ) );
2682 fct_chk( outlen == 0 );
2686 fct_chk( 0 == memcmp(inbuf, decbuf, length) );
2693 #ifdef POLARSSL_CIPHER_NULL_CIPHER
2695 FCT_TEST_BGN(null_encrypt_and_decrypt_32_bytes_in_multiple_parts_1)
2696 size_t first_length = 16;
2697 size_t second_length = 16;
2698 size_t length = first_length + second_length;
2699 unsigned char key[32];
2700 unsigned char iv[16];
2706 unsigned char inbuf[64];
2707 unsigned char encbuf[64];
2708 unsigned char decbuf[64];
2711 size_t totaloutlen = 0;
2714 memset( key, 0, 32 );
2715 memset( iv , 0, 16 );
2717 memset( &ctx_dec, 0,
sizeof( ctx_dec ) );
2718 memset( &ctx_enc, 0,
sizeof( ctx_enc ) );
2720 memset( inbuf, 5, 64 );
2721 memset( encbuf, 0, 64 );
2722 memset( decbuf, 0, 64 );
2726 fct_chk( NULL != cipher_info);
2748 fct_chk( 0 ==
cipher_update( &ctx_enc, inbuf, first_length, encbuf, &outlen ) );
2749 totaloutlen = outlen;
2750 fct_chk( 0 ==
cipher_update( &ctx_enc, inbuf + first_length, second_length, encbuf + totaloutlen, &outlen ) );
2751 totaloutlen += outlen;
2758 fct_chk( totaloutlen == enclen );
2760 fct_chk( 0 ==
cipher_finish( &ctx_enc, encbuf + totaloutlen, &outlen ) );
2761 totaloutlen += outlen;
2768 fct_chk( outlen == 0 );
2772 fct_chk( 0 ==
cipher_update( &ctx_dec, encbuf, enclen, decbuf, &outlen ) );
2779 fct_chk( enclen == outlen );
2781 fct_chk( 0 ==
cipher_finish( &ctx_dec, decbuf + outlen, &outlen ) );
2788 fct_chk( outlen == 0 );
2792 fct_chk( 0 == memcmp(inbuf, decbuf, length) );