Repository navigation
Commit db220db
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. These declines, and every XMSS
request, are decided from the key before a session is opened, so a token
that cannot be opened or logged into never fails an operation software
can do, and never leaves a software LMS key marked bad.
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 no session opens, or 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.
wc_LmsKey_Reload and wc_XmssKey_Reload now leave a key named by id or
label on the device even when a read callback is set, as key generation
already does, so a named key is never reloaded in software from storage
its key generation never wrote. A devId on an unnamed key with a read
callback still means the caller holds the state.
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 db220db
8 files changed
Lines changed: 1795 additions & 47 deletions
File tree
- tests/api
- wolfcrypt/src
- wolfssl/wolfcrypt
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
562 | 562 | | |
563 | 563 | | |
564 | 564 | | |
| 565 | + | |
565 | 566 | | |
566 | 567 | | |
567 | 568 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
500 | 500 | | |
501 | 501 | | |
502 | 502 | | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
| 510 | + | |
| 511 | + | |
| 512 | + | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
503 | 516 | | |
504 | 517 | | |
505 | 518 | | |
| |||
1099 | 1112 | | |
1100 | 1113 | | |
1101 | 1114 | | |
| 1115 | + | |
| 1116 | + | |
| 1117 | + | |
| 1118 | + | |
| 1119 | + | |
| 1120 | + | |
| 1121 | + | |
| 1122 | + | |
| 1123 | + | |
| 1124 | + | |
| 1125 | + | |
| 1126 | + | |
| 1127 | + | |
1102 | 1128 | | |
1103 | 1129 | | |
1104 | 1130 | | |
| |||
0 commit comments