Skip to content
Merged
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
2 changes: 1 addition & 1 deletion benchmark/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ CSTD ?= -std=c90

ASFLAGS ?= $(ARCHFLAGS)
CFLAGS ?= $(ARCHFLAGS) $(CSTD) $(CFLAGS_EXTRA)
LDFLAGS ?= $(ARCHFLAGS)
LDFLAGS ?= $(ARCHFLAGS)

# Enable garbage collection. Inexact handling of dead_strip
OS_NAME := $(shell uname -s | tr A-Z a-z)
Expand Down
14 changes: 14 additions & 0 deletions benchmark/bench_modules/wh_bench_mod_all.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,21 @@ int wh_Bench_Mod_Sha256(whClientContext* client, whBenchOpContext* ctx, int id,

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

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

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

int wh_Bench_Mod_Sha512Dma(whClientContext* client, whBenchOpContext* ctx,
int id, void* params);
/*
* SHA3 benchmark module prototypes (wh_bench_mod_sha3.c)
*/
Expand Down
363 changes: 363 additions & 0 deletions benchmark/bench_modules/wh_bench_mod_sha2.c
Original file line number Diff line number Diff line change
Expand Up @@ -146,4 +146,367 @@ int wh_Bench_Mod_Sha256Dma(whClientContext* client, whBenchOpContext* ctx,

#endif /* !defined(NO_SHA256) */


#if defined(WOLFSSL_SHA224)

int _benchSha224(whClientContext* client, whBenchOpContext* ctx, int id,
int devId)
{
(void)client;

int ret = 0;
wc_Sha224 sha224[1];
uint8_t out[WC_SHA224_DIGEST_SIZE];
int i = 0;
int sha224Initialized = 0;
const uint8_t* in;
size_t inLen;

#if defined(WOLFHSM_CFG_DMA)
if (devId == WH_DEV_ID_DMA) {
in = WH_BENCH_DMA_BUFFER;
inLen = WOLFHSM_CFG_BENCH_DMA_BUFFER_SIZE;
}
else
#endif
{
in = WH_BENCH_DATA_IN_BUFFER;
inLen = WOLFHSM_CFG_BENCH_DATA_BUFFER_SIZE;
#if defined(WOLFHSM_CFG_BENCH_INIT_DATA_BUFFERS)
memset(WH_BENCH_DATA_IN_BUFFER, 0xAA, inLen);
#endif
}

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

for (i = 0; i < WOLFHSM_CFG_BENCH_CRYPT_ITERS; i++) {
int benchStartRet;
int benchStopRet;
int initRet;
int updateRet;
int finalRet;

/* Defer error checking until after all operations are complete */
benchStartRet = wh_Bench_StartOp(ctx, id);
initRet = wc_InitSha224_ex(sha224, NULL, devId);
updateRet = wc_Sha224Update(sha224, in, inLen);
finalRet = wc_Sha224Final(sha224, out);
benchStopRet = wh_Bench_StopOp(ctx, id);

/* Check for errors after all operations are complete */
if (benchStartRet != 0) {
WH_BENCH_PRINTF("Failed to wh_Bench_StartOp: %d\n", benchStartRet);
ret = benchStartRet;
break;
}
if (initRet != 0) {
WH_BENCH_PRINTF("Failed to wc_InitSha224_ex %d\n", initRet);
ret = initRet;
break;
}

sha224Initialized = 1;

if (updateRet != 0) {
WH_BENCH_PRINTF("Failed to wc_Sha224Update %d\n", updateRet);
ret = updateRet;
break;
}
if (finalRet != 0) {
WH_BENCH_PRINTF("Failed to wc_Sha224Final %d\n", finalRet);
ret = finalRet;
break;
}
if (benchStopRet != 0) {
WH_BENCH_PRINTF("Failed to wh_Bench_StopOp: %d\n", benchStopRet);
ret = benchStopRet;
break;
}
}

/* Only free SHA224 if it was initialized */
if (sha224Initialized) {
(void)wc_Sha224Free(sha224);
}

return ret;
}

int wh_Bench_Mod_Sha224(whClientContext* client, whBenchOpContext* ctx, int id,
void* params)
{
#if defined(WOLFHSM_CFG_DMA)
(void)params;
return _benchSha224(client, ctx, id, WH_DEV_ID);
#else
(void)client;
(void)ctx;
(void)id;
(void)params;
return WH_ERROR_NOTIMPL;
#endif
}

int wh_Bench_Mod_Sha224Dma(whClientContext* client, whBenchOpContext* ctx,
int id, void* params)
{
#if defined(WOLFHSM_CFG_DMA)
(void)params;
return _benchSha224(client, ctx, id, WH_DEV_ID_DMA);
#else
(void)client;
(void)ctx;
(void)id;
(void)params;
return WH_ERROR_NOTIMPL;
#endif
}

#endif /* WOLFSSL_SHA224 */

#if defined(WOLFSSL_SHA384)

int _benchSha384(whClientContext* client, whBenchOpContext* ctx, int id,
int devId)
{
(void)client;

int ret = 0;
wc_Sha384 sha384[1];
uint8_t out[WC_SHA384_DIGEST_SIZE];
int i = 0;
int sha384Initialized = 0;
const uint8_t* in;
size_t inLen;

#if defined(WOLFHSM_CFG_DMA)
if (devId == WH_DEV_ID_DMA) {
in = WH_BENCH_DMA_BUFFER;
inLen = WOLFHSM_CFG_BENCH_DMA_BUFFER_SIZE;
}
else
#endif
{
in = WH_BENCH_DATA_IN_BUFFER;
inLen = WOLFHSM_CFG_BENCH_DATA_BUFFER_SIZE;
#if defined(WOLFHSM_CFG_BENCH_INIT_DATA_BUFFERS)
memset(WH_BENCH_DATA_IN_BUFFER, 0xAA, inLen);
#endif
}

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

for (i = 0; i < WOLFHSM_CFG_BENCH_CRYPT_ITERS; i++) {
int benchStartRet;
int benchStopRet;
int initRet;
int updateRet;
int finalRet;

/* Defer error checking until after all operations are complete */
benchStartRet = wh_Bench_StartOp(ctx, id);
initRet = wc_InitSha384_ex(sha384, NULL, devId);
updateRet = wc_Sha384Update(sha384, in, inLen);
finalRet = wc_Sha384Final(sha384, out);
benchStopRet = wh_Bench_StopOp(ctx, id);

/* Check for errors after all operations are complete */
if (benchStartRet != 0) {
WH_BENCH_PRINTF("Failed to wh_Bench_StartOp: %d\n", benchStartRet);
ret = benchStartRet;
break;
}
if (initRet != 0) {
WH_BENCH_PRINTF("Failed to wc_InitSha384_ex %d\n", initRet);
ret = initRet;
break;
}

sha384Initialized = 1;

if (updateRet != 0) {
WH_BENCH_PRINTF("Failed to wc_Sha384Update %d\n", updateRet);
ret = updateRet;
break;
}
if (finalRet != 0) {
WH_BENCH_PRINTF("Failed to wc_Sha384Final %d\n", finalRet);
ret = finalRet;
break;
}
if (benchStopRet != 0) {
WH_BENCH_PRINTF("Failed to wh_Bench_StopOp: %d\n", benchStopRet);
ret = benchStopRet;
break;
}
}

/* Only free SHA384 if it was initialized */
if (sha384Initialized) {
(void)wc_Sha384Free(sha384);
}

return ret;
}

int wh_Bench_Mod_Sha384(whClientContext* client, whBenchOpContext* ctx, int id,
void* params)
{
#if defined(WOLFHSM_CFG_DMA)
(void)params;
return _benchSha384(client, ctx, id, WH_DEV_ID);
#else
(void)client;
(void)ctx;
(void)id;
(void)params;
return WH_ERROR_NOTIMPL;
#endif
}

int wh_Bench_Mod_Sha384Dma(whClientContext* client, whBenchOpContext* ctx,
int id, void* params)
{
#if defined(WOLFHSM_CFG_DMA)
(void)params;
return _benchSha384(client, ctx, id, WH_DEV_ID_DMA);
#else
(void)client;
(void)ctx;
(void)id;
(void)params;
return WH_ERROR_NOTIMPL;
#endif
}

#endif /* WOLFSSL_SHA384 */
#if defined(WOLFSSL_SHA512)

int _benchSha512(whClientContext* client, whBenchOpContext* ctx, int id,
int devId)
{
(void)client;

int ret = 0;
wc_Sha512 sha512[1];
uint8_t out[WC_SHA512_DIGEST_SIZE];
int i = 0;
int sha512Initialized = 0;
const uint8_t* in;
size_t inLen;

#if defined(WOLFHSM_CFG_DMA)
if (devId == WH_DEV_ID_DMA) {
in = WH_BENCH_DMA_BUFFER;
inLen = WOLFHSM_CFG_BENCH_DMA_BUFFER_SIZE;
}
else
#endif
{
in = WH_BENCH_DATA_IN_BUFFER;
inLen = WOLFHSM_CFG_BENCH_DATA_BUFFER_SIZE;
#if defined(WOLFHSM_CFG_BENCH_INIT_DATA_BUFFERS)
memset(WH_BENCH_DATA_IN_BUFFER, 0xAA, inLen);
#endif
}

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

for (i = 0; i < WOLFHSM_CFG_BENCH_CRYPT_ITERS; i++) {
int benchStartRet;
int benchStopRet;
int initRet;
int updateRet;
int finalRet;

/* Defer error checking until after all operations are complete */
benchStartRet = wh_Bench_StartOp(ctx, id);
initRet = wc_InitSha512_ex(sha512, NULL, devId);
updateRet = wc_Sha512Update(sha512, in, inLen);
finalRet = wc_Sha512Final(sha512, out);
benchStopRet = wh_Bench_StopOp(ctx, id);

/* Check for errors after all operations are complete */
if (benchStartRet != 0) {
WH_BENCH_PRINTF("Failed to wh_Bench_StartOp: %d\n", benchStartRet);
ret = benchStartRet;
break;
}
if (initRet != 0) {
WH_BENCH_PRINTF("Failed to wc_InitSha512_ex %d\n", initRet);
ret = initRet;
break;
}

sha512Initialized = 1;

if (updateRet != 0) {
WH_BENCH_PRINTF("Failed to wc_Sha512Update %d\n", updateRet);
ret = updateRet;
break;
}
if (finalRet != 0) {
WH_BENCH_PRINTF("Failed to wc_Sha512Final %d\n", finalRet);
ret = finalRet;
break;
}
if (benchStopRet != 0) {
WH_BENCH_PRINTF("Failed to wh_Bench_StopOp: %d\n", benchStopRet);
ret = benchStopRet;
break;
}
}

/* Only free SHA512 if it was initialized */
if (sha512Initialized) {
(void)wc_Sha512Free(sha512);
}

return ret;
}

int wh_Bench_Mod_Sha512(whClientContext* client, whBenchOpContext* ctx, int id,
void* params)
{
#if defined(WOLFHSM_CFG_DMA)
(void)params;
return _benchSha512(client, ctx, id, WH_DEV_ID);
#else
(void)client;
(void)ctx;
(void)id;
(void)params;
return WH_ERROR_NOTIMPL;
#endif
}

int wh_Bench_Mod_Sha512Dma(whClientContext* client, whBenchOpContext* ctx,
int id, void* params)
{
#if defined(WOLFHSM_CFG_DMA)
(void)params;
return _benchSha512(client, ctx, id, WH_DEV_ID_DMA);
#else
(void)client;
(void)ctx;
(void)id;
(void)params;
return WH_ERROR_NOTIMPL;
#endif
}

#endif /* WOLFSSL_SHA512 */

#endif /* WOLFHSM_CFG_BENCH_ENABLE */
Loading