From b1c1eddea8c52a1af2cb9153c02d3b767d4e288e Mon Sep 17 00:00:00 2001 From: Zhi Guan Date: Wed, 24 Jun 2026 11:04:49 +0800 Subject: [PATCH] Default Enable LMS/XMSS CL on macOS --- CMakeLists.txt | 23 ++++++++++++++++--- include/gmssl/version.h | 2 +- tools/xmssmtkeygen.c | 25 --------------------- tools/xmssmtsign.c | 28 ----------------------- tools/xmsssign.c | 49 ----------------------------------------- 5 files changed, 21 insertions(+), 106 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ea8646ea..9f621622 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -39,6 +39,8 @@ set(GMSSL_DEFAULT_ENABLE_SM4_AVX2 OFF) set(GMSSL_DEFAULT_ENABLE_SM4_AESNI OFF) set(GMSSL_DEFAULT_ENABLE_SM2_AMD64 OFF) set(GMSSL_DEFAULT_ENABLE_SM3_SSE OFF) +set(GMSSL_DEFAULT_ENABLE_LMS_CL OFF) +set(GMSSL_DEFAULT_ENABLE_XMSS_CL OFF) if (NOT MSVC) if (GMSSL_TARGET_PROCESSOR MATCHES "^(aarch64|arm64)$") @@ -89,6 +91,21 @@ if (NOT MSVC) endif() endif() +if (APPLE) + include(CheckCSourceCompiles) + set(GMSSL_CMAKE_REQUIRED_LIBRARIES_SAVE "${CMAKE_REQUIRED_LIBRARIES}") + set(CMAKE_REQUIRED_LIBRARIES "-framework OpenCL") + check_c_source_compiles( + "#include + int main(void) { cl_uint n = 0; clGetPlatformIDs(0, 0, &n); return 0; }" + GMSSL_HAVE_MACOS_OPENCL) + set(CMAKE_REQUIRED_LIBRARIES "${GMSSL_CMAKE_REQUIRED_LIBRARIES_SAVE}") + if (GMSSL_HAVE_MACOS_OPENCL) + set(GMSSL_DEFAULT_ENABLE_LMS_CL ON) + set(GMSSL_DEFAULT_ENABLE_XMSS_CL ON) + endif() +endif() + option(ENABLE_TEST_SPEED "Enable test speed" OFF) option(ENABLE_SLOW_TEST "Enable slow tests" OFF) @@ -112,8 +129,8 @@ option(ENABLE_SM3_SSE "Enable SM3 SSE assembly implementation" ${GMSSL_DEFAULT_E option(ENABLE_SM4_CTR_AESNI_AVX "Enable SM4 CTR AESNI+AVX assembly implementation" OFF) option(ENABLE_SM4_CL "Enable SM4 OpenCL" OFF) -option(ENABLE_LMS_CL "Enable LMS OpenCL" OFF) -option(ENABLE_XMSS_CL "Enable XMSS OpenCL" OFF) +option(ENABLE_LMS_CL "Enable LMS OpenCL" ${GMSSL_DEFAULT_ENABLE_LMS_CL}) +option(ENABLE_XMSS_CL "Enable XMSS OpenCL" ${GMSSL_DEFAULT_ENABLE_XMSS_CL}) option(ENABLE_INTEL_RDRAND "Enable Intel RDRAND instructions" OFF) @@ -981,7 +998,7 @@ endif() # set(CPACK_PACKAGE_NAME "GmSSL") set(CPACK_PACKAGE_VENDOR "GmSSL develop team") -set(CPACK_PACKAGE_VERSION "3.3.0-dev.1165") +set(CPACK_PACKAGE_VERSION "3.3.0-dev.1166") set(CPACK_PACKAGE_DESCRIPTION_FILE ${PROJECT_SOURCE_DIR}/README.md) set(CPACK_NSIS_MODIFY_PATH ON) include(CPack) diff --git a/include/gmssl/version.h b/include/gmssl/version.h index 472c0969..2cd3c8e0 100644 --- a/include/gmssl/version.h +++ b/include/gmssl/version.h @@ -18,7 +18,7 @@ extern "C" { #define GMSSL_VERSION_NUM 30300 -#define GMSSL_VERSION_STR "GmSSL 3.3.0-dev.1165" +#define GMSSL_VERSION_STR "GmSSL 3.3.0-dev.1166" int gmssl_version_num(void); const char *gmssl_version_str(void); diff --git a/tools/xmssmtkeygen.c b/tools/xmssmtkeygen.c index 1975451d..5a1c6bf3 100644 --- a/tools/xmssmtkeygen.c +++ b/tools/xmssmtkeygen.c @@ -15,9 +15,6 @@ #include #include #include -#ifdef ENABLE_XMSS_CL -#include -#endif static const char *usage = "-xmssmt_type type -out file [-pubout file] [-verbose]\n"; @@ -55,15 +52,8 @@ int xmssmtkeygen_main(int argc, char **argv) uint8_t *pout; uint8_t *ppubout = pubout; size_t outlen = 0, puboutlen = 0; -#ifdef ENABLE_XMSS_CL - XMSS_CL_CTX cl_ctx; - int cl_inited = 0; -#endif memset(&key, 0, sizeof(key)); -#ifdef ENABLE_XMSS_CL - memset(&cl_ctx, 0, sizeof(cl_ctx)); -#endif argc--; argv++; @@ -123,22 +113,10 @@ bad: goto end; } -#ifdef ENABLE_XMSS_CL - if (xmss_cl_init(&cl_ctx) != 1) { - error_print(); - goto end; - } - cl_inited = 1; - if (xmssmt_cl_key_generate(&cl_ctx, &key, xmssmt_type_val) != 1) { - error_print(); - goto end; - } -#else if (xmssmt_key_generate(&key, xmssmt_type_val) != 1) { error_print(); return -1; } -#endif if (verbose) { xmssmt_public_key_print(stderr, 0, 0, "xmssmt_public_key", &key); } @@ -173,9 +151,6 @@ bad: ret = 0; end: -#ifdef ENABLE_XMSS_CL - if (cl_inited) xmss_cl_cleanup(&cl_ctx); -#endif xmssmt_key_cleanup(&key); if (out) { gmssl_secure_clear(out, outlen); diff --git a/tools/xmssmtsign.c b/tools/xmssmtsign.c index 9b603b14..a711a1b4 100644 --- a/tools/xmssmtsign.c +++ b/tools/xmssmtsign.c @@ -15,9 +15,6 @@ #include #include #include -#ifdef ENABLE_XMSS_CL -#include -#endif static const char *usage = "-key file [-in file] [-out file] [-verbose]\n"; @@ -72,15 +69,8 @@ int xmssmtsign_main(int argc, char **argv) XMSSMT_SIGN_CTX ctx; uint8_t sig[XMSSMT_SIGNATURE_MAX_SIZE]; size_t siglen; -#ifdef ENABLE_XMSS_CL - XMSS_CL_CTX cl_ctx; - int cl_inited = 0; -#endif memset(&key, 0, sizeof(key)); -#ifdef ENABLE_XMSS_CL - memset(&cl_ctx, 0, sizeof(cl_ctx)); -#endif argc--; argv++; @@ -136,14 +126,6 @@ bad: goto end; } -#ifdef ENABLE_XMSS_CL - if (xmss_cl_init(&cl_ctx) != 1) { - error_print(); - goto end; - } - cl_inited = 1; -#endif - if (xmssmt_private_key_from_file(&key, keyfp) != 1) { fprintf(stderr, "%s: read private key failure\n", prog); goto end; @@ -158,17 +140,10 @@ bad: goto end; } -#ifdef ENABLE_XMSS_CL - if (xmssmt_cl_sign_init(&cl_ctx, &ctx, &key) != 1) { - error_print(); - goto end; - } -#else if (xmssmt_sign_init(&ctx, &key) != 1) { error_print(); goto end; } -#endif while (1) { uint8_t buf[1024]; @@ -196,9 +171,6 @@ bad: ret = 0; end: -#ifdef ENABLE_XMSS_CL - if (cl_inited) xmss_cl_cleanup(&cl_ctx); -#endif xmssmt_key_cleanup(&key); gmssl_secure_clear(&ctx, sizeof(ctx)); if (keyfp) fclose(keyfp); diff --git a/tools/xmsssign.c b/tools/xmsssign.c index f7b93cb6..b75c4248 100644 --- a/tools/xmsssign.c +++ b/tools/xmsssign.c @@ -16,9 +16,6 @@ #include #include #include -#ifdef ENABLE_XMSS_CL -#include -#endif static const char *usage = "-key file [-in file] [-out file] [-verbose]\n"; @@ -71,17 +68,8 @@ int xmsssign_main(int argc, char **argv) XMSS_SIGN_CTX ctx; uint8_t sig[XMSS_SIGNATURE_MAX_SIZE]; size_t siglen; -#ifdef ENABLE_XMSS_CL - XMSS_CL_CTX cl_ctx; - uint8_t *keybuf = NULL; - size_t keylen = 0; - int cl_inited = 0; -#endif memset(&key, 0, sizeof(key)); -#ifdef ENABLE_XMSS_CL - memset(&cl_ctx, 0, sizeof(cl_ctx)); -#endif argc--; argv++; @@ -137,40 +125,10 @@ bad: goto end; } -#ifdef ENABLE_XMSS_CL - if (xmss_cl_init(&cl_ctx) != 1) { - error_print(); - goto end; - } - cl_inited = 1; - if (fseek(keyfp, 0, SEEK_END) != 0 - || (keylen = (size_t)ftell(keyfp)) == (size_t)-1 - || fseek(keyfp, 0, SEEK_SET) != 0) { - error_print(); - goto end; - } - if (!(keybuf = malloc(keylen))) { - error_print(); - goto end; - } - if (fread(keybuf, 1, keylen, keyfp) != keylen) { - fprintf(stderr, "%s: read private key failure\n", prog); - goto end; - } - { - const uint8_t *cp = keybuf; - size_t len = keylen; - if (xmss_cl_private_key_from_bytes(&cl_ctx, &key, &cp, &len) != 1 || len) { - fprintf(stderr, "%s: read private key failure\n", prog); - goto end; - } - } -#else if (xmss_private_key_from_file(&key, keyfp) != 1) { fprintf(stderr, "%s: read private key failure\n", prog); goto end; } -#endif if (verbose) { xmss_public_key_print(stderr, 0, 0, "lms_public_key", &key); @@ -212,13 +170,6 @@ bad: ret = 0; end: -#ifdef ENABLE_XMSS_CL - if (cl_inited) xmss_cl_cleanup(&cl_ctx); - if (keybuf) { - gmssl_secure_clear(keybuf, keylen); - free(keybuf); - } -#endif xmss_key_cleanup(&key); gmssl_secure_clear(&ctx, sizeof(ctx)); if (keyfp) fclose(keyfp);