Repository navigation
x86-64 vg_rsa_crt_values: qInv's factor 2^(5B) by one word-level reduction for balanced keys - #4980
Merged
Merged
Conversation
…Divide under the guard Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHFdT7ugYMSPA3JMuhh
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHFdT7ugYMSPA3JMuhh
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHFdT7ugYMSPA3JMuhh
…e public guard Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHFdT7ugYMSPA3JMuhh
alex
marked this pull request as ready for review
November 12, 2026 00:40
This was referenced Nov 12, 2026
Merged
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.
vg_rsa_crt_valueson x86-64 computes qInv with a batched divsteps inverse (50 batches of 59 divsteps at 2048 bits). Its result needs a final factor 2^K, K = 5B = 15n + 10, which the inverse applied as K one-bit modular doublings of n + 1 words: 250 doublings at 2048 bits, about 32% ofcrt_values, and 490 at 4096 bits, about 35%. This PR replaces them, for balanced keys, with one word-level reduction by theWordDividethatcrt_valuesandcheck_keyalready use (#4971).Shape.
invPart = [guarded inverseNS inverseN] ++ gcdPart ++ [guarded qTail skip], whereguardediswordChoice's public guard (weven,n_len = 8w = 2·p_len,p_len = q_len, n's top bit set) followed by.ite.inverseN, code and proof unchanged.inverseNSis the inverse without its K doublings;Inv.finishSkeeps one conditional subtraction, so x₂ < p.qTail: (K − 1) mod 64 + 1 one-bit doublings of x₂'s low n + 1 words, then x₂ placed ⌊(K − 1)/64⌋ words up inWordDivide's dividend, so the dividend is x₂·2^K; the existingWordDividereduces it modulo p (normalize + code, w steps). d is saved in array 10 meanwhile and restored after.Value.
cvQTail_okgives x₂·2^K mod p, given 2^(64n−1) ≤ p < 2^(64n) and x₂ < p. Those bounds come fromWordDivide.factors_word, under the guard and p·q = n, which the output mask requires, so the outputs equal the spec for every input that reaches them.cvInv_ok's post-condition is unchanged: p ∣ x₂·q − gcd and x₂ < p. Since x₂ < p < 2^(64n) and the one-bit doublings are at most 64, x₂·2^T < 2^(64(n+1)): they never carry out of word n.Constant time. The guard reads only lengths and n's top byte, already public. The tail's counts (T, Q, n + 1) depend on w alone. Each piece is checked with
taint_decide(guarded_ct,invQS_ct,tailDbl_ct,placeCopy_ct,qTail_ct,invPart_ct).Trust
No change to
TCB/orSpec/.InvLaw, the class the registrations instantiate, gains a fieldinverseNS_ok, proved inInvB/Main.Measurements
callgrind, one x86-64 call per key, main (3fc218b) → this branch:
crt_valuesfrom_primesPossible follow-ups, about 2% of
crt_valueseach: a variable shift instead of the one-bit doublings, and startingWordDivideat the dividend's top nonzero word (as the AArch64 version does, which needsWordDivide's step count as a parameter).Benchmarks
Run 43125859343 (x86_64, module
rsa, groupsrsa_from_.*, base 3fc218b, with OpenSSL and aws-lc-rs).from_primesrunscrt_values, so it is 10.8–15.9% faster;from_crt(which checks the given CRT values instead of computing them) andfrom_components(prime recovery) don't use this inverse and are within ±0.4%.from_primesis now 1.7–2.1× faster than OpenSSL's.rsa_from_components/256rsa_from_components/384rsa_from_components/512rsa_from_crt/256rsa_from_crt/384rsa_from_crt/512rsa_from_primes/256rsa_from_primes/384rsa_from_primes/512Checks (on 50fd766)
lake build,Emit.leanandEmit.lean --checkexit 0; onlycrates/verified-garbage-asm-x86_64rsa.rs/rsa.schanged.cargo test rsaon x86-64 with Wycheproof, default andVG_CPU_FEATURES=none.check_mcdt,check_vectors,run_unit_tests);check_lean_public_imports.pyon the edited modules.mainafter AArch64 R² mod m: word steps by a 3-by-2 estimate and one fused pass #4968, RSA-OAEP decrypt: vg_rsa_oaep_decrypt_precomputed on every architecture #4972 and x86 (i686) RSA key import: word-level remainders and products for balanced keys #4979, none of which changes the x86-64crt_valuesor its proofs.🤖 Generated with Claude Code
https://claude.ai/code/session_01TKUFHH1um6BHmQjMB1jTPh