Repository navigation
HMAC: choose with its generated dispatchers - #4505
Merged
Merged
Conversation
`streaming_hmac!` calls `vg_hmac_<hash>_init_auto` and `vg_hmac_<hash>_finalize_auto` (`crate::arch::dispatch::hmac_<hash>`) instead of matching on the hash's backend enum, chosen by its `select`, for each of `init`, `finalize` and `mac`. It takes the two dispatchers alone and loses the per-implementation lists and the checks of their features. The inner hash's `from_state` no longer takes a backend, and `streaming_hash!` loses `backend()`, which only HMAC used. 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. `init`, the text's `update` and `finalize` each check their own features, so they could differ only on feature sets no CPU has; every implementation keeps the same streaming state (the same contract), so any of them may follow another. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHFuGsz7F32Tm9DLkuP
alex
enabled auto-merge
November 7, 2026 17:57
Member
Author
|
Generated by Claude Code |
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.
HMAC's
initandfinalize(and the one-callmac) now runvg_hmac_<hash>_init_autoandvg_hmac_<hash>_finalize_auto(crate::arch::dispatch::hmac_<hash>). They no longer follow the hash's backend enum, which the hash'sselectchose in Rust.Changes
streaming_hmac!takes only the two dispatchers, the state size and the digest size. It loses the per-implementation lists, thematches and the compile-time checks of their features.src/hmac/<hash>.rsfiles are now that one invocation and its imports.streaming_hash!:from_stateno longer takes a backend, andbackend(), which only HMAC used, is gone. The text'supdateis still the hash's own; that moves to its dispatcher with the hash migration.Choice
The choice is today's:
init,updateandfinalizeeach check their own features. They could differ only on feature sets no CPU has. Every implementation of these functions has the same contract over the same streaming state, so any one may follow another.Unchanged
one_call,long_key,verify) test the API, not a choice, so they stay, andci/cpu_tests.pyis unchanged.Benchmark
One scoped run (
hmac_sha1,hmac_sha256,hmac_sha512, on x86-64, AArch64 and x86, each in its configurations), against the merge base: https://github.com/pyca/verified-garbage/actions/runs/42397948866Checks
cargo fmt --checkcargo clippy --all-targets -D warningsfor x86-64 (also withoutalloc), AArch64, i686, ARMv7, RISC-V 64 and PPC64LEcheck_arch_gates.py,check_variants.py,cpu_tests.py lintandrun_unit_tests.pyhmac::andhashes::unit tests, plushmac,rfc4231andrfc6979integration tests (with Wycheproof), withVG_CPU_FEATURESunset and set tonone,sha,ssse3andavx,avx2,bmi1,bmi2Generated by Claude Code