Repository navigation
PPC64LE DSA: R² mod p by r2Hi (r2Prime when p's top word is zero) - #4678
Merged
Merged
Conversation
|
This pull request has conflicts with Posted by |
`setupP` computed R² mod p = 2^(128 w) mod p by `Precompute.r2`: 128 w modular doublings, each over all of p's digits, about as much work as fifty Montgomery multiplications for a 2048-bit p, once per check of a key or a domain and per signature or verification. It now computes `-p⁻¹ mod 2³²` first and uses `Precompute.r2Prime`, proven for any odd p: 65 w doublings of 64-bit words and six Montgomery squares. `Precompute.r2Hi` (64 + w doublings) needs p's top word not zero, which the checks of a key do not establish (they check p's bit length, not that p fills `p_len` octets), so it is not used here. `setupP_ok` takes that p is odd, which every caller has checked. No change to the TCB, the specs or the Rust code. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHEf743DNZVAyToasZ6
p is public (the checks of a key already branch on it), so `setupP` now branches on p's top word: when it is not zero, which every key with p of `p_len` octets has, `Precompute.r2Hi` (64 + w doublings from 2^(64 (w - 1)), then six Montgomery squares); else `r2Prime`, as before. `setupPre` loads p, computes `-p⁻¹ mod 2³²`, the bases of arrays 1-3 and p's top word into r3. `setupP_ok` proves both branches (`top_gt`: an odd number whose top word is not zero is above 2^(64 (w - 1)), as `r2Hi_ok` needs). For constant time, `setupP_rel` replaces the taint analysis of all of `setupP` (t4): the taint analysis checks `setupPre` and each branch, and both runs take the same branch because r3 is zero exactly when the public p's top word is (`w_pre0`, `zero_iff_agree`). No change to the TCB, the specs or the Rust code. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHEf743DNZVAyToasZ6
alex
force-pushed
the
claude/ppc64le-dsa-r2
branch
from
November 8, 2026 20:41
f8299ff to
c14404e
Compare
alex
marked this pull request as ready for review
November 8, 2026 20:41
alex
enabled auto-merge
November 8, 2026 20:47
This was referenced Nov 8, 2026
6 tasks done
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.
Part of #4141 (finding 7 of the PPC64LE audit). #4667 has merged, and this branch is restacked onto
main(cd0c332). The full build and emitter leave the generated crate current. This PR changes noSpec/orTCB/file and no Rust code outside the generated PPC64LE crate.What was slow
setupPcomputed R² mod p = 2^(128 w) mod p withPrecompute.r2: 128·w modular doublings, each over every digit of p. For a 2048-bit p that is about as much work as fifty Montgomery multiplications. It runs once for each check of a key or a domain, and for each signature and verification. The bignum session found the same cost in FFDH (#4658).What changed
Two commits:
r2Prime(Impl/Dsa/PPC64LE/Common.lean).setupPcomputes-p⁻¹ mod 2³²first (PublicChecked.minv), thenPrecompute.r2Prime, which is already verified for any odd modulus: 65·w doublings of 64-bit words and six Montgomery squares.r2Hiwhen p's top word is nonzero.Precompute.r2Hi(64 + w doublings from 2^(64(w−1)), then six squares) needs p's top word to be nonzero. The checks of a key don't guarantee that: they check p's bit length, not that p fills itsp_lenoctets. p is public data, though, and the key checks already branch on it. SosetupPnow branches on p's top word:setupPreloads p, computes-p⁻¹and the bases of arrays 1–3, and loads p's top word intor3(topWord).ite r3 = 0 (r2Prime; copy) (r2Hi; copy).p_lenoctets, takes ther2Hipath.Proofs:
setupP_ok(Proof/Dsa/PPC64LE/Elem.lean) is built fromsetupPre_ok, which includestopWord_ok, andsetupTail_ok, which covers either arm.r2Hiarm gets its precondition fromtop_gt: an odd number of 2w digits whose top word is nonzero is above 2^(64(w−1)). It is proved fromval32_top, which splits a number at its top word.setupP_oktakes that p is odd. Its callers pass the oddness check they already made.setupP_rel(CT/Key.lean) replaces the taint analysis of all ofsetupP(the oldt4) at its four call sites (checkParamsandcheckKeyinCT/Key,DeriveChecked/CT,Prevalidated/CT,PrevalidatedSign/CT).setupPre(t4) and each arm (t4a,t4b, from the P space's registers and the bases).r3is zero exactly when the public p's top word is (w_pre0,top_div,zero_iff_agree,rel_ite_zero). The other key checks already argue their branches the same way.Numbers
Each run below is one run of each side on POWER9,
dsamodule, with OpenSSL. Both were measured before the restack.r2Primeagainst #4667's branch: run 42513407754. Signing, verification, cold verification and key generation were 30–48% faster. A few rows read 64–69%, which overstates the effect, because the base column was noisy: the same code measured 4.54 ms in one run and 8.97 ms in another.r2Hiagainstr2Prime(f8299ff against ee64e5b): run 42515529342.r2Prime)r2Hi)dsa_sign_q160/1024dsa_sign_q160/2048dsa_sign_q224/2048dsa_sign_q256/2048dsa_sign_q256/3072dsa_verify_q160/1024dsa_verify_q160/2048dsa_verify_q224/2048dsa_verify_q256/2048dsa_verify_q256/3072dsa_verify_cold_q160/1024dsa_verify_cold_q160/2048dsa_verify_cold_q224/2048dsa_verify_cold_q256/2048dsa_verify_cold_q256/3072dsa_generate_key_q160/1024dsa_generate_key_q160/2048dsa_generate_key_q224/2048dsa_generate_key_q256/2048dsa_generate_key_q256/3072Every benchmark is faster, typically by 12–25%. The spread (2–47%) shows how noisy one run on these shared VMs is. I did not rerun anything.
Together with #4662 and #4667, against the audit (
mainat 0bb4dbe), DSA on POWER9 goes:Checks
lake build(every module, on main's CI cache) and the full emitter pass, and the emitter leaves the tree clean. The Static checks pass.check_lean_public_imports.pyis OK onElemandCT/Key.cargo build --release --target powerpc64le-unknown-linux-gnu --libbuilds the regenerated crate. CI's ppc64le jobs run the tests.🤖 Generated with Claude Code
https://claude.ai/code/session_01TKUFHEf743DNZVAyToasZ6