Skip to content

Commit cafea6b

Browse files
committed
Add test/bench_AesEcbInit helper
1 parent 95059b0 commit cafea6b

File tree

2 files changed

+60
-5
lines changed

2 files changed

+60
-5
lines changed

wolfcrypt/benchmark/benchmark.c

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

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

58275847
/* init keys */
58285848
for (i = 0; i < BENCH_MAX_PENDING; i++) {
5829-
if ((ret = wc_AesInit(enc[i], HEAP_HINT,
5849+
if ((ret = bench_AesEcbInit(enc[i], HEAP_HINT,
58305850
useDeviceID ? devId: INVALID_DEVID)) != 0) {
58315851
printf("AesInit failed at L%d, ret = %d\n", __LINE__, ret);
58325852
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)
@@ -1362,6 +1383,20 @@ static WC_MAYBE_UNUSED Aes* test_AesCbcNew(void* heap, int declaredDevId,
13621383
}
13631384
#endif /* !NO_AES && HAVE_AES_CBC */
13641385

1386+
#if !defined(NO_AES) && \
1387+
(defined(HAVE_AES_ECB) || defined(WOLFSSL_AES_DIRECT))
1388+
static WC_MAYBE_UNUSED Aes* test_AesEcbNew(void* heap, int declaredDevId,
1389+
int* ret)
1390+
{
1391+
#if defined(WOLF_PRIVATE_KEY_ID) && defined(WC_TEST_AES_ECB_ID)
1392+
return wc_AesNew_Id(testAesEcbId, testAesEcbIdLen, heap, declaredDevId,
1393+
ret);
1394+
#else
1395+
return wc_AesNew(heap, declaredDevId, ret);
1396+
#endif
1397+
}
1398+
#endif /* !NO_AES && (HAVE_AES_ECB || WOLFSSL_AES_DIRECT) */
1399+
13651400
#if !defined(NO_AES) && defined(HAVE_AESGCM)
13661401
static WC_MAYBE_UNUSED Aes* test_AesGcmNew(void* heap, int declaredDevId,
13671402
int* ret)
@@ -16767,20 +16802,20 @@ static wc_test_ret_t aes_ecb_direct_test(void)
1676716802
#endif
1676816803

1676916804
#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
16770-
enc = wc_AesNew(HEAP_HINT, devId, &ret);
16805+
enc = test_AesEcbNew(HEAP_HINT, devId, &ret);
1677116806
if (enc == NULL)
1677216807
ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
1677316808
#ifdef HAVE_AES_DECRYPT
16774-
dec = wc_AesNew(HEAP_HINT, devId, &ret);
16809+
dec = test_AesEcbNew(HEAP_HINT, devId, &ret);
1677516810
if (dec == NULL)
1677616811
ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
1677716812
#endif
1677816813
#else
16779-
ret = wc_AesInit(enc, HEAP_HINT, devId);
16814+
ret = test_AesEcbInit(enc, HEAP_HINT, devId);
1678016815
if (ret != 0)
1678116816
ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
1678216817
#ifdef HAVE_AES_DECRYPT
16783-
ret = wc_AesInit(dec, HEAP_HINT, devId);
16818+
ret = test_AesEcbInit(dec, HEAP_HINT, devId);
1678416819
if (ret != 0)
1678516820
ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
1678616821
#endif

0 commit comments

Comments
 (0)