Skip to content

Commit b487287

Browse files
committed
wolfcrypt/benchmark/benchmark.c: smallstack refactor of bench_mlkem_encap()
1 parent e70e7cb commit b487287

File tree

1 file changed

+24
-8
lines changed

1 file changed

+24
-8
lines changed

wolfcrypt/benchmark/benchmark.c

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10554,35 +10554,39 @@ static void bench_mlkem_encap(int type, const char* name, int keySize,
1055410554
int ret = 0, times, count, pending = 0;
1055510555
double start;
1055610556
const char**desc = bench_desc_words[lng_index];
10557-
byte ct[WC_ML_KEM_MAX_CIPHER_TEXT_SIZE];
10558-
byte ss[WC_ML_KEM_SS_SZ];
10559-
byte pub[WC_ML_KEM_MAX_PUBLIC_KEY_SIZE];
10557+
WC_DECLARE_VAR(ct, byte, WC_ML_KEM_MAX_CIPHER_TEXT_SIZE, HEAP_HINT);
10558+
WC_DECLARE_VAR(ss, byte, WC_ML_KEM_SS_SZ, HEAP_HINT);
10559+
WC_DECLARE_VAR(pub, byte, WC_ML_KEM_MAX_PUBLIC_KEY_SIZE, HEAP_HINT);
1056010560
word32 pubLen;
1056110561
word32 ctSz;
1056210562
DECLARE_MULTI_VALUE_STATS_VARS()
1056310563

1056410564
bench_stats_prepare();
1056510565

10566+
WC_ALLOC_VAR(ct, byte, WC_ML_KEM_MAX_CIPHER_TEXT_SIZE, HEAP_HINT);
10567+
WC_ALLOC_VAR(ss, byte, WC_ML_KEM_SS_SZ, HEAP_HINT);
10568+
WC_ALLOC_VAR(pub, byte, WC_ML_KEM_MAX_PUBLIC_KEY_SIZE, HEAP_HINT);
10569+
1056610570
ret = wc_KyberKey_PublicKeySize(key1, &pubLen);
1056710571
if (ret != 0) {
10568-
return;
10572+
goto exit;
1056910573
}
1057010574
ret = wc_KyberKey_EncodePublicKey(key1, pub, pubLen);
1057110575
if (ret != 0) {
10572-
return;
10576+
goto exit;
1057310577
}
1057410578
ret = wc_KyberKey_Init(type, key2, HEAP_HINT, INVALID_DEVID);
1057510579
if (ret != 0) {
10576-
return;
10580+
goto exit;
1057710581
}
1057810582
ret = wc_KyberKey_DecodePublicKey(key2, pub, pubLen);
1057910583
if (ret != 0) {
10580-
return;
10584+
goto exit;
1058110585
}
1058210586

1058310587
ret = wc_KyberKey_CipherTextSize(key2, &ctSz);
1058410588
if (ret != 0) {
10585-
return;
10589+
goto exit;
1058610590
}
1058710591

1058810592
#ifndef WOLFSSL_MLKEM_NO_ENCAPSULATE
@@ -10641,7 +10645,19 @@ static void bench_mlkem_encap(int type, const char* name, int keySize,
1064110645
#ifdef MULTI_VALUE_STATISTICS
1064210646
bench_multi_value_stats(max, min, sum, squareSum, runs);
1064310647
#endif
10648+
1064410649
#endif
10650+
10651+
exit:
10652+
10653+
WC_FREE_VAR(ct, HEAP_HINT);
10654+
WC_FREE_VAR(ss, HEAP_HINT);
10655+
WC_FREE_VAR(pub, HEAP_HINT);
10656+
10657+
if (ret != 0)
10658+
printf("error: bench_mlkem_encap() failed with code %d.\n", ret);
10659+
10660+
return;
1064510661
}
1064610662
#endif
1064710663

0 commit comments

Comments
 (0)