Skip to content

DSA: choose with its generated dispatchers - #4508

Merged
alex merged 4 commits into
mainfrom
claude/dsa-dispatch
Nov 7, 2026
Merged

alex merged 4 commits into
mainfrom
claude/dsa-dispatch

Conversation

@alex

@alex alex commented Nov 7, 2026 •

Copy link
Copy Markdown
Member

What changes

DSA chose its implementations in Rust:

  • src/dsa.rs stored a Backend (the baseline or _adx) in every key.
  • Parameter generation matched SHA-1's, SHA-256's and the Miller–Rabin round's backends to name one of 27 implementations of vg_dsa_parameter_search on x86-64.

Key derivation, generation, validation, signing, verification and the parameter search (including its _init) now call their _auto dispatchers.

Removed from the Rust:

  • Backend and Round, each select and select_backends;
  • the per-ABI Search types and the backend stored in keys;
  • their tests, which called each implementation directly.

The parameter search keeps one test of the searcher's steps, steps, which runs through the dispatcher.

Only the combinations a CPU gets

Of the 27 x86-64 combinations, the dispatcher can choose only some: SHA-1's and SHA-256's code needs the same features in pairs. For example:

  • SHA-1's SHA extensions with SHA-256's AVX2 code never runs, because SHA-256's SHA extensions run wherever SHA-1's do.
  • SHA-1's AVX/BMI code needs BMI2, which CPU detection reports only with AVX2. So it always comes with SHA-256's AVX2 code.

The generic registrations (Generic/{MdHash/MdHash,Sha1/Sha256}/MillerRabin/<T>/Dsa.lean) now pair a SHA-1 and a SHA-256 backend for the same CPUs, as #4502 does for Argon2:

Target SHA-1 / SHA-256 pairs
x86-64 both baselines; SHA extensions with SHA extensions; _avx_bmi with _avx2
x86 both baselines; both SHA extensions
AArch64 both baselines; both SHA-2 extensions

Each pair comes with every Miller–Rabin round, so x86-64 has 9 parameter searches, down from 27.

Two generated dispatcher branches had been covered only by the deleted unit test: IFMA's round without SHA-NI, with SHA-1 AVX/BMI and SHA-256 AVX2, and with both hashes' baselines. To cover them, ci/rust_matrix.toml now runs dsa_parameters on the two icx lines that have AVX512_IFMA but not SHA.

check_variants.py

The parameter searches' suffixes are now _sha1_avx_bmi_sha256_avx2 and _sha1_shani_sha256_shani (and their _mr_*), with no _sha1_avx_bmi alone. Two of the checker's rules matched suffixes too literally, so it now:

  • accepts a qualified part <tag>_<suffix> of a variant's suffix as an internal function's suffix, when its <suffix> is a variant suffix. vg_dsa_parameter_search_1024_sha1_avx_bmi is the case here; vg_keccak_f1600_x2 is still not accepted.
  • accepts a callee's variant in any part of a qualified suffix, not only the last. SHA-1's part comes first in _sha1_avx_bmi_sha256_avx2. Argon2's _blake2b_avx2_g_avx2 only passed before because both its parts end in _avx2.

ci/test_check_variants.py has a test for each. Both tests fail without the change.

No TCB or Spec change.

Benchmark

Run of dsa:

  • architectures: x86_64, aarch64, x86 and arm, each of which has a choice;
  • base: ae39a25, this branch's base.

It ran 12 jobs, one per architecture and VG_CPU_FEATURES configuration that chooses an implementation, each with 43 DSA benchmarks. I compared each benchmark's median estimate, head against base, from the uploaded samples:

Job Median Worst row Best row
aarch64 (2 jobs) −0.1%, −0.1% +5.7%, +13.4% −10.4%, −3.9%
arm 0.0% +32.9% −13.5%
x86 (2 jobs) 0.0%, 0.0% +11.9%, +12.5% −2.3%, −15.3%
x86_64 (7 jobs) −1.2% to +0.5% +1.5% to +22.6% −17.4% to −36.6%

The outliers go both ways, on rows that run the same machine code as before:

  • dsa_public_key_* and dsa_private_key_* (20–340 ns) move by up to ±36%. Key import calls no verified code: it allocates and copies.
  • dsa_generate_key_* calls the implementation each CPU got before. That includes ARM's +32.9% at 3072 bits, where vg_dsa_generate_key has a single implementation, the same as on main.

No benchmark was rerun.

Checks

  • lake build; Emit.lean (crates regenerated)
  • every Static checks step, including check_variants.py with its unit tests
  • cargo fmt --check
  • cargo clippy --all-targets -D warnings on x86-64, AArch64 and i686
  • DSA tests (release) with VG_CPU_FEATURES unset and set to each of:
    • sha,ssse3,avx,avx2,bmi1,bmi2,adx
    • avx,avx2,bmi1,bmi2,adx
    • avx,bmi1
    • sha,ssse3
    • none

https://claude.ai/code/session_01TKUFHE2dqL6Q2PDogxfD5f


Generated by Claude Code

`src/dsa.rs` chose a `Backend` (the baseline or `_adx`) for every key, and
parameter generation matched SHA-1's, SHA-256's and the Miller-Rabin
round's backends, 27 combinations on x86-64, to name an implementation
of `vg_dsa_parameter_search`. Key import, generation, validation, signing,
verification and the parameter search now call their `_auto`
dispatchers. `Backend`, `Round`, each `select`, the per-ABI `Search`
types, the stored backend and their tests go; the parameter search keeps
its test of the searcher's steps, through the dispatcher.

The `#[cfg(not(any(...)))]` branches for targets outside the module's
own were dead: the module exists only on those six architectures.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TKUFHE2dqL6Q2PDogxfD5f
@github-actions

github-actions Bot commented Nov 7, 2026

Copy link
Copy Markdown

This pull request has conflicts with main, found after 3596120 landed on main: rebase it to resolve them. Before rebasing, see CLAUDE.md on checking how much Lean main changed, and on restacking a stacked pull request.

Posted by .github/workflows/conflicts.yml, once per push to a conflicting pull request.

…e CPUs (WIP: crates not yet regenerated)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TKUFHE2dqL6Q2PDogxfD5f
…ny position

With only the paired SHA-1 and SHA-256 backends, the parameter search's
suffixes are `_sha1_avx_bmi_sha256_avx2` and `_sha1_shani_sha256_shani`
(and their `_mr_*`): no function with a signature has `_sha1_avx_bmi`
alone. `check_variants.py` now takes a qualified part `<tag>_<suffix>` of
a variant's suffix, whose `<suffix>` is one, as an internal function's
suffix (`vg_dsa_parameter_search_1024_sha1_avx_bmi`), and a callee's
variant in any part of a qualified suffix, not only the last.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TKUFHE2dqL6Q2PDogxfD5f
@alex
alex enabled auto-merge November 7, 2026 19:22
@alex
alex added this pull request to the merge queue Nov 7, 2026
Merged via the queue into main with commit 0a655db Nov 7, 2026
56 checks passed
@alex
alex deleted the claude/dsa-dispatch branch November 7, 2026 19:41
alex pushed a commit that referenced this pull request Nov 7, 2026
Resolves the conflict with #4508: src/dsa/parameters/search.rs and its
tests take main's dispatchers, and riscv64 joins search.rs's module
gate. The RISC-V crate is regenerated with the full emitter, which picks
up #4514's Montgomery code.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TKUFHGhkN8REQLPW8yxN5A
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