Fix for RX TSIP AES GCM 128 unit test resultP/C sizes causing failure.

pull/8206/head
David Garske 2024-11-20 13:48:05 -08:00
parent d109f38cbd
commit c5e43280b9
1 changed files with 44 additions and 32 deletions

View File

@ -408,10 +408,10 @@ static int tsip_aesgcm256_test(int prnt, tsip_aes_key_index_t* aes256_key)
printf(" tsip_aes256_gcm_test() "); printf(" tsip_aes256_gcm_test() ");
} }
ForceZero(resultT, sizeof(resultT)); XMEMSET(resultT, 0, sizeof(resultT));
ForceZero(resultC, sizeof(resultC)); XMEMSET(resultC, 0, sizeof(resultC));
ForceZero(resultP, sizeof(resultP)); XMEMSET(resultP, 0, sizeof(resultP));
ForceZero(&userContext, sizeof(TsipUserCtx)); XMEMSET(&userContext, 0, sizeof(TsipUserCtx));
if (wc_AesInit(enc, NULL, INVALID_DEVID) != 0) { if (wc_AesInit(enc, NULL, INVALID_DEVID) != 0) {
ret = -1; ret = -1;
@ -434,10 +434,11 @@ static int tsip_aesgcm256_test(int prnt, tsip_aes_key_index_t* aes256_key)
} }
/* AES-GCM encrypt and decrypt both use AES encrypt internally */ /* AES-GCM encrypt and decrypt both use AES encrypt internally */
result = wc_tsip_AesGcmEncrypt(enc, resultC, p, sizeof(p), result = wc_tsip_AesGcmEncrypt(enc,
resultC, p, sizeof(p),
(byte*)iv1, sizeof(iv1), resultT, sizeof(resultT), (byte*)iv1, sizeof(iv1), resultT, sizeof(resultT),
a, sizeof(a), &userContext); a, sizeof(a), &userContext
);
if (result != 0) { if (result != 0) {
ret = -4; ret = -4;
goto out; goto out;
@ -451,9 +452,11 @@ static int tsip_aesgcm256_test(int prnt, tsip_aes_key_index_t* aes256_key)
dec->ctx.keySize = enc->keylen; dec->ctx.keySize = enc->keylen;
} }
result = wc_tsip_AesGcmDecrypt(dec, resultP, resultC, sizeof(c1), result = wc_tsip_AesGcmDecrypt(dec,
resultP, resultC, sizeof(c1),
iv1, sizeof(iv1), resultT, sizeof(resultT), iv1, sizeof(iv1), resultT, sizeof(resultT),
a, sizeof(a), &userContext); a, sizeof(a), &userContext
);
if (result != 0){ if (result != 0){
ret = -8; ret = -8;
goto out; goto out;
@ -469,18 +472,21 @@ static int tsip_aesgcm256_test(int prnt, tsip_aes_key_index_t* aes256_key)
wc_AesGcmSetKey(enc, k1, sizeof(k1)); wc_AesGcmSetKey(enc, k1, sizeof(k1));
/* AES-GCM encrypt and decrypt both use AES encrypt internally */ /* AES-GCM encrypt and decrypt both use AES encrypt internally */
result = wc_tsip_AesGcmEncrypt(enc, resultC, p, sizeof(p), iv1, sizeof(iv1), result = wc_tsip_AesGcmEncrypt(enc,
resultC, p, sizeof(p), iv1, sizeof(iv1),
resultT + 1, sizeof(resultT) - 1, resultT + 1, sizeof(resultT) - 1,
a, sizeof(a), &userContext); a, sizeof(a), &userContext
);
if (result != 0) { if (result != 0) {
ret = -10; ret = -10;
goto out; goto out;
} }
result = wc_tsip_AesGcmDecrypt(enc, resultP, resultC, sizeof(p), result = wc_tsip_AesGcmDecrypt(enc,
resultP, resultC, sizeof(p),
iv1, sizeof(iv1), resultT + 1, sizeof(resultT) - 1, iv1, sizeof(iv1), resultT + 1, sizeof(resultT) - 1,
a, sizeof(a), &userContext); a, sizeof(a), &userContext
);
if (result != 0) { if (result != 0) {
ret = -11; ret = -11;
goto out; goto out;
@ -568,9 +574,9 @@ static int tsip_aesgcm128_test(int prnt, tsip_aes_key_index_t* aes128_key)
0x31, 0x2e, 0x2a, 0xf9, 0x57, 0x7a, 0x1e, 0xa6 0x31, 0x2e, 0x2a, 0xf9, 0x57, 0x7a, 0x1e, 0xa6
}; };
byte resultT[16]; byte resultT[sizeof(t3)];
byte resultP[60 + AES_BLOCK_SIZE]; byte resultP[sizeof(p3) + AES_BLOCK_SIZE];
byte resultC[60 + AES_BLOCK_SIZE]; byte resultC[sizeof(p3) + AES_BLOCK_SIZE];
int result = 0; int result = 0;
int ret; int ret;
@ -581,10 +587,10 @@ static int tsip_aesgcm128_test(int prnt, tsip_aes_key_index_t* aes128_key)
printf(" tsip_aes128_gcm_test() "); printf(" tsip_aes128_gcm_test() ");
} }
ForceZero(resultT, sizeof(resultT)); XMEMSET(resultT, 0, sizeof(resultT));
ForceZero(resultC, sizeof(resultC)); XMEMSET(resultC, 0, sizeof(resultC));
ForceZero(resultP, sizeof(resultP)); XMEMSET(resultP, 0, sizeof(resultP));
ForceZero(&userContext, sizeof(TsipUserCtx)); XMEMSET(&userContext, 0, sizeof(TsipUserCtx));
if (wc_AesInit(enc, NULL, INVALID_DEVID) != 0) { if (wc_AesInit(enc, NULL, INVALID_DEVID) != 0) {
ret = -1; ret = -1;
@ -607,21 +613,27 @@ static int tsip_aesgcm128_test(int prnt, tsip_aes_key_index_t* aes128_key)
enc->ctx.keySize = enc->keylen; enc->ctx.keySize = enc->keylen;
} }
/* AES-GCM encrypt and decrypt both use AES encrypt internally */ /* AES-GCM encrypt and decrypt both use AES encrypt internally */
result = wc_tsip_AesGcmEncrypt(enc, resultC, p3, sizeof(p3), result = wc_tsip_AesGcmEncrypt(enc,
resultC, p3, sizeof(p3),
iv3, sizeof(iv3), iv3, sizeof(iv3),
resultT, sizeof(t3), resultT, sizeof(t3),
a3, sizeof(a3), &userContext); a3, sizeof(a3), &userContext
);
if (result != 0) { if (result != 0) {
ret = -4; ret = -4;
goto out; goto out;
} }
result = wc_tsip_AesGcmDecrypt(enc, resultP, resultC, sizeof(c3),
result = wc_tsip_AesGcmDecrypt(enc,
resultP, resultC, sizeof(c3),
iv3, sizeof(iv3), resultT, sizeof(resultT), iv3, sizeof(iv3), resultT, sizeof(resultT),
a3, sizeof(a3), &userContext); a3, sizeof(a3), &userContext
);
if (result != 0) { if (result != 0) {
ret = -5; ret = -5;
goto out; goto out;
} }
if (XMEMCMP(p3, resultP, sizeof(p3))) { if (XMEMCMP(p3, resultP, sizeof(p3))) {
ret = -6; ret = -6;
goto out; goto out;