Skip to content

Add support for ML-DSA in PKCS#11#9836

Open
Frauschi wants to merge 1 commit intowolfSSL:masterfrom
Frauschi:pkcs11_dilithium
Open

Add support for ML-DSA in PKCS#11#9836
Frauschi wants to merge 1 commit intowolfSSL:masterfrom
Frauschi:pkcs11_dilithium

Conversation

@Frauschi
Copy link
Contributor

@Frauschi Frauschi commented Feb 26, 2026

This PR adds ML-DSA signature support to the PKCS#11 interface.

It enables offloading the following ML-DSA operations onto a PKCS#11 token via the cryptoCb interface:

  • Key generation
  • Signature generation
  • Signature verification
  • Key import
  • Private key checking

Both the pure and pre-hash versions of ML-DSA are supported. Not yet supported are the pre-hash versions that also offload the hashing onto the token.

This also fixes casting errors introduced in #9780 due to the usage of uintptr_t, which is unavailable without including stdint.h on some platforms. We now use the own wc_ptr_t instead.

Within wc_pkcs11.c, the new MlDsa_xxx functions are already used to simplify the upcoming name change from Dilithium to MlDsa. For that, some new macros have been added to cover all required functions.

The new functionality has been tested successfully with wolfPKCS11 using wolfSSL/wolfPKCS11#161 as well as with a prototype PKCS#11 middleware for a new PQC-capable secure element from [redacted].

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request adds ML-DSA (Module-Lattice-Based Digital Signature Algorithm, formerly known as Dilithium) signature support to the PKCS#11 interface, enabling hardware security module offloading for post-quantum cryptographic operations. The implementation follows the established patterns for RSA and ECC in the wolfSSL PKCS#11 integration, and also fixes casting errors introduced in PR #9780 by replacing uintptr_t with the portable wc_ptr_t type.

Changes:

  • Added ML-DSA key type, mechanisms, and parameter structures to PKCS#11 header definitions
  • Implemented ML-DSA key generation, signing, verification, import, and private key checking functions
  • Fixed casting issues using wc_ptr_t instead of uintptr_t for better portability
  • Added new macro wrappers for ML-DSA functions to support upcoming Dilithium to ML-DSA naming transition

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 9 comments.

Show a summary per file
File Description
wolfssl/wolfcrypt/wc_pkcs11.h Added PKCS11_KEY_TYPE_MLDSA enum value for ML-DSA key type
wolfssl/wolfcrypt/pkcs11.h Added PKCS#11 constants (CKK_ML_DSA, CKM_ML_DSA, etc.) and structures for ML-DSA parameter sets and signing contexts
wolfssl/wolfcrypt/dilithium.h Added macro wrappers for sign/verify context hash functions and key decode functions to support naming transition
wolfcrypt/src/wc_pkcs11.c Core implementation: ML-DSA key creation, finding, generation, signing, verification, and checking functions; fixed casting from uintptr_t to wc_ptr_t
.wolfssl_known_macro_extras Added NO_PKCS11_MLDSA macro for disabling ML-DSA PKCS#11 support

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@Frauschi
Copy link
Contributor Author

Copilot feedback is addressed and incorporated.

Offload ML-DSA operations onto a PKCS#11 token via the cryptoCb
interface:
* Key generation
* Signature generation
* Signature verification
* Key import

Both the pure and pre-hash versions are supported. Not yet supported are
the pre-hash versions that also offload the hashing onto the token.

This also fixes casting errors introduced in wolfSSL#9780 due to usage of
uintptr_t, which is unavailable without including stdint.h on some
platforms. Use the wolfssl own wc_ptr_t instead.
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 14 out of 14 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +1638 to +1646
* Create a PKCS#11 object containing the ML-DSA private key data.
*
* @param handle [out] Handle to private key object.
* @param session [in] Session object.
* @param key [in] ML-DSA key.
* @param mechInfo [in] Pointer to a filled MECHANISM_INFO object.
* @return WC_HW_E when a PKCS#11 library call fails.
* @return 0 on success.
*/
Copy link

Copilot AI Feb 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing asterisk at the beginning of the comment line. The comment block should have consistent formatting with an asterisk on each line.

Suggested change
* Create a PKCS#11 object containing the ML-DSA private key data.
*
* @param handle [out] Handle to private key object.
* @param session [in] Session object.
* @param key [in] ML-DSA key.
* @param mechInfo [in] Pointer to a filled MECHANISM_INFO object.
* @return WC_HW_E when a PKCS#11 library call fails.
* @return 0 on success.
*/
* Create a PKCS#11 object containing the ML-DSA private key data.
*
* @param handle [out] Handle to private key object.
* @param session [in] Session object.
* @param key [in] ML-DSA key.
* @param mechInfo [in] Pointer to a filled MECHANISM_INFO object.
* @return WC_HW_E when a PKCS#11 library call fails.
* @return 0 on success.
*/

Copilot uses AI. Check for mistakes.
paramSet.preHash.pContext = NULL;
paramSet.preHash.ulContextLen = 0;
}
paramSet.preHash.hedgeVariant = CKH_HEDGE_REQUIRED;
Copy link

Copilot AI Feb 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The hedge variant is hardcoded to CKH_HEDGE_REQUIRED in the signing function. Consider making this configurable through the info structure to allow callers to specify deterministic or preferred hedge modes when needed.

Copilot uses AI. Check for mistakes.
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