Repository navigation
Conversation
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHHgwmxoKvRUNy64bKd
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHHgwmxoKvRUNy64bKd
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHHgwmxoKvRUNy64bKd
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHHgwmxoKvRUNy64bKd
…ADX) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHHgwmxoKvRUNy64bKd
…riant Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHHgwmxoKvRUNy64bKd
Member
Author
|
Split by entrypoint at alex's request into #4943 (stacked on #4940). Generated by Claude Code |
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. This adds the x86-64 implementation of
vg_rsa_private_precompute, verified against the spec'sprivatePrecomputeContract. It is an implementation only: no spec change, no TCB change.The code (
Impl/Rsa/X86_64/PrivPre.lean)It is one function, and most of it is
vg_rsa_private_crt's own code (Crt.lean):entrysaves the callee-saved registers and the arguments in the working space's header.pregoes in three slots: the output, the input andqInv.pandqalso go in the exponents' slots, which nothing reads.zeroPrezeroespre's8 pre_lenbytes (the loop is the same asfail's). The input andqInvthe CRT code reads are therefore 0.invalid) branches onn, which is public.failruns and returns 0.preis all zeros.Crt.nSetup,Crt.primesSetupandCrt.checksrun. They given,R² mod n, the primes' workspaces and the mask. The mask is the mask ofp q = n, because0 < nand0 < pfollow from it. Where the mask is clear,pandqare replaced by 3.r2At: in each prime's workspace,aY := 1, thendoublesruns128 w_Xtimes. That gives2^(128 w_X) mod X'. The count depends only on public lengths.outcopiesn,R² mod n,R_p² mod pandR_q² mod qtopre. Every word is and-ed with the mask, and the mask's low bit is returned.The function is registered with
CallMont.baseand withCallMont.adx, asvg_rsa_public_precomputeis. So there is a_adxvariant, which the dispatcher chooses with ADX.Proofs (
Proof/Bignum/X86_64/PrivPre/)Contract:ppContract, the contract on the registers, andpp_implies, which shows it implies the shared contract with 8 bytes of stack.Head:entryandzeroPre. From there,ppPre_ofbuildsvg_rsa_private_crt'sCrtPre: the input ispre's zeros,qInvis zeros, and the exponents arepandq. This lets the CRT'sfront_okbe reused unchanged.R2:r2X_ok, which appliesdoubles_okin a prime's workspace, thenr2P_okandr2Q_ok.Out:copyMasked_ok,outArr_ok,outAt_okandout_ok.Correct:code_correct.nis invalid,preis zeros.pre's words are those ofprivatePrecompute, or zeros ifp q ≠ n(wordsAt_out,main_post).CTR2has thedouble/doublesrelational lemmas for a workspace whose-m⁻¹is secret (GoodW), thenr2X_ctandr2At_ct.CTOuthasoutArr_ctandout_ct.CTMainreuses the CRT's stages (nSetup_ct,setupS_ct,checksS_ct), extended withpre's facts (SX).CTCodecovers entry, zero, the check, andfail/main(code_constantTime).Verified:pp_call_verified(viaVerified.of_inline_sig), pluspp_patchandpp_postOut.pp_postOutmeans the registration goes throughX86_64.Scrub.withScrubAll: the function returns without secret residue, and nothing is added toci/residue_allowlist.txt.No Rust caller yet
The Rust code is unchanged.
PrivateKey::precomputestill callsvg_rsa_private_precomputeonly on PPC64LE. The planned single Rust switch PR will make every architecture computepre, and its benchmark run (from_crt/from_primes) belongs there. This PR therefore has no benchmark. The dispatcher has no caller, so it does not count toward coverage.Checks
Static checksjob passes.check_lean_single_importer.pywas run with--base origin/main.lake buildpasses, as doEmit.leanandEmit.lean --check.rsafiles:vg_rsa_private_precompute,vg_rsa_private_precompute_adxand their dispatcher.check_lean_public_imports.pypasses on the new modules.cargo fmt --checkpasses, as doescargo clippy --all-targets -- -D warnings, as do the RSA tests (Wycheproof included).PrivateKey::precomputeon x86-64; that change is not in this PR):VG_CPU_FEATURES=none) returned 1.prematchedn,2^(128w) mod n,2^(128 w_p) mod pand2^(128 w_q) mod q, computed in Python.Generated by Claude Code