Skip to content

Add PKCS#11 provider support for ML-KEM#663

Merged
mtrojnar merged 3 commits into
OpenSC:masterfrom
olszomal:asym_kem
Jul 24, 2026
Merged

Add PKCS#11 provider support for ML-KEM#663
mtrojnar merged 3 commits into
OpenSC:masterfrom
olszomal:asym_kem

Conversation

@olszomal

Copy link
Copy Markdown
Collaborator

Pull Request Type

  • Bug fix
  • New feature
  • Code style / formatting / renaming
  • Refactoring (no functional or API changes)
  • Build / CI related changes
  • Documentation
  • Other (please describe):

Related Issue

Issue number: N/A

Current Behavior

The PKCS#11 provider does not support ML-KEM keys or KEM operations.
PKCS#11 modules are loaded using the legacy function list, so the PKCS#11 3.2 C_DecapsulateKey function is not available.

New Behavior

The PKCS#11 provider supports ML-KEM-512, ML-KEM-768 and ML-KEM-1024 key generation, encapsulation and decapsulation.

Encapsulation is performed using the public key, while decapsulation is performed on the token through the PKCS#11 3.2 C_DecapsulateKey interface.

Scope of Changes

  • Add ML-KEM key generation and provider support.
  • Add encapsulation and PKCS#11 3.2 token-backed decapsulation.
  • Add an ML-KEM-768 example and provider tests.

Testing

  • Existing tests
  • New tests added
  • Manual testing

Tested with:

  • Thales TCT Luna T-5000 Network HSM
  • SoftHSM built from the current master branch
  • OpenSSL 3.5 or later

Additional Notes

License Declaration

  • I hereby agree to license my contribution under the project's license.

Update the bundled PKCS#11 header to version 3.2 and load the
optional 3.2 function list through `C_GetInterface`, while
preserving the legacy function list.

This enables `C_EncapsulateKey` and `C_DecapsulateKey` for ML-KEM.
Comment thread src/p11_pkey.c
Comment thread src/p11_front.c
Comment thread src/provider_helpers.c
@mtrojnar

Copy link
Copy Markdown
Member

Duplicate CKA_DERIVE attribute

CKA_DERIVE is added to privtmpl here and again at line 697. Some PKCS#11 modules reject templates containing duplicate attributes with CKR_TEMPLATE_INCONSISTENT, which would break EC key generation.

Please remove this occurrence; the addition in the private-key attributes section below is sufficient.

olszomal added 2 commits July 23, 2026 13:07
Add PKCS#11 provider support for ML-KEM-512, ML-KEM-768
and ML-KEM-1024 key generation, encapsulation and decapsulation.

Use the PKCS#11 3.2 C_DecapsulateKey interface
for private-key decapsulation on the token.
@mtrojnar
mtrojnar merged commit 9835ecd into OpenSC:master Jul 24, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants