Skip to content

Wire ML-DSA into the crypto backend#2342

Merged
michelle-clayton-work merged 3 commits into
microsoft/mainfrom
dev/mclayton/mldsa-backend
Jun 8, 2026
Merged

Wire ML-DSA into the crypto backend#2342
michelle-clayton-work merged 3 commits into
microsoft/mainfrom
dev/mclayton/mldsa-backend

Conversation

@michelle-clayton-work

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

Copy link
Copy Markdown
Contributor

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

Copilot AI 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 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

gdams commented Jun 3, 2026

Copy link
Copy Markdown
Member

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
Comment thread patches/0002-Add-crypto-backends.patch Outdated
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 3 times, most recently from 756f2ef to 3d900a3 Compare June 3, 2026 20:50
Comment thread eng/_util/cmd/updatecryptodocs/docs.go Outdated
Mechanical bump + 'go mod vendor' regen. No source changes in microsoft/go itself; the large diff is upstream maintenance accumulated since the previously-pinned versions (May 12), including the fakecgo 'DO NOT EDIT' header pass (go-crypto-darwin#209).

Prerequisite for the crypto/mldsa Equal wiring follow-up PR.
Adds ML-DSA shims to backend_{linux,darwin,windows}.go and nobackend.go; updates crypto/mldsa std-lib to dispatch via the configured backend (boring.Equal, boring.Sign, boring.Verify) when available, falling back to the Go implementation otherwise. Also adds ML-DSA to the cross-platform crypto documentation.

Depends on #<bump-backends PR>.
@michelle-clayton-work michelle-clayton-work force-pushed the dev/mclayton/mldsa-backend branch 2 times, most recently from de726a5 to b348d6d Compare June 8, 2026 01:55
Comment thread patches/0002-Add-crypto-backends.patch Outdated
+ if boring.Enabled && boring.SupportsMLDSA(boring.MLDSA65()) {
+ switch runtime.GOOS {
+ case "darwin", "windows":
+ expected = 16

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.

On my Windows machine, which supports ML-DSA, this tests only produces 8 allocations. 16 seems is too conservative.

Comment thread patches/0002-Add-crypto-backends.patch Outdated
The by-value boring.PrivateKeyMLDSA/PublicKeyMLDSA fields made mldsa.PrivateKey and mldsa.PublicKey too large to keep on the stack, regressing the Go-path allocation count and failing crypto/mldsa TestAllocations on CI (where no runner's system crypto implements ML-DSA, so the Go fallback always runs). Store the backend keys by pointer instead, which only grows the wrappers by one word, and update TestAllocations to expect the backend count when ML-DSA is backend-implemented and one extra allocation on the fallback path.

@qmuntal qmuntal left a comment

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.

LGTM!

@michelle-clayton-work michelle-clayton-work merged commit 86df9da into microsoft/main Jun 8, 2026
54 checks passed
@michelle-clayton-work michelle-clayton-work deleted the dev/mclayton/mldsa-backend branch June 8, 2026 20:34
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