Skip to content
Open
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
38 changes: 19 additions & 19 deletions wolfcrypt/benchmark/benchmark.c
Original file line number Diff line number Diff line change
Expand Up @@ -2548,7 +2548,7 @@ typedef enum bench_stat_type {

if (bstat == NULL) {
/* allocate new and put on list */
bstat = (bench_stats_t*)XMALLOC(sizeof(bench_stats_t), NULL,
bstat = (bench_stats_t*)XMALLOC(sizeof(bench_stats_t), HEAP_HINT,
DYNAMIC_TYPE_INFO);
if (bstat) {
XMEMSET(bstat, 0, sizeof(bench_stats_t));
Expand Down Expand Up @@ -3614,7 +3614,7 @@ static WC_INLINE void bench_stats_free(void)
bench_stats_t* bstat;
for (bstat = bench_stats_head; bstat != NULL; ) {
bench_stats_t* next = bstat->next;
XFREE(bstat, NULL, DYNAMIC_TYPE_INFO);
XFREE(bstat, HEAP_HINT, DYNAMIC_TYPE_INFO);
bstat = next;
}
bench_stats_head = NULL;
Expand Down Expand Up @@ -5968,7 +5968,7 @@ static void bench_aesofb_internal(const byte* key,

bench_stats_prepare();

ret = wc_AesInit(&enc, NULL, INVALID_DEVID);
ret = wc_AesInit(&enc, HEAP_HINT, INVALID_DEVID);
Copy link

Copilot AI Apr 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Device-id usage is inconsistent across benchmarks: many call sites in this PR were changed to pass devId, but AES-OFB still uses INVALID_DEVID. If devId is the benchmark’s intended device selection mechanism, consider standardizing on devId here too for consistent behavior and easier benchmarking comparisons across algorithms.

Suggested change
ret = wc_AesInit(&enc, HEAP_HINT, INVALID_DEVID);
ret = wc_AesInit(&enc, HEAP_HINT, devId);

Copilot uses AI. Check for mistakes.
if (ret != 0) {
printf("AesInit failed at L%d, ret = %d\n", __LINE__, ret);
return;
Expand Down Expand Up @@ -11035,7 +11035,7 @@ static void bench_lms_keygen(enum wc_LmsParm parm, byte* pub)
return;
}

ret = wc_LmsKey_Init(&key, NULL, INVALID_DEVID);
ret = wc_LmsKey_Init(&key, HEAP_HINT, devId);
Copy link

Copilot AI Apr 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR is titled around using heap hints, but this change (and several others in the diff) also switches the device id argument from INVALID_DEVID to devId, which can materially change runtime behavior (e.g., selecting a crypto device/accelerator). If the devId switch is intentional, please update the PR title/description accordingly; otherwise, consider keeping the device-id argument unchanged and limiting the PR to heap-hint wiring.

Copilot uses AI. Check for mistakes.
if (ret) {
printf("wc_LmsKey_Init failed: %d\n", ret);
wc_FreeRng(&rng);
Expand All @@ -11051,7 +11051,7 @@ static void bench_lms_keygen(enum wc_LmsParm parm, byte* pub)

wc_LmsKey_Free(&key);

ret = wc_LmsKey_Init(&key, NULL, INVALID_DEVID);
ret = wc_LmsKey_Init(&key, HEAP_HINT, devId);
if (ret) {
printf("wc_LmsKey_Init failed: %d\n", ret);
goto exit_lms_keygen;
Expand Down Expand Up @@ -11140,7 +11140,7 @@ static void bench_lms_sign_verify(enum wc_LmsParm parm, byte* pub)

bench_stats_prepare();

ret = wc_LmsKey_Init(&key, NULL, INVALID_DEVID);
ret = wc_LmsKey_Init(&key, HEAP_HINT, devId);
if (ret) {
printf("wc_LmsKey_Init failed: %d\n", ret);
goto exit_lms_sign_verify;
Expand Down Expand Up @@ -11571,7 +11571,7 @@ static void bench_xmss_sign_verify(const char * params)

freeRng = 1;

ret = wc_XmssKey_Init(&key, NULL, INVALID_DEVID);
ret = wc_XmssKey_Init(&key, HEAP_HINT, devId);
if (ret != 0) {
printf("wc_XmssKey_Init failed: %d\n", ret);
goto exit_xmss_sign_verify;
Expand Down Expand Up @@ -12056,7 +12056,7 @@ void bench_slhdsa(enum SlhDsaParam param)
WC_ALLOC_VAR_EX(sig, byte, WC_SLHDSA_MAX_SIG_LEN, HEAP_HINT,
DYNAMIC_TYPE_TMP_BUFFER, goto exit);

ret = wc_SlhDsaKey_Init(key, param, NULL, INVALID_DEVID);
ret = wc_SlhDsaKey_Init(key, param, HEAP_HINT, devId);
if (ret != 0) {
goto exit;
}
Expand Down Expand Up @@ -12105,7 +12105,7 @@ void bench_slhdsa(enum SlhDsaParam param)
goto exit;
}

ret = wc_SlhDsaKey_Init(key_vfy, param, NULL, INVALID_DEVID);
ret = wc_SlhDsaKey_Init(key_vfy, param, HEAP_HINT, devId);
if (ret != 0) {
goto exit;
}
Expand Down Expand Up @@ -13583,7 +13583,7 @@ void bench_eccsiKeyGen(void)
bench_stats_start(&count, &start);
do {
for (i = 0; i < genTimes; i++) {
wc_InitEccsiKey(genKey, NULL, INVALID_DEVID);
wc_InitEccsiKey(genKey, HEAP_HINT, devId);
ret = wc_MakeEccsiKey(genKey, &gRng);
wc_FreeEccsiKey(genKey);
if (ret != 0) {
Expand Down Expand Up @@ -13628,7 +13628,7 @@ void bench_eccsiPairGen(void)

(void)mp_init(ssk);
pvt = wc_ecc_new_point();
wc_InitEccsiKey(genKey, NULL, INVALID_DEVID);
wc_InitEccsiKey(genKey, HEAP_HINT, devId);
(void)wc_MakeEccsiKey(genKey, &gRng);

/* RSK Gen */
Expand Down Expand Up @@ -13687,7 +13687,7 @@ void bench_eccsiValidate(void)

(void)mp_init(ssk);
pvt = wc_ecc_new_point();
wc_InitEccsiKey(genKey, NULL, INVALID_DEVID);
wc_InitEccsiKey(genKey, HEAP_HINT, devId);
(void)wc_MakeEccsiKey(genKey, &gRng);
(void)wc_MakeEccsiPair(genKey, &gRng, WC_HASH_TYPE_SHA256, id, sizeof(id),
ssk, pvt);
Expand Down Expand Up @@ -13752,7 +13752,7 @@ void bench_eccsi(void)

(void)mp_init(ssk);
pvt = wc_ecc_new_point();
(void)wc_InitEccsiKey(genKey, NULL, INVALID_DEVID);
(void)wc_InitEccsiKey(genKey, HEAP_HINT, devId);
(void)wc_MakeEccsiKey(genKey, &gRng);
(void)wc_MakeEccsiPair(genKey, &gRng, WC_HASH_TYPE_SHA256, id, sizeof(id),
ssk, pvt);
Expand Down Expand Up @@ -13843,7 +13843,7 @@ void bench_sakkeKeyGen(void)
bench_stats_start(&count, &start);
do {
for (i = 0; i < genTimes; i++) {
wc_InitSakkeKey_ex(genKey, 128, ECC_SAKKE_1, NULL, INVALID_DEVID);
wc_InitSakkeKey_ex(genKey, 128, ECC_SAKKE_1, HEAP_HINT, devId);
ret = wc_MakeSakkeKey(genKey, &gRng);
if (ret != 0) {
printf("wc_MakeSakkeKey failed: %d\n", ret);
Expand Down Expand Up @@ -13885,7 +13885,7 @@ void bench_sakkeRskGen(void)
WC_ALLOC_VAR(genKey, SakkeKey, 1, HEAP_HINT);

rsk = wc_ecc_new_point();
wc_InitSakkeKey_ex(genKey, 128, ECC_SAKKE_1, NULL, INVALID_DEVID);
wc_InitSakkeKey_ex(genKey, 128, ECC_SAKKE_1, HEAP_HINT, devId);
(void)wc_MakeSakkeKey(genKey, &gRng);

/* RSK Gen */
Expand Down Expand Up @@ -13938,7 +13938,7 @@ void bench_sakkeValidate(void)
WC_ALLOC_VAR(genKey, SakkeKey, 1, HEAP_HINT);

rsk = wc_ecc_new_point();
(void)wc_InitSakkeKey_ex(genKey, 128, ECC_SAKKE_1, NULL, INVALID_DEVID);
(void)wc_InitSakkeKey_ex(genKey, 128, ECC_SAKKE_1, HEAP_HINT, devId);
(void)wc_MakeSakkeKey(genKey, &gRng);
(void)wc_MakeSakkeRsk(genKey, id, sizeof(id), rsk);
(void)wc_ValidateSakkeRsk(genKey, id, sizeof(id), rsk, &valid);
Expand Down Expand Up @@ -14002,7 +14002,7 @@ void bench_sakke(void)
XMEMCPY(ssv, ssv_init, sizeof ssv);

rsk = wc_ecc_new_point();
(void)wc_InitSakkeKey_ex(genKey, 128, ECC_SAKKE_1, NULL, INVALID_DEVID);
(void)wc_InitSakkeKey_ex(genKey, 128, ECC_SAKKE_1, HEAP_HINT, devId);
(void)wc_MakeSakkeKey(genKey, &gRng);
(void)wc_MakeSakkeRsk(genKey, id, sizeof(id), rsk);
(void)wc_SetSakkeRsk(genKey, rsk, NULL, 0);
Expand Down Expand Up @@ -14229,9 +14229,9 @@ void bench_falconKeySign(byte level)

bench_stats_prepare();

ret = wc_falcon_init(&key);
ret = wc_falcon_init_ex(&key, HEAP_HINT, devId);
if (ret != 0) {
printf("wc_falcon_init failed %d\n", ret);
printf("wc_falcon_init_ex failed %d\n", ret);
Comment on lines +14232 to +14234
Copy link

Copilot AI Apr 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Switching from wc_falcon_init to wc_falcon_init_ex may reduce build compatibility if some configurations expose Falcon but not the _ex initializer. Consider gating this with an appropriate feature macro and falling back to wc_falcon_init(&key) when _ex isn’t available, while still using heap-hint/device-id aware init when it is.

Copilot uses AI. Check for mistakes.
return;
}

Expand Down
Loading