Add LMS/HSS CL

This commit is contained in:
Zhi Guan
2026-06-24 10:23:18 +08:00
parent dadd2a3e0d
commit e7c0a28f9b
10 changed files with 1677 additions and 20 deletions

View File

@@ -15,6 +15,9 @@
#include <gmssl/mem.h>
#include <gmssl/error.h>
#include <gmssl/lms.h>
#ifdef ENABLE_LMS_CL
#include <gmssl/lms_cl.h>
#endif
static const char *usage = "-key file [-in file] [-out file] [-verbose]\n";
@@ -75,8 +78,15 @@ int hsssign_main(int argc, char **argv)
HSS_SIGN_CTX ctx;
uint8_t sig[HSS_SIGNATURE_MAX_SIZE];
size_t siglen;
#ifdef ENABLE_LMS_CL
LMS_CL_CTX cl_ctx;
int cl_initialized = 0;
#endif
memset(&key, 0, sizeof(key));
#ifdef ENABLE_LMS_CL
memset(&cl_ctx, 0, sizeof(cl_ctx));
#endif
argc--;
argv++;
@@ -136,10 +146,22 @@ bad:
fprintf(stderr, "%s: read private key failure\n", prog);
goto end;
}
#ifdef ENABLE_LMS_CL
if (lms_cl_init(&cl_ctx) != 1) {
error_print();
goto end;
}
cl_initialized = 1;
if (hss_cl_private_key_from_bytes(&cl_ctx, &key, &cp, &keylen) != 1) {
error_print();
goto end;
}
#else
if (hss_private_key_from_bytes(&key, &cp, &keylen) != 1) {
error_print();
goto end;
}
#endif
if (keylen) {
error_print();
goto end;
@@ -154,10 +176,17 @@ bad:
goto end;
}
#ifdef ENABLE_LMS_CL
if (hss_cl_sign_init(&cl_ctx, &ctx, &key) != 1) {
error_print();
goto end;
}
#else
if (hss_sign_init(&ctx, &key) != 1) {
error_print();
goto end;
}
#endif
while (1) {
uint8_t buf[1024];
@@ -185,6 +214,9 @@ bad:
ret = 0;
end:
#ifdef ENABLE_LMS_CL
if (cl_initialized) lms_cl_cleanup(&cl_ctx);
#endif
hss_key_cleanup(&key);
gmssl_secure_clear(keybuf, sizeof(keybuf));
gmssl_secure_clear(&ctx, sizeof(ctx));