Fix LMS/HSS key cleanup

This commit is contained in:
Zhi Guan
2025-12-18 18:36:25 +08:00
parent a03f5132cd
commit f813838ad4
4 changed files with 12 additions and 4 deletions

View File

@@ -56,6 +56,8 @@ int hsskeygen_main(int argc, char **argv)
uint8_t *ppubout = pubout; uint8_t *ppubout = pubout;
size_t outlen = 0, puboutlen = 0; size_t outlen = 0, puboutlen = 0;
memset(&key, 0, sizeof(key));
argc--; argc--;
argv++; argv++;
@@ -150,7 +152,7 @@ bad:
ret = 0; ret = 0;
end: end:
gmssl_secure_clear(&key, sizeof(key)); hss_key_cleanup(&key);
gmssl_secure_clear(out, outlen); gmssl_secure_clear(out, outlen);
if (outfile && outfp) fclose(outfp); if (outfile && outfp) fclose(outfp);
if (puboutfile && puboutfp) fclose(puboutfp); if (puboutfile && puboutfp) fclose(puboutfp);

View File

@@ -46,6 +46,8 @@ int hsssign_main(int argc, char **argv)
uint8_t sig[HSS_SIGNATURE_MAX_SIZE]; uint8_t sig[HSS_SIGNATURE_MAX_SIZE];
size_t siglen; size_t siglen;
memset(&key, 0, sizeof(key));
argc--; argc--;
argv++; argv++;
@@ -160,8 +162,8 @@ bad:
ret = 0; ret = 0;
end: end:
hss_key_cleanup(&key);
gmssl_secure_clear(keybuf, sizeof(keybuf)); gmssl_secure_clear(keybuf, sizeof(keybuf));
gmssl_secure_clear(&key, sizeof(key));
gmssl_secure_clear(&ctx, sizeof(ctx)); gmssl_secure_clear(&ctx, sizeof(ctx));
if (keyfp) fclose(keyfp); if (keyfp) fclose(keyfp);
if (infp && infp != stdin) fclose(infp); if (infp && infp != stdin) fclose(infp);

View File

@@ -50,6 +50,8 @@ int lmskeygen_main(int argc, char **argv)
uint8_t *ppubout = pubout; uint8_t *ppubout = pubout;
size_t outlen = 0, puboutlen = 0; size_t outlen = 0, puboutlen = 0;
memset(&key, 0, sizeof(key));
argc--; argc--;
argv++; argv++;
@@ -136,7 +138,7 @@ bad:
ret = 0; ret = 0;
end: end:
gmssl_secure_clear(&key, sizeof(key)); lms_key_cleanup(&key);
gmssl_secure_clear(out, outlen); gmssl_secure_clear(out, outlen);
if (outfile && outfp) fclose(outfp); if (outfile && outfp) fclose(outfp);
if (puboutfile && puboutfp) fclose(puboutfp); if (puboutfile && puboutfp) fclose(puboutfp);

View File

@@ -46,6 +46,8 @@ int lmssign_main(int argc, char **argv)
uint8_t sig[LMS_SIGNATURE_MAX_SIZE]; uint8_t sig[LMS_SIGNATURE_MAX_SIZE];
size_t siglen; size_t siglen;
memset(&key, 0, sizeof(key));
argc--; argc--;
argv++; argv++;
@@ -160,8 +162,8 @@ bad:
ret = 0; ret = 0;
end: end:
lms_key_cleanup(&key);
gmssl_secure_clear(keybuf, sizeof(keybuf)); gmssl_secure_clear(keybuf, sizeof(keybuf));
gmssl_secure_clear(&key, sizeof(key));
gmssl_secure_clear(&ctx, sizeof(ctx)); gmssl_secure_clear(&ctx, sizeof(ctx));
if (keyfp) fclose(keyfp); if (keyfp) fclose(keyfp);
if (infp && infp != stdin) fclose(infp); if (infp && infp != stdin) fclose(infp);