|
37 | 37 | #include <tests/utils.h> |
38 | 38 | #include <tests/api/test_lms_xmss.h> |
39 | 39 |
|
| 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 | + |
40 | 46 | /*----------------------------------------------------------------------------*/ |
41 | 47 | /* LMS tests */ |
42 | 48 | /*----------------------------------------------------------------------------*/ |
|
45 | 51 |
|
46 | 52 | #include <wolfssl/wolfcrypt/wc_lms.h> |
47 | 53 |
|
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() |
49 | 70 |
|
50 | 71 | static int test_lms_write_key(const byte* priv, word32 privSz, void* context) |
51 | 72 | { |
@@ -1056,7 +1077,23 @@ int test_rfc9802_lms_x509_gen(void) |
1056 | 1077 | #if defined(WOLFSSL_ASN_TEMPLATE) && defined(WOLFSSL_HAVE_XMSS) && \ |
1057 | 1078 | !defined(WOLFSSL_XMSS_VERIFY_ONLY) && \ |
1058 | 1079 | 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() |
1060 | 1097 | static enum wc_XmssRc xmss_gen_write_key(const byte* priv, word32 privSz, |
1061 | 1098 | void* context) |
1062 | 1099 | { |
|
0 commit comments