Skip to content

Commit c5e4328

Browse files
committed
Fix for RX TSIP AES GCM 128 unit test resultP/C sizes causing failure.
1 parent d109f38 commit c5e4328

1 file changed

Lines changed: 44 additions & 32 deletions

File tree

IDE/Renesas/e2studio/RX72N/EnvisionKit/wolfssl_demo/wolfssl_tsip_unit_test.c

Lines changed: 44 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -408,10 +408,10 @@ static int tsip_aesgcm256_test(int prnt, tsip_aes_key_index_t* aes256_key)
408408
printf(" tsip_aes256_gcm_test() ");
409409
}
410410

411-
ForceZero(resultT, sizeof(resultT));
412-
ForceZero(resultC, sizeof(resultC));
413-
ForceZero(resultP, sizeof(resultP));
414-
ForceZero(&userContext, sizeof(TsipUserCtx));
411+
XMEMSET(resultT, 0, sizeof(resultT));
412+
XMEMSET(resultC, 0, sizeof(resultC));
413+
XMEMSET(resultP, 0, sizeof(resultP));
414+
XMEMSET(&userContext, 0, sizeof(TsipUserCtx));
415415

416416
if (wc_AesInit(enc, NULL, INVALID_DEVID) != 0) {
417417
ret = -1;
@@ -434,10 +434,11 @@ static int tsip_aesgcm256_test(int prnt, tsip_aes_key_index_t* aes256_key)
434434
}
435435

436436
/* AES-GCM encrypt and decrypt both use AES encrypt internally */
437-
result = wc_tsip_AesGcmEncrypt(enc, resultC, p, sizeof(p),
438-
(byte*)iv1, sizeof(iv1), resultT, sizeof(resultT),
439-
a, sizeof(a), &userContext);
440-
437+
result = wc_tsip_AesGcmEncrypt(enc,
438+
resultC, p, sizeof(p),
439+
(byte*)iv1, sizeof(iv1), resultT, sizeof(resultT),
440+
a, sizeof(a), &userContext
441+
);
441442
if (result != 0) {
442443
ret = -4;
443444
goto out;
@@ -451,9 +452,11 @@ static int tsip_aesgcm256_test(int prnt, tsip_aes_key_index_t* aes256_key)
451452
dec->ctx.keySize = enc->keylen;
452453
}
453454

454-
result = wc_tsip_AesGcmDecrypt(dec, resultP, resultC, sizeof(c1),
455-
iv1, sizeof(iv1), resultT, sizeof(resultT),
456-
a, sizeof(a), &userContext);
455+
result = wc_tsip_AesGcmDecrypt(dec,
456+
resultP, resultC, sizeof(c1),
457+
iv1, sizeof(iv1), resultT, sizeof(resultT),
458+
a, sizeof(a), &userContext
459+
);
457460
if (result != 0){
458461
ret = -8;
459462
goto out;
@@ -469,18 +472,21 @@ static int tsip_aesgcm256_test(int prnt, tsip_aes_key_index_t* aes256_key)
469472

470473
wc_AesGcmSetKey(enc, k1, sizeof(k1));
471474
/* AES-GCM encrypt and decrypt both use AES encrypt internally */
472-
result = wc_tsip_AesGcmEncrypt(enc, resultC, p, sizeof(p), iv1, sizeof(iv1),
473-
resultT + 1, sizeof(resultT) - 1,
474-
a, sizeof(a), &userContext);
475+
result = wc_tsip_AesGcmEncrypt(enc,
476+
resultC, p, sizeof(p), iv1, sizeof(iv1),
477+
resultT + 1, sizeof(resultT) - 1,
478+
a, sizeof(a), &userContext
479+
);
475480
if (result != 0) {
476481
ret = -10;
477482
goto out;
478483
}
479484

480-
result = wc_tsip_AesGcmDecrypt(enc, resultP, resultC, sizeof(p),
481-
iv1, sizeof(iv1), resultT + 1, sizeof(resultT) - 1,
482-
a, sizeof(a), &userContext);
483-
485+
result = wc_tsip_AesGcmDecrypt(enc,
486+
resultP, resultC, sizeof(p),
487+
iv1, sizeof(iv1), resultT + 1, sizeof(resultT) - 1,
488+
a, sizeof(a), &userContext
489+
);
484490
if (result != 0) {
485491
ret = -11;
486492
goto out;
@@ -568,9 +574,9 @@ static int tsip_aesgcm128_test(int prnt, tsip_aes_key_index_t* aes128_key)
568574
0x31, 0x2e, 0x2a, 0xf9, 0x57, 0x7a, 0x1e, 0xa6
569575
};
570576

571-
byte resultT[16];
572-
byte resultP[60 + AES_BLOCK_SIZE];
573-
byte resultC[60 + AES_BLOCK_SIZE];
577+
byte resultT[sizeof(t3)];
578+
byte resultP[sizeof(p3) + AES_BLOCK_SIZE];
579+
byte resultC[sizeof(p3) + AES_BLOCK_SIZE];
574580
int result = 0;
575581
int ret;
576582

@@ -581,10 +587,10 @@ static int tsip_aesgcm128_test(int prnt, tsip_aes_key_index_t* aes128_key)
581587
printf(" tsip_aes128_gcm_test() ");
582588
}
583589

584-
ForceZero(resultT, sizeof(resultT));
585-
ForceZero(resultC, sizeof(resultC));
586-
ForceZero(resultP, sizeof(resultP));
587-
ForceZero(&userContext, sizeof(TsipUserCtx));
590+
XMEMSET(resultT, 0, sizeof(resultT));
591+
XMEMSET(resultC, 0, sizeof(resultC));
592+
XMEMSET(resultP, 0, sizeof(resultP));
593+
XMEMSET(&userContext, 0, sizeof(TsipUserCtx));
588594

589595
if (wc_AesInit(enc, NULL, INVALID_DEVID) != 0) {
590596
ret = -1;
@@ -607,21 +613,27 @@ static int tsip_aesgcm128_test(int prnt, tsip_aes_key_index_t* aes128_key)
607613
enc->ctx.keySize = enc->keylen;
608614
}
609615
/* AES-GCM encrypt and decrypt both use AES encrypt internally */
610-
result = wc_tsip_AesGcmEncrypt(enc, resultC, p3, sizeof(p3),
611-
iv3, sizeof(iv3),
612-
resultT, sizeof(t3),
613-
a3, sizeof(a3), &userContext);
616+
result = wc_tsip_AesGcmEncrypt(enc,
617+
resultC, p3, sizeof(p3),
618+
iv3, sizeof(iv3),
619+
resultT, sizeof(t3),
620+
a3, sizeof(a3), &userContext
621+
);
614622
if (result != 0) {
615623
ret = -4;
616624
goto out;
617625
}
618-
result = wc_tsip_AesGcmDecrypt(enc, resultP, resultC, sizeof(c3),
619-
iv3, sizeof(iv3), resultT, sizeof(resultT),
620-
a3, sizeof(a3), &userContext);
626+
627+
result = wc_tsip_AesGcmDecrypt(enc,
628+
resultP, resultC, sizeof(c3),
629+
iv3, sizeof(iv3), resultT, sizeof(resultT),
630+
a3, sizeof(a3), &userContext
631+
);
621632
if (result != 0) {
622633
ret = -5;
623634
goto out;
624635
}
636+
625637
if (XMEMCMP(p3, resultP, sizeof(p3))) {
626638
ret = -6;
627639
goto out;

0 commit comments

Comments
 (0)