Repository navigation
MD5, SHA-1, SHA-2, SM3: choose with their generated dispatchers - #4537
Merged
Merged
Conversation
`streaming_hash!` calls the dispatchers of each hash's `init`, `update`, `finalize` and one-shot `digest` (`crate::arch::dispatch::<module>`, `vg_<f>_auto`) instead of matching on its backend enum, chosen in Rust when a computation started. The enums (`Md5Backend`, `Sha1Backend`, …, `Sm3Backend`), their `REQUIRES` and `select`, and the computations' `backend` field go: their other users, the tables (#4501), HMAC (#4505), PBKDF2 (#4503), DSA's parameter search (#4508) and RSA's PKCS #1 v1.5 decryption (#4509), call their own dispatchers. The choice is today's: SHA-NI, then AVX2 (SHA-1: AVX+BMI) on x86-64; SHA2 (SHA-512's family: SHA3) on AArch64; SHA-NI on x86. Each function checks its own features, so they could differ only on feature sets no CPU has; every implementation has the same contract over the same state. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHFuGsz7F32Tm9DLkuP
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.
streaming_hash!now calls each hash's generated dispatchers (crate::arch::dispatch::<module>::vg_<f>_auto) forinit,update,finalizeand the one-shotdigest. Before, it matched on a backend enum, which Rust chose when a computation started.Changes
init: …, update: …, finalize: … (, digest: …), and each hash file (md5,sha1,sha224,sha256,sha384,sha512,sha512_224,sha512_256,sm3) is that one invocation.Md5Backend,Sha1Backend, …,Sm3Backend);REQUIRESandselect;backendfield.main: the tables (Hash tables: choose with the generated table dispatchers #4501), HMAC (HMAC: choose with its generated dispatchers #4505), PBKDF2 (PBKDF2-HMAC: choose with its generated dispatchers #4503), DSA (DSA: choose with its generated dispatchers #4508) and RSA (RSA key generation, PKCS#1 v1.5 and precomputation: choose with their dispatchers #4509, RSA-OAEP and RSA-PSS: choose with their dispatchers; delete rsa::Backend #4533).CLAUDE.md, "An optimized implementation reaches everything built on it": the Rust code now calls only dispatchers, names no variant and chooses nothing. TheNEVER_WITHand vendor sentences now say "the dispatchers choose" rather than describing a Rust choice and its unit tests. The coordinating session asked for this edit to go in this PR.Choice
The choice is the same as today:
Each function checks its own features, so
init,updateandfinalizecould pick different implementations only on feature sets no CPU has. Every implementation has the same contract over the same state.Unchanged
ci/cpu_tests.pyis unchanged.Benchmark
One scoped run (
sha1,sha256,sha512on x86-64, AArch64 and x86, each in its configurations), against the merge basef9b68739: https://github.com/pyca/verified-garbage/actions/runs/42409068583Checks
cargo fmt --check.cargo clippy --all-targets -D warningson x86-64, AArch64, i686, ARMv7, RISC-V 64 and PPC64LE.check_variants.py,check_arch_gates.py,cpu_tests.py lint,run_unit_tests.py.cargo test --releasewith Wycheproof, withVG_CPU_FEATURESunset,none,sha,ssse3andavx,avx2,bmi1,bmi2(--features cpu-features-env).Generated by Claude Code