Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
165 changes: 165 additions & 0 deletions benchmark/bench_modules/wh_bench_mod_aes.c
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,171 @@ int wh_Bench_Mod_Aes256CBCDecrypt(whClientContext* client,
return _benchAesCbc(client, ctx, id, (uint8_t*)key256, sizeof(key256),
DECRYPT);
}

#ifdef WOLFHSM_CFG_DMA
static int _benchAesCbcDma(whClientContext* client, whBenchOpContext* ctx,
int id, const uint8_t* key, size_t keyLen,
int encrypt)
{
int ret = 0;
int needEvict = 0;
whKeyId keyId = WH_KEYID_ERASED;
Aes aes[1];
char keyLabel[] = "key label";
byte iv[WC_AES_BLOCK_SIZE] = {0, 1, 2, 3, 4, 5, 6, 7,
8, 9, 10, 11, 12, 13, 14, 15};
const size_t inLen = WOLFHSM_CFG_BENCH_DMA_BUFFER_SIZE / 2;
int i;
const uint8_t* in = NULL;
uint8_t* out = NULL;

#if defined(WOLFHSM_CFG_TEST_POSIX)
/* Allocate buffers using XMALLOC with heap hints for DMA */
if (ctx->transportType == WH_BENCH_TRANSPORT_POSIX_DMA) {
void* heap =
posixTransportShm_GetDmaHeap(client->comm->transport_context);
in = XMALLOC(inLen, heap, DYNAMIC_TYPE_TMP_BUFFER);
if (in == NULL) {
WH_BENCH_PRINTF("Failed to allocate memory for DMA input\n");
return WH_ERROR_NOSPACE;
}

out = XMALLOC(inLen, heap, DYNAMIC_TYPE_TMP_BUFFER);
if (out == NULL) {
WH_BENCH_PRINTF("Failed to allocate memory for DMA output\n");
XFREE((uint8_t*)in, heap, DYNAMIC_TYPE_TMP_BUFFER);
return WH_ERROR_NOSPACE;
}
}
else
#endif /* WOLFHSM_CFG_TEST_POSIX */
{
in = WH_BENCH_DMA_BUFFER;
out = (uint8_t*)in + inLen;
}

#if defined(WOLFHSM_CFG_BENCH_INIT_DATA_BUFFERS)
/* Initialize the input buffer with something non-zero */
memset((uint8_t*)in, 0xAA, inLen);
memset(out, 0xAA, inLen);
#endif

/* Initialize the aes struct */
ret = wc_AesInit(aes, NULL, WH_DEV_ID);
if (ret != 0) {
WH_BENCH_PRINTF("Failed to wc_AesInit %d\n", ret);
goto exit;
}

/* cache the key on the HSM */
ret = wh_Client_KeyCache(client, 0, (uint8_t*)keyLabel, sizeof(keyLabel),
(uint8_t*)key, keyLen, &keyId);
if (ret != 0) {
WH_BENCH_PRINTF("Failed to wh_Client_KeyCache %d\n", ret);
goto exit;
}

needEvict = 1;

/* set the keyId on the struct */
ret = wh_Client_AesSetKeyId(aes, keyId);
if (ret != 0) {
WH_BENCH_PRINTF("Failed to wh_Client_SetKeyIdAes %d\n", ret);
goto exit;
}

ret = wh_Bench_SetDataSize(ctx, id, inLen);
if (ret != 0) {
WH_BENCH_PRINTF("Failed to wh_Bench_SetDataSize %d\n", ret);
goto exit;
}

/* Perform the benchmark */
for (i = 0; i < WOLFHSM_CFG_BENCH_CRYPT_ITERS; i++) {
int benchStartRet;
int benchStopRet;

/* Reset IV for each iteration to ensure independent operations */
memcpy(aes->reg, iv, WC_AES_BLOCK_SIZE);

benchStartRet = wh_Bench_StartOp(ctx, id);
ret = wh_Client_AesCbcDma(client, aes, encrypt, in, inLen, out);
benchStopRet = wh_Bench_StopOp(ctx, id);

if (benchStartRet != 0) {
WH_BENCH_PRINTF("Failed to wh_Bench_StartOp %d\n", benchStartRet);
ret = benchStartRet;
goto exit;
}
if (ret != 0) {
WH_BENCH_PRINTF("Failed to wh_Client_AesCbcDma %d\n", ret);
goto exit;
}
if (benchStopRet != 0) {
WH_BENCH_PRINTF("Failed to wh_Bench_StopOp %d\n", benchStopRet);
ret = benchStopRet;
goto exit;
}
}

exit:
if (needEvict) {
(void)wh_Client_KeyEvict(client, keyId);
}
wc_AesFree(aes);

#if defined(WOLFHSM_CFG_TEST_POSIX)
if (ctx->transportType == WH_BENCH_TRANSPORT_POSIX_DMA) {
void* heap =
posixTransportShm_GetDmaHeap(client->comm->transport_context);
if (in != NULL) {
XFREE((uint8_t*)in, heap, DYNAMIC_TYPE_TMP_BUFFER);
}
if (out != NULL) {
XFREE(out, heap, DYNAMIC_TYPE_TMP_BUFFER);
}
}
#endif /* WOLFHSM_CFG_TEST_POSIX */

return ret;
}

int wh_Bench_Mod_Aes128CBCEncryptDma(whClientContext* client,
whBenchOpContext* ctx, int id,
void* params)
{
(void)params;
return _benchAesCbcDma(client, ctx, id, (uint8_t*)key128, sizeof(key128),
ENCRYPT);
}

int wh_Bench_Mod_Aes128CBCDecryptDma(whClientContext* client,
whBenchOpContext* ctx, int id,
void* params)
{
(void)params;
return _benchAesCbcDma(client, ctx, id, (uint8_t*)key128, sizeof(key128),
DECRYPT);
}

int wh_Bench_Mod_Aes256CBCEncryptDma(whClientContext* client,
whBenchOpContext* ctx, int id,
void* params)
{
(void)params;
return _benchAesCbcDma(client, ctx, id, (uint8_t*)key256, sizeof(key256),
ENCRYPT);
}

int wh_Bench_Mod_Aes256CBCDecryptDma(whClientContext* client,
whBenchOpContext* ctx, int id,
void* params)
{
(void)params;
return _benchAesCbcDma(client, ctx, id, (uint8_t*)key256, sizeof(key256),
DECRYPT);
}
#endif /* WOLFHSM_CFG_DMA */
#endif /* HAVE_AES_CBC */

#if defined(HAVE_AESGCM)
Expand Down
16 changes: 16 additions & 0 deletions benchmark/bench_modules/wh_bench_mod_all.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,17 @@ int wh_Bench_Mod_Aes128ECBDecrypt(whClientContext* client,
int wh_Bench_Mod_Aes128CBCEncrypt(whClientContext* client,
whBenchOpContext* ctx, int id, void* params);

int wh_Bench_Mod_Aes128CBCEncryptDma(whClientContext* client,
whBenchOpContext* ctx, int id,
void* params);

int wh_Bench_Mod_Aes128CBCDecrypt(whClientContext* client,
whBenchOpContext* ctx, int id, void* params);

int wh_Bench_Mod_Aes128CBCDecryptDma(whClientContext* client,
whBenchOpContext* ctx, int id,
void* params);

int wh_Bench_Mod_Aes128GCMEncrypt(whClientContext* client,
whBenchOpContext* ctx, int id, void* params);

Expand Down Expand Up @@ -74,9 +82,17 @@ int wh_Bench_Mod_Aes256ECBDecrypt(whClientContext* client,
int wh_Bench_Mod_Aes256CBCEncrypt(whClientContext* client,
whBenchOpContext* ctx, int id, void* params);

int wh_Bench_Mod_Aes256CBCEncryptDma(whClientContext* client,
whBenchOpContext* ctx, int id,
void* params);

int wh_Bench_Mod_Aes256CBCDecrypt(whClientContext* client,
whBenchOpContext* ctx, int id, void* params);

int wh_Bench_Mod_Aes256CBCDecryptDma(whClientContext* client,
whBenchOpContext* ctx, int id,
void* params);

int wh_Bench_Mod_Aes256GCMEncrypt(whClientContext* client,
whBenchOpContext* ctx, int id, void* params);

Expand Down
8 changes: 8 additions & 0 deletions benchmark/wh_bench.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,12 @@ typedef enum BenchModuleIdx {
#if defined(HAVE_AES_CBC)
BENCH_MODULE_IDX_AES_128_CBC_ENCRYPT,
BENCH_MODULE_IDX_AES_128_CBC_DECRYPT,
BENCH_MODULE_IDX_AES_128_CBC_ENCRYPT_DMA,
BENCH_MODULE_IDX_AES_128_CBC_DECRYPT_DMA,
BENCH_MODULE_IDX_AES_256_CBC_ENCRYPT,
BENCH_MODULE_IDX_AES_256_CBC_DECRYPT,
BENCH_MODULE_IDX_AES_256_CBC_ENCRYPT_DMA,
BENCH_MODULE_IDX_AES_256_CBC_DECRYPT_DMA,
#endif /* HAVE_AES_CBC */
#if defined(HAVE_AESGCM)
BENCH_MODULE_IDX_AES_128_GCM_ENCRYPT,
Expand Down Expand Up @@ -269,8 +273,12 @@ static BenchModule g_benchModules[] = {
#if defined(HAVE_AES_CBC)
[BENCH_MODULE_IDX_AES_128_CBC_ENCRYPT] = {"AES-128-CBC-Encrypt", wh_Bench_Mod_Aes128CBCEncrypt, BENCH_THROUGHPUT_XBPS, 0, NULL},
[BENCH_MODULE_IDX_AES_128_CBC_DECRYPT] = {"AES-128-CBC-Decrypt", wh_Bench_Mod_Aes128CBCDecrypt, BENCH_THROUGHPUT_XBPS, 0, NULL},
[BENCH_MODULE_IDX_AES_128_CBC_ENCRYPT_DMA] = {"AES-128-CBC-Encrypt-DMA", wh_Bench_Mod_Aes128CBCEncryptDma, BENCH_THROUGHPUT_XBPS, 0, NULL},
[BENCH_MODULE_IDX_AES_128_CBC_DECRYPT_DMA] = {"AES-128-CBC-Decrypt-DMA", wh_Bench_Mod_Aes128CBCDecryptDma, BENCH_THROUGHPUT_XBPS, 0, NULL},
[BENCH_MODULE_IDX_AES_256_CBC_ENCRYPT] = {"AES-256-CBC-Encrypt", wh_Bench_Mod_Aes256CBCEncrypt, BENCH_THROUGHPUT_XBPS, 0, NULL},
[BENCH_MODULE_IDX_AES_256_CBC_DECRYPT] = {"AES-256-CBC-Decrypt", wh_Bench_Mod_Aes256CBCDecrypt, BENCH_THROUGHPUT_XBPS, 0, NULL},
[BENCH_MODULE_IDX_AES_256_CBC_ENCRYPT_DMA] = {"AES-256-CBC-Encrypt-DMA", wh_Bench_Mod_Aes256CBCEncryptDma, BENCH_THROUGHPUT_XBPS, 0, NULL},
[BENCH_MODULE_IDX_AES_256_CBC_DECRYPT_DMA] = {"AES-256-CBC-Decrypt-DMA", wh_Bench_Mod_Aes256CBCDecryptDma, BENCH_THROUGHPUT_XBPS, 0, NULL},
#endif /* HAVE_AES_CBC */
#if defined(HAVE_AESGCM)
[BENCH_MODULE_IDX_AES_128_GCM_ENCRYPT] = {"AES-128-GCM-Encrypt", wh_Bench_Mod_Aes128GCMEncrypt, BENCH_THROUGHPUT_XBPS, 0, NULL},
Expand Down
2 changes: 1 addition & 1 deletion benchmark/wh_bench_ops.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#include <stdint.h>

/* Maximum number of operations that can be registered */
#define MAX_BENCH_OPS 88
#define MAX_BENCH_OPS 92
/* Maximum length of operation name */
#define MAX_OP_NAME 64

Expand Down
Loading
Loading