Skip to content

MD5, SHA-1, SHA-2, SM3: choose with their generated dispatchers - #4537

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

alex merged 1 commit into
mainfrom
claude/streaming-hash-dispatch

Conversation

@alex

@alex alex commented Nov 7, 2026

Copy link
Copy Markdown
Member

streaming_hash! now calls each hash's generated dispatchers (crate::arch::dispatch::<module>::vg_<f>_auto) for init, update, finalize and the one-shot digest. Before, it matched on a backend enum, which Rust chose when a computation started.

Changes

Choice

The choice is the same as today:

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

Each function checks its own features, so init, update and finalize could pick different implementations only on feature sets no CPU has. Every implementation has the same contract over the same state.

Unchanged

  • The remaining unit tests test the API, so ci/cpu_tests.py is unchanged.
  • No TCB, Spec or Lean change, and the generated crates are unchanged.

Benchmark

One scoped run (sha1, sha256, sha512 on x86-64, AArch64 and x86, each in its configurations), against the merge base f9b68739: https://github.com/pyca/verified-garbage/actions/runs/42409068583

Checks

  • cargo fmt --check.
  • cargo clippy --all-targets -D warnings on 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 --release with Wycheproof, with VG_CPU_FEATURES unset, none, sha,ssse3 and avx,avx2,bmi1,bmi2 (--features cpu-features-env).

Generated by Claude Code

`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
@alex
alex added this pull request to the merge queue Nov 7, 2026
Merged via the queue into main with commit c3921f0 Nov 7, 2026
54 checks passed
@alex
alex deleted the claude/streaming-hash-dispatch branch November 7, 2026 20:38
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