Skip to content

Implement X.509, PKCS#12 and PKCS#8 for ML-KEM - #132768

Closed
vcsjones wants to merge 8 commits into
dotnet:mainfrom
vcsjones:pkcs8-export-mlkem
Closed

Implement X.509, PKCS#12 and PKCS#8 for ML-KEM#132768
vcsjones wants to merge 8 commits into
dotnet:mainfrom
vcsjones:pkcs8-export-mlkem

Conversation

@vcsjones

Copy link
Copy Markdown
Member

Windows now supports encrypted exports for ML-KEM PKCS#8, as well as PKCS#12. Let's remove our work around and enable the tests.

The changes and implementation here are more or less a straight port of ML-DSA's.

vcsjonesand others added 5 commits August 25, 2026 16:42
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Wire the Microsoft.Bcl.Cryptography .NET Framework certificate accessors, retain platform support gating, and align the private-key association tests with the PKCS#8 contract.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).
13 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @bartonjs, @vcsjones, @dotnet/area-system-security
See info in area-owners.md if you want to be subscribed.

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR enables Windows support for ML-KEM X.509 private key association and key export scenarios (PKCS#8 and PKCS#12), and updates tests to run on Windows when ML-KEM is supported.

Changes:

  • Enable Windows certificate private-key association for ML-KEM (GetMLKemPrivateKey/CopyWithPrivateKey) using CNG and PKCS#8 import/export paths.
  • Add ML-KEM Windows implementation plumbing to create ephemeral CNG keys and support encrypted-only export scenarios.
  • Remove the Windows-exclusion test gate and update/expand ML-KEM X.509/PKCS#12 test coverage accordingly.
Show a summary per file
FileDescription
src/libraries/System.Security.Cryptography/tests/X509Certificates/X509Certificate2PemTests.csRun ML-KEM PEM load tests based on MLKem.IsSupported (includes Windows).
src/libraries/System.Security.Cryptography/tests/X509Certificates/PfxTests.csRun ML-KEM PKCS#12/PFX import tests based on MLKem.IsSupported.
src/libraries/System.Security.Cryptography/tests/X509Certificates/ExportTests.csRun ML-KEM PKCS#12 roundtrip export test based on MLKem.IsSupported.
src/libraries/System.Security.Cryptography/tests/X509Certificates/CertTests.csEnable ML-KEM CopyWithPrivateKey/ExportPrivate tests on Windows.
src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/X509Certificates/CertificatePal.Windows.PrivateKey.csImplement ML-KEM private key retrieval and CopyWithPrivateKey on Windows.
src/libraries/System.Security.Cryptography/src/System.Security.Cryptography.csprojInclude new ML-KEM CNG creation helper source file.
src/libraries/Microsoft.Bcl.Cryptography/src/System/Security/Cryptography/X509Certificates/X509CertificateKeyAccessors.csAdd Windows-only implementations for ML-KEM key accessors outside NET / NETSTANDARD.
src/libraries/Microsoft.Bcl.Cryptography/src/Microsoft.Bcl.Cryptography.csprojInclude new ML-KEM CNG creation helper source file.
src/libraries/Common/tests/System/Security/Cryptography/X509Certificates/CertificateCreation/PrivateKeyAssociationTests.Shared.csUpdate ML-KEM certificate association assertions to validate functional decapsulation.
src/libraries/Common/tests/System/Security/Cryptography/PlatformSupport.csRemove IsPqcMLKemX509Supported (Windows exclusion) gate.
src/libraries/Common/tests/System/Security/Cryptography/MLKemCngTests.Windows.csAdjust ML-KEM CNG tests for PKCS#8 behavior and expected Windows error codes.
src/libraries/Common/tests/System/Security/Cryptography/MLKemBaseTests.csCentralize “export PKCS#8 from public key” assertions via a virtual helper.
src/libraries/Common/src/System/Security/Cryptography/X509Certificates/CertificateHelpers.Windows.csAdd ML-KEM CopyWithPrivateKey implementation on Windows, including CNG/PKCS#8 import fallback.
src/libraries/Common/src/System/Security/Cryptography/MLKemImplementation.CreateCng.csNew helper to create an ephemeral CngKey from MLKemImplementation key material.
src/libraries/Common/src/System/Security/Cryptography/MLKemCng.Windows.csImplement PKCS#8 import and support encrypted-only export workflows for ML-KEM keys.
src/libraries/Common/src/System/Security/Cryptography/MLDsaCng.Windows.csReuse shared Helpers.TrimAndTrack utility.
src/libraries/Common/src/System/Security/Cryptography/Helpers.csAdd shared TrimAndTrack helper for safe trimming/clearing of key material arrays.

Review details

  • Files reviewed: 17/17 changed files
  • Comments generated: 1
  • Review effort level: Lite

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
CopilotAI review requested due to automatic review settings August 26, 2026 14:29

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Review details

  • Files reviewed: 18/18 changed files
  • Comments generated: 0 new
  • Review effort level: Lite

CopilotAI review requested due to automatic review settings August 27, 2026 11:36

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Review details

  • Files reviewed: 18/18 changed files
  • Comments generated: 0 new
  • Review effort level: Lite

@vcsjonesvcsjones added the NO-REVIEW Experimental/testing PR, do NOT review it label Aug 27, 2026
CopilotAI review requested due to automatic review settings August 27, 2026 20:12

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

Review tier: Lite
Findings: None

@vcsjones

Copy link
Copy Markdown
MemberAuthor

Seems like our CI images have not had ML-KEM flow down through servicing yet. Will Re-open when I get better information about PKCS#8 exports from ncrypt.

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-System.SecurityNO-MERGEThe PR is not ready for merge yet (see discussion for detailed reasons)NO-REVIEWExperimental/testing PR, do NOT review it

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

@vcsjones@bartonjs