Skip to content

Commit 8510488

Browse files
Merge pull request #10910 from Frauschi/lms_xmss_test_fix
Testing: unique per-process temp paths for stateful LMS/XMSS key tests
2 parents fc74ebd + fc87614 commit 8510488

1 file changed

Lines changed: 39 additions & 2 deletions

File tree

tests/api/test_lms_xmss.c

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@
3737
#include <tests/utils.h>
3838
#include <tests/api/test_lms_xmss.h>
3939

40+
/* getpid() gives the stateful LMS/XMSS test key files a per-process name so
41+
* parallel unit.test runs on a shared /tmp do not clobber each other. */
42+
#if defined(HAVE_GETPID) && !defined(WOLFSSL_NO_GETPID)
43+
#include <unistd.h>
44+
#endif
45+
4046
/*----------------------------------------------------------------------------*/
4147
/* LMS tests */
4248
/*----------------------------------------------------------------------------*/
@@ -45,7 +51,22 @@
4551

4652
#include <wolfssl/wolfcrypt/wc_lms.h>
4753

48-
#define LMS_TEST_PRIV_KEY_FILE "/tmp/wolfssl_test_lms.key"
54+
/* Per-process temp file: parallel unit.test runs (e.g. CI shards that share
55+
* /tmp) must not clobber each other's stateful LMS private key. */
56+
static const char* lms_test_priv_key_file(void)
57+
{
58+
static char lmsPath[64];
59+
if (lmsPath[0] == '\0') {
60+
#if defined(HAVE_GETPID) && !defined(WOLFSSL_NO_GETPID)
61+
(void)XSNPRINTF(lmsPath, sizeof(lmsPath),
62+
"/tmp/wolfssl_test_lms_%d.key", (int)getpid());
63+
#else
64+
(void)XSNPRINTF(lmsPath, sizeof(lmsPath), "/tmp/wolfssl_test_lms.key");
65+
#endif
66+
}
67+
return lmsPath;
68+
}
69+
#define LMS_TEST_PRIV_KEY_FILE lms_test_priv_key_file()
4970

5071
static int test_lms_write_key(const byte* priv, word32 privSz, void* context)
5172
{
@@ -1056,7 +1077,23 @@ int test_rfc9802_lms_x509_gen(void)
10561077
#if defined(WOLFSSL_ASN_TEMPLATE) && defined(WOLFSSL_HAVE_XMSS) && \
10571078
!defined(WOLFSSL_XMSS_VERIFY_ONLY) && \
10581079
defined(WOLFSSL_CERT_GEN) && !defined(NO_FILESYSTEM) && !defined(NO_CERTS)
1059-
#define XMSS_GEN_TEST_PRIV_KEY_FILE "/tmp/wolfssl_test_xmss_gen.key"
1080+
/* Per-process temp file: parallel unit.test runs (e.g. CI shards that share
1081+
* /tmp) must not clobber each other's stateful XMSS private key. */
1082+
static const char* xmss_gen_priv_key_file(void)
1083+
{
1084+
static char xmssPath[64];
1085+
if (xmssPath[0] == '\0') {
1086+
#if defined(HAVE_GETPID) && !defined(WOLFSSL_NO_GETPID)
1087+
(void)XSNPRINTF(xmssPath, sizeof(xmssPath),
1088+
"/tmp/wolfssl_test_xmss_gen_%d.key", (int)getpid());
1089+
#else
1090+
(void)XSNPRINTF(xmssPath, sizeof(xmssPath),
1091+
"/tmp/wolfssl_test_xmss_gen.key");
1092+
#endif
1093+
}
1094+
return xmssPath;
1095+
}
1096+
#define XMSS_GEN_TEST_PRIV_KEY_FILE xmss_gen_priv_key_file()
10601097
static enum wc_XmssRc xmss_gen_write_key(const byte* priv, word32 privSz,
10611098
void* context)
10621099
{

0 commit comments

Comments
 (0)