summaryrefslogtreecommitdiff
path: root/src/regress/lib
diff options
context:
space:
mode:
authortb <>2024-12-26 12:35:25 +0000
committertb <>2024-12-26 12:35:25 +0000
commit977dfab65b591c5ed733a63ca434edfcc661d5c9 (patch)
tree81523f79b4f9cb97ccde36edf9a10caf3006c33f /src/regress/lib
parent69bd06490cab79fac2c91dd0af8fb80cf7cc3a0b (diff)
downloadopenbsd-977dfab65b591c5ed733a63ca434edfcc661d5c9.tar.gz
openbsd-977dfab65b591c5ed733a63ca434edfcc661d5c9.tar.bz2
openbsd-977dfab65b591c5ed733a63ca434edfcc661d5c9.zip
Fix the unittest with Emscripten
Split main into two helper functions since having a few ML-KEM key blobs on the stack makes Emscripten's stack explode, leading to inscrutable silent failures unles ASAN is enabled. Go figure.
Diffstat (limited to 'src/regress/lib')
-rw-r--r--src/regress/lib/libcrypto/mlkem/mlkem_unittest.c31
1 files changed, 26 insertions, 5 deletions
diff --git a/src/regress/lib/libcrypto/mlkem/mlkem_unittest.c b/src/regress/lib/libcrypto/mlkem/mlkem_unittest.c
index 3f7e2886b9..23b3d8b261 100644
--- a/src/regress/lib/libcrypto/mlkem/mlkem_unittest.c
+++ b/src/regress/lib/libcrypto/mlkem/mlkem_unittest.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: mlkem_unittest.c,v 1.5 2024/12/26 00:04:24 tb Exp $ */ 1/* $OpenBSD: mlkem_unittest.c,v 1.6 2024/12/26 12:35:25 tb Exp $ */
2/* 2/*
3 * Copyright (c) 2024 Google Inc. 3 * Copyright (c) 2024 Google Inc.
4 * Copyright (c) 2024 Bob Beck <beck@obtuse.com> 4 * Copyright (c) 2024 Bob Beck <beck@obtuse.com>
@@ -182,8 +182,8 @@ MlKemUnitTest(struct unittest_ctx *ctx)
182 return failed; 182 return failed;
183} 183}
184 184
185int 185static int
186main(void) 186mlkem768_unittest(void)
187{ 187{
188 struct MLKEM768_private_key mlkem768_priv, mlkem768_priv2; 188 struct MLKEM768_private_key mlkem768_priv, mlkem768_priv2;
189 struct MLKEM768_public_key mlkem768_pub, mlkem768_pub2; 189 struct MLKEM768_public_key mlkem768_pub, mlkem768_pub2;
@@ -207,6 +207,13 @@ main(void)
207 .encode_public_key = mlkem768_encode_public_key, 207 .encode_public_key = mlkem768_encode_public_key,
208 .public_from_private = mlkem768_public_from_private, 208 .public_from_private = mlkem768_public_from_private,
209 }; 209 };
210
211 return MlKemUnitTest(&mlkem768_test);
212}
213
214static int
215mlkem1024_unittest(void)
216{
210 struct MLKEM1024_private_key mlkem1024_priv, mlkem1024_priv2; 217 struct MLKEM1024_private_key mlkem1024_priv, mlkem1024_priv2;
211 struct MLKEM1024_public_key mlkem1024_pub, mlkem1024_pub2; 218 struct MLKEM1024_public_key mlkem1024_pub, mlkem1024_pub2;
212 uint8_t mlkem1024_encoded_public_key[MLKEM1024_PUBLIC_KEY_BYTES]; 219 uint8_t mlkem1024_encoded_public_key[MLKEM1024_PUBLIC_KEY_BYTES];
@@ -229,10 +236,24 @@ main(void)
229 .encode_public_key = mlkem1024_encode_public_key, 236 .encode_public_key = mlkem1024_encode_public_key,
230 .public_from_private = mlkem1024_public_from_private, 237 .public_from_private = mlkem1024_public_from_private,
231 }; 238 };
239
240 return MlKemUnitTest(&mlkem1024_test);
241}
242
243int
244main(void)
245{
232 int failed = 0; 246 int failed = 0;
233 247
234 failed |= MlKemUnitTest(&mlkem768_test); 248 /*
235 failed |= MlKemUnitTest(&mlkem1024_test); 249 * XXX - this is split into two helper functions since having a few
250 * ML-KEM key blobs on the stack makes Emscripten's stack explode,
251 * leading to inscrutable silent failures unles ASAN is enabled.
252 * Go figure.
253 */
254
255 failed |= mlkem768_unittest();
256 failed |= mlkem1024_unittest();
236 257
237 return failed; 258 return failed;
238} 259}