Skip to content

Commit 9e2a7b3

Browse files
authored
Feature/multiple aes siv ads (#7911)
* Proposed new interface for AesSivEncrypt with number of ADs != 1. * Implement AES SIV S2V computation with a number of ADs not equal to 1. * Add Example A.1 from RFC5297 to AES SIV test vectors. * Add tests for new AES SIV interface, and add test vectors for examples given in RFC5297. * Include the nonce in count of maximum number of ADs. * Addressing review comments. * Addressing review comments: Use uppercase 'U' suffix on unsigned constant. * Rename local variables named 'ad0' to 'ad', since the zero makes no sense, especially since in the RFC 5297 document they're actually counting the ADs from 1.
1 parent 088dfab commit 9e2a7b3

3 files changed

Lines changed: 183 additions & 29 deletions

File tree

wolfcrypt/src/aes.c

Lines changed: 68 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -13609,7 +13609,7 @@ int wc_AesXtsDecryptConsecutiveSectors(XtsAes* aes, byte* out, const byte* in,
1360913609
* See RFC 5297 Section 2.4.
1361013610
*/
1361113611
static WARN_UNUSED_RESULT int S2V(
13612-
const byte* key, word32 keySz, const byte* assoc, word32 assocSz,
13612+
const byte* key, word32 keySz, const AesSivAssoc* assoc, word32 numAssoc,
1361313613
const byte* nonce, word32 nonceSz, const byte* data,
1361413614
word32 dataSz, byte* out)
1361513615
{
@@ -13623,6 +13623,8 @@ static WARN_UNUSED_RESULT int S2V(
1362313623
#endif
1362413624
word32 macSz = AES_BLOCK_SIZE;
1362513625
int ret = 0;
13626+
byte tmpi = 0;
13627+
word32 ai;
1362613628
word32 zeroBytes;
1362713629

1362813630
#ifdef WOLFSSL_SMALL_STACK
@@ -13635,32 +13637,48 @@ static WARN_UNUSED_RESULT int S2V(
1363513637
}
1363613638
if (ret == 0)
1363713639
#endif
13638-
{
13640+
13641+
if ((numAssoc > 126) || ((nonceSz > 0) && (numAssoc > 125))) {
13642+
/* See RFC 5297 Section 7. */
13643+
WOLFSSL_MSG("Maximum number of ADs (including the nonce) for AES SIV is"
13644+
" 126.");
13645+
ret = BAD_FUNC_ARG;
13646+
}
13647+
13648+
if (ret == 0) {
1363913649
XMEMSET(tmp[1], 0, AES_BLOCK_SIZE);
1364013650
XMEMSET(tmp[2], 0, AES_BLOCK_SIZE);
1364113651

1364213652
ret = wc_AesCmacGenerate(tmp[0], &macSz, tmp[1], AES_BLOCK_SIZE,
1364313653
key, keySz);
13644-
if (ret == 0) {
13645-
ShiftAndXorRb(tmp[1], tmp[0]);
13646-
ret = wc_AesCmacGenerate(tmp[0], &macSz, assoc, assocSz, key,
13647-
keySz);
13648-
if (ret == 0) {
13649-
xorbuf(tmp[1], tmp[0], AES_BLOCK_SIZE);
13650-
}
13651-
}
1365213654
}
1365313655

1365413656
if (ret == 0) {
13655-
if (nonceSz > 0) {
13656-
ShiftAndXorRb(tmp[0], tmp[1]);
13657-
ret = wc_AesCmacGenerate(tmp[1], &macSz, nonce, nonceSz, key,
13658-
keySz);
13657+
/* Loop over authenticated associated data AD1..ADn */
13658+
for (ai = 0; ai < numAssoc; ++ai) {
13659+
ShiftAndXorRb(tmp[1-tmpi], tmp[tmpi]);
13660+
ret = wc_AesCmacGenerate(tmp[tmpi], &macSz, assoc[ai].assoc,
13661+
assoc[ai].assocSz, key, keySz);
13662+
if (ret != 0)
13663+
break;
13664+
xorbuf(tmp[1-tmpi], tmp[tmpi], AES_BLOCK_SIZE);
13665+
tmpi = 1 - tmpi;
13666+
}
13667+
13668+
/* Add nonce as final AD. See RFC 5297 Section 3. */
13669+
if ((ret == 0) && (nonceSz > 0)) {
13670+
ShiftAndXorRb(tmp[1-tmpi], tmp[tmpi]);
13671+
ret = wc_AesCmacGenerate(tmp[tmpi], &macSz, nonce,
13672+
nonceSz, key, keySz);
1365913673
if (ret == 0) {
13660-
xorbuf(tmp[0], tmp[1], AES_BLOCK_SIZE);
13674+
xorbuf(tmp[1-tmpi], tmp[tmpi], AES_BLOCK_SIZE);
1366113675
}
13676+
tmpi = 1 - tmpi;
1366213677
}
13663-
else {
13678+
13679+
/* For simplicity of the remaining code, make sure the "final" result
13680+
is always in tmp[0]. */
13681+
if (tmpi == 1) {
1366413682
XMEMCPY(tmp[0], tmp[1], AES_BLOCK_SIZE);
1366513683
}
1366613684
}
@@ -13727,8 +13745,8 @@ static WARN_UNUSED_RESULT int S2V(
1372713745
}
1372813746

1372913747
static WARN_UNUSED_RESULT int AesSivCipher(
13730-
const byte* key, word32 keySz, const byte* assoc,
13731-
word32 assocSz, const byte* nonce, word32 nonceSz,
13748+
const byte* key, word32 keySz, const AesSivAssoc* assoc,
13749+
word32 numAssoc, const byte* nonce, word32 nonceSz,
1373213750
const byte* data, word32 dataSz, byte* siv, byte* out,
1373313751
int enc)
1373413752
{
@@ -13752,7 +13770,7 @@ static WARN_UNUSED_RESULT int AesSivCipher(
1375213770

1375313771
if (ret == 0) {
1375413772
if (enc == 1) {
13755-
ret = S2V(key, keySz / 2, assoc, assocSz, nonce, nonceSz, data,
13773+
ret = S2V(key, keySz / 2, assoc, numAssoc, nonce, nonceSz, data,
1375613774
dataSz, sivTmp);
1375713775
if (ret != 0) {
1375813776
WOLFSSL_MSG("S2V failed.");
@@ -13799,7 +13817,7 @@ static WARN_UNUSED_RESULT int AesSivCipher(
1379913817
}
1380013818

1380113819
if (ret == 0 && enc == 0) {
13802-
ret = S2V(key, keySz / 2, assoc, assocSz, nonce, nonceSz, out, dataSz,
13820+
ret = S2V(key, keySz / 2, assoc, numAssoc, nonce, nonceSz, out, dataSz,
1380313821
sivTmp);
1380413822
if (ret != 0) {
1380513823
WOLFSSL_MSG("S2V failed.");
@@ -13826,7 +13844,10 @@ int wc_AesSivEncrypt(const byte* key, word32 keySz, const byte* assoc,
1382613844
word32 assocSz, const byte* nonce, word32 nonceSz,
1382713845
const byte* in, word32 inSz, byte* siv, byte* out)
1382813846
{
13829-
return AesSivCipher(key, keySz, assoc, assocSz, nonce, nonceSz, in, inSz,
13847+
AesSivAssoc ad;
13848+
ad.assoc = assoc;
13849+
ad.assocSz = assocSz;
13850+
return AesSivCipher(key, keySz, &ad, 1U, nonce, nonceSz, in, inSz,
1383013851
siv, out, 1);
1383113852
}
1383213853

@@ -13837,7 +13858,32 @@ int wc_AesSivDecrypt(const byte* key, word32 keySz, const byte* assoc,
1383713858
word32 assocSz, const byte* nonce, word32 nonceSz,
1383813859
const byte* in, word32 inSz, byte* siv, byte* out)
1383913860
{
13840-
return AesSivCipher(key, keySz, assoc, assocSz, nonce, nonceSz, in, inSz,
13861+
AesSivAssoc ad;
13862+
ad.assoc = assoc;
13863+
ad.assocSz = assocSz;
13864+
return AesSivCipher(key, keySz, &ad, 1U, nonce, nonceSz, in, inSz,
13865+
siv, out, 0);
13866+
}
13867+
13868+
/*
13869+
* See RFC 5297 Section 2.6.
13870+
*/
13871+
int wc_AesSivEncrypt_ex(const byte* key, word32 keySz, const AesSivAssoc* assoc,
13872+
word32 numAssoc, const byte* nonce, word32 nonceSz,
13873+
const byte* in, word32 inSz, byte* siv, byte* out)
13874+
{
13875+
return AesSivCipher(key, keySz, assoc, numAssoc, nonce, nonceSz, in, inSz,
13876+
siv, out, 1);
13877+
}
13878+
13879+
/*
13880+
* See RFC 5297 Section 2.7.
13881+
*/
13882+
int wc_AesSivDecrypt_ex(const byte* key, word32 keySz, const AesSivAssoc* assoc,
13883+
word32 numAssoc, const byte* nonce, word32 nonceSz,
13884+
const byte* in, word32 inSz, byte* siv, byte* out)
13885+
{
13886+
return AesSivCipher(key, keySz, assoc, numAssoc, nonce, nonceSz, in, inSz,
1384113887
siv, out, 0);
1384213888
}
1384313889

wolfcrypt/test/test.c

Lines changed: 101 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -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

5863358636
WOLFSSL_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

wolfssl/wolfcrypt/aes.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -728,6 +728,11 @@ WOLFSSL_API int wc_AesInit_Label(Aes* aes, const char* label, void* heap,
728728
WOLFSSL_API void wc_AesFree(Aes* aes);
729729

730730
#ifdef WOLFSSL_AES_SIV
731+
typedef struct AesSivAssoc {
732+
const byte* assoc;
733+
word32 assocSz;
734+
} AesSivAssoc;
735+
731736
WOLFSSL_API
732737
int wc_AesSivEncrypt(const byte* key, word32 keySz, const byte* assoc,
733738
word32 assocSz, const byte* nonce, word32 nonceSz,
@@ -736,6 +741,15 @@ WOLFSSL_API
736741
int wc_AesSivDecrypt(const byte* key, word32 keySz, const byte* assoc,
737742
word32 assocSz, const byte* nonce, word32 nonceSz,
738743
const byte* in, word32 inSz, byte* siv, byte* out);
744+
745+
WOLFSSL_API
746+
int wc_AesSivEncrypt_ex(const byte* key, word32 keySz, const AesSivAssoc* assoc,
747+
word32 numAssoc, const byte* nonce, word32 nonceSz,
748+
const byte* in, word32 inSz, byte* siv, byte* out);
749+
WOLFSSL_API
750+
int wc_AesSivDecrypt_ex(const byte* key, word32 keySz, const AesSivAssoc* assoc,
751+
word32 numAssoc, const byte* nonce, word32 nonceSz,
752+
const byte* in, word32 inSz, byte* siv, byte* out);
739753
#endif
740754

741755
#ifdef WOLFSSL_AES_EAX

0 commit comments

Comments
 (0)