Skip to content

Commit 6d3a5d5

Browse files
committed
Fix AES GCM MC/DC test configuration and setup
1 parent fb57eec commit 6d3a5d5

2 files changed

Lines changed: 27 additions & 17 deletions

File tree

‎tests/api/test_aes.c‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5367,7 +5367,8 @@ int test_wc_AesGcmStream_ReinitAfterFinal(void)
53675367
#endif
53685368
#endif
53695369
return EXPECT_RESULT();
5370-
}
5370+
} /* END test_wc_AesGcmStream_ReinitAfterFinal */
5371+
53715372
/*
53725373
* MC/DC for the stream wc_AesGcmEncryptFinal() invocation-count guard
53735374
* (aes.c, stream builds):
@@ -5395,7 +5396,7 @@ int test_wc_AesGcmStreamMcdc(void)
53955396
{
53965397
EXPECT_DECLS;
53975398
#if !defined(NO_AES) && defined(WOLFSSL_AES_128) && defined(HAVE_AESGCM) && \
5398-
defined(WOLFSSL_AESGCM_STREAM)
5399+
defined(WOLFSSL_AESGCM_STREAM) && !defined(WC_NO_RNG)
53995400
WC_RNG rng[1];
54005401
Aes aes[1];
54015402
byte key[AES_128_KEY_SIZE] = { 0 };
@@ -5439,7 +5440,7 @@ int test_wc_AesGcmStreamMcdc(void)
54395440
ExpectIntEQ(wc_AesInit(aes, NULL, INVALID_DEVID), 0);
54405441
ExpectIntEQ(wc_AesGcmInit(aes, key, sizeof(key), iv, sizeof(iv)), 0);
54415442
ExpectIntEQ(wc_AesGcmSetIV(aes, GCM_NONCE_MID_SZ, NULL, 0, rng), 0);
5442-
ExpectIntEQ(wc_AesGcmEncryptFinal(aes, tag, 5),
5443+
ExpectIntEQ(wc_AesGcmEncryptFinal(aes, tag, WC_AES_BLOCK_SIZE + 1),
54435444
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
54445445
wc_AesFree(aes);
54455446

@@ -5461,7 +5462,7 @@ int test_wc_AesGcmStreamMcdc(void)
54615462
wc_FreeRng(rng);
54625463
#endif
54635464
return EXPECT_RESULT();
5464-
}
5465+
} /* END test_wc_AesGcmStreamMcdc */
54655466

54665467
int test_wc_AesGcmStream_BadAuthTag(void)
54675468
{

‎tests/unit-mcdc/test_aes_whitebox.c‎

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1311,10 +1311,6 @@ static void wb_gcmccm_pending(void)
13111311
return;
13121312
}
13131313

1314-
/* Zero the device table (a zeroed slot has devId==0, not INVALID_DEVID,
1315-
* so registration finds no free slot until this runs). */
1316-
wc_CryptoCb_Init();
1317-
13181314
/* GCM: baseline (ret==0) then PENDING. */
13191315
mcdc_cb_uninstall();
13201316
if (wc_AesInit(&aes, NULL, MCDC_CB_DEVID) == 0 &&
@@ -1741,7 +1737,8 @@ static void wb_slow_vaes(void)
17411737
* GcmCountInvocation() on every call, which is enough to drive all three
17421738
* operand rows.
17431739
* ------------------------------------------------------------------------- */
1744-
#if !defined(NO_AES) && defined(HAVE_AESGCM) && defined(WOLFSSL_AES_128)
1740+
#if !defined(NO_AES) && defined(HAVE_AESGCM) && defined(WOLFSSL_AES_128) && \
1741+
!defined(WC_NO_RNG)
17451742
static void wb_gcm_count_invocation(void)
17461743
{
17471744
Aes aes;
@@ -1757,14 +1754,23 @@ static void wb_gcm_count_invocation(void)
17571754
XMEMSET(key, 0x61, sizeof(key));
17581755
XMEMSET(in, 0x62, sizeof(in));
17591756

1760-
if (wc_AesInit(&aes, NULL, INVALID_DEVID) != 0 ||
1761-
wc_InitRng(&rng) != 0 ||
1762-
wc_AesGcmSetKey(&aes, key, sizeof(key)) != 0 ||
1757+
if (wc_AesInit(&aes, NULL, INVALID_DEVID) != 0) {
1758+
WB_NOTE("wc_AesInit failed (GcmCountInvocation skipped)");
1759+
wb_fail = 1;
1760+
return;
1761+
}
1762+
if (wc_InitRng(&rng) != 0) {
1763+
WB_NOTE("wc_InitRng failed (GcmCountInvocation skipped)");
1764+
wb_fail = 1;
1765+
wc_AesFree(&aes);
1766+
return;
1767+
}
1768+
if (wc_AesGcmSetKey(&aes, key, sizeof(key)) != 0 ||
17631769
wc_AesGcmSetIV(&aes, sizeof(iv), NULL, 0, &rng) != 0) {
17641770
WB_NOTE("GCM setup failed (GcmCountInvocation skipped)");
17651771
wb_fail = 1;
1766-
if (rng.status == 0)
1767-
wc_FreeRng(&rng);
1772+
wc_FreeRng(&rng);
1773+
wc_AesFree(&aes);
17681774
return;
17691775
}
17701776

@@ -1799,7 +1805,7 @@ static void wb_gcm_count_invocation(void)
17991805
}
18001806
#else
18011807
static void wb_gcm_count_invocation(void)
1802-
{ WB_NOTE("AESGCM off; GcmCountInvocation guard skipped"); }
1808+
{ WB_NOTE("GcmCountInvocation prerequisites unavailable"); }
18031809
#endif
18041810

18051811
/* ------------------------------------------------------------------------- *
@@ -1866,7 +1872,7 @@ static void wb_getkeysize_claimed(void)
18661872
* first byte stops it at i == 0 (idx0 T, idx1 F).
18671873
* ------------------------------------------------------------------------- */
18681874
#if !defined(NO_AES) && defined(HAVE_AESGCM) && defined(WOLFSSL_AES_128) && \
1869-
defined(WOLF_CRYPTO_CB)
1875+
defined(WOLF_CRYPTO_CB) && !defined(WC_NO_RNG)
18701876
static byte wb_rng_fill;
18711877

18721878
static int wb_rng_fill_cb(int devId, wc_CryptoInfo* info, void* ctx)
@@ -1923,7 +1929,7 @@ static void wb_gcm_setiv_carry(void)
19231929
}
19241930
#else
19251931
static void wb_gcm_setiv_carry(void)
1926-
{ WB_NOTE("AESGCM/WOLF_CRYPTO_CB off; GcmSetIV carry scan skipped"); }
1932+
{ WB_NOTE("GcmSetIV carry scan prerequisites unavailable"); }
19271933
#endif
19281934

19291935
/* ------------------------------------------------------------------------- *
@@ -2038,6 +2044,9 @@ int main(void)
20382044
printf(" NO_AES defined; nothing to exercise\n");
20392045
return 0;
20402046
#else
2047+
#ifdef WOLF_CRYPTO_CB
2048+
wc_CryptoCb_Init();
2049+
#endif
20412050
wb_ghash_classic();
20422051
wb_ghash_update();
20432052
wb_aesnew_common();

0 commit comments

Comments
 (0)