@@ -58619,24 +58619,29 @@ typedef struct {
5861958619 word32 keySz;
5862058620 const byte nonce[49];
5862158621 word32 nonceSz;
58622- const byte assoc[81];
58623- word32 assocSz;
58622+ byte numAssoc;
58623+ const byte assoc1[81];
58624+ word32 assoc1Sz;
58625+ const byte assoc2[11];
58626+ word32 assoc2Sz;
5862458627 const byte plaintext[83];
5862558628 word32 plaintextSz;
5862658629 const byte siv[AES_BLOCK_SIZE+1];
5862758630 const byte ciphertext[82];
5862858631 word32 ciphertextSz;
5862958632} AesSivTestVector;
5863058633
58631- #define AES_SIV_TEST_VECTORS 7
58634+ #define AES_SIV_TEST_VECTORS 9
5863258635
5863358636WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aes_siv_test(void)
5863458637{
58635- /* These test vectors come from chrony 4.1's SIV unit tests. */
5863658638 WOLFSSL_SMALL_STACK_STATIC const AesSivTestVector testVectors[AES_SIV_TEST_VECTORS] = {
58639+ /* These test vectors come from chrony 4.1's SIV unit tests. */
5863758640 { "\x01\x23\x45\x67\x89\xab\xcd\xef\xf0\x12\x34\x56\x78\x9a\xbc\xde"
5863858641 "\xef\x01\x23\x45\x67\x89\xab\xcd\xde\xf0\x12\x34\x56\x78\x9a\xbc", 32,
5863958642 "\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f", 16,
58643+ 1,
58644+ "", 0,
5864058645 "", 0,
5864158646 "", 0,
5864258647 "\x22\x3e\xb5\x94\xe0\xe0\x25\x4b\x00\x25\x8e\x21\x9a\x1c\xa4\x21",
@@ -58645,14 +58650,18 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aes_siv_test(void)
5864558650 { "\x01\x23\x45\x67\x89\xab\xcd\xef\xf0\x12\x34\x56\x78\x9a\xbc\xde"
5864658651 "\xef\x01\x23\x45\x67\x89\xab\xcd\xde\xf0\x12\x34\x56\x78\x9a\xbc", 32,
5864758652 "\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f", 16,
58653+ 1,
5864858654 "\x4c\x9d\x4f\xca\xed\x8a\xe2\xba\xad\x3f\x3e\xa6\xe9\x3c\x8c\x8b", 16,
5864958655 "", 0,
58656+ "", 0,
5865058657 "\xd7\x20\x19\x89\xc6\xdb\xc6\xd6\x61\xfc\x62\xbc\x86\x5e\xee\xef",
5865158658 "", 0
5865258659 },
5865358660 { "\x01\x23\x45\x67\x89\xab\xcd\xef\xf0\x12\x34\x56\x78\x9a\xbc\xde"
5865458661 "\xef\x01\x23\x45\x67\x89\xab\xcd\xde\xf0\x12\x34\x56\x78\x9a\xbc", 32,
5865558662 "\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f", 16,
58663+ 1,
58664+ "", 0,
5865658665 "", 0,
5865758666 "\x4c\x9d\x4f\xca\xed\x8a\xe2\xba\xad\x3f\x3e\xa6\xe9\x3c\x8c\x8b", 16,
5865858667 "\xb6\xc1\x60\xe9\xc2\xfd\x2a\xe8\xde\xc5\x36\x8b\x2a\x33\xed\xe1",
@@ -58661,15 +58670,19 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aes_siv_test(void)
5866158670 { "\x01\x23\x45\x67\x89\xab\xcd\xef\xf0\x12\x34\x56\x78\x9a\xbc\xde"
5866258671 "\xef\x01\x23\x45\x67\x89\xab\xcd\xde\xf0\x12\x34\x56\x78\x9a\xbc", 32,
5866358672 "\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e", 15,
58673+ 1,
5866458674 "\x4c\x9d\x4f\xca\xed\x8a\xe2\xba\xad\x3f\x3e\xa6\xe9\x3c\x8c", 15,
58675+ "", 0,
5866558676 "\xba\x99\x79\x31\x23\x7e\x3c\x53\x58\x7e\xd4\x93\x02\xab\xe4", 15,
5866658677 "\x03\x8c\x41\x51\xba\x7a\x8f\x77\x6e\x56\x31\x99\x42\x0b\xc7\x03",
5866758678 "\xe7\x6c\x67\xc9\xda\xb7\x0d\x5b\x44\x06\x26\x5a\xd0\xd2\x3b", 15
5866858679 },
5866958680 { "\x01\x23\x45\x67\x89\xab\xcd\xef\xf0\x12\x34\x56\x78\x9a\xbc\xde"
5867058681 "\xef\x01\x23\x45\x67\x89\xab\xcd\xde\xf0\x12\x34\x56\x78\x9a\xbc", 32,
5867158682 "\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f", 16,
58683+ 1,
5867258684 "\x4c\x9d\x4f\xca\xed\x8a\xe2\xba\xad\x3f\x3e\xa6\xe9\x3c\x8c\x8b", 16,
58685+ "", 0,
5867358686 "\xba\x99\x79\x31\x23\x7e\x3c\x53\x58\x7e\xd4\x93\x02\xab\xe4\xa7", 16,
5867458687 "\x5c\x05\x23\x65\xf4\x57\x0a\xa0\xfb\x38\x3e\xce\x9b\x75\x85\xeb",
5867558688 "\x68\x85\x19\x36\x0c\x7c\x48\x11\x40\xcb\x9b\x57\x9a\x0e\x65\x32", 16
@@ -58678,8 +58691,10 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aes_siv_test(void)
5867858691 "\xef\x01\x23\x45\x67\x89\xab\xcd\xde\xf0\x12\x34\x56\x78\x9a\xbc", 32,
5867958692 "\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f"
5868058693 "\xd5", 17,
58694+ 1,
5868158695 "\x4c\x9d\x4f\xca\xed\x8a\xe2\xba\xad\x3f\x3e\xa6\xe9\x3c\x8c\x8b"
5868258696 "\xa0", 17,
58697+ "", 0,
5868358698 "\xba\x99\x79\x31\x23\x7e\x3c\x53\x58\x7e\xd4\x93\x02\xab\xe4\xa7"
5868458699 "\x08", 17,
5868558700 "\xaf\x58\x4b\xe7\x82\x1e\x96\x19\x29\x91\x25\xe0\xdd\x80\x3b\x49",
@@ -58691,11 +58706,13 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aes_siv_test(void)
5869158706 "\xb0\x5a\x1b\xc7\x56\xe7\xb6\x2c\xb4\x85\xe5\x56\xa5\x28\xc0\x6c"
5869258707 "\x2f\x3b\x0b\x9d\x1a\x0c\xdf\x69\x47\xe0\xcc\xc0\x87\xaa\x5c\x09"
5869358708 "\x98\x48\x8d\x6a\x8e\x1e\x05\xd7\x8b\x68\x74\x83\xb5\x1d\xf1\x2c", 48,
58709+ 1,
5869458710 "\xe5\x8b\xd2\x6a\x30\xc5\xc5\x61\xcc\xbd\x7c\x27\xbf\xfe\xf9\x06"
5869558711 "\x00\x5b\xd7\xfc\x11\x0b\xcf\x16\x61\xef\xac\x05\xa7\xaf\xec\x27"
5869658712 "\x41\xc8\x5e\x9e\x0d\xf9\x2f\xaf\x20\x79\x17\xe5\x17\x91\x2a\x27"
5869758713 "\x34\x1c\xbc\xaf\xeb\xef\x7f\x52\xe7\x1e\x4c\x2a\xca\xbd\x2b\xbe"
5869858714 "\x34\xd6\xfb\x69\xd3\x3e\x49\x59\x60\xb4\x26\xc9\xb8\xce\xba", 79,
58715+ "", 0,
5869958716 "\x6c\xe7\xcf\x7e\xab\x7b\xa0\xe1\xa7\x22\xcb\x88\xde\x5e\x42\xd2"
5870058717 "\xec\x79\xe0\xa2\xcf\x5f\x0f\x6f\x6b\x89\x57\xcd\xae\x17\xd4\xc2"
5870158718 "\xf3\x1b\xa2\xa8\x13\x78\x23\x2f\x83\xa8\xd4\x0c\xc0\xd2\xf3\x99"
@@ -58709,17 +58726,53 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aes_siv_test(void)
5870958726 "\x48\xc9\x55\xc5\x2f\x40\x73\x3f\x98\xbb\x8d\x69\x78\x46\x64\x17"
5871058727 "\x8d\x49\x2f\x14\x62\xa4\x7c\x2a\x57\x38\x87\xce\xc6\x72\xd3\x5c"
5871158728 "\xa1", 81
58712- }};
58729+ },
58730+ /* Example A.1 from RFC5297 */
58731+ {
58732+ "\xff\xfe\xfd\xfc\xfb\xfa\xf9\xf8\xf7\xf6\xf5\xf4\xf3\xf2\xf1\xf0"
58733+ "\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff", 32,
58734+ "", 0,
58735+ 1,
58736+ "\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f"
58737+ "\x20\x21\x22\x23\x24\x25\x26\x27", 24,
58738+ "", 0,
58739+ "\x11\x22\x33\x44\x55\x66\x77\x88\x99\xaa\xbb\xcc\xdd\xee", 14,
58740+ "\x85\x63\x2d\x07\xc6\xe8\xf3\x7f\x95\x0a\xcd\x32\x0a\x2e\xcc\x93",
58741+ "\x40\xc0\x2b\x96\x90\xc4\xdc\x04\xda\xef\x7f\x6a\xfe\x5c", 14
58742+ },
58743+ /* Example A.2 from RFC5297 */
58744+ {
58745+ "\x7f\x7e\x7d\x7c\x7b\x7a\x79\x78\x77\x76\x75\x74\x73\x72\x71\x70"
58746+ "\x40\x41\x42\x43\x44\x45\x46\x47\x48\x49\x4a\x4b\x4c\x4d\x4e\x4f", 32,
58747+ "\x09\xf9\x11\x02\x9d\x74\xe3\x5b\xd8\x41\x56\xc5\x63\x56\x88\xc0", 16,
58748+ 2,
58749+ "\x00\x11\x22\x33\x44\x55\x66\x77\x88\x99\xaa\xbb\xcc\xdd\xee\xff"
58750+ "\xde\xad\xda\xda\xde\xad\xda\xda\xff\xee\xdd\xcc\xbb\xaa\x99\x88"
58751+ "\x77\x66\x55\x44\x33\x22\x11\x00", 40,
58752+ "\x10\x20\x30\x40\x50\x60\x70\x80\x90\xa0", 10,
58753+ "\x74\x68\x69\x73\x20\x69\x73\x20\x73\x6f\x6d\x65\x20\x70\x6c\x61"
58754+ "\x69\x6e\x74\x65\x78\x74\x20\x74\x6f\x20\x65\x6e\x63\x72\x79\x70"
58755+ "\x74\x20\x75\x73\x69\x6e\x67\x20\x53\x49\x56\x2d\x41\x45\x53", 47,
58756+ "\x7b\xdb\x6e\x3b\x43\x26\x67\xeb\x06\xf4\xd1\x4b\xff\x2f\xbd\x0f",
58757+ "\xcb\x90\x0f\x2f\xdd\xbe\x40\x43\x26\x60\x19\x65\xc8\x89\xbf\x17"
58758+ "\xdb\xa7\x7c\xeb\x09\x4f\xa6\x63\xb7\xa3\xf7\x48\xba\x8a\xf8\x29"
58759+ "\xea\x64\xad\x54\x4a\x27\x2e\x9c\x48\x5b\x62\xa3\xfd\x5c\x0d", 47
58760+ }
58761+ };
5871358762 int i;
5871458763 byte computedCiphertext[82];
5871558764 byte computedPlaintext[82];
5871658765 byte siv[AES_BLOCK_SIZE];
5871758766 wc_test_ret_t ret = 0;
5871858767 WOLFSSL_ENTER("aes_siv_test");
5871958768
58769+ /* First test legacy "exactly one Assoc" interface. */
5872058770 for (i = 0; i < AES_SIV_TEST_VECTORS; ++i) {
58771+ if (testVectors[i].numAssoc != 1)
58772+ continue;
58773+
5872158774 ret = wc_AesSivEncrypt(testVectors[i].key, testVectors[i].keySz,
58722- testVectors[i].assoc , testVectors[i].assocSz ,
58775+ testVectors[i].assoc1 , testVectors[i].assoc1Sz ,
5872358776 testVectors[i].nonce, testVectors[i].nonceSz,
5872458777 testVectors[i].plaintext,
5872558778 testVectors[i].plaintextSz, siv,
@@ -58737,7 +58790,7 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aes_siv_test(void)
5873758790 return WC_TEST_RET_ENC_NC;
5873858791 }
5873958792 ret = wc_AesSivDecrypt(testVectors[i].key, testVectors[i].keySz,
58740- testVectors[i].assoc , testVectors[i].assocSz ,
58793+ testVectors[i].assoc1 , testVectors[i].assoc1Sz ,
5874158794 testVectors[i].nonce, testVectors[i].nonceSz,
5874258795 computedCiphertext, testVectors[i].plaintextSz,
5874358796 siv, computedPlaintext);
@@ -58751,6 +58804,47 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aes_siv_test(void)
5875158804 }
5875258805 }
5875358806
58807+ /* Then test "multiple Assoc" interface. */
58808+ for (i = 0; i < AES_SIV_TEST_VECTORS; ++i) {
58809+ const struct AesSivAssoc assoc[2] = {
58810+ { testVectors[i].assoc1, testVectors[i].assoc1Sz },
58811+ { testVectors[i].assoc2, testVectors[i].assoc2Sz }
58812+ };
58813+
58814+ ret = wc_AesSivEncrypt_ex(testVectors[i].key, testVectors[i].keySz,
58815+ assoc, testVectors[i].numAssoc,
58816+ testVectors[i].nonce, testVectors[i].nonceSz,
58817+ testVectors[i].plaintext,
58818+ testVectors[i].plaintextSz, siv,
58819+ computedCiphertext);
58820+ if (ret != 0) {
58821+ return WC_TEST_RET_ENC_EC(ret);
58822+ }
58823+ ret = XMEMCMP(siv, testVectors[i].siv, AES_BLOCK_SIZE);
58824+ if (ret != 0) {
58825+ return WC_TEST_RET_ENC_NC;
58826+ }
58827+ ret = XMEMCMP(computedCiphertext, testVectors[i].ciphertext,
58828+ testVectors[i].ciphertextSz);
58829+ if (ret != 0) {
58830+ return WC_TEST_RET_ENC_NC;
58831+ }
58832+ ret = wc_AesSivDecrypt_ex(testVectors[i].key, testVectors[i].keySz,
58833+ assoc, testVectors[i].numAssoc,
58834+ testVectors[i].nonce, testVectors[i].nonceSz,
58835+ computedCiphertext,
58836+ testVectors[i].plaintextSz, siv,
58837+ computedPlaintext);
58838+ if (ret != 0) {
58839+ return WC_TEST_RET_ENC_EC(ret);
58840+ }
58841+ ret = XMEMCMP(computedPlaintext, testVectors[i].plaintext,
58842+ testVectors[i].plaintextSz);
58843+ if (ret != 0) {
58844+ return WC_TEST_RET_ENC_NC;
58845+ }
58846+ }
58847+
5875458848 return 0;
5875558849}
5875658850#endif
0 commit comments