Skip to content

C# Wrapper: ML-KEM and ML-DSA (Dilithium) Support#10191

Merged
SparkiDev merged 4 commits intowolfSSL:masterfrom
dgarske:csharp_pqc
Apr 14, 2026
Merged

C# Wrapper: ML-KEM and ML-DSA (Dilithium) Support#10191
SparkiDev merged 4 commits intowolfSSL:masterfrom
dgarske:csharp_pqc

Conversation

@dgarske
Copy link
Copy Markdown
Contributor

@dgarske dgarske commented Apr 10, 2026

Description

Adds post-quantum ML-KEM and ML-DSA support to the wolfSSL C# wrapper, with
build/test instructions, peer review fixes, and a switch to FIPS 204 compliant
Dilithium APIs.

Changes

  • ML-KEM wrapper functions: MlKemMakeKey, MlKemEncode/DecodePublicKey,
    MlKemEncode/DecodePrivateKey, MlKemEncapsulate, MlKemDecapsulate,
    MlKemFreeKey (supports ML_KEM_512, ML_KEM_768, ML_KEM_1024).
  • ML-DSA (Dilithium) wrapper functions: DilithiumMakeKey,
    DilithiumExport/Import for public/private keys, DilithiumSignMsg,
    DilithiumVerifyMsg, DilithiumFreeKey (supports ML_DSA_44/65/87).
  • Sign/verify use the FIPS 204 wc_dilithium_sign_ctx_msg /
    wc_dilithium_verify_ctx_msg APIs (with ctx=NULL/ctxLen=0) so the wrapper
    works without WOLFSSL_DILITHIUM_NO_CTX.
  • user_settings.h: enables HAVE_MLKEM, WOLFSSL_WC_MLKEM, HAVE_DILITHIUM,
    WOLFSSL_WC_DILITHIUM, WOLFSSL_SHAKE128/256, plus WOLFSSL_DTLS_CH_FRAG
    (required for PQC + DTLS 1.3).
  • NamedGroup enum extended with WOLFSSL_ML_KEM_512/768/1024 and the
    hybrid groups (SECP256R1MLKEM768, X25519MLKEM768, SECP384R1MLKEM1024).
  • New mlkem_test and mldsa_test cases in wolfCrypt-Test.cs covering
    keygen, encode/decode (or export/import), and full encap/decap or
    sign/verify roundtrips for every parameter set.
  • README.md: documents a sudo-free build with
    --prefix=$(pwd)/install and running the test via
    LD_LIBRARY_PATH=./install/lib mono wrapper/CSharp/wolfcrypttest.exe so
    mono picks up the freshly-built library instead of any stale system one.
  • Peer review fixes: stricter return-code checks on wc_MlKemKey_*Size /
    wc_MlDsaKey_Get*Len callers, MEMORY_E (not EXCEPTION_E) on RNG alloc
    failure in DilithiumSignMsg, dead null re-checks removed from the Free
    helpers, indentation cleanup, consistent wolfcrypt. prefix in
    mldsa_test, and removal of the C-only WOLF_ENUM_DUMMY_LAST_ELEMENT
    from NamedGroup.

Testing

  • ./autogen.sh && cp wrapper/CSharp/user_settings.h . && ./configure --enable-usersettings --prefix=$(pwd)/install && make && make install
  • cd wrapper/CSharp && mcs wolfCrypt-Test/wolfCrypt-Test.cs wolfSSL_CSharp/{wolfCrypt,wolfSSL,X509}.cs -OUT:wolfcrypttest.exe
  • LD_LIBRARY_PATH=./install/lib mono wrapper/CSharp/wolfcrypttest.exe — all
    tests pass, including ML-KEM 512/768/1024 and ML-DSA 44/65/87
    (signature lengths 2420/3309/4627).

Checklist

  • added tests
  • updated/added doxygen
  • updated appropriate READMEs
  • Updated manual and documentation

@dgarske dgarske self-assigned this Apr 10, 2026
Copilot AI review requested due to automatic review settings April 10, 2026 19:04
Copy link
Copy Markdown
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

Adds post-quantum ML-KEM (KEM) and ML-DSA/Dilithium (signature) support to the wolfSSL C# wrapper, including test coverage and updated build/run instructions.

Changes:

  • Added C# P/Invoke + managed wrapper APIs for ML-KEM (keygen, encode/decode, encaps/decaps, free) and ML-DSA/Dilithium (keygen, export/import, sign/verify, free).
  • Extended the wolfSSL C# wrapper with TLS 1.3 UseKeyShare support and added a NamedGroup enum covering PQC/hybrid groups.
  • Added new C# wrapper tests for ML-KEM and ML-DSA, plus updated README/user settings for local-prefix builds and running under mono.

Reviewed changes

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

Show a summary per file
File Description
wrapper/CSharp/wolfSSL_CSharp/wolfSSL.cs Adds NamedGroup and UseKeyShare() wrapper for TLS 1.3 key shares (incl. PQC/hybrid IDs).
wrapper/CSharp/wolfSSL_CSharp/wolfCrypt.cs Adds ML-KEM and ML-DSA/Dilithium wolfCrypt wrappers and related constants/enums.
wrapper/CSharp/wolfCrypt-Test/wolfCrypt-Test.cs Adds ML-KEM and ML-DSA roundtrip tests (keygen + encode/decode or export/import + encaps/decaps or sign/verify).
wrapper/CSharp/user_settings.h Enables ML-KEM/ML-DSA and required primitives/options in the wrapper build.
wrapper/CSharp/README.md Updates build/install steps to use a local prefix and run tests with LD_LIBRARY_PATH.

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

@dgarske dgarske assigned wolfSSL-Bot and unassigned dgarske Apr 12, 2026
@dgarske dgarske requested a review from SparkiDev April 13, 2026 17:26
Copy link
Copy Markdown

@wolfSSL-Fenrir-bot wolfSSL-Fenrir-bot left a comment

Choose a reason for hiding this comment

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

Fenrir Automated Review — PR #10191

No scan targets match the changed files in this PR. Review skipped.

@SparkiDev
Copy link
Copy Markdown
Contributor

Please resolve conflict.

Copilot AI review requested due to automatic review settings April 13, 2026 22:31
@dgarske dgarske removed their assignment Apr 13, 2026
Copy link
Copy Markdown
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 4 out of 4 changed files in this pull request and generated 5 comments.


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

@dgarske dgarske requested a review from SparkiDev April 14, 2026 16:30
@SparkiDev SparkiDev merged commit 8fd896a into wolfSSL:master Apr 14, 2026
613 of 618 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.

6 participants