Skip to content

ML-DSA: Add BCrypt support in Microsoft.Bcl.Cryptography #116616

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 13, 2025

Conversation

PranavSenthilnathan
Copy link
Member

@PranavSenthilnathan PranavSenthilnathan commented Jun 13, 2025

And fix failing tests.

Fixes #116598

@PranavSenthilnathan PranavSenthilnathan added this to the 10.0.0 milestone Jun 13, 2025
@PranavSenthilnathan PranavSenthilnathan self-assigned this Jun 13, 2025
@Copilot Copilot AI review requested due to automatic review settings June 13, 2025 02:27
Copy link
Contributor

@Copilot 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 PR introduces BCrypt support for ML-DSA by adding a new CNG implementation file and updating project files and interop helpers. Key changes include:

  • Adding MLDsaImplementation.CreateCng.cs to provide an ephemeral CNG key creation implementation.
  • Updating csproj files to include new interop files and the new CNG implementation.
  • Refactoring memory marshalling usage in PqcBlobHelpers and removing duplicate implementations in MLDsaImplementation.Windows.cs.

Reviewed Changes

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

Show a summary per file
File Description
src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/MLDsaImplementation.CreateCng.cs Introduces a new method to create ephemeral CNG keys using BCrypt.
src/libraries/System.Security.Cryptography/src/System.Security.Cryptography.csproj Adds the new CNG implementation file to the compilation.
src/libraries/Microsoft.Bcl.Cryptography/src/Microsoft.Bcl.Cryptography.csproj Includes new interop files necessary for BCrypt support.
src/libraries/Common/src/System/Security/Cryptography/PqcBlobHelpers.cs Updates memory marshalling usage to use MemoryMarshal.Cast for proper blob header extraction.
src/libraries/Common/src/System/Security/Cryptography/MLDsaImplementation.Windows.cs Refactors duplicate key creation code and improves debug assertions and logging.
Comments suppressed due to low confidence (1)

src/libraries/Common/src/System/Security/Cryptography/MLDsaImplementation.Windows.cs:165

  • Converting parameterSet to an array in the debug message reduces readability; consider logging parameterSet directly to improve clarity.
Debug.Fail(..., $"{nameof(parameterSet)}: {parameterSet.ToArray()}, ", ...)

Copy link
Contributor

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

Comment on lines +174 to +176
<data name="Cryptography_MLDsaNoSecretKey" xml:space="preserve">
<value>The current instance does not contain a secret key.</value>
</data>
Copy link
Member

Choose a reason for hiding this comment

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

Secret Key vs Decapsulation Key means that to share this with ML-KEM we'd have to parameterize it. But MLDsaNoSeed and MLKemNoSeed seem pretty sharable. Do we really need the same string twice under two names?

Copy link
Member Author

Choose a reason for hiding this comment

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

I can put this in a future PR to avoid merge conflicts since MLKemNoSeed is still in PR pending merge. I like the logical separation of ML-KEM and ML-DSA but it is unfortunate that it would result in more resources in the dll.

Copy link
Member

Choose a reason for hiding this comment

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

Mine's not even approved yet, so if you want to rename yours to something like Cryptography_PqcNoSeed I can merge in main when you merge and then use the de-duped name.

Copy link
Member Author

Choose a reason for hiding this comment

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

The CI is going to be green for this besides the known test failures, so it's probably faster for me to merge and you to change the name rather than both of us waiting for CI.

Copy link
Member

@bartonjs bartonjs left a comment

Choose a reason for hiding this comment

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

LGTM, modulo the (presumably) duplicated string.

@PranavSenthilnathan
Copy link
Member Author

/ba-g #116647, #116558 and #104426

@PranavSenthilnathan PranavSenthilnathan merged commit 2a91d5b into dotnet:main Jun 13, 2025
83 of 87 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Jul 14, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Test Failure: MLDsaTests.IsSupported_AgreesWithPlatform
3 participants