Repository navigation
PBKDF2-HMAC: choose with its generated dispatchers - #4503
Merged
Merged
Conversation
Each hash's `pbkdf2_derive` calls `vg_pbkdf2_hmac_<hash>_auto` (`crate::arch::dispatch::pbkdf2_<hash>`) instead of matching on the hash's backend enum, chosen by its `select` in Rust. `whole_pbkdf2!` takes the dispatcher alone and loses the per-implementation lists and the checks of their features. 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 derivation now checks its own function's features, not those of the hash's update and finalize, so they differ only on feature sets no CPU has. 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.
Each hash's
Pbkdf2Hash::pbkdf2_derivenow callsvg_pbkdf2_hmac_<hash>_auto(crate::arch::dispatch::pbkdf2_<hash>). Before, it matched on the hash's backend enum, which the hash'sselectchose in Rust.Changes
whole_pbkdf2!takes only the dispatcher and the digest size:whole_pbkdf2!(Sha256, pbkdf2: vg_pbkdf2_hmac_sha256_auto, output: 32).Backend::REQUIRES.src/kdf/pbkdf2_hmac/<hash>.rsfiles shrink to that one line plus imports.Choice
The dispatchers choose the same implementations as before:
Each derivation now checks its own function's features rather than those of the hash's
updateandfinalize. The two sets differ only on feature sets no CPU has.The unit tests (
prefix_and_verify) test the API, not a choice, so they stay.ci/cpu_tests.pyis unchanged.No TCB, Spec or Lean change, and the generated crates are unchanged.
Benchmark
One scoped run, against the merge base:
pbkdf2_sha1,pbkdf2_sha256andpbkdf2_sha512on x86-64, AArch64 and x86, each in its own configurations. https://github.com/pyca/verified-garbage/actions/runs/42397773080Checks
cargo fmt --checkcargo clippy --all-targets -D warningsfor x86-64, AArch64, i686, ARMv7, RISC-V 64 and PPC64LEStatic checkssteps that read Rust:check_arch_gates.py,check_variants.py,cpu_tests.py lint,run_unit_tests.pyandalgorithms_table.py --checkVG_CPU_FEATURESunset and set tonone,sha,ssse3andavx,avx2,bmi1,bmi2Generated by Claude Code