Skip to content

Commit 48e8442

Browse files
committed
Add test/bench_AesEcbInit helper
1 parent c74f01a commit 48e8442

2 files changed

Lines changed: 60 additions & 5 deletions

File tree

wolfcrypt/benchmark/benchmark.c

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5080,6 +5080,26 @@ static WC_MAYBE_UNUSED int bench_CmacInit(Cmac* cmac, const byte* key,
50805080
}
50815081
#endif /* WOLFSSL_CMAC */
50825082

5083+
/* --- AES ECB --- */
5084+
#if defined(HAVE_AES_ECB) || \
5085+
(defined(HAVE_FIPS) && defined(WOLFSSL_AES_DIRECT))
5086+
#if defined(WOLF_PRIVATE_KEY_ID) && defined(WC_TEST_AES_ECB_ID)
5087+
static unsigned char benchAesEcbId[] = WC_TEST_AES_ECB_ID;
5088+
static int benchAesEcbIdLen = (int)sizeof(benchAesEcbId);
5089+
#endif
5090+
5091+
static WC_MAYBE_UNUSED int bench_AesEcbInit(Aes* aes, void* heap,
5092+
int declaredDevId)
5093+
{
5094+
#if defined(WOLF_PRIVATE_KEY_ID) && defined(WC_TEST_AES_ECB_ID)
5095+
return wc_AesInit_Id(aes, benchAesEcbId, benchAesEcbIdLen, heap,
5096+
declaredDevId);
5097+
#else
5098+
return wc_AesInit(aes, heap, declaredDevId);
5099+
#endif
5100+
}
5101+
#endif /* HAVE_AES_ECB || (HAVE_FIPS && WOLFSSL_AES_DIRECT) */
5102+
50835103
/* --- ECC --- */
50845104
#ifdef HAVE_ECC
50855105
#if defined(WOLF_PRIVATE_KEY_ID) && defined(WC_TEST_ECC_PAIR_P256_ID)
@@ -5827,7 +5847,7 @@ static void bench_aesecb_internal(int useDeviceID,
58275847

58285848
/* init keys */
58295849
for (i = 0; i < BENCH_MAX_PENDING; i++) {
5830-
if ((ret = wc_AesInit(enc[i], HEAP_HINT,
5850+
if ((ret = bench_AesEcbInit(enc[i], HEAP_HINT,
58315851
useDeviceID ? devId: INVALID_DEVID)) != 0) {
58325852
printf("AesInit failed at L%d, ret = %d\n", __LINE__, ret);
58335853
goto exit;

wolfcrypt/test/test.c

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -582,6 +582,27 @@ static WC_MAYBE_UNUSED int test_AesCbcInit(Aes* aes, void* heap,
582582

583583
#endif /* !NO_AES && HAVE_AES_CBC */
584584

585+
/* --- AES ECB id[] and init helper --- */
586+
#if !defined(NO_AES) && \
587+
(defined(HAVE_AES_ECB) || defined(WOLFSSL_AES_DIRECT))
588+
#if defined(WOLF_PRIVATE_KEY_ID) && defined(WC_TEST_AES_ECB_ID)
589+
static unsigned char testAesEcbId[] = WC_TEST_AES_ECB_ID;
590+
static int testAesEcbIdLen = (int)sizeof(testAesEcbId);
591+
#endif
592+
593+
static WC_MAYBE_UNUSED int test_AesEcbInit(Aes* aes, void* heap,
594+
int declaredDevId)
595+
{
596+
#if defined(WOLF_PRIVATE_KEY_ID) && defined(WC_TEST_AES_ECB_ID)
597+
return wc_AesInit_Id(aes, testAesEcbId, testAesEcbIdLen, heap,
598+
declaredDevId);
599+
#else
600+
return wc_AesInit(aes, heap, declaredDevId);
601+
#endif
602+
}
603+
604+
#endif /* !NO_AES && (HAVE_AES_ECB || WOLFSSL_AES_DIRECT) */
605+
585606
/* --- AES GCM id[] and init helper --- */
586607
#if !defined(NO_AES) && defined(HAVE_AESGCM)
587608
#if defined(WOLF_PRIVATE_KEY_ID) && defined(WC_TEST_AES_GCM_ID)
@@ -1366,6 +1387,20 @@ static WC_MAYBE_UNUSED Aes* test_AesCbcNew(void* heap, int declaredDevId,
13661387
}
13671388
#endif /* !NO_AES && HAVE_AES_CBC */
13681389

1390+
#if !defined(NO_AES) && \
1391+
(defined(HAVE_AES_ECB) || defined(WOLFSSL_AES_DIRECT))
1392+
static WC_MAYBE_UNUSED Aes* test_AesEcbNew(void* heap, int declaredDevId,
1393+
int* ret)
1394+
{
1395+
#if defined(WOLF_PRIVATE_KEY_ID) && defined(WC_TEST_AES_ECB_ID)
1396+
return wc_AesNew_Id(testAesEcbId, testAesEcbIdLen, heap, declaredDevId,
1397+
ret);
1398+
#else
1399+
return wc_AesNew(heap, declaredDevId, ret);
1400+
#endif
1401+
}
1402+
#endif /* !NO_AES && (HAVE_AES_ECB || WOLFSSL_AES_DIRECT) */
1403+
13691404
#if !defined(NO_AES) && defined(HAVE_AESGCM)
13701405
static WC_MAYBE_UNUSED Aes* test_AesGcmNew(void* heap, int declaredDevId,
13711406
int* ret)
@@ -16806,20 +16841,20 @@ static wc_test_ret_t aes_ecb_direct_test(void)
1680616841
#endif
1680716842

1680816843
#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
16809-
enc = wc_AesNew(HEAP_HINT, devId, &ret);
16844+
enc = test_AesEcbNew(HEAP_HINT, devId, &ret);
1681016845
if (enc == NULL)
1681116846
ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
1681216847
#ifdef HAVE_AES_DECRYPT
16813-
dec = wc_AesNew(HEAP_HINT, devId, &ret);
16848+
dec = test_AesEcbNew(HEAP_HINT, devId, &ret);
1681416849
if (dec == NULL)
1681516850
ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
1681616851
#endif
1681716852
#else
16818-
ret = wc_AesInit(enc, HEAP_HINT, devId);
16853+
ret = test_AesEcbInit(enc, HEAP_HINT, devId);
1681916854
if (ret != 0)
1682016855
ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
1682116856
#ifdef HAVE_AES_DECRYPT
16822-
ret = wc_AesInit(dec, HEAP_HINT, devId);
16857+
ret = test_AesEcbInit(dec, HEAP_HINT, devId);
1682316858
if (ret != 0)
1682416859
ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
1682516860
#endif

0 commit comments

Comments
 (0)