Move HMAC fallback logic to cryptobackend - #2511
Merged
Merged
Conversation
Move backend dispatch and pure-Go fallback into cryptobackend/hmac, matching the SHA packages. Keep FIPS-only validation in crypto/hmac and reduce the standard-library integration to an import change. Updates #2489.
|
Azure Pipelines: Successfully started running 1 pipeline(s). There may be pipelines that require an authorized user to comment /azp run to run. |
George Adams (gdams)
approved these changes
Sep 22, 2026
Contributor
There was a problem hiding this comment.
Copilot review overview
🔵 Needs a closer look
It changes cryptographic backend dispatch/fallback behavior and patch-vendored stdlib wiring, which warrants careful human validation across build tags and platforms.
Review effort: Lite
Findings: None
What changed in this PR
This PR moves HMAC backend selection + fallback into github.com/microsoft/go/cryptobackend/hmac, so the standard library crypto/hmac integration can be reduced to swapping the internal crypto/internal/fips140/hmac import for the corresponding cryptobackend package while keeping the existing FIPS-only enforcement logic in crypto/hmac.
Changes:
- Add a
cryptobackend/hmac.Newwrapper that dispatches to a platform backend implementation when enabled, otherwise falls back (or panics outsidemsgostd). - Rename platform-specific exported
Newimplementations to an unexportednewBackendHMAChelper to avoid symbol conflicts and match the “wrapper + per-platform helper” pattern used elsewhere. - Update the patch set so
src/crypto/hmac/hmac.goimportsgithub.com/microsoft/go/cryptobackend/hmacinstead ofcrypto/internal/fips140/hmac.
Patches are happy!
| File | Description |
|---|---|
| patches/0002-Add-crypto-backends.patch | Switch crypto/hmac to use cryptobackend/hmac instead of the internal fips140/hmac import. |
| patches/0001-Vendor-external-dependencies.patch | Vendor the new cryptobackend/hmac wrapper + build-tagged fallback/backend split into src/vendor. |
| cryptobackend/hmac/hmac.go | New wrapper entrypoint that selects backend vs fallback. |
| cryptobackend/hmac/hmac_{darwin,windows,openssl}.go | Rename backend entrypoints to newBackendHMAC. |
| cryptobackend/hmac/{hmac_msgostd,hmac_nomsgostd}.go | Add fallback implementation for msgostd and panic stub for non-msgostd. |
| cryptobackend/hmac/nobackend.go | Update stub to newBackendHMAC for non-systemcrypto builds. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Move HMAC backend selection and fallback into cryptobackend, following the SHA packages. This reduces the crypto/hmac integration to replacing its internal HMAC import while preserving FIPS-only checks.
Updates #2489.
Validation: HMAC tests with system crypto enabled and disabled, FIPS-enabled HMAC tests, FIPS-only enforcement, dependency checks, and standalone backend checks.