add support for PKCS11 v3.2 - #191
Conversation
proof of concept to upgrade to v3 of pkcs11 Signed-off-by: Miek Gieben <miek@miek.nl>
Signed-off-by: Miek Gieben <miek@miek.nl>
… CKA_TRUST_EMAIL_PROTECTION, CKA_TRUST_TIME_STAMPING, and CKA_TRUST_OCSP_SIGNING are now defined as standard PKCS#11 v3.2 attributes in pkcs11t.h/zconst.go.
…golang.org/x/tools/go/analysis/passes/printf Signed-off-by: Nicolas-Peiffer <102670102+Nicolas-Peiffer@users.noreply.github.com>
C_AsyncComplete allocates CK_ASYNC_DATA.pValue on the token side. The caller is responsible for freeing it. Add defer C.free() after copying the bytes into Go-managed memory via C.GoBytes, preventing a memory leak on every successful async result retrieval. Signed-off-by: Nicolas-Peiffer <102670102+Nicolas-Peiffer@users.noreply.github.com>
Add Encapsulate/Decapsulate on PublicKey/PrivateKey to expose the PKCS miekg#11 v3.2 ML-KEM key encapsulation API (§5.19) at the p11 layer. Add VerifyStateless on PublicKey for the v3.2 stateless signature verification flow (§5.15) where the signature is bound at init time. Add KEMKeyPair to give callers a typed container for KEM key pairs. Signed-off-by: Nicolas-Peiffer <102670102+Nicolas-Peiffer@users.noreply.github.com>
TestV32AuthenticatedWrap — renamed to skippedTestV32AuthenticatedWrap with a //nolint:unused directive and a TODO comment explaining the SoftHSMv3 bug (wrap produces the right blob size but unwrap returns wrong key value). The test body is preserved in full so it can be re-enabled once the upstream issue is fixed. TestV32GetSessionValidationFlags — new test for C_GetSessionValidationFlags (v3.2 §5.8.4). Performs an RSA sign, then queries the FIPS validation status of the session. Skips gracefully if the token doesn't support it (acceptable for non-FIPS mode). TestV32PQCParamSetReadback — new table-driven test that verifies CKA_PARAMETER_SET is correctly stored and returned by C_GetAttributeValue for all three PQC families (ML-KEM-768, ML-DSA-65, SLH-DSA-SHA2-128s). This exercises the v3.2 attribute infrastructure and ensures key templates are persisted correctly — useful because a broken attribute store would silently break all PQC key usage downstream. Signed-off-by: Nicolas-Peiffer <102670102+Nicolas-Peiffer@users.noreply.github.com> nolint
… into pkcs11-v3.2-pr
a21ac90 to
042baa6
Compare
Signed-off-by: Nicolas-Peiffer <102670102+Nicolas-Peiffer@users.noreply.github.com>
Signed-off-by: Nicolas-Peiffer <102670102+Nicolas-Peiffer@users.noreply.github.com>
Signed-off-by: Nicolas-Peiffer <102670102+Nicolas-Peiffer@users.noreply.github.com>
Signed-off-by: Nicolas-Peiffer <102670102+Nicolas-Peiffer@users.noreply.github.com>
…atest SoftHSMv3 needMech now probes via GetMechanismList instead of GetMechanismInfo; newer SoftHSMv3 returns CKR_MECHANISM_INVALID from C_GetMechanismInfo for mechanisms that are present in C_GetMechanismList. TestPSSParams switches from CKM_RSA_PKCS_PSS (raw pre-hashed digest) to CKM_SHA256_RSA_PKCS_PSS (hash-then-sign); the raw PSS mechanism is no longer advertised by the latest SoftHSMv3. TestOAEPParams was failing with CKR_KEY_FUNCTION_NOT_PERMITTED at EncryptInit because getRSA delegated to generateRSAKeyPair which only sets CKA_VERIFY/CKA_SIGN. getRSA now generates the key pair inline with CKA_ENCRYPT and CKA_DECRYPT set. Also fixes a typo in getRSA where the private key lookup used CKO_PUBLIC_KEY. Tested with pqctoday-org/pqctoday-hsm@37bf66a Signed-off-by: Nicolas-Peiffer <102670102+Nicolas-Peiffer@users.noreply.github.com>
Tested with pqctoday-org/pqctoday-hsm@37bf66a Signed-off-by: Nicolas-Peiffer <102670102+Nicolas-Peiffer@users.noreply.github.com>
| { | ||
| params->pOAEPParams = pOAEPParams; | ||
| } | ||
| */ |
There was a problem hiding this comment.
Missing bindings for CK_SIGN_ADDITIONAL_CONTEXT. Should have a C method to populate this struct and Go methods to create it.
ML-DSA Signature
...
The mechanism has an optional parameter CK_SIGN_ADDITIONAL_CONTEXT. If no parameter is supplied the HedgeVariant is set to CKH_HEDGE_PREFERRED, ulContextLen is set to zero and pContext is set to NULL.
There was a problem hiding this comment.
Hi, TY @spencerpogo for your review.
I tried to cover your request in commit ed5b5af. To be transparent, I used a LLM to take into account your comment.
My current level of confidence is the tests that are passing. But I do not know if this is enough.
There was a problem hiding this comment.
Need support for ML-DSA signing context here
| param, arena = cECDH1DeriveParams(p, arena) | ||
| case *RSAAESKeyWrapParams: | ||
| param, arena = cRSAAESKeyWrapParams(p, arena) | ||
| } |
There was a problem hiding this comment.
Need support for ML-DSA signing context here
Implement Go wrappers for the two PKCS#11 v3.2 ML-DSA mechanism parameter structures: - MLDSAParams (CK_SIGN_ADDITIONAL_CONTEXT): hedge variant + optional context bytes, for use with CKM_ML_DSA. - HashMLDSAParams (CK_HASH_SIGN_ADDITIONAL_CONTEXT): hedge variant + optional context bytes + hash mechanism, for use with CKM_HASH_ML_DSA and its SHA/SHAKE variants. Both types are accepted by NewMechanism and serialized to their C counterparts in cMechanism, following the same pointer-deferral pattern used by OAEPParams and RSAAESKeyWrapParams. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> CC miekg#191 (comment) miekg#191 (comment) miekg#191 (comment)
933f947 to
ed5b5af
Compare
Related
#189
Tests
Tests are passing with softhsmv3:
Waiting on your feedbacks, testing and improvements 😄