From 977dfab65b591c5ed733a63ca434edfcc661d5c9 Mon Sep 17 00:00:00 2001 From: tb <> Date: Thu, 26 Dec 2024 12:35:25 +0000 Subject: 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. --- src/regress/lib/libcrypto/mlkem/mlkem_unittest.c | 31 ++++++++++++++++++++---- 1 file changed, 26 insertions(+), 5 deletions(-) (limited to 'src') 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 @@ -/* $OpenBSD: mlkem_unittest.c,v 1.5 2024/12/26 00:04:24 tb Exp $ */ +/* $OpenBSD: mlkem_unittest.c,v 1.6 2024/12/26 12:35:25 tb Exp $ */ /* * Copyright (c) 2024 Google Inc. * Copyright (c) 2024 Bob Beck @@ -182,8 +182,8 @@ MlKemUnitTest(struct unittest_ctx *ctx) return failed; } -int -main(void) +static int +mlkem768_unittest(void) { struct MLKEM768_private_key mlkem768_priv, mlkem768_priv2; struct MLKEM768_public_key mlkem768_pub, mlkem768_pub2; @@ -207,6 +207,13 @@ main(void) .encode_public_key = mlkem768_encode_public_key, .public_from_private = mlkem768_public_from_private, }; + + return MlKemUnitTest(&mlkem768_test); +} + +static int +mlkem1024_unittest(void) +{ struct MLKEM1024_private_key mlkem1024_priv, mlkem1024_priv2; struct MLKEM1024_public_key mlkem1024_pub, mlkem1024_pub2; uint8_t mlkem1024_encoded_public_key[MLKEM1024_PUBLIC_KEY_BYTES]; @@ -229,10 +236,24 @@ main(void) .encode_public_key = mlkem1024_encode_public_key, .public_from_private = mlkem1024_public_from_private, }; + + return MlKemUnitTest(&mlkem1024_test); +} + +int +main(void) +{ int failed = 0; - failed |= MlKemUnitTest(&mlkem768_test); - failed |= MlKemUnitTest(&mlkem1024_test); + /* + * XXX - this is split 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. + */ + + failed |= mlkem768_unittest(); + failed |= mlkem1024_unittest(); return failed; } -- cgit v1.2.3-55-g6feb