Skip to content

PPC64LE P-256 ECDH: [d]P by four-bit windows - #4712

Merged
alex merged 2 commits into
mainfrom
claude/ppc64le-ec-verify
Nov 8, 2026
Merged

alex merged 2 commits into
mainfrom
claude/ppc64le-ec-verify

Conversation

@alex

@alex alex commented Nov 8, 2026 •

Copy link
Copy Markdown
Member

Part of #4141 (PPC64LE audit, finding 1, the variable-base half). vg_ecdh_p256 computed [d]P with the Montgomery ladder: one complete addition and one complete doubling for each of the 256 bits (863 µs on POWER9, 8.5× OpenSSL).

What changes

[d]P now uses RISC-V's four-bit windows (Impl/Ecdsa/RISCV64/Window.lean), ported to PPC64LE's layout and field calls:

  • Impl/Ecdsa/PPC64LE/Window.lean: the code, generic over the signature's layout (the slots of P and of b R mod p are parameters).
    1. A table of [e]P for e < 16 is built by complete additions for a = -3 (rcb3). It sits past the tables of bits, at bitsAt n 3.
    2. For each of the 64 windows, the code does four Jacobian doublings (toJ, 4 × dblJ, fromJ, with Y = 1 where Z = 0). It then adds the selected entry with one complete addition.
    3. The entry is the nibble read from the table of d's bits. It is selected by scanning all 16 entries under the mask of nibble = e, so the only branch is on the public counter and every address is r3 plus a constant.
  • Proof/Ecdsa/PPC64LE/P256/Window.lean: mul_ok, which proves R = [k]P for every k < 2^256. The proof covers the field programs on slots, R = 16 R (InvJ), the table, the scan, and the loop (wstep).
  • ECDH's stages accept any multiplication that meets MulPowOk (Impl/Ecdh/PPC64LE.lean's exchangeWith, Proof/Ecdh/PPC64LE/Main.lean's exchangeWith_ok). The ladder goes through it too (qMul_mulPowOk), so every other curve's ECDH is unchanged.
  • Proof/Ecdh/PPC64LE/Verified.lean: win_mulPowOk composes the window with the power Z^(p-2). P-256's Verified now uses it. Constant time is checked by taint_decide on the new code's literal, as before.

ECDH is self-contained here; it does not depend on #4675's GeneratorPost. Signing, public keys and verification are untouched: other sessions own those.

No TCB or Spec change. No sorry, native_decide, bv_decide or new axioms.

Testing

  • The full lake build and Emit.lean --check pass. The only crate change is crates/verified-garbage-asm-powerpc64le/src/ecdh_p256.rs and its assembly.
  • The static checks and check_lean_public_imports.py pass, and cargo fmt --check is clean.
  • CI's ppc64le Rust job passes, including the ECDH tests and Wycheproof.

Benchmark

Benchmarks run 42519323905, with arches=powerpc64, modules=ecdh_p256 and base b7c10de, on POWER9:

Benchmark Base Head Change
ecdh_p256/32 873.63 µs 412.60 µs 52.8% faster
ec_p256_public_key/65 873.22 µs 871.75 µs 0.2% faster (untouched)

🤖 Generated with Claude Code

https://claude.ai/code/session_01TKUFHH4GefHP3pmPRSL4N4

vg_ecdh_p256 computed [d]P by the Montgomery ladder of complete additions
over every bit. It now uses RISC-V's four-bit windows: a table of [e]P for
e < 16 (built by complete additions for a = -3), then per window four
Jacobian doublings and one complete addition of the entry selected by a
constant-time scan of the table under masks.

ECDH's stages take any multiplication that meets MulPowOk (exchangeWith_ok);
the ladder's curves go through it unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TKUFHH4GefHP3pmPRSL4N4
@github-actions github-actions Bot added the untrusted-only This changes exclusively implementations and proofs, and thus is entirely formally verified. label Nov 8, 2026
@alex
alex added this pull request to the merge queue Nov 8, 2026
Merged via the queue into main with commit cd0c332 Nov 8, 2026
24 checks passed
@alex
alex deleted the claude/ppc64le-ec-verify branch November 8, 2026 20:31
alex pushed a commit that referenced this pull request Nov 8, 2026
P-256's ECDH windows (#4712) now take Z^(p-2) by the addition chain too.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TKUFHJ728Kwktcff5BR2sx
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

untrusted-only This changes exclusively implementations and proofs, and thus is entirely formally verified.

Development

Successfully merging this pull request may close these issues.

2 participants