Skip to content

Commit f5027fc

Browse files
committed
Fix AES GCM MC/DC test configuration and setup
1 parent bdf3662 commit f5027fc

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
@@ -1309,10 +1309,6 @@ static void wb_gcmccm_pending(void)
13091309
return;
13101310
}
13111311

1312-
/* Zero the device table (a zeroed slot has devId==0, not INVALID_DEVID,
1313-
* so registration finds no free slot until this runs). */
1314-
wc_CryptoCb_Init();
1315-
13161312
/* GCM: baseline (ret==0) then PENDING. */
13171313
mcdc_cb_uninstall();
13181314
if (wc_AesInit(&aes, NULL, MCDC_CB_DEVID) == 0 &&
@@ -1739,7 +1735,8 @@ static void wb_slow_vaes(void)
17391735
* GcmCountInvocation() on every call, which is enough to drive all three
17401736
* operand rows.
17411737
* ------------------------------------------------------------------------- */
1742-
#if !defined(NO_AES) && defined(HAVE_AESGCM) && defined(WOLFSSL_AES_128)
1738+
#if !defined(NO_AES) && defined(HAVE_AESGCM) && defined(WOLFSSL_AES_128) && \
1739+
!defined(WC_NO_RNG)
17431740
static void wb_gcm_count_invocation(void)
17441741
{
17451742
Aes aes;
@@ -1755,14 +1752,23 @@ static void wb_gcm_count_invocation(void)
17551752
XMEMSET(key, 0x61, sizeof(key));
17561753
XMEMSET(in, 0x62, sizeof(in));
17571754

1758-
if (wc_AesInit(&aes, NULL, INVALID_DEVID) != 0 ||
1759-
wc_InitRng(&rng) != 0 ||
1760-
wc_AesGcmSetKey(&aes, key, sizeof(key)) != 0 ||
1755+
if (wc_AesInit(&aes, NULL, INVALID_DEVID) != 0) {
1756+
WB_NOTE("wc_AesInit failed (GcmCountInvocation skipped)");
1757+
wb_fail = 1;
1758+
return;
1759+
}
1760+
if (wc_InitRng(&rng) != 0) {
1761+
WB_NOTE("wc_InitRng failed (GcmCountInvocation skipped)");
1762+
wb_fail = 1;
1763+
wc_AesFree(&aes);
1764+
return;
1765+
}
1766+
if (wc_AesGcmSetKey(&aes, key, sizeof(key)) != 0 ||
17611767
wc_AesGcmSetIV(&aes, sizeof(iv), NULL, 0, &rng) != 0) {
17621768
WB_NOTE("GCM setup failed (GcmCountInvocation skipped)");
17631769
wb_fail = 1;
1764-
if (rng.status == 0)
1765-
wc_FreeRng(&rng);
1770+
wc_FreeRng(&rng);
1771+
wc_AesFree(&aes);
17661772
return;
17671773
}
17681774

@@ -1797,7 +1803,7 @@ static void wb_gcm_count_invocation(void)
17971803
}
17981804
#else
17991805
static void wb_gcm_count_invocation(void)
1800-
{ WB_NOTE("AESGCM off; GcmCountInvocation guard skipped"); }
1806+
{ WB_NOTE("GcmCountInvocation prerequisites unavailable"); }
18011807
#endif
18021808

18031809
/* ------------------------------------------------------------------------- *
@@ -1864,7 +1870,7 @@ static void wb_getkeysize_claimed(void)
18641870
* first byte stops it at i == 0 (idx0 T, idx1 F).
18651871
* ------------------------------------------------------------------------- */
18661872
#if !defined(NO_AES) && defined(HAVE_AESGCM) && defined(WOLFSSL_AES_128) && \
1867-
defined(WOLF_CRYPTO_CB)
1873+
defined(WOLF_CRYPTO_CB) && !defined(WC_NO_RNG)
18681874
static byte wb_rng_fill;
18691875

18701876
static int wb_rng_fill_cb(int devId, wc_CryptoInfo* info, void* ctx)
@@ -1921,7 +1927,7 @@ static void wb_gcm_setiv_carry(void)
19211927
}
19221928
#else
19231929
static void wb_gcm_setiv_carry(void)
1924-
{ WB_NOTE("AESGCM/WOLF_CRYPTO_CB off; GcmSetIV carry scan skipped"); }
1930+
{ WB_NOTE("GcmSetIV carry scan prerequisites unavailable"); }
19251931
#endif
19261932

19271933
/* ------------------------------------------------------------------------- *
@@ -2036,6 +2042,9 @@ int main(void)
20362042
printf(" NO_AES defined; nothing to exercise\n");
20372043
return 0;
20382044
#else
2045+
#ifdef WOLF_CRYPTO_CB
2046+
wc_CryptoCb_Init();
2047+
#endif
20392048
wb_ghash_classic();
20402049
wb_ghash_update();
20412050
wb_aesnew_common();

0 commit comments

Comments
 (0)