Skip to content

cryptobackend/chacha20poly1305: reject FIPS 140-only mode in New - #2722

Merged
Quim Muntal (qmuntal) merged 1 commit into
microsoft/mainfrom
dev/qmuntal/chacha20poly1305-fips-only
Nov 13, 2026
Merged

Quim Muntal (qmuntal) merged 1 commit into
microsoft/mainfrom
dev/qmuntal/chacha20poly1305-fips-only

Conversation

@qmuntal

Copy link
Copy Markdown
Member

Move the FIPS 140-only rejection for ChaCha20-Poly1305 into the common New in cryptobackend/chacha20poly1305, before the native-backend/Go-fallback selection.

Previously each platform newBackend (openssl, windows, darwin) repeated the check, and the Go fallback relied on x/crypto's own. There is now a single check that does not depend on which backend is compiled in or on what Supports() reports.

There is no behavior change: the error is the same on every path.

Changes

  • chacha20poly1305.go: return the FIPS 140-only error when fips140.Enforced(), ahead of backend.Enabled && Supports().
  • chacha20poly1305_{openssl,windows,darwin}.go: drop the duplicated check and the now-unused imports.
  • Regenerated the vendored copy with go mod vendor and folded it into 0002-Vendor-external-dependencies.patch (plus patches/index.json) using git go-patch rebase and extract. No other patch changes.

Testing

No new tests: the existing TestFIPS140Only in crypto/internal/fips140only already asserts that HPKE ChaCha20-Poly1305 Seal/Open fail under fips140=only.

  • cryptobackend: go test ./... with system Go and with the built toolchain (CNG).
  • go vet of the vendored package and crypto/hpke for linux/{amd64,arm64}, darwin/{arm64,amd64}, windows/amd64 and freebsd/amd64, plus the nobackend build (MS_GO_NOSYSTEMCRYPTO=1).
  • go test -short crypto/hpke crypto/tls crypto/internal/fips140only, and TestFIPS140Only run with GODEBUG=fips140=only.
  • go test go/build dependency tests, with and without MS_GO_NOSYSTEMCRYPTO=1.
  • eng/_util patchcheck test. Applying the patch series to the submodule base reproduces the tested tree.

The OpenSSL path could only be compile-checked locally (cross-vet); CI covers it at runtime.

Updates #2489.

Check fips140.Enforced() once in the common New, before choosing
between the native backend and the Go fallback, instead of repeating
the check in each platform's newBackend. The policy no longer depends
on which backend is compiled in or on what Supports() reports.

The returned error is unchanged, so behavior is the same as before.

Regenerate the vendored copy in the vendor patch.

Updates #2489.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@qmuntal
Quim Muntal (qmuntal) requested a review from a team as a code owner November 13, 2026 09:43
Copilot AI balanced review requested due to automatic review settings November 13, 2026 09:43
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).
There may be pipelines that require an authorized user to comment /azp run to run.

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.

🟢 Approval recommended

No active review issues are recorded for the change centralizing ChaCha20-Poly1305’s FIPS 140-only rejection in the shared constructor.

No open issues 🎉

What changed in this PR

Centralizes ChaCha20-Poly1305’s FIPS 140-only rejection in the common cryptobackend.New constructor, supporting #2489’s consolidation of crypto behavior in the backend layer.

Changes:

  • Checks FIPS 140-only mode before selecting the native backend or Go fallback, and documents this behavior.
  • Removes duplicate checks and unused imports from the three platform implementations.
  • Synchronizes the vendored code and patch index metadata.

Patches are happy!

File Description
patches/​index.json Updates the vendor patch hash and index entries.
patches/​0002-Vendor-external-dependencies.patch Mirrors the constructor and platform changes in vendored code.
cryptobackend/​chacha20poly1305/​chacha20poly1305.go Adds and documents the shared FIPS 140-only guard.
cryptobackend/​chacha20poly1305/​chacha20poly1305_windows.go Removes the duplicate Windows guard and unused imports.
cryptobackend/​chacha20poly1305/​chacha20poly1305_openssl.go Removes the duplicate OpenSSL guard and unused imports.
cryptobackend/​chacha20poly1305/​chacha20poly1305_darwin.go Removes the duplicate Darwin guard and unused imports.

Review effort: Balanced

@qmuntal
Quim Muntal (qmuntal) merged commit 88e8934 into microsoft/main Nov 13, 2026
77 checks passed
@qmuntal
Quim Muntal (qmuntal) deleted the dev/qmuntal/chacha20poly1305-fips-only branch November 13, 2026 12:05
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.

3 participants