Skip to content

Commit ef08f21

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

2 files changed

Lines changed: 57 additions & 5 deletions

File tree

wolfcrypt/benchmark/benchmark.c

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

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

58275846
/* init keys */
58285847
for (i = 0; i < BENCH_MAX_PENDING; i++) {
5829-
if ((ret = wc_AesInit(enc[i], HEAP_HINT,
5848+
if ((ret = bench_AesEcbInit(enc[i], HEAP_HINT,
58305849
useDeviceID ? devId: INVALID_DEVID)) != 0) {
58315850
printf("AesInit failed at L%d, ret = %d\n", __LINE__, ret);
58325851
goto exit;

wolfcrypt/test/test.c

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -582,6 +582,26 @@ 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) && defined(HAVE_AES_ECB)
587+
#if defined(WOLF_PRIVATE_KEY_ID) && defined(WC_TEST_AES_ECB_ID)
588+
static unsigned char testAesEcbId[] = WC_TEST_AES_ECB_ID;
589+
static int testAesEcbIdLen = (int)sizeof(testAesEcbId);
590+
#endif
591+
592+
static WC_MAYBE_UNUSED int test_AesEcbInit(Aes* aes, void* heap,
593+
int declaredDevId)
594+
{
595+
#if defined(WOLF_PRIVATE_KEY_ID) && defined(WC_TEST_AES_ECB_ID)
596+
return wc_AesInit_Id(aes, testAesEcbId, testAesEcbIdLen, heap,
597+
declaredDevId);
598+
#else
599+
return wc_AesInit(aes, heap, declaredDevId);
600+
#endif
601+
}
602+
603+
#endif /* !NO_AES && HAVE_AES_ECB */
604+
585605
/* --- AES GCM id[] and init helper --- */
586606
#if !defined(NO_AES) && defined(HAVE_AESGCM)
587607
#if defined(WOLF_PRIVATE_KEY_ID) && defined(WC_TEST_AES_GCM_ID)
@@ -1362,6 +1382,19 @@ static WC_MAYBE_UNUSED Aes* test_AesCbcNew(void* heap, int declaredDevId,
13621382
}
13631383
#endif /* !NO_AES && HAVE_AES_CBC */
13641384

1385+
#if !defined(NO_AES) && defined(HAVE_AES_ECB)
1386+
static WC_MAYBE_UNUSED Aes* test_AesEcbNew(void* heap, int declaredDevId,
1387+
int* ret)
1388+
{
1389+
#if defined(WOLF_PRIVATE_KEY_ID) && defined(WC_TEST_AES_ECB_ID)
1390+
return wc_AesNew_Id(testAesEcbId, testAesEcbIdLen, heap, declaredDevId,
1391+
ret);
1392+
#else
1393+
return wc_AesNew(heap, declaredDevId, ret);
1394+
#endif
1395+
}
1396+
#endif /* !NO_AES && HAVE_AES_ECB */
1397+
13651398
#if !defined(NO_AES) && defined(HAVE_AESGCM)
13661399
static WC_MAYBE_UNUSED Aes* test_AesGcmNew(void* heap, int declaredDevId,
13671400
int* ret)
@@ -16767,20 +16800,20 @@ static wc_test_ret_t aes_ecb_direct_test(void)
1676716800
#endif
1676816801

1676916802
#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
16770-
enc = wc_AesNew(HEAP_HINT, devId, &ret);
16803+
enc = test_AesEcbNew(HEAP_HINT, devId, &ret);
1677116804
if (enc == NULL)
1677216805
ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
1677316806
#ifdef HAVE_AES_DECRYPT
16774-
dec = wc_AesNew(HEAP_HINT, devId, &ret);
16807+
dec = test_AesEcbNew(HEAP_HINT, devId, &ret);
1677516808
if (dec == NULL)
1677616809
ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
1677716810
#endif
1677816811
#else
16779-
ret = wc_AesInit(enc, HEAP_HINT, devId);
16812+
ret = test_AesEcbInit(enc, HEAP_HINT, devId);
1678016813
if (ret != 0)
1678116814
ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
1678216815
#ifdef HAVE_AES_DECRYPT
16783-
ret = wc_AesInit(dec, HEAP_HINT, devId);
16816+
ret = test_AesEcbInit(dec, HEAP_HINT, devId);
1678416817
if (ret != 0)
1678516818
ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
1678616819
#endif

0 commit comments

Comments
 (0)