Skip to content
Open
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 @@ -40,7 +40,7 @@ ARCHFLAGS ?=
# Enable extra C compiler warnings
CFLAGS_EXTRA = -Werror -Wall -Wextra
# Place functions / data into separate sections to allow unused code removal
CFLAGS_EXTRA += -ffunction-sections -fdata-sections
CFLAGS_EXTRA += -ffunction-sections -fdata-sections -Wdeclaration-after-statement

# C standard to use (default to c90 if not specified)
CSTD ?= -std=c90
Expand Down
10 changes: 5 additions & 5 deletions benchmark/bench_modules/wh_bench_mod_curve25519.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,16 @@ uint8_t key2_der[] = {
int wh_Bench_Mod_Curve25519KeyGen(whClientContext* client,
whBenchOpContext* ctx, int id, void* params)
{
(void)client;
(void)params;

int ret = 0;
curve25519_key key[1] = {0};
WC_RNG rng[1] = {0};
int i;
int initialized_rng = 0;
int initialized_key = 0;

(void)client;
(void)params;

/* Initialize the RNG for key generation */
ret = wc_InitRng_ex(rng, NULL, WH_DEV_ID);
if (ret != 0) {
Expand Down Expand Up @@ -126,8 +126,6 @@ int wh_Bench_Mod_Curve25519SharedSecret(whClientContext* client,
whBenchOpContext* ctx, int id,
void* params)
{
(void)params;

int ret = 0;
word32 outLen;
curve25519_key keyAlice[1] = {0};
Expand All @@ -140,6 +138,8 @@ int wh_Bench_Mod_Curve25519SharedSecret(whClientContext* client,
whKeyId keyIdBob = WH_KEYID_ERASED;
char keyLabel[] = "bench-key";

(void)params;

/* Cache Alice's key in the HSM */
ret = wh_Client_KeyCache(client, WH_NVM_FLAGS_USAGE_ANY, (uint8_t*)keyLabel,
strlen(keyLabel), key1_der, sizeof(key1_der),
Expand Down
4 changes: 2 additions & 2 deletions benchmark/bench_modules/wh_bench_mod_ecc.c
Original file line number Diff line number Diff line change
Expand Up @@ -293,15 +293,15 @@ int _benchEccVerify(whClientContext* client, whBenchOpContext* ctx, int id,
int _benchEccKeyGen(whClientContext* client, whBenchOpContext* ctx, int id,
int curveSize, int devId)
{
(void)client;

int ret = 0;
ecc_key key[1] = {0};
WC_RNG rng[1] = {0};
int i;
int initialized_rng = 0;
int initialized_key = 0;

(void)client;

/* Initialize the RNG for key generation */
ret = wc_InitRng_ex(rng, NULL, devId);
if (ret != 0) {
Expand Down
4 changes: 2 additions & 2 deletions benchmark/bench_modules/wh_bench_mod_echo.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@
int wh_Bench_Mod_Echo(whClientContext* client, whBenchOpContext* benchCtx,
int id, void* params)
{
(void)params;

int i;
int ret;
uint16_t send_len;
Expand All @@ -36,6 +34,8 @@ int wh_Bench_Mod_Echo(whClientContext* client, whBenchOpContext* benchCtx,
int startRet;
int stopRet;

(void)params;

/* Send an entire comm buffer's worth of data */
memset(send_buffer, 0xAA, sizeof(send_buffer));
memset(recv_buffer, 0x55, sizeof(recv_buffer));
Expand Down
4 changes: 2 additions & 2 deletions benchmark/bench_modules/wh_bench_mod_hmac.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ static const size_t keyLen = sizeof(key) - 1; /* -1 for null terminator */
int _benchHmacSha256(whClientContext* client, whBenchOpContext* ctx, int id,
int devId)
{
(void)client;

int ret = 0;
Hmac hmac[1];
uint8_t out[WC_SHA256_DIGEST_SIZE];
Expand All @@ -44,6 +42,8 @@ int _benchHmacSha256(whClientContext* client, whBenchOpContext* ctx, int id,
const uint8_t* in;
size_t inLen;

(void)client;

#if defined(WOLFHSM_CFG_DMA)
if (devId == WH_DEV_ID_DMA) {
in = WH_BENCH_DMA_BUFFER;
Expand Down
5 changes: 3 additions & 2 deletions benchmark/bench_modules/wh_bench_mod_mldsa.c
Original file line number Diff line number Diff line change
Expand Up @@ -898,15 +898,16 @@ static int _benchMlDsaVerify(whClientContext* client, whBenchOpContext* ctx,
static int _benchMlDsaKeyGen(whClientContext* client, whBenchOpContext* ctx,
int id, int securityLevel, int devId)
{
(void)client;

int ret = 0;
MlDsaKey key;
WC_RNG rng[1] = {0};
int i;
int initialized_rng = 0;
int initialized_key = 0;

(void)client;


/* Initialize the RNG */
ret = wc_InitRng_ex(rng, NULL, devId);
if (ret != 0) {
Expand Down
4 changes: 2 additions & 2 deletions benchmark/bench_modules/wh_bench_mod_rng.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@

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

int ret = 0;
WC_RNG rng;
int i = 0;
int rngInitialized = 0;
uint8_t* out = WH_BENCH_DATA_OUT_BUFFER;
word32 outLen = WOLFHSM_CFG_BENCH_DATA_BUFFER_SIZE;

(void)client;

ret = wc_InitRng_ex(&rng, NULL, devId);
if (ret != 0) {
WH_BENCH_PRINTF("Failed to wc_InitRng_ex %d\n", ret);
Expand Down
11 changes: 6 additions & 5 deletions benchmark/bench_modules/wh_bench_mod_rsa.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
* You should have received a copy of the GNU General Public License
* along with wolfHSM. If not, see <http://www.gnu.org/licenses/>.
*/
#include <string.h>
#include "wh_bench_mod.h"
#include "wolfhsm/wh_error.h"
#include "wolfhsm/wh_client.h"
Expand Down Expand Up @@ -384,10 +385,10 @@ int _benchRsaCrypt(whClientContext* client, whBenchOpContext* ctx, int id,
goto exit;
}

strcpy((char*)inBuf, inStr);
strncpy((char*)inBuf, inStr, sizeof(inBuf)-1);

/* Do an initial encryption to get the size of the output */
encSz = ret = wc_RsaPublicEncrypt(inBuf, sizeof(inStr), outBuf,
encSz = ret = wc_RsaPublicEncrypt(inBuf, strlen(inStr), outBuf,
sizeof(outBuf), rsa, rng);
if (ret < 0) {
WH_BENCH_PRINTF("Failed to wc_RsaPublicEncrypt %d\n", ret);
Expand All @@ -408,7 +409,7 @@ int _benchRsaCrypt(whClientContext* client, whBenchOpContext* ctx, int id,

if (operation == RSA_PUBLIC_ENCRYPT) {
benchStartRet = wh_Bench_StartOp(ctx, id);
opRet = wc_RsaPublicEncrypt(inBuf, sizeof(inStr), outBuf,
opRet = wc_RsaPublicEncrypt(inBuf, strlen(inStr), outBuf,
sizeof(outBuf), rsa, rng);
benchStopRet = wh_Bench_StopOp(ctx, id);
}
Expand Down Expand Up @@ -696,8 +697,6 @@ int _benchRsaSign(whClientContext* client, whBenchOpContext* ctx, int id,
int _benchRsaKeyGen(whClientContext* client, whBenchOpContext* ctx, int id,
int keySize, int devId)
{
(void)client;

int ret = 0;
RsaKey rsa[1];
WC_RNG rng[1];
Expand All @@ -706,6 +705,8 @@ int _benchRsaKeyGen(whClientContext* client, whBenchOpContext* ctx, int id,
int initialized_rsa = 0;
long exponent = WC_RSA_EXPONENT; /* Standard RSA exponent (65537) */

(void)client;

/* Initialize RNG for RSA operations */
ret = wc_InitRng_ex(rng, NULL, devId);
if (ret != 0) {
Expand Down
16 changes: 8 additions & 8 deletions benchmark/bench_modules/wh_bench_mod_sha2.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@
int _benchSha256(whClientContext* client, whBenchOpContext* ctx, int id,
int devId)
{
(void)client;

int ret = 0;
wc_Sha256* sha256 = NULL;
wc_Sha256 sha256Stack;
Expand All @@ -46,6 +44,8 @@ int _benchSha256(whClientContext* client, whBenchOpContext* ctx, int id,
const uint8_t* in;
size_t inLen;

(void)client;

sha256 = &sha256Stack;
out = outStack;

Expand Down Expand Up @@ -192,8 +192,6 @@ int wh_Bench_Mod_Sha256Dma(whClientContext* client, whBenchOpContext* ctx,
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];
Expand All @@ -202,6 +200,8 @@ int _benchSha224(whClientContext* client, whBenchOpContext* ctx, int id,
const uint8_t* in;
size_t inLen;

(void)client;

#if defined(WOLFHSM_CFG_DMA)
if (devId == WH_DEV_ID_DMA) {
in = WH_BENCH_DMA_BUFFER;
Expand Down Expand Up @@ -313,8 +313,6 @@ int wh_Bench_Mod_Sha224Dma(whClientContext* client, whBenchOpContext* ctx,
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];
Expand All @@ -323,6 +321,8 @@ int _benchSha384(whClientContext* client, whBenchOpContext* ctx, int id,
const uint8_t* in;
size_t inLen;

(void)client;

#if defined(WOLFHSM_CFG_DMA)
if (devId == WH_DEV_ID_DMA) {
in = WH_BENCH_DMA_BUFFER;
Expand Down Expand Up @@ -433,8 +433,6 @@ int wh_Bench_Mod_Sha384Dma(whClientContext* client, whBenchOpContext* ctx,
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];
Expand All @@ -443,6 +441,8 @@ int _benchSha512(whClientContext* client, whBenchOpContext* ctx, int id,
const uint8_t* in;
size_t inLen;

(void)client;

#if defined(WOLFHSM_CFG_DMA)
if (devId == WH_DEV_ID_DMA) {
in = WH_BENCH_DMA_BUFFER;
Expand Down
39 changes: 20 additions & 19 deletions benchmark/wh_bench.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@
/* Buffer sizes for transport */
/* Large enough to handle an RSA 4096 key */
#define BUFFER_SIZE \
sizeof(whTransportMemCsr) + sizeof(whCommHeader) + WOLFHSM_CFG_COMM_DATA_LEN
(sizeof(whTransportMemCsr) + sizeof(whCommHeader) + \
WOLFHSM_CFG_COMM_DATA_LEN)
#define FLASH_RAM_SIZE (1024 * 1024) /* 1MB */

typedef struct BenchModule {
Expand Down Expand Up @@ -826,14 +827,14 @@ static void _whBenchClientServerThreadTest(whClientConfig* c_conf,
rc = pthread_create(&cthread, NULL, _whBenchClientTask, &clientData);
if (rc == 0) {
/* Wait for client to finish, then cancel server */
pthread_join(cthread, &retval);
pthread_cancel(sthread);
pthread_join(sthread, &retval);
(void)pthread_join(cthread, &retval);
(void)pthread_cancel(sthread);
(void)pthread_join(sthread, &retval);
}
else {
/* If client thread creation failed, cancel server */
pthread_cancel(sthread);
pthread_join(sthread, &retval);
(void)pthread_cancel(sthread);
(void)pthread_join(sthread, &retval);
}
}
}
Expand Down Expand Up @@ -1029,19 +1030,6 @@ int wh_Bench_ClientServer_Posix(int transport, int moduleIndex)
/* Server configuration/contexts */
whServerConfig s_conf[1] = {{0}};

/* Configure transport based on type */
ret = _configureClientTransport(transport, c_conf);
if (ret != WH_ERROR_OK) {
WH_BENCH_PRINTF("Failed to configure client transport: %d\n", ret);
return ret;
}

ret = _configureServerTransport(transport, s_conf);
if (ret != WH_ERROR_OK) {
WH_BENCH_PRINTF("Failed to configure server transport: %d\n", ret);
return ret;
}

/* RamSim Flash state and configuration */
whFlashRamsimCtx fc[1] = {0};
whFlashRamsimCfg fc_conf[1] = {{
Expand Down Expand Up @@ -1076,6 +1064,19 @@ int wh_Bench_ClientServer_Posix(int transport, int moduleIndex)
}};
#endif

/* Configure transport based on type */
ret = _configureClientTransport(transport, c_conf);
if (ret != WH_ERROR_OK) {
WH_BENCH_PRINTF("Failed to configure client transport: %d\n", ret);
return ret;
}

ret = _configureServerTransport(transport, s_conf);
if (ret != WH_ERROR_OK) {
WH_BENCH_PRINTF("Failed to configure server transport: %d\n", ret);
return ret;
}

/* Set up server configuration with NVM and crypto */
s_conf[0].nvm = nvm;
#ifndef WOLFHSM_CFG_NO_CRYPTO
Expand Down
3 changes: 2 additions & 1 deletion benchmark/wh_bench_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ int main(int argc, char** argv)
int transport = WH_BENCH_TRANSPORT_MEM;
int moduleIndex = -1;
int i;
int ret = 0;

WH_BENCH_PRINTF("wolfHSM POSIX benchmark built with wolfSSL version %s\n",
LIBWOLFSSL_VERSION_STRING);
Expand Down Expand Up @@ -82,7 +83,7 @@ int main(int argc, char** argv)
}

#if defined(WOLFHSM_CFG_TEST_POSIX)
int ret = wh_Bench_ClientServer_Posix(transport, moduleIndex);
ret = wh_Bench_ClientServer_Posix(transport, moduleIndex);
if (ret != 0) {
WH_BENCH_PRINTF("Memory transport benchmark failed: %d\n", ret);
return ret;
Expand Down
20 changes: 10 additions & 10 deletions benchmark/wh_bench_ops.c
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@ int wh_Bench_PrintResults(whBenchOpContext* ctx)
{
int i;
uint64_t avgTime;
char buffer[20] = {0};

if (ctx == NULL) {
return WH_ERROR_BADARGS;
Expand Down Expand Up @@ -340,33 +341,32 @@ int wh_Bench_PrintResults(whBenchOpContext* ctx)
(unsigned long long)ctx->ops[i].maxTimeUs);

/* Print throughput - directly using printf with formatting */
char buffer[20] = {0};
if (ctx->ops[i].throughputType == BENCH_THROUGHPUT_XBPS) {
double throughput = ctx->ops[i].throughput;

if (throughput < 1024.0) {
/* Bytes per second */
WH_BENCH_SNPRINTF(buffer, sizeof(buffer), "%.2f B/s",
throughput);
(void)WH_BENCH_SNPRINTF(buffer, sizeof(buffer), "%.2f B/s",
throughput);
}
else if (throughput < 1024.0 * 1024.0) {
/* Kilobytes per second */
WH_BENCH_SNPRINTF(buffer, sizeof(buffer), "%.2f KB/s",
throughput / 1024.0);
(void)WH_BENCH_SNPRINTF(buffer, sizeof(buffer), "%.2f KB/s",
throughput / 1024.0);
}
else {
/* Megabytes per second */
WH_BENCH_SNPRINTF(buffer, sizeof(buffer), "%.2f MB/s",
throughput / (1024.0 * 1024.0));
(void)WH_BENCH_SNPRINTF(buffer, sizeof(buffer), "%.2f MB/s",
throughput / (1024.0 * 1024.0));
}
}
else if (ctx->ops[i].throughputType == BENCH_THROUGHPUT_OPS) {
WH_BENCH_SNPRINTF(buffer, sizeof(buffer), "%.2f ops/s",
ctx->ops[i].throughput);
(void)WH_BENCH_SNPRINTF(buffer, sizeof(buffer), "%.2f ops/s",
ctx->ops[i].throughput);
}
else {
/* No throughput */
WH_BENCH_SNPRINTF(buffer, sizeof(buffer), "N/A");
(void)WH_BENCH_SNPRINTF(buffer, sizeof(buffer), "N/A");
}
WH_BENCH_PRINTF("%-18s |\n", buffer);
}
Expand Down
Loading