Repository navigation
PPC64LE Montgomery multiplication: the accumulator in registers - #4757
Merged
Merged
Conversation
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHH4GefHP3pmPRSL4N4
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHH4GefHP3pmPRSL4N4
…multiplication Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHH4GefHP3pmPRSL4N4
…the memory accumulator's code Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHH4GefHP3pmPRSL4N4
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 (PPC64LE audit, finding 1: per-operation cost of the curves).
Every curve's field multiplication on PPC64LE,
vg_<curve>_mul_mod_<p|n>, kept the CIOS accumulatorTin memory. Each step of a row loadedt_jand stored it back, so every carry chain ran through store-to-load forwarding. In P-256's ECDH this function is about 70% of the time: 52 calls per window, about 470 instructions each.Change
Impl/Mont/PPC64LE.lean:rmulreplacesmul. Then + 1words ofTlive inr15–r(15 + n)(treg).rrowB,rrowM), the step (rmac) and the reduction (rcsub) aremul's, with registers in place of words: the second row moves each word one register down.rmulsaves them in its own working space, where the accumulator was, clears them, and restores them at the end.T.mul, its rows and their proofs) is deleted.Proof/Mont/PPC64LE/Ops.lean:rmul_ok, with the same statement as the oldmul_ok: the same result, written ranges andKp opClob.Kphold.rmacs_ok,rrow_ok(invariantRLoopInv),rloop_ok,rcsub_okand the save, clear and restore lemmas.Proof/Weierstrass/PPC64LE/MontFn.lean:mulFn_okusesrmul_ok. Its statement is unchanged, so no caller's proof changes.Callers: which registers stay public
The constant-time analysis (
Proof/Framework/PPC64LE/Taint.lean) treats memory as secret. A register restored from the stack is therefore secret after a call, even though it holds the caller's value again. A value that must be public after a field multiplication — a pointer or a counter — has to be inr14orr25–r31.That is why
tregstarts atr15: the signing, key and ECDH code keep their output pointer inr14and their counters inr31. The rule is stated inImpl/Weierstrass/PPC64LE/Call.lean's module doc and inmulCall_ok's docstring. The open PPC64LE curve branches (the combs, brainpool, #4747) keep their public values only inr14andr31.No TCB or Spec change.
Testing
lake build,Emit.leanand--checkpass. The crate changes are every curve'sinternal/vg_*_mul_mod_{p,n}andecdh_p256.rs(its literal includes the callee).taint_decideagain.check_lean_public_imports.pypass.Benchmark
POWER9, run 42528026249 against main (cd85a7b),
arches=powerpc64, ECDH, ECDSA and keys for P-256, P-224 and brainpoolP256r1, with OpenSSL. The deterministic operations:ecdh_p256/32ecdh_p224/28ecdh_brainpoolp256r1/32ec_p256_public_key/65ec_p224_public_key/57ec_brainpoolp256r1_public_key/65An earlier run (42526697406, on the previous base) measured
ecdh_p256409 → 314 µs andec_p256_public_key861 → 648 µs, from before #4729's comb.The ECDSA rows of the same run are noisy on this runner, between 23% slower and 68% faster for the same code at different message sizes. Most are faster: P-256 signing 12–32%, P-256 verification 1–52%, P-224 signing 42–68%. Two of brainpoolP256r1's verification rows came out 12% and 24% slower. Nothing in this change runs more instructions, so I read those two rows as the runner's variance; they can be re-measured on request.
Generated by Claude Code