Skip to content

HMAC: choose with its generated dispatchers - #4505

Merged
alex merged 1 commit into
mainfrom
claude/hmac-dispatch
Nov 7, 2026
Merged

alex merged 1 commit into
mainfrom
claude/hmac-dispatch

Conversation

@alex

@alex alex commented Nov 7, 2026

Copy link
Copy Markdown
Member

HMAC's init and finalize (and the one-call mac) now run vg_hmac_<hash>_init_auto and vg_hmac_<hash>_finalize_auto (crate::arch::dispatch::hmac_<hash>). They no longer follow the hash's backend enum, which the hash's select chose in Rust.

Changes

  • streaming_hmac! takes only the two dispatchers, the state size and the digest size. It loses the per-implementation lists, the matches and the compile-time checks of their features.
  • The eight src/hmac/<hash>.rs files are now that one invocation and its imports.
  • streaming_hash!: from_state no longer takes a backend, and backend(), which only HMAC used, is gone. The text's update is still the hash's own; that moves to its dispatcher with the hash migration.

Choice

The choice is today's:

  • x86-64: SHA-NI, then AVX2 (SHA-1: AVX+BMI)
  • AArch64: SHA2 (SHA-512's family: SHA3)
  • x86: SHA-NI

init, update and finalize each 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

  • The unit tests (one_call, long_key, verify) test the API, not a choice, so they stay, and ci/cpu_tests.py is unchanged.
  • No TCB, Spec or Lean change, and the generated crates are 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/42397948866

Checks

  • cargo fmt --check
  • cargo clippy --all-targets -D warnings for x86-64 (also without alloc), AArch64, i686, ARMv7, RISC-V 64 and PPC64LE
  • check_arch_gates.py, check_variants.py, cpu_tests.py lint and run_unit_tests.py
  • The hmac:: and hashes:: unit tests, plus hmac, rfc4231 and rfc6979 integration tests (with Wycheproof), with VG_CPU_FEATURES unset and set to none, sha,ssse3 and avx,avx2,bmi1,bmi2

Generated by Claude Code

`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
alex enabled auto-merge November 7, 2026 17:57

alex commented Nov 7, 2026

Copy link
Copy Markdown
Member Author

all-green failed on attempt 1 because Lean: shard (1) was cancelled, not because a check failed. Every other job on that attempt passed, and this PR changes no Lean. The shard is re-running on attempt 2.


Generated by Claude Code

@alex
alex added this pull request to the merge queue Nov 7, 2026
Merged via the queue into main with commit f701f99 Nov 7, 2026
112 of 116 checks passed
@alex
alex deleted the claude/hmac-dispatch branch November 7, 2026 19:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants