Skip to content

Wire ML-DSA into the crypto backend#2342

Open
michelle-clayton-work wants to merge 2 commits into
microsoft/mainfrom
dev/mclayton/mldsa-backend
Open

Wire ML-DSA into the crypto backend#2342
michelle-clayton-work wants to merge 2 commits into
microsoft/mainfrom
dev/mclayton/mldsa-backend

Conversation

@michelle-clayton-work
Copy link
Copy Markdown
Contributor

@michelle-clayton-work michelle-clayton-work commented Jun 2, 2026

Wires ML-DSA into the system crypto backend, mirroring the existing ML-KEM integration. When the backend is enabled and supports the requested parameter set, crypto/mldsa dispatches key generation, parsing, hedged signing, and verification to the native backend (OpenSSL / CNG / CryptoKit); otherwise it falls back to the Go FIPS 140-3 module.

  • crypto/internal/backend: add ML-DSA shims for backend_linux.go (OpenSSL), backend_windows.go (CNG), backend_darwin.go (CryptoKit), and panic stubs in nobackend.go.
  • crypto/mldsa/mldsa_fips140v1.26.go: add a boring backend handle to PrivateKey/PublicKey, a useBoringMLDSA gate, and backend dispatch for GenerateKey, NewPrivateKey, newPublicKey, Bytes, PublicKey, Equal, Parameters, hedged Sign, and Verify.

@michelle-clayton-work michelle-clayton-work marked this pull request as ready for review June 3, 2026 04:15
@michelle-clayton-work michelle-clayton-work requested a review from a team as a code owner June 3, 2026 04:15
Copilot AI review requested due to automatic review settings June 3, 2026 04:15
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

This PR extends the system crypto backend integration to ML-DSA, mirroring the existing ML-KEM wiring: when the crypto backend is enabled and supports the requested ML-DSA parameter set, crypto/mldsa routes keygen/parsing/sign/verify through the platform backend; otherwise it falls back to the Go FIPS 140-3 module.

Changes:

  • Add ML-DSA shims to crypto/internal/backend across Linux (OpenSSL), Windows (CNG), and Darwin (CryptoKit), plus nobackend panic stubs.
  • Update crypto/mldsa/mldsa_fips140v1.26.go to carry backend handles in key types and dispatch supported operations to the backend (with fallback for unsupported operations like deterministic/external-mu signing).
  • Adjust crypto/mldsa tests to account for backend-backed key handles and backend-dependent allocation behavior.

Patches are happy!

@gdams
Copy link
Copy Markdown
Member

gdams commented Jun 3, 2026

You'll need to update https://github.com/microsoft/go/blob/microsoft/main/eng/_util/cmd/updatecryptodocs/docs.go and run the generator to add ML-DSA to the crypto docs.

Comment thread patches/0002-Add-crypto-backends.patch Outdated
Comment thread patches/0002-Add-crypto-backends.patch Outdated
Comment thread patches/0002-Add-crypto-backends.patch Outdated
+ // Bytes returns only the 32-byte seed, which is the same length for all
+ // parameter sets, so the parameter sets must be compared separately to
+ // match the standard library Equal, which distinguishes them.
+ return sk.paramSet() == other.paramSet() &&
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Hmm, think should Go into the backends. As a general rule (which has exceptions), we shouldn't implement in this layer operations that upstream implements in internal/fips140. For example, OpenSSL support EVP_PKEY_eq. I'm not sure ifCNG/CryptoKit provide similar helpers. If they don't, then we can always fallback to comparing the bytes in the backend.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

In theory this block implements compatibility between boring sk and Go other and vice versa, it sounds like there should be a new initial "both boring" case that calls into the backend to implement this (if supported) rather than using subtle.ConstantTimeCompare?

Comment thread patches/0002-Add-crypto-backends.patch
Comment thread patches/0002-Add-crypto-backends.patch Outdated
@gdams gdams linked an issue Jun 3, 2026 that may be closed by this pull request
Comment thread patches/0002-Add-crypto-backends.patch Outdated
@michelle-clayton-work michelle-clayton-work force-pushed the dev/mclayton/mldsa-backend branch 2 times, most recently from 465bf73 to 756f2ef Compare June 3, 2026 20:33
@michelle-clayton-work michelle-clayton-work force-pushed the dev/mclayton/mldsa-backend branch from 756f2ef to 3d900a3 Compare June 3, 2026 20:50
Title: "ML-DSA",
ColumnHeader: "Parameters",
Packages: []string{"crypto/mldsa"},
MinGoVersion: "1.26",
Copy link
Copy Markdown
Member

@dagood dagood Jun 3, 2026

Choose a reason for hiding this comment

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

Is it true that we're planning to backport this from 1.27?
(If so, we should hold off on the doc change until we actually do.)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't think it's possible to backport this as it only landed in gotip. Let's update this to be 1.27

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
MinGoVersion: "1.26",
MinGoVersion: "1.27",

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.

Patch mldsa

5 participants