Repository navigation
Add CKM_AES_KEY_WRAP_KWP (RFC 5649 key wrap with padding) - #376
Open
Princemachiavelli wants to merge 1 commit into
Open
Princemachiavelli wants to merge 1 commit into
Princemachiavelli wants to merge 1 commit into
Conversation
Collaborator
|
Looks good in general. Would it be possible to add tests for using this mechanism? 🤔 |
PKCS#11 3.0 added `CKM_AES_KEY_WRAP_KWP` (0x210B) for AES key wrap with padding as specified in RFC 5649, because the 2.40 `CKM_AES_KEY_WRAP_PAD` (0x210A) was ambiguous about which padding it means. Modules implementing 3.x offer the new ID; kryoptic, for example, lists 0x210B (and 0x210C, `CKM_AES_KEY_WRAP_PKCS7`) but not 0x210A. `cryptoki-sys` already has the constant; `cryptoki` has no `MechanismType` or `Mechanism` for it, and a raw `MechanismType` can only be built in the vendor range, so the mechanism cannot be used. This PR adds `MechanismType::AES_KEY_WRAP_KWP` (with its `Display` name and `TryFrom` arm) and a parameterless `Mechanism::AesKeyWrapKwp`, mirroring `AES_KEY_WRAP_PAD`. A wrap/unwrap test runs where the token offers the mechanism (kryoptic) and is skipped elsewhere (SoftHSM). We need it to move private keys between tokens: wrapped with RFC 5649 on one module and unwrapped on another. Between SoftHSM 2.7 (`CKM_AES_KEY_WRAP_PAD`) and kryoptic 1.5.4 (`CKM_AES_KEY_WRAP_KWP`) the wrapped bytes are interchangeable in both directions, for secret keys and for PKCS#8 private keys, so the two IDs name one format there, but the mechanism must be requested by the ID the module offers. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Josh Hoffer <jhoffer@sansorgan.es>
Princemachiavelli
force-pushed
the
jhoffer/Add-CKM_AES_KEY_WRAP_KWP
branch
from
November 15, 2026 19:21
26925d0 to
2cde156
Compare
Author
|
@wiktor-k Yup, added test to this and also it's companion PR #377. I'll give both a second look over when I get home in a bit. With these mechanisms added, we should be able to natively migrate objects between common cloud HSM providers. (I think I have already tested... AWS <-> GCP HSM should work). |
Collaborator
That's really cool! I'm looking forward to this getting merged! It seems we've got a minor issue with the CI but otherwise I like it 👏 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PKCS#11 3.0 added
CKM_AES_KEY_WRAP_KWP(0x210B) for AES key wrap with padding as specified in RFC 5649, because the 2.40CKM_AES_KEY_WRAP_PAD(0x210A) was ambiguous about which padding it means. Modules implementing 3.x offer the new ID; kryoptic, for example, lists 0x210B (and 0x210C,CKM_AES_KEY_WRAP_PKCS7) but not 0x210A.cryptoki-sysalready has the constant;cryptokihas noMechanismTypeorMechanismfor it, and a rawMechanismTypecan only be built in the vendor range, so the mechanism cannot be used.This PR adds
MechanismType::AES_KEY_WRAP_KWP(with itsDisplayname andTryFromarm) and a parameterlessMechanism::AesKeyWrapKwp, mirroringAES_KEY_WRAP_PAD.We need it to move private keys between tokens: wrapped with RFC 5649 on one module and unwrapped on another. Between SoftHSM 2.7 (
CKM_AES_KEY_WRAP_PAD) and kryoptic 1.5.4 (CKM_AES_KEY_WRAP_KWP) the wrapped bytes are interchangeable in both directions, for secret keys and for PKCS#8 private keys, so the two IDs name one format there, but the mechanism must be requested by the ID the module offers.