Skip to content

Move hash fallback logic to cryptobackend - #2491

Open
Quim Muntal (qmuntal) wants to merge 1 commit into
microsoft/mainfrom
dev/qmuntal/cryptobackend-hash-fallback
Open

Move hash fallback logic to cryptobackend#2491
Quim Muntal (qmuntal) wants to merge 1 commit into
microsoft/mainfrom
dev/qmuntal/cryptobackend-hash-fallback

Conversation

@qmuntal

@qmuntal Quim Muntal (qmuntal) commented Sep 3, 2026

Copy link
Copy Markdown
Member

This change moves SHA-256, SHA-512, fixed-output SHA-3, SHAKE, and cSHAKE backend/fallback dispatch into cryptobackend. Keeping that decision in one place makes the standard-library integration much closer to upstream and the patches smaller.

Updates #2489

@qmuntal
Quim Muntal (qmuntal) requested a review from a team as a code owner September 3, 2026 14:40
Copilot AI lite review requested due to automatic review settings September 3, 2026 14:40
@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.

@qmuntal Quim Muntal (qmuntal) changed the title crypto: move hash fallback logic to cryptobackend Move hash fallback logic to cryptobackend Sep 3, 2026

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.

Copilot review overview

🟡 Changes recommended

The updated crypto/sha256 Sum224 path can still route into an unsupported backend implementation under systemcrypto (missing capability gating), risking runtime panics on Windows/Darwin.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Review tier: Lite
Findings: 1 High severity · 1 Low severity

New issues introduced by this change (2)
Severity Finding
High severity patches/​0002-Add-crypto-backends.patch — In the sha256.Sum224 patch hunk, the implementation still unconditionally uses…
Low severity cryptobackend/​sha3/​shake.go — This file imports the root cryptobackend package without the conventional boring alias and then…
What changed in this PR

This PR moves SHA-2/SHA-3 (fixed-output), SHAKE, and cSHAKE backend-vs-fallback dispatch logic into github.com/microsoft/go/cryptobackend, replacing scattered capability checks in stdlib packages with generated dispatcher wrappers that centralize support checks, cloning, marshaling, and fallback behavior.

Changes:

  • Add generated cryptobackend/{sha256,sha3,sha512} dispatchers (plus SHAKE/cSHAKE helpers) that select backend implementations when supported and fall back otherwise.
  • Update stdlib integration (via patches/0002-Add-crypto-backends.patch) to call the new cryptobackend/* wrappers and adjust FIPS/hash unwrap paths accordingly.
  • Remove the redundant cryptobackend/hash package and route FIPS approval checks through backend-specific callbacks.
File Description
patches/​0001-Vendor-external-dependencies.patch Vendors updated cryptobackend code generation output and removes the vendored cryptobackend/hash package.
patches/​0002-Add-crypto-backends.patch Updates stdlib crypto packages and internal FIPS plumbing to use cryptobackend for hash dispatch/fallback and unwrap behavior.
cryptobackend/​backend_darwin.go Adds backend-level fipsApprovedHash callback implementation for Darwin.
cryptobackend/​backend_msgostd.go Wires crypto/internal/fips140only.BackendApprovedHash to the backend callback under msgostd.
cryptobackend/​backend_openssl.go Adds backend-level fipsApprovedHash callback implementation for OpenSSL.
cryptobackend/​backend_windows.go Adds backend-level fipsApprovedHash callback implementation for Windows.
cryptobackend/​backend_test.go Updates backend tests to reflect removal of the hash subpackage.
cryptobackend/​hash/​hash_darwin.go Removes the obsolete cryptobackend/hash implementation (Darwin).
cryptobackend/​hash/​hash_openssl.go Removes the obsolete cryptobackend/hash implementation (OpenSSL).
cryptobackend/​hash/​hash_windows.go Removes the obsolete cryptobackend/hash implementation (Windows).
cryptobackend/​hash/​nobackend.go Removes the obsolete cryptobackend/hash stub.
cryptobackend/​internal/​hashgen/​main.go Adds a code generator that produces native/fallback hash dispatchers for multiple algorithms.
cryptobackend/​sha256/​nobackend.go Updates SHA-256 backend stubs to match the generated dispatcher structure.
cryptobackend/​sha256/​sha256.go Adds SHA-256 one-shot sum wrappers that select backend or fallback.
cryptobackend/​sha256/​sha256_darwin.go Implements backend plumbing and capability checks for SHA-256 on Darwin.
cryptobackend/​sha256/​sha256_openssl.go Implements backend plumbing and capability checks for SHA-256 on OpenSSL.
cryptobackend/​sha256/​sha256_windows.go Implements backend plumbing and capability checks for SHA-256 on Windows.
cryptobackend/​sha256/​zsha256.go Generated SHA-256 hash dispatcher (backend vs fallback) with cloning/marshal support.
cryptobackend/​sha256/​zsha256_msgostd.go msgostd fallback bindings + constructors + Unwrap.
cryptobackend/​sha256/​zsha256_nomsgostd.go Non-msgostd panic stubs + constructors.
cryptobackend/​sha3/​init.go (Integration) Ensures sha3 backend package is pulled in when enabled.
cryptobackend/​sha3/​nobackend.go Updates SHA-3 backend stubs to match generated dispatcher expectations.
cryptobackend/​sha3/​sha3.go Adds fixed-output SHA-3 one-shot sum wrappers that select backend or fallback.
cryptobackend/​sha3/​sha3_darwin.go Implements backend plumbing and capability checks for SHA-3 on Darwin.
cryptobackend/​sha3/​sha3_openssl.go Implements backend plumbing and capability checks for SHA-3/SHAKE/cSHAKE on OpenSSL.
cryptobackend/​sha3/​sha3_windows.go Implements backend plumbing and capability checks for SHA-3/SHAKE/cSHAKE on Windows.
cryptobackend/​sha3/​shake.go Adds SHAKE/cSHAKE dispatch layer (backend vs fallback) and one-shot sum helpers.
cryptobackend/​sha3/​shake_msgostd.go msgostd fallback bindings for SHAKE/cSHAKE.
cryptobackend/​sha3/​shake_nomsgostd.go Non-msgostd panic stubs for SHAKE/cSHAKE fallback.
cryptobackend/​sha3/​zsha3.go Generated SHA-3 hash dispatcher (backend vs fallback) with cloning/marshal support.
cryptobackend/​sha3/​zsha3_msgostd.go msgostd fallback bindings + constructors + Unwrap.
cryptobackend/​sha3/​zsha3_nomsgostd.go Non-msgostd panic stubs + constructors.
cryptobackend/​sha512/​nobackend.go Updates SHA-512 backend stubs to match generated dispatcher structure.
cryptobackend/​sha512/​sha512.go Adds SHA-512 one-shot sum wrappers that select backend or fallback.
cryptobackend/​sha512/​sha512_darwin.go Implements backend plumbing and capability checks for SHA-512 on Darwin.
cryptobackend/​sha512/​sha512_openssl.go Implements backend plumbing and capability checks for SHA-512 on OpenSSL.
cryptobackend/​sha512/​sha512_windows.go Implements backend plumbing and capability checks for SHA-512 on Windows.
cryptobackend/​sha512/​zsha512.go Generated SHA-512 hash dispatcher (backend vs fallback) with cloning/marshal support.
cryptobackend/​sha512/​zsha512_msgostd.go msgostd fallback bindings + constructors + Unwrap.
cryptobackend/​sha512/​zsha512_nomsgostd.go Non-msgostd panic stubs + constructors.
Files not reviewed (6)
  • cryptobackend/sha256/zsha256.go: Generated file
  • cryptobackend/sha256/zsha256_msgostd.go: Generated file
  • cryptobackend/sha256/zsha256_nomsgostd.go: Generated file
  • cryptobackend/sha3/zsha3.go: Generated file
  • cryptobackend/sha3/zsha3_msgostd.go: Generated file
  • cryptobackend/sha3/zsha3_nomsgostd.go: Generated file

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread patches/0002-Add-crypto-backends.patch
Comment thread cryptobackend/sha3/shake.go
@qmuntal
Quim Muntal (qmuntal) force-pushed the dev/qmuntal/cryptobackend-hash-fallback branch 2 times, most recently from 16602ce to 33c4e50 Compare September 3, 2026 15:42
@qmuntal
Quim Muntal (qmuntal) force-pushed the dev/qmuntal/cryptobackend-hash-fallback branch from 33c4e50 to 39f0326 Compare September 3, 2026 16:23
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.

2 participants