Skip to content

Commit 6af6838

Browse files
committed
Add LMS/HSS key generation, signing and verification over PKCS#11
wc_Pkcs11_CryptoDevCb now handles the stateful signature callbacks for LMS keys, using the PKCS#11 HSS mechanisms. Key generation passes CKA_HSS_LEVELS with the per-level lists CKA_HSS_LMS_TYPES and CKA_HSS_LMOTS_TYPES in the private key template, as PKCS#11 3.1, 3.2 and the 3.3 draft define it; the single-value CKA_HSS_LMS_TYPE and CKA_HSS_LMOTS_TYPE are attributes the token gives the public key. The private key is a token object, private, sensitive, not extractable and not copyable, since the token keeps the one-time-signature state; the public key is kept on the token too so a later process can verify by id or label. Keys without an id or label are declined, so software LMS keys that carry a devId still sign in software, and a token key without a name would be left behind on the token. Key generation also fails with BAD_STATE_E when an HSS object, token or session, already has the key's id or label, as a later lookup by name could otherwise find the older key; with WC_PKCS11_FIND_WITH_ID_ONLY the id check covers every private and public key, whatever its type, as the lookups do, and Pkcs11FindKeyOfClass now tells a failed search apart from no match so either stops key generation. Keys are always found by id or label; no object handle is kept in devCtx, as a handle no longer names the key once the library is set up again. A key whose state software holds signs, counts its signatures and verifies in software. Before signing or counting signatures left, the token key's CKA_HSS_LEVELS and type lists are compared with the LmsKey's parameters, and a mismatch fails with WC_KEY_MISMATCH_E before the token uses a one-time key, so SigsLeft reports 0 for a key Sign refuses. That includes a token key with more levels than the build supports, whose type lists come back CKR_BUFFER_TOO_SMALL. CKR_KEY_EXHAUSTED maps to KEY_EXHAUSTED_E; any other signing failure, including a signature whose length does not match the parameters, is reported as WC_HW_E and wolfCrypt treats the key as bad. Signatures left come from CKA_KEYS_REMAINING, the PKCS#11 3.3 name, added with CKA_HSS_KEYS_REMAINING as an alias. Verification uses the public key held by the LmsKey when it has one, falling back to software when the token does not take it or fails with it, and otherwise the public key named on the token. CKR_SIGNATURE_LEN_RANGE is reported as SIG_VERIFY_E like CKR_SIGNATURE_INVALID. There is no free handler, as generated private keys are always token objects and freeing a key never destroys one. NO_PKCS11_LMS leaves LMS out; verify-only LMS builds only get verification. The HSS constants and CKR_BUFFER_TOO_SMALL are added to pkcs11.h.
1 parent 198b4f9 commit 6af6838

6 files changed

Lines changed: 1648 additions & 29 deletions

File tree

‎.wolfssl_known_macro_extras‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -562,6 +562,7 @@ NO_PKCS11_ECC
562562
NO_PKCS11_ECDH
563563
NO_PKCS11_EC_KEYGEN
564564
NO_PKCS11_HMAC
565+
NO_PKCS11_LMS
565566
NO_PKCS11_MLDSA
566567
NO_PKCS11_MLKEM
567568
NO_PKCS11_RNG

0 commit comments

Comments
 (0)