Repository navigation
RSA PKCS#1 v1.5 decrypt: vg_rsa_pkcs1_decrypt_precomputed on every architecture - #4959
Merged
Merged
Conversation
… and PrivateKey computes pre everywhere vg_rsa_private_precompute, verified, on x86-64 (base and ADX), x86, AArch64, Arm and RISC-V (PPC64LE's is #4940, which this is stacked on), and the shared framework the *_precomputed entrypoints use: Verified.withSlice and its per-ISA instances, and Proof/Rsa/PreKey.lean. PrivateKey computes the key's precomputed values on every architecture. Each factor's R_p² mod p comes from R² mod n, which the precompute computes anyway: steps of a Montgomery reduction of R² mod n (chunked, then whole words while more than 2 w_p are left) give 2^(64 e) mod p when p divides n, then at most a few doublings and squarings (Proof/Bignum/PrimeR2.lean's counts on RISC-V, PPC64LE, AArch64 and Arm; a chunked REDC on x86 and x86-64). Squashes #4917, #4928, #4929, #4930 and #4931, and the per-architecture fast R_p² work. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHG7VqNCm5vQWRrXrv5
The precompute checked p q = n with vg_rsa_private_crt's Crt.checkPQ, a Montgomery multiplication modulo 2^(64 W) - 1 at X's width W = 2 ⌈k / 8⌉. It now multiplies p's ⌈p_len / 8⌉ words by q's ⌈q_len / 8⌉ (schoolbook rows, PrivPre.checkPQs) into array 6 and compares the product with n as checkPQ does (Crt.pqEq, factored out of checkPQ). vg_rsa_private_crt's code is unchanged. Crt.checks is now checksWith checkPQ, and checksWith_ok takes any check of p q = n that meets PQOk; checks_ok is its instance for checkPQ. The two lengths are loaded before the checks (PrivPre.pqLens), so the constant-time proof pins a3 and t1 at the cuts after it (pins50, pins51) and its cut indices move by one before the checks and by -5 after them. Instructions of vg_rsa_private_precompute under qemu-riscv64, balanced keys: 2048 bits 327,716 -> 241,199; 3072 bits 692,010 -> 499,853; 4096 bits 1,191,470 -> 852,073. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHEBn13MbzWmGJdqbMB
The precompute checked p q = n with vg_rsa_private_crt's checkPQ, a Montgomery product modulo 2^(64 W) - 1 at X's width W = 2 ceil(k / 8), twice the modulus's. It now multiplies p's w_p = ceil(p_len / 8) words by q's w_q = ceil(q_len / 8) (schoolbook rows, `PrivPre.checkPQs`) into array 6, zeroed first, and compares the product with n as checkPQ does (`Crt.pqEq`, factored out of it). The widths are loaded before the checks (`pqLens`), into r5 and r7, which checkN and checkLt keep. Proofs: `Crt.checksWith pq` and `Crt.phaseAWith_ok` take the check of p q = n as a parameter (`Crt.PQOk`), with `checkPQ_pqOk` for the CRT's own; `PrivPrePQ.lean` proves the rows (`rows_ok`) and `checkPQs_ok`; the constant-time chain pins r5 and r7 after `pqLens` (cuts 50 and 51), and the later cuts move by one. No TCB or Spec change. Instructions (qemu-ppc64le, one call): 2048: 431,212 -> 386,422; 3072: 825,780 -> 726,198; 4096: 1,340,988 -> 1,164,982. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHEBn13MbzWmGJdqbMB
The precompute checked p q = n with the private CRT's validation product, CrtRt.wideProduct: all W = B / 4 words of p by all W of q, W rows of W words, for factors of about half the modulus's length. It now multiplies p's ceil(p_len / 4) words by q's ceil(q_len / 4) (the lengths are public arguments), and compares the product with n as before. `CrtRt.productBy cols rowsEnd b` is wideProduct with its two counts as parameters (code that sets a register to a count's bytes, `Counts`, and `EndsAt`); `wideProduct` is `productBy (widthC 0 .wide) []`, the same code, so the private CRT is unchanged. `productBy_ok` generalizes `wideProduct_ok`, which is now its instance; `rowSetup_ok` and `rowTail_ok` take the counts. The precompute's `pqCheck` uses `productBy (lenW 9) (lenW 7 .eax)`; `pqCheck_ok` takes the factors' bounds from their lengths (`counts_lenW`, `val32_fit`). The constant-time proof is unchanged: the taint analysis checks the new code (the lengths are arguments, public). No TCB or Spec change. Instructions (qemu-i386, one call): 2048: 501,419 -> 460,203; 3072: 990,347 -> 898,571; 4096: 1,640,043 -> 1,477,739. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHEBn13MbzWmGJdqbMB
The precompute checks p q = n with the private CRT's validation, whose product (Crt.factorProduct) multiplies all 2 W words of p by all 2 W of q, for factors of about half the modulus's length. Its counts are now ceil(p_len / 4) rows of ceil(q_len / 4) words (`Crt.lengthCount`, from the CRT frame's lengths of p and q, slots 68 and 76), and the product is compared with n as before: the output is cleared first, so the words above the product stay zero. `productArgsWith`, `factorProductWith`, `validateProductWith` and `CrtFn.validateWith` take the counts as a parameter; `productArgs`, `factorProduct`, `validateProduct` and `CrtFn.validate` are their instances with `productCount`, the same code, so the private CRT is unchanged. The proofs take the counts as `CountFrom` (the block that sets them, from any state that agrees outside the workspace) and their constant time from equal r0 and sp: `crt_productArgsWith_ok`, `crt_productArgsWith_ready`, `crt_factorProductWith_ok`, `crt_validateProductWith_ok`, `crt_productStageWith_ok` and `crt_validateStageWith_ok`, and the CT lemmas `crt_productArgsWith_ct`, `crt_factorProductWith_ct`, `crt_validateProductWith_ct` and `crt_validateStageWith_ct`; the CRT's are their instances (`countFrom_productCount`). The precompute's: `countFrom_lengthCount`, `pp_lengthCounts` (the factors fit the counts) and `lengthCount_ct` (its loads at sp, its stores at r0, by `loadStack_ct`, the taint analysis and `relCT_keep_r0`). No TCB or Spec change. Instructions (qemu-arm, one call): 2048: 1,244,559 -> 1,185,139; 3072: 2,707,007 -> 2,574,099; 4096: 4,730,607 -> 4,495,027. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHEBn13MbzWmGJdqbMB
d0743f2 regenerated crates/verified-garbage-asm-powerpc64le/src/rsa.rs with EmitOne, which writes only one registration's functions and so dropped the `mod` lines of internal functions other registrations emit. This is the full emitter's output (`Emit.lean`). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHEBn13MbzWmGJdqbMB
…recomputed private path vg_rsa_pkcs1_decrypt_precomputed now calls vg_rsa_private_checked_precomputed on RISC-V, x86-64 (all four variants), i686 and Arm, in place of vg_rsa_pkcs1_decrypt's code proven against the weaker contract. That function copies n's values from pre instead of vg_rsa_public_precompute, and calls vg_rsa_private_crt_precomputed, which copies R_p² and R_q² from pre (on x86-64 R² mod n, and on IFMA also R_p² and R_q²) and drops the checks' p·q = n product, which privatePrecompute = some pre implies. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHG7VqNCm5vQWRrXrv5
The committed Arm crate predated the Lean of vg_rsa_private_precompute; these are the two files a full lake build and Emit.lean write on defc3ca, nothing else. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHHgwmxoKvRUNy64bKd
The tree is claude/rsa-private-precompute-v3 (ecaf7ae): this branch's commits rebased onto 48ea507 with the PPC64LE crate regenerated by the full emitter. Full lake build, Emit --check (exit 0), six-arch RSA tests, fmt/clippy and the static checks pass on it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHH1um6BHmQjMB1jTPh
The tree is the decrypt commit applied to #4956's head, verified with a full lake build, Emit and Emit --check (exit 0), and cargo test rsa on all six architectures. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHG7VqNCm5vQWRrXrv5
…ting n's values The layout gains the further regions the function may read (X), and the correctness and constant-time proofs are stated for any stage in place of vg_rsa_public_precompute's call, for vg_rsa_private_checked_precomputed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHHu5XUqPT84QNkv9Dw
vg_rsa_private_checked's frames, CRT and check, with n's values copied from the key's precomputed values in place of calling vg_rsa_public_precompute, verified against privateCheckedPrecomputedContract. The proofs run on the call narrowed to the regions they read (vg_rsa_private_checked's, stack argument 12, and n's values at the start of pre), and widen to the call. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHHu5XUqPT84QNkv9Dw
…te-key operation The slots move up 16 bytes (the frame from 208 to 224 bytes), so that the frame's bottom can hold vg_rsa_private_checked_precomputed's 14 stack arguments. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHHu5XUqPT84QNkv9Dw
The layout gains the further regions the function may read and pre's place, the code takes the block that sets up the call (codeWith), and correctness takes the setup and the call as a hypothesis, for the precomputed variant. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHHu5XUqPT84QNkv9Dw
…l (WIP) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHHu5XUqPT84QNkv9Dw
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHHu5XUqPT84QNkv9Dw
…precomputed vg_rsa_pkcs1_decrypt_precomputed: vg_rsa_pkcs1_decrypt's code, moving pre and pre_len to the precomputed private operation's stack arguments, proven against decryptPrecomputedContract on the call narrowed to the regions the proofs read, and registered. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHHu5XUqPT84QNkv9Dw
…ng vg_rsa_private_checked_precomputed Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHHu5XUqPT84QNkv9Dw
Base automatically changed from
claude/rsa-private-precompute-on-main
to
main
November 11, 2026 15:27
|
This pull request has conflicts with Posted by |
…omputed proven vg_rsa_private_crt's code (both its four-bit and five-bit main computations, the dispatch between them and the entry) takes its key checks as a parameter, and its proofs are generic over them: correctness over a stage that meets checks_ok's statement for keys with a property G of (n, p, q) (ChecksOk), constant time over one that is constant time (ChecksCTOf), with G carried through the stages (RG) and the contract's relation (CCRel). checks is checksGiven, the checks but p q = n, after the product and its comparison. vg_rsa_private_crt_precomputed, the code with checksGiven, is proven against privateCrtProductContract, an internal contract: vg_rsa_private_crt's, for a key whose factors' product is the modulus. The emitted code of vg_rsa_private_crt does not change. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHHu5XUqPT84QNkv9Dw
…recomputed vg_rsa_private_checked's proofs take the CRT they call as a CrtCallee: its code, verified against vg_rsa_private_crt's contract for call states with K. vg_rsa_private_checked calls vg_rsa_private_crt (K true); vg_rsa_private_checked_precomputed calls vg_rsa_private_crt_precomputed (K: the key's factors' product is its modulus), which its pre implies (privatePrecompute_mul). CrtImpl gains vg_rsa_private_crt_precomputed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHHu5XUqPT84QNkv9Dw
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHG7VqNCm5vQWRrXrv5
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHG7VqNCm5vQWRrXrv5
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHG7VqNCm5vQWRrXrv5
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHG7VqNCm5vQWRrXrv5
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHG7VqNCm5vQWRrXrv5
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHG7VqNCm5vQWRrXrv5
|
This pull request has conflicts with Posted by |
Conflicts: Proof/RsaPkcs1Sig/RISCV64/Sign/Call.lean takes main's, #4958's generic version; Proof/RsaPkcs1Enc/RISCV64/Dec/Calls.lean keeps the branch's, generic over pc, which main's PreP false adaptation is a case of. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHG7VqNCm5vQWRrXrv5
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHG7VqNCm5vQWRrXrv5
…as memberships (#4970) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHG7VqNCm5vQWRrXrv5
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHG7VqNCm5vQWRrXrv5
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHG7VqNCm5vQWRrXrv5
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.
Replaces #4945. Follows #4956 (the precompute) and #4958 (its
vg_rsa_private_checked_precomputed), both merged.This adds the PKCS#1 v1.5 decrypt entrypoint that takes the key's precomputed values (
pre),vg_rsa_pkcs1_decrypt_precomputed, on every architecture, and switchesPrivateKey's PKCS#1 v1.5 decrypt to it everywhere. It is verified againstdecryptPrecomputedContract; no architecture registers it by weakening the old contract. Each one calls avg_rsa_private_checked_precomputedthat readspre, and the CRT behind it skips per-call work thatprealready holds:main, #4908)vg_rsa_private_crt_precomputed); its CRT never computes R_p²The p·q product can go because the precondition
pre = privatePrecompute n p qimpliesp q = n.No changes to
TCB/orSpec/.Benchmarks
Run 43069479634:
rsa_pkcs1_enc, grouprsa_pkcs1_decrypt, every architecture, basemainat 8564b91, head 0ab2fda. Later merges ofmain(#4948, #4964, #4965) change the public R² mod n precompute; only on AArch64 does one (#4948's word step for R² mod m) also reach the CRT, inmain'svg_rsa_private_crtas in this PR's, so both sides of the AArch64 comparison change alike. "−" is faster.VG_CPU_FEATURES)sha,ssse3at 4096 bits (+10.1%) is runner noise, not this change. That configuration runsvg_rsa_pkcs1_decrypt_precomputed_sha256_shani, which calls the samevg_rsa_private_checked_precomputedas thenoneconfiguration'svg_rsa_pkcs1_decrypt_precomputed(they differ only in the SHA-256 of the implicit rejection, which this PR does not change).noneat 4096 bits is 8.97 → 8.93 ms (−0.4%), and thesha,ssse3job's 2048- and 3072-bit rows are flat. That head sample's mean is far from its median.VG_CPU_FEATURESthat names features the CPU lacks.main, and the workflow'sopenssloption was off, as the benchmarking skill says to leave it.Checks (on a0554d7:
main3fc218b, e502ca9 and 1328178 merged)main3fc218b (RSA PKCS#1 v1.5 sign: vg_rsa_pkcs1_sign_precomputed on every architecture #4958, x86-64 vg_rsa_check_key: word-level remainders for balanced keys #4971), e502ca9 (RSA-PSS sign: vg_rsa_pss_sign_precomputed on every architecture #4970) and 1328178 (RSA-OAEP decrypt: vg_rsa_oaep_decrypt_precomputed on every architecture #4972, AArch64 R² mod m: word steps by a 3-by-2 estimate and one fused pass #4968, x86 (i686) RSA key import: word-level remainders and products for balanced keys #4979).Proof/RsaPkcs1Sig/RISCV64/Sign/Call.leantakesmain's version (RSA PKCS#1 v1.5 sign: vg_rsa_pkcs1_sign_precomputed on every architecture #4958's generic one);Proof/RsaPkcs1Enc/RISCV64/Dec/Calls.leankeeps this branch's, which is generic over the private call and coversmain's case. The fullEmit.leanrewrote nothing, so the merges need no regeneration.RsaPkcs1Sig/X86/Lay.Ok(rdandwrbecame memberships, andargsWis a new field), which broke two x86 decrypt proofs,R2W.narrowinX86/DecP/Body.leanandok_narrowinX86/DecP/Verified.lean; both are adapted (no TCB or Spec change). The 1328178 merge needed nothing.lake buildof every registration on every architecture;Emit.lean --check(exit status 0); the Static-checks steps;cargo fmtandclippy -D warnings.cargo test rsawith Wycheproof on all six architectures (x86-64 native; i686, AArch64, ARMv7, riscv64 and ppc64le under qemu): 65 passed, 0 failed on each.main57d3b56 (after x86-64 vg_rsa_crt_values: qInv's factor 2^(5B) by one word-level reduction for balanced keys #4980, with which it shares no files); the one file it shares with RSA-PSS sign: vg_rsa_pss_sign_precomputed on every architecture #4970/RSA-OAEP decrypt: vg_rsa_oaep_decrypt_precomputed on every architecture #4972,Proof/RsaPkcs1Sig/X86/PrivCallP.lean, is identical tomain's.Checks (on d8643b8,
mainade8505 merged)vg_rsa_private_crt_precomputed, which shares AArch64 R² mod m for a public m: word steps for any top word #4948's new word-step R² mod m withmain'svg_rsa_private_crt(regenerated in AArch64 R² mod m for a public m: word steps for any top word #4948 too); the AArch64 rows above predate AArch64 R² mod m for a public m: word steps for any top word #4948 on both sideslake buildof the RSA, FFDH and DSA registrations of every architecture and every registration of AArch64, x86, x86-64 and RISC-V (whatmain's merged changes and this PR's reach), on the published cache;Emit.lean --check(exit status 0)check_lean_public_imports.pyon every module this PR edits (each OK); theStatic checksjob's stepscargo test rsaon all six architectures (x86-64 native; i686, AArch64, ARMv7, riscv64 and ppc64le under qemu), with Wycheproof;cargo fmtandclippy🤖 Generated with Claude Code
https://claude.ai/code/session_01TKUFHG7VqNCm5vQWRrXrv5