Repository navigation
dit::scope: run many calls under one turn of data independent timing - #4357
Closed
reaperhulk wants to merge 137 commits into
Closed
reaperhulk wants to merge 137 commits into
reaperhulk wants to merge 137 commits into
Conversation
This was referenced Nov 6, 2026
reaperhulk
force-pushed
the
claude/dit-scope
branch
from
November 7, 2026 00:25
74c45ee to
dca7463
Compare
reaperhulk
force-pushed
the
claude/dit-scope
branch
from
November 7, 2026 01:12
dca7463 to
f843e3a
Compare
* WIP: ML-DSA x86 sign core with KEYS word; sign entries * WIP: ML-DSA x86 verify core with t1 argument; verify entries * WIP: ML-DSA x86 prepare_signing_key and prepare_verifying_key * WIP: ML-DSA x86 satisfiability witnesses for the prepared contracts * WIP: ML-DSA x86 message proofs over the key argument * WIP: ML-DSA x86 entries, prepared message functions: instances * WIP: x86 prepared keys in the Rust API * WIP: x86 prepared-key registrations * ML-DSA x86: describe vg_mldsa*_sign_core * ML-DSA x86: regenerate the crate with prepared keys Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015ajQWwDf2TWyuN7bZSQDiU --------- Co-authored-by: Claude <noreply@anthropic.com>
#4388) Stitch.batch and Stitch.dbody take a store mode (ix): back to the data, or to rdx + r8. StitchFrom.decR uses Stitch.dbody true, and its separate loop and proof are removed; the proofs of the batch, the GHASH state and the loop body are generic over the mode, the in-place lemmas their cases. Claude-Session: https://claude.ai/code/session_015ajQWvqXkQxFyWZxghqxBG Co-authored-by: Claude <noreply@anthropic.com>
…4390) * AES-GCM x86-64: AVX-512 decryption loops generic over the store mode (WIP) StitchZH.batch, dbody, dbody48 and bigDP take the store mode; the proofs of the batch, the GHASH states, the loop bodies and the 48-block loop are generic over it, the in-place lemmas their cases. StitchZH.decFromR is the out-of-place loop (its proof follows). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015ajQWvqXkQxFyWZxghqxBG * AES-GCM x86-64: prove the out-of-place AVX-512 decryption loop Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015ajQWvqXkQxFyWZxghqxBG * AES-GCM x86-64: one-pass out-of-place decryption in the AVX-512 variant The VaesVpclmulAvx512 variant names its out-of-place loop (StitchToName.decFromR, StitchZH.decFromR) for prepared key contexts. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015ajQWvqXkQxFyWZxghqxBG * Regenerate the x86-64 crate Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015ajQWvqXkQxFyWZxghqxBG * AES-GCM x86-64: take the 512-bit loops' field facts as a hypothesis The out-of-place loop's proof no longer imports the field algebra; the instances prove PowFinZ, as they do PowFinD. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015ajQWvqXkQxFyWZxghqxBG --------- Co-authored-by: Claude <noreply@anthropic.com>
… (WIP) (#4391) Stitch.batch takes the load mode (ld: the data read at rdx + r8); StitchTo's batch, its XOR and their proofs are replaced by Stitch.batchM_ok. The distance in r8 moves from AInvM to the loops' invariants. Claude-Session: https://claude.ai/code/session_015ajQWvqXkQxFyWZxghqxBG Co-authored-by: Claude <noreply@anthropic.com>
…partial-segment XOR (#4394) * Proof: CFB of a message's last piece from the whole-block functions' results Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHGJJidJdRDMDSSd58W * WIP: x86-64 CFB final functions around the whole-block functions Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHGJJidJdRDMDSSd58W * WIP: x86-64 CFB final functions: the XOR loop's proof Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHGJJidJdRDMDSSd58W * WIP: x86-64 CFB final functions: a pushed frame, the block at rsp + 8 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHGJJidJdRDMDSSd58W * WIP: x86-64 CFB final functions: straight-line step lemmas Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHGJJidJdRDMDSSd58W * WIP: x86-64 CFB final functions: zeroing the working block Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHGJJidJdRDMDSSd58W * WIP: x86-64 CFB final functions: the state at the first call Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHGJJidJdRDMDSSd58W * WIP: x86-64 CFB final functions: the state at the second call Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHGJJidJdRDMDSSd58W * WIP: x86-64 CFB final functions: the exit Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHGJJidJdRDMDSSd58W * WIP: x86-64 CFB final functions: the first call Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHGJJidJdRDMDSSd58W * WIP: x86-64 CFB final functions: the partial last segment Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHGJJidJdRDMDSSd58W * WIP: x86-64 CFB final functions: step blocks without unfolding runStep Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHGJJidJdRDMDSSd58W * WIP: x86-64 CFB final functions: the whole function's correctness Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHGJJidJdRDMDSSd58W * WIP: x86-64 CFB final functions: what the whole function writes; IDEA's code Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHGJJidJdRDMDSSd58W * WIP: IDEA-CFB64 final functions on x86-64: the first call's precondition Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHGJJidJdRDMDSSd58W * WIP: IDEA-CFB64 final functions on x86-64: the second call's precondition Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHGJJidJdRDMDSSd58W * WIP: IDEA-CFB64 final functions on x86-64: frame helpers Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHGJJidJdRDMDSSd58W * WIP: IDEA-CFB64 final functions on x86-64: the zero block Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHGJJidJdRDMDSSd58W * WIP: IDEA-CFB64 final encryption on x86-64 meets Spec.Cfb.EncryptFinal Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHGJJidJdRDMDSSd58W * WIP: IDEA-CFB64 final decryption on x86-64 meets Spec.Cfb.DecryptFinal Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHGJJidJdRDMDSSd58W * WIP: IDEA-CFB64 final functions on x86-64: the code as literals Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHGJJidJdRDMDSSd58W * WIP: x86-64 CFB final functions: relational constant-time combinators Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHGJJidJdRDMDSSd58W * WIP: x86-64 CFB final functions in constant time, from the inlined functions' Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHGJJidJdRDMDSSd58W * IDEA x86-64: the final CFB functions in constant time Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHGJJidJdRDMDSSd58W * WIP: IDEA x86-64 final CFB functions, verified and registered (wrapper design) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHGJJidJdRDMDSSd58W * WIP: x86-64 fbFinal mode: OFB/CFB over segments, the last partial, proven Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHGJJidJdRDMDSSd58W * IDEA x86-64: final CFB64 functions on the modes' fbFinal Replaces the wrapper design (a frame around inlined whole-block functions) with a mode that handles the partial last segment itself: the cipher's code appears once. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHGJJidJdRDMDSSd58W * Blowfish and SEED x86-64: final CFB functions on fbFinal Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHGJJidJdRDMDSSd58W * SM4 and Triple DES x86-64: final CFB functions on fbFinal Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHGJJidJdRDMDSSd58W * Camellia and CAST5 x86-64: final CFB functions on fbFinal Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHGJJidJdRDMDSSd58W * WIP Rust: CFB's final calls use the verified _final functions Deletes the partial-segment XOR in Rust for Blowfish, Camellia, CAST5, IDEA, SEED, SM4 and Triple DES. Other targets' crates lack the _final functions until their Lean implementations land. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHGJJidJdRDMDSSd58W * WIP: AArch64 fbFinal mode: code and the partial segment's byte loop, proven Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHGJJidJdRDMDSSd58W * WIP: AArch64 fbFinal mode: the segment loop, proven Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHGJJidJdRDMDSSd58W * WIP: AArch64 fbFinal mode: the whole function, proven Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHGJJidJdRDMDSSd58W * IDEA AArch64: final CFB64 functions on the modes' fbFinal Ports the x86-64 fbFinal mode (segments of a block, the last partial) to AArch64: Impl/Modes/AArch64/FbFinal.lean, whose test for fewer than a block's bytes is `lsr x8, leftReg, #lg` and `cbz x8`, and its proof in one module, Proof/Modes/AArch64/FbFinal.lean (the byte loop, the segment loop and the whole function). IDEA's vg_idea_cfb64_{en,de}crypt_final on AArch64 are fbFinal over its core, with the IV's address in x25 and 208 bytes of stack scratch, as its whole-block CFB64. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHGJJidJdRDMDSSd58W * Merge the final modes' proof modules into their single importers Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHGJJidJdRDMDSSd58W * Blowfish AArch64: final CFB64 functions on the modes' fbFinal Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHGJJidJdRDMDSSd58W * SEED AArch64: final CFB128 functions on the modes' fbFinal The feedback modes' precondition takes the data's length (fbPre len), as on x86-64; the whole-block contracts are unchanged (fbPre blkLen). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHGJJidJdRDMDSSd58W * SM4 AArch64: final CFB128 functions on the modes' fbFinal Both over the serial core of OFB and CFB encryption, with the IV's address in x19. The feedback modes' precondition takes the data's length (fbPre len), as on x86-64; the whole-block contracts are unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHGJJidJdRDMDSSd58W * Triple DES AArch64: final CFB64 functions on the modes' fbFinal Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHGJJidJdRDMDSSd58W * WIP: x86 seqFinal mode: code and the partial segment's byte loop, proven Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHGJJidJdRDMDSSd58W * Camellia AArch64: final CFB128 functions on the modes' fbFinal Both over the serial core of OFB and CFB encryption, with the IV's address in x19, for the subkeys at the schedule (cfbEncryptFinal_of_sk). The feedback modes' precondition takes the data's length (fbPre len), as on x86-64; the whole-block contracts are unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHGJJidJdRDMDSSd58W * CAST5 AArch64: final CFB64 functions on the modes' fbFinal The feedback modes' precondition takes the data's length (FPre len), as on x86-64; the whole-block contracts are unchanged (FPre blkLen). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHGJJidJdRDMDSSd58W * WIP: x86 seqFinal mode: a whole segment, proven Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHGJJidJdRDMDSSd58W * WIP: x86 seqFinal mode: the partial segment, proven Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHGJJidJdRDMDSSd58W * WIP: x86 seqFinal mode: the segment loop, proven Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHGJJidJdRDMDSSd58W * WIP: x86 seqFinal mode: the whole function and CFB's results, proven Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHGJJidJdRDMDSSd58W * IDEA x86: final CFB64 functions on the 32-bit modes' seqFinal Adds seqFinal to the 32-bit x86 modes (Impl/Modes/X86/SeqFinal.lean): seq over the len bytes at the data in segments of a block, the count in nSlot the bytes left. Each segment is seq's pre and the core's crypt, then cmp ebp, L and jb: a whole block runs post and moves on by L bytes; a partial one copies the buffer (O_n) to the chaining value and XORs its first r bytes into the data a byte at a time (ebx, esi, ebp), so the core appears once. Both ways store the pointer and the count back from registers, for the analysis of constant time. Its proof, Proof/Modes/X86/SeqFinal.lean, reuses seq's steps (Step.lean) with the whole blocks, and the partial segment as a step of r bytes; Fixed now takes the data within a writable region rather than equal to one. CfbFinalScratch gains the input-side locality lemmas the 32-bit stack frame needs. IDEA's vg_idea_cfb64_{en,de}crypt_final on x86 are seqFinal over its core, with 208 bytes of stack scratch as its whole-block CFB64. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHGJJidJdRDMDSSd58W * Arm seqFinal mode: CFB over a message's last piece, proven correct seq's prologue and epilogue over len bytes, in segments of a block, the core called once per segment on the chaining block; a partial last segment XORs the chaining block's first bytes into the data a byte at a time. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHGJJidJdRDMDSSd58W * Blowfish x86: final CFB64 functions on the 32-bit modes' seqFinal vg_blowfish_cfb64_{en,de}crypt_final on x86 are seqFinal over Blowfish's encrypting core, with 112 bytes of stack scratch as its whole-block CFB64. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHGJJidJdRDMDSSd58W * SEED x86: final CFB128 functions on the 32-bit modes' seqFinal vg_seed_cfb128_{en,de}crypt_final on x86 are seqFinal over SEED's core in the encryption direction, with 1168 bytes of stack scratch and the core's 20 bytes of stack as its whole-block CFB128. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHGJJidJdRDMDSSd58W * Arm seqFinal mode: constant time, and seqFinal_verified Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHGJJidJdRDMDSSd58W * SM4 x86: final CFB128 functions on the 32-bit modes' seqFinal vg_sm4_cfb128_{en,de}crypt_final on x86 are seqFinal over SM4's core in the encryption direction, with 1496 bytes of stack scratch and the core's 20 bytes of stack as its whole-block CFB128; constant time by the calls' summaries. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHGJJidJdRDMDSSd58W * IDEA Arm: final CFB64 functions on the modes' seqFinal The final posts' locality for the memory on entry (encFinalPostIn_local, decFinalPostIn_local), which ARMv7's stack-scratch frame needs. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHGJJidJdRDMDSSd58W * Triple DES x86: final CFB64 functions on the 32-bit modes' seqFinal vg_triple_des_cfb64_{en,de}crypt_final on x86 are seqFinal over Triple DES's core in the encryption direction, with 968 bytes of stack scratch and 16 bytes for the block function's call, as its whole-block CFB64. The proof reuses the whole-block contract with steps of a byte (Fb.fbX86 1), as CFB8's, and the block function's taint summary. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHGJJidJdRDMDSSd58W * Blowfish, SEED, Triple DES Arm: final CFB functions on the modes' seqFinal Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHGJJidJdRDMDSSd58W * Camellia x86: final CFB128 functions on the 32-bit modes' seqFinal vg_camellia_cfb128_{en,de}crypt_final on x86 are seqFinal over Camellia's core in the encryption direction, with 2756 bytes of stack scratch and the core's 16 bytes of stack as its whole-block CFB128. CfbFinalScratch gains the input-side locality lemmas the 32-bit stack frame needs (cfbFinalPre_local, cfbEncryptFinalPost_local, cfbDecryptFinalPost_local). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHGJJidJdRDMDSSd58W * CAST5: the final posts' and precondition's locality for the memory on entry For ARMv7's stack-scratch frame (cfbFinalPre_local, cfbEncFinalPost_local, cfbDecFinalPost_local). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHGJJidJdRDMDSSd58W * Camellia Arm: final CFB128 functions on the modes' seqFinal Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHGJJidJdRDMDSSd58W * CAST5 Arm: final CFB64 functions on the modes' seqFinal Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHGJJidJdRDMDSSd58W * SM4 Arm: final CFB128 functions on the modes' seqFinal Over SM4's ECB encryption, as Arm's SM4-OFB is (the whole-block CFB functions are the serial and batched ones). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHGJJidJdRDMDSSd58W * CAST5 x86: final CFB64 functions on the 32-bit modes' seqFinal vg_cast5_cfb64_{en,de}crypt_final on x86 are seqFinal over CAST5's encrypting core, with 332 bytes of stack scratch and the core's word below esp as its whole-block CFB64, and the table of S-boxes as a constant. The precondition is the modes' MPre with the data len bytes (FPre); the contracts use the input-side locality of CfbFinal.lean. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHGJJidJdRDMDSSd58W * Camellia and SEED x86 final CFB: meta-import the native taint hints native_taint_decide(_sum) searches its hints compiled only with Proof.Framework.X86.NativeHintData imported for meta code (ci/check_lean_speed.py). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHGJJidJdRDMDSSd58W * WIP: PPC64LE seqFinal mode: code, the partial segment's byte loop and a step within the bytes Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHGJJidJdRDMDSSd58W * WIP: PPC64LE seqFinal mode: a whole segment, proven Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHGJJidJdRDMDSSd58W * WIP: PPC64LE seqFinal mode: the partial segment, proven Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHGJJidJdRDMDSSd58W * PPC64LE seqFinal mode: CFB over a message's last piece, proven correct Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHGJJidJdRDMDSSd58W * IDEA PPC64LE: final CFB64 functions on the modes' seqFinal Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHGJJidJdRDMDSSd58W * RISC-V modes: seqFinal, CFB of a message's last piece for any core seqWith_changesO_wp: seq's function around loops that leave any data and chaining value; seqFinal runs segments of a block over a count of bytes, the last of which may be partial, with the core inlined once. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHGJJidJdRDMDSSd58W * Blowfish PPC64LE: final CFB64 functions on the modes' seqFinal Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHGJJidJdRDMDSSd58W * Triple DES PPC64LE: final CFB64 functions on the modes' seqFinal Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHGJJidJdRDMDSSd58W * IDEA RISC-V: final CFB64 functions on the modes' seqFinal Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHGJJidJdRDMDSSd58W * Blowfish RISC-V: final CFB64 functions on the modes' seqFinal Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHGJJidJdRDMDSSd58W * SM4 PPC64LE: final CFB128 functions on the modes' seqFinal Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHGJJidJdRDMDSSd58W * SEED PPC64LE: final CFB128 functions on the modes' seqFinal Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHGJJidJdRDMDSSd58W * SEED RISC-V: final CFB128 functions on the modes' seqFinal Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHGJJidJdRDMDSSd58W * SM4 RISC-V: final CFB128 functions on the modes' seqFinal Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHGJJidJdRDMDSSd58W * Triple DES RISC-V: final CFB64 functions on the modes' seqFinal Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHGJJidJdRDMDSSd58W * Camellia RISC-V: final CFB128 functions on the modes' seqFinal Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHGJJidJdRDMDSSd58W * PPC64LE seqFinal mode: what the final CFB functions change Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHGJJidJdRDMDSSd58W * Camellia PPC64LE: final CFB128 functions on the modes' seqFinal Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHGJJidJdRDMDSSd58W * CAST5 RISC-V: final CFB64 functions on the modes' seqFinal Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHGJJidJdRDMDSSd58W * CAST5 PPC64LE: final CFB64 functions on the modes' seqFinal Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHGJJidJdRDMDSSd58W * CAST5 and Camellia x86-64 CBC: follow fbPre's length parameter Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHGJJidJdRDMDSSd58W * Regenerate the crates with the full emitter Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHGJJidJdRDMDSSd58W * SM4 Arm final CFB: own its ECB core after #4333; CAST5 registrations leave consts to the default #4333 removed SM4 Arm's ecbCore and ecbSpec, which only the final functions use now: define them in their modules. #4380 leaves registrations' tables of constants to the default; drop the CAST5 final entries' consts likewise (the generated code is unchanged). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHGJJidJdRDMDSSd58W * CFB decrypt_final: the whole blocks with the whole-block function Decryption of whole blocks need not chain, and the whole-block functions of Camellia and SM4 on AArch64 decrypt several at once; the final function decrypts one block at a time, 2.5 to 4.6 times slower there (Benchmarks run 42335546119). decrypt_final now gives the whole blocks to the whole-block function and only the rest, fewer than a block, to the final function, from the IV the whole blocks leave. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHGJJidJdRDMDSSd58W * CFB finals: whole blocks with the whole-block function, the rest with the final one The whole-block functions are the faster for whole blocks: SM4's on Arm prepares its round keys once (encryption 11-21% slower through the final function, Benchmarks run 42335904986), and a message of whole blocks need not call the final function, whose frame costs a small message up to 22% on RISC-V (run 42336235715). Both directions now give the whole blocks to the whole-block function and only a partial last segment to the final one. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHGJJidJdRDMDSSd58W --------- Co-authored-by: Claude <noreply@anthropic.com>
* WIP: x86-64 RSA key generation controller and its correctness proof Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHJ2FcxfeqKwuVNLR6Y * RSA key generation: the x86-64 controller, vg_rsa_generate, in verified code The whole generation (VG.Spec.RsaKeyGen.generate) runs in vg_rsa_generate over random tapes that crate::entropy::serve supplies, after vg_rsa_generate_init: the prime searches, the key from the primes, drawing both again while d is too small, and the four generations. On x86-64 the Rust outer loop is gone; the other targets keep it until their controllers land. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHJ2FcxfeqKwuVNLR6Y * RSA key generation: build on main's FFDH frame after its cleanup main deleted freed_mem from Ffdh.X86_64.Generation.Frame as dead; the x86-64 controller's proofs use it, so it is back next to freed_reg. Generate/Loop imports the frame it uses directly. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHJ2FcxfeqKwuVNLR6Y * RSA key generation: the AArch64 controller, vg_rsa_generate, in verified code Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHJ2FcxfeqKwuVNLR6Y * RSA key generation: the PPC64LE controller, vg_rsa_generate, in verified code Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHJ2FcxfeqKwuVNLR6Y * RSA key generation: the Arm controller, vg_rsa_generate, in verified code Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHJ2FcxfeqKwuVNLR6Y * RSA key generation: the x86 controller, vg_rsa_generate, in verified code Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHJ2FcxfeqKwuVNLR6Y * RSA key generation: restore the Rust backends removed by mistake The previous commits staged their deletion before the Rust that replaces them; they go with that change. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHJ2FcxfeqKwuVNLR6Y * RSA key generation: the RISC-V controller, vg_rsa_generate, in verified code Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHJ2FcxfeqKwuVNLR6Y * RSA key generation: one Rust path over vg_rsa_generate on every target Regenerate the crates for the controllers of x86, AArch64, Arm, PPC64LE and RISC-V, and drop the Rust outer loop: keygen.rs serves vg_rsa_generate random tapes on every architecture, chosen by rsa::Backend. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHJ2FcxfeqKwuVNLR6Y * Regenerate the crates after merging main Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHJ2FcxfeqKwuVNLR6Y --------- Co-authored-by: Claude <noreply@anthropic.com>
* Remove dead declarations and modules: second pass (work in progress) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015ajQWu4wLufJmG4YMhAHx3 * Restore declarations found by name and re-add lost imports Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015ajQWu4wLufJmG4YMhAHx3 * Fix remaining lost imports Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015ajQWu4wLufJmG4YMhAHx3 * Re-add imports passed on by deleted modules Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015ajQWu4wLufJmG4YMhAHx3 * Remove the generator-two exponent declarations left dead Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015ajQWu4wLufJmG4YMhAHx3 --------- Co-authored-by: Claude <noreply@anthropic.com>
…4396) vg_dsa_sign_random checks the whole key on every call, including g^q mod p = 1 and g^x mod p = y: two modular exponentiations the size of signing's own g^k mod p, so that every signature costs three. As vg_dsa_validate_public_key does for verification, an owner of an immutable private key validates it once with vg_dsa_validate_private_key (every check signBytes makes of the key alone) and then signs with vg_dsa_sign_random_prevalidated, whose precondition is that validation of the exact key bytes, and whose result, consumption, output zeroing and leakage are exactly vg_dsa_sign_random's (randomSignContract). Part of #4141. Claude-Session: https://claude.ai/code/session_01TKUFHEBgoBubRhZoJviYcu Co-authored-by: Claude <noreply@anthropic.com>
* AES-CBC x86-64 AVX-512 decryption: no legacy SSE in the zmm loop `finish4` of `vg_aes_cbc_decrypt_vaes_avx512` built the feedback vector [C(-1), C0, C1, C2] with a legacy-SSE `movdqa xmm14, xmm15` and loaded C3 with a legacy `movdqu xmm15, [rdx+...]`, after zmm writes, so each paid an SSE/AVX transition: 1 MiB decrypted in 2.47 ms against 79 µs now. It now joins lane 0 of zmm15 to the loaded lanes with two `vshufi32x4`s and loads C3 with VEX `vmovdqu`; `finish4_ok`'s statement is unchanged. Add ci/check_avx_transitions.py to the Static checks: following each generated x86 function's control flow and its calls, it fails when a legacy-SSE instruction writes an xmm register while a ymm/zmm write may have left the upper state dirty, or a `ret` or indirect call is reached dirty. Part of #4141. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHGKcLy5wmHTbLPkr17 * Drop the SSE/AVX transition check Review: too specific; the benchmarks catch it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHGKcLy5wmHTbLPkr17 * Drop the SSE/AVX transition check's CI step Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHGKcLy5wmHTbLPkr17 --------- Co-authored-by: Claude <noreply@anthropic.com>
CFB decryption's input blocks are the IV and the preceding ciphertext blocks, all known before any block is decrypted, but x86-64's Camellia CFB128 decryption used the generic feedback mode, enciphering one block per call of the eight-block bitsliced core. Add the modes' batched CFB decryption for x86-64 (Impl/Modes/X86_64/CfbDec.lean), as AArch64's: each group of up to eight input blocks is gathered in the core's buffer, enciphered at once and XORed into the ciphertext, with the chaining value kept in the mode's slots and the IV updated at entry as CBC decryption does. Its proof (Proof/Modes/X86_64/CfbDec.lean) follows CBC decryption's; the architecture-independent lemmas of AArch64's proof move to Proof/Modes/CfbDec.lean so both use them. Part of #4141. Claude-Session: https://claude.ai/code/session_01TKUFHHS92w298ZipjNLXwp Co-authored-by: Claude <noreply@anthropic.com>
Key generation computed each row of t = NTT⁻¹(Σⱼ Â[i,j] ŝ₁[j]) with a
multiply, ℓ - 1 multiply-adds and an inverse NTT: ℓ + 1 calls, each
paying for its own MXCSR prologue and epilogue (two lfences and two
ldmxcsr). It now calls vg_mldsa_dot_inverse{ℓ}, the fused sum of products
and inverse NTT that signing already uses, once per row, in one MXCSR
region: a row of ML-DSA-65 takes about 0.54 µs instead of 1.2 µs.
The proof composes the existing dotInverseContract (Proof/MlDsa/
FusedInverseContract.lean) in place of the multiply, multiply-add and
inverse-NTT pieces (dotInvAt_ok, dotInvAt_tr, dot_piece). No TCB or Spec
change.
Claude-Session: https://claude.ai/code/session_01TKUFHGFkg2MycSz2r3GcQY
Co-authored-by: Claude <noreply@anthropic.com>
…t AVX (#4400) `vg_aes_xts_{en,de}crypt[_to]_aesni_pclmul`, the one-pass functions for CPUs with AES-NI and PCLMULQDQ but not VAES, required AVX only for a few VEX instructions in their tweak handling: `vpxor` with a memory operand (the tweaks XORed in), `vmovq`, and the three-operand `vpsrldq`, `vpclmulqdq`, `vpslldq` and `vpxor` of the tweak step. Without AVX (Westmere-class CPUs, `VG_CPU_FEATURES=ssse3,aes,pclmulqdq`) XTS fell back to the two-pass `_aesni` functions, which write every tweak to the data, call the block function and XOR them in again: 2.2x OpenSSL at 1 MiB. The 128-bit tweak helpers (`X86_64Vaes.tPre`/`tPost`, `X86_64VaesTo.tPre`) and the AES-NI loop's `stepT` and `constK` are now legacy SSE, with the tweak loaded into `xmm9` (legacy `pxor` requires an aligned memory operand) and `movdqa` copying it before the shift. The `_aesni_pclmul` functions now need only AES-NI and PCLMULQDQ, so `select` chooses them without AVX. The VAES functions' tails (after `vzeroupper`) use the same helpers. Interleaved A/B against main (ci/bench_compare.py, 3 rounds, 1 MiB): ssse3,aes,pclmulqdq: AES-128 out of place 328.6 -> 144.6 us (56% faster), in place 325.7 -> 181.1 us; AES-256 out of place 382.6 -> 188.1 us. With AVX and with AVX2: within 0.1-2.2% (noise). Claude-Session: https://claude.ai/code/session_01TKUFHEHakcDWS9PDNhTTa7 Co-authored-by: Claude <noreply@anthropic.com>
…0Poly1305::decrypt (#4384) Out-of-place ChaCha20-Poly1305 decryption on RISC-V, without a copy: vg_chacha20_poly1305_open_to (Spec.ChaCha20Poly1305.openToApi) reads the ciphertext from src and writes the plaintext to dst, through vg_chacha20_xor from src to dst. One body serves open and open_to: it reads the source at a4 and writes the destination it finds in t6, which it keeps in s6 (saved in the context, so the working space grows from 77 to 78 doublewords). seal and open run it in place (inPlace, t6 = a4); open_to enters through toEntry, which takes dst from a6 and tag and work from its stack arguments. The proofs are open's, with the destination equal to or apart from the source (APre.alias), and one relational constant-time proof of the body (open_rel) that every entry uses. open_to's working space is wiped after the code, as seal's and open's are: Verified.stackScratchArgsWiped (Proof/Framework/RISCV64/ StackScratchArgsWipe.lean) is Verified.stackScratchArgs for withStackScratchArgsWiped, whose postcondition may read the memory on return only within the buffers when the precondition holds. Proof/ChaCha20Poly1305/OpenToScratch.lean has open_to's scratch contract and the locality of its contract, for every target's open_to. ChaCha20Poly1305::decrypt(nonce, aad, ciphertext, tag, out), for riscv64 until each target has open_to: out must be as long as ciphertext (InvalidOutputLength, out untouched); a wrong tag zeroes out. Tests: decrypt_out_of_place (every length to 300 bytes at several alignments, a wrong tag, the length errors) and every Wycheproof vector out of place. Benchmark: chacha20poly1305-decrypt-out-of-place, next to OpenSSL's and aws-lc-rs's open_separate_gather. No change to TCB/ or Spec/. Claude-Session: https://claude.ai/code/session_015ajQWwrECv53ESEcwjcHaU Co-authored-by: Claude <noreply@anthropic.com>
#4401) * FFDH parameter generation on x86-64: screen q's small primes before the sieve Each fresh candidate p that passed the generator's congruence went straight to the full trial division of p by RSA's 511 primes, whose cost does not depend on where it finds a divisor, and only then was q = (p - 1)/2 checked. With g = 5 the congruence (p = 3 or 7 mod 10) lets 2/5 of all candidates through, among them every p whose q is even or divisible by 3, so most candidates paid for a sieve that q's checks then rejected. The congruence check now reduces p modulo 840 (g = 2) or 420 (g = 5), in the same single pass as before, and accepts only the remainders for which neither 2, 3, 5 nor 7 rules out p or q: a remainder in a fixed list, tested without a branch. Everything it rejects the trial division of p or q would reject (`congruent_sieved`), so the search, its result and its tape consumption are unchanged; only fewer candidates reach the sieve. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHGjpPevDhRbNs9mJKT * FFDH parameter generation on x86-64: fold the candidate before reducing it The congruence check reduced each fresh full-width candidate bit by bit, 64 conditional subtractions per word: about 1.4 us of each candidate at 512 bits, most of what remained of the search after the sieve was screened. Since 2^64 = 1 modulo 2^64 - 1, the candidate is congruent to the sum of its words with end-around carries (`fold`: an add and an adc per word), and 255 = 3 * 5 * 17 divides 2^64 - 1: one word reduced bit by bit (`reduce255`) gives p mod 3, 5 and 17, and the low word gives p mod 8. The check accepts p mod 255 in a fixed list (q's and p's 3, 5 and 17) and p = 3 mod 8 (g = 2) or p = 3 mod 4 (g = 5); 7 is no longer screened, 17 is. As before, it rejects only what the trial division of p or q would (`congruent_sieved`), so the search's result and tape consumption are unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHGjpPevDhRbNs9mJKT --------- Co-authored-by: Claude <noreply@anthropic.com>
…ock function (#4404) * AES-CBC and AES-CFB128 x86-64: decrypt four blocks per call of the block function (WIP) Baseline CBC and CFB128 decryption called vg_aes_*_blocks once per block, re-bitslicing the round keys each time. They now take four blocks per call while at least four are left, keeping the blocks they need in the unused last 64 bytes of the scratch buffer, and the rest one at a time. Proofs for both, generic over the block functions. The generated crates are not yet regenerated. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHFSgDu14jwXRky7oBm * AES-CTR and XTS-AES x86-64 proofs: the loop invariant's frame with the group slots (WIP) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHFSgDu14jwXRky7oBm * Regenerate the x86-64 AES-CBC and AES-CFB128 crates Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHFSgDu14jwXRky7oBm --------- Co-authored-by: Claude <noreply@anthropic.com>
Without the SHA extensions, SHA-1 ran vg_sha1_compress, whose schedule goes through memory one word at a time. vg_sha1_compress_avx_bmi computes the message schedule four words at a time in SSE registers (VEX.128) and keeps W + K in the same 64-byte window of the scratch space, from which each round adds it to e; Ch and Maj are sums of two disjoint masks (andn for Ch) and the rotations are rorx. It needs AVX, BMI1 and BMI2, uses the scalar function's 112 bytes of scratch space and saves the same registers, so the streaming, HMAC, PBKDF2 and DSA parameter-search functions follow it through their generic registrations with no change to their working space. Proven against the scalar function's contract (Proof/Sha1/X86_64/AvxBmi/Compress.lean), reusing its precondition, prologue and epilogue. Part of #4141. Claude-Session: https://claude.ai/code/session_01TKUFHEFnN3Cg4JT9EcrSqB Co-authored-by: Claude <noreply@anthropic.com>
The x86-64 signature computed [k]G by the ladder of complete additions, 256 doublings and additions of 17 products each, since x86-64's comb adds by the complete formulas for a = -3 and brainpoolP256r1's a is not -3. Add TCombCfg.generalComb, the comb with the complete addition for any a (rcb, with 3b R mod p in the slot of -y, as AArch64's generalComb), its proof (generalComb_ok, from tcomb_ok's), and Cfg.signG, the signature with [k]G by it, from the 7-bit comb tables AArch64, ARMv7 and RISC-V already use (Proof/BrainpoolP256r1/Comb7.lean checks them): 37 additions. The tables are the static VG_BRAINPOOLP256R1_COMB, which the signing configuration declares as its gtab, so that combConsts and the RFC 6979 contract list it. ECDH, verification and the public key keep the ladder. No change to TCB/ or Spec/. Claude-Session: https://claude.ai/code/session_01TKUFHFtUGDUpzkcbWbx7P7 Co-authored-by: Claude <noreply@anthropic.com>
check_variants.py required, for every caller of a function with variants, a variant of the caller for each of the callee's variants, composed with the caller's own. Some of those combinations can never be chosen: ChaCha20's 4-way SSSE3 code (in progress) is chosen only on CPUs without AVX and AVX2, while every Poly1305 variant needs both, so ChaCha20-Poly1305 over SSSE3 ChaCha20 and AVX2/AVX-512/IFMA Poly1305 would be dead code that the check demanded anyway. NEVER_WITH lists, for each target, the implementations the Rust code never chooses on a CPU with all of the features of a set (it chooses another implementation of the same function there). A variant of a function that is or calls such an implementation, for a callee's variant whose features together with the caller's include one of those sets, is no longer required. The table starts empty; the ChaCha20 SSSE3 change adds its entry. Each entry must name a generated function of its target whose own features do not include the set (else it could never be chosen), and CLAUDE.md and the adding-a-primitive skill say its Rust choice must be unit-tested both ways. Only the "missing combination" error is affected: a variant that exists still may not call the baseline, and "callers reach the best callee" is unchanged. Part of #4141. Claude-Session: https://claude.ai/code/session_01TKUFHFyzdwwyDWb9QSQqR1 Co-authored-by: Claude <noreply@anthropic.com>
) On 32-bit ARM, `SigningKey::prepare` and `VerifyingKey::prepare` now keep the key's polynomials in the NTT domain, as on AArch64, so that each signature and verification skips decoding and transforming the key. - Signing and verification share one kernel each with their ordinary entries: `vg_mldsa*_sign_with_cache` and `vg_mldsa*_verify_with_cache` take an optional pointer to the prepared polynomials (on the stack) and copy them rather than decode and transform the key. `vg_mldsa*_sign` and `vg_mldsa*_verify` call them with none, and the new internal entries `vg_mldsa*_sign_prepared` and `vg_mldsa*_verify_prepared` with those after the encoded key. Their stacks grow from 28 to 44 and 36 to 52 bytes, and the message functions' from 36 to 52. - `vg_mldsa*_prepare_signing_key` and `vg_mldsa*_prepare_verifying_key` copy the key and unpack and transform each of its polynomials into its place, with the existing ARM primitives. - `vg_mldsa*_sign_message_prepared` and `vg_mldsa*_verify_message_prepared` are the message functions over the prepared entries. Everything is verified against the merged specs (`preparePublicKeyContract`, `prepareSecretKeyContract`, `preparedSignMessageContract`, `preparedVerifyMessageContract`, and the existing `signContract`, `verifyContract`, `signMessageContract` and `verifyMessageCachedContract`), including constant time. No change to `Spec/` or `TCB/`. Claude-Session: https://claude.ai/code/session_015ajQWvR3MP1uqjW6gePco1 Co-authored-by: Claude <noreply@anthropic.com>
…ine vg_aes_ctr32 (#4410) * AES-CTR x86-64: eight blocks at a time in SSE2 registers in the baseline vg_aes_ctr32 WIP: proofs; crates not yet regenerated. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHFAHEwRUgwg8TfgQXC * Regenerate vg_aes_ctr32 on x86-64 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHFyzdwwyDWb9QSQqR1 --------- Co-authored-by: Claude <noreply@anthropic.com>
…ation (#4407) * DSA x86-64: validate a private key once, then sign with one exponentiation vg_dsa_sign_random checks the whole key on every call, g^q mod p = 1 and g^x mod p = y, so a signature costs three exponentiations the size of its own g^k mod p: 910 µs at 2048/256, 2.3x OpenSSL, though one such exponentiation takes about 300 µs, as fast as FFDH's. On x86-64, PrivateKey now validates its immutable packed key on its first signature with vg_dsa_validate_private_key (Spec/Dsa/PrevalidatedSign.lean), caches the result as PublicKey::verify does, and signs with vg_dsa_sign_random_prevalidated, whose precondition is that validation and whose result and leakage are vg_dsa_sign_random's. Both have baseline and ADX implementations. * Impl/Dsa/X86_64/PrevalidatedSign.lean: the validator is the domain check's register entry with the nonce field pointing at x, then the signer's key checks (Checks.signingKey, Checks.privateKey); the signing attempt is the signer's program with those two checks replaced by rebuilding q-2 and the nonce's range check. * Proofs: correctness, constant time and the contracts of both, reusing the signer's lemmas (signAccepted_prevalidated: validation makes the omitted checks' mask true). The randomized wrapper's proofs are now generic over the signer it calls (Signer, with the key-validity predicate of its contract, signContractWith), so one proof covers the fully checked signer and the prevalidated one. * x86-64 no longer emits vg_dsa_sign_random, which nothing calls there. * bench: dsa_sign_cold, import plus the first signature. On an Intel Xeon @ 2.10 GHz (Sapphire Rapids), 2048/256: dsa_sign 910 -> 324 µs at full features (OpenSSL 391 µs), 1.27 ms -> 468 µs at VG_CPU_FEATURES=none; the first signature of a key, with its validation, 876 µs. Part of #4141. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHEBgoBubRhZoJviYcu * Cover the x86-64 invalid-key signing test without an RNG draw On x86-64 an invalid key is rejected before any nonce is drawn, so the draw-counting closure never ran there and its lines went uncovered. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHEBgoBubRhZoJviYcu --------- Co-authored-by: Claude <noreply@anthropic.com>
CFB decryption's input blocks are the ciphertext blocks before each, all in the buffer, so SM4's decryption now uses the modes' batched CFB decryption (`cfbDecryptBatched`, `CfbDec.batched_wp`), which enciphers up to sixteen blocks per call of the bitsliced core instead of one. 16 KiB: 1.08 ms -> 70 µs locally (OpenSSL: 156 µs). Part of #4141. Claude-Session: https://claude.ai/code/session_01TKUFHJ2XF1wYNccoZUrVGC Co-authored-by: Claude <noreply@anthropic.com>
vg_seed_cfb128_decrypt enciphered one block per call of the 16-lane SEED kernel, though each block's input (the previous ciphertext block) is already in the data. Use the modes' batched CFB decryption (Core.cfbDecryptBatched, CfbDec.batched_wp) over SEED's encryption core, with a test decrypting a 110-block message whole and in pieces across the group boundaries, then encrypting it back. Part of #4141. Claude-Session: https://claude.ai/code/session_01TKUFHHP5jxQHHjXq9hqkCQ Co-authored-by: Claude <noreply@anthropic.com>
…4524) The baseline implementation (no PMULL) now has the functions of the AArch64 single GCM layout, so that every implementation registers them and the dispatchers alone choose: * `vg_aes_gcm_store_powers` (`Impl.Gcm.AArch64.keyPowers`): `H` from byte 240 of the key context, then for `k` from 1 to 8 `preparedPower(Hᵏ)` stored at its place in `Powers8Repr`, and `Hᵏ⁺¹` by the bit-by-bit multiplication of `vg_ghash`. Only caller-saved registers, straight-line but for the multiplications' counted loops; constant time by `taint_decide` (`Proof/Gcm/AArch64/KeyPowers.lean`). * `vg_aes_gcm_seal_with_powers` and `vg_aes_gcm_open_with_powers` of an implementation without code that reads the powers: its `seal` and `open`, which never read the buffer, whose address is the next stack argument (`Generic/AesGcm/AArch64/AesGcm.lean`, `basePwArtifacts`; `Proof/AesGcm/AArch64/BasePw.lean`). * `AArch64.Verified.dropTrailingRo` (`Proof/Framework/AArch64/TrailingRo.lean`): code verified for a function with at least one stack argument is verified for it with one more, last, a read-only array it never reads, with a stronger precondition and the same postcondition and leak. It narrows the state to the old contract's regions (`RegionModel.verified_narrowTo`). No TCB or Spec change. Nothing in Rust calls the new functions yet. Claude-Session: https://claude.ai/code/session_01TKUFHFuGsz7F32Tm9DLkuP Co-authored-by: Claude <noreply@anthropic.com>
`streaming_hmac!` calls `vg_hmac_<hash>_init_auto` and `vg_hmac_<hash>_finalize_auto` (`crate::arch::dispatch::hmac_<hash>`) instead of matching on the hash's backend enum, chosen by its `select`, for each of `init`, `finalize` and `mac`. It takes the two dispatchers alone and loses the per-implementation lists and the checks of their features. The inner hash's `from_state` no longer takes a backend, and `streaming_hash!` loses `backend()`, which only HMAC used. The choice is today's: SHA-NI, then AVX2 (SHA-1: AVX+BMI) on x86-64; SHA2 (SHA-512's family: SHA3) on AArch64; SHA-NI on x86. `init`, the text's `update` and `finalize` each check their own features, so they could differ only on feature sets no CPU has; every implementation keeps the same streaming state (the same contract), so any of them may follow another. Claude-Session: https://claude.ai/code/session_01TKUFHFuGsz7F32Tm9DLkuP Co-authored-by: Claude <noreply@anthropic.com>
… sieve (#4525) p is now divided by only the first 16 words of RSA's table (64 primes) before q's whole sieve, and by the rest of the table after q passes. Most candidates that pass the screen have a small factor among those 64 primes, and a q with a small factor is now rejected before p's whole sieve. - `sieveFirst`/`earlyCheck`: oddness, then the sieve with a fixed count of `firstWords` words, stopping at the first divisor as the whole sieve does. - `sieveP`: p's whole sieve, after q's (`sieveQ`), before the witnesses. - `earlyOk_of_sieved`: the early check rejects only what p's whole sieve rejects, so the order of the checks does not change the result (`candidate_result`). - Timing: `sieveFirst_ct`/`earlyCheck_ct` (the sieve's relational proof, now over any count of words) and `sieveP_ct`. Claude-Session: https://claude.ai/code/session_01TKUFHGjpPevDhRbNs9mJKT Co-authored-by: Claude <noreply@anthropic.com>
`StackScratch.lean`, `StackScratchX86.lean` and `StackScratchArm.lean`
prove `Verified.stackScratch` on MD5's streaming `update`, with a
scratch-less signature and contract "local to this test". Since the spec
dropped MD5's scratch argument, the production proofs prove the same
thing against `Spec.Md5.updateContract`, which is the tests' local
contract: `Proof/Md5/{X86_64,AArch64,X86,Arm}/Shared.lean`'s `update`
(the x86-64 one with 120 bytes of scratch instead of 128). The tests'
`updateScratchContract = Sig.scratchContract …` examples and `writesSp`
guard are side conditions those proofs discharge, and `Arm`'s
`Verified.regScratch`, which the Arm test also exercises on `compress`,
is used by 16 production proofs.
Claude-Session: https://claude.ai/code/session_01TKUFHGWcdWepar47ghKUMy
Co-authored-by: Claude <noreply@anthropic.com>
vg_dsa_generate_key checks the domain with vg_dsa_check_parameters, whose g^q mod p = 1 is an exponentiation modulo p by q, then derives the key with vg_dsa_derive_key, whose checkParams repeats that check (checkElem's elemOrder on g) before computing g^x: three such exponentiations. Key generation now derives with vg_dsa_derive_key_checked (Derive.deriveChecked), an internal function: vg_dsa_derive_key with checkDomain for checkParams, the same checks of the domain but g's g^q mod p = 1 (rangeElem: g's load and range check, without elemOrder). It is proven against dcContract, dContract for a domain whose exact octets pass checkParametersBytes, and verified against the existing deriveKeyDomainCheckedContract (Spec/Dsa/DomainChecked.lean). Key generation's proof establishes the precondition from the domain check's result (chkOf) and the unchanged domain octets (Ctx.par). The constant-time proof follows vg_dsa_derive_key's, with the domain's validity as a fact of the public data (KD). vg_dsa_derive_key, which PrivateKey::from_private_components calls, is unchanged. No Spec/ or TCB/ change; the generated PPC64LE crate changes only by the call and the new internal function. Part of #4141. Claude-Session: https://claude.ai/code/session_01TKUFHH5MNu65G8ZwHFGXrL Co-authored-by: Claude <noreply@anthropic.com>
* DSA: choose with its generated dispatchers `src/dsa.rs` chose a `Backend` (the baseline or `_adx`) for every key, and parameter generation matched SHA-1's, SHA-256's and the Miller-Rabin round's backends, 27 combinations on x86-64, to name an implementation of `vg_dsa_parameter_search`. Key import, generation, validation, signing, verification and the parameter search now call their `_auto` dispatchers. `Backend`, `Round`, each `select`, the per-ABI `Search` types, the stored backend and their tests go; the parameter search keeps its test of the searcher's steps, through the dispatcher. The `#[cfg(not(any(...)))]` branches for targets outside the module's own were dead: the module exists only on those six architectures. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHE2dqL6Q2PDogxfD5f * DSA: parameter search only for SHA-1 and SHA-256 backends for the same CPUs (WIP: crates not yet regenerated) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHE2dqL6Q2PDogxfD5f * DSA: regenerate the crates; check_variants reads qualified parts in any position With only the paired SHA-1 and SHA-256 backends, the parameter search's suffixes are `_sha1_avx_bmi_sha256_avx2` and `_sha1_shani_sha256_shani` (and their `_mr_*`): no function with a signature has `_sha1_avx_bmi` alone. `check_variants.py` now takes a qualified part `<tag>_<suffix>` of a variant's suffix, whose `<suffix>` is one, as an internal function's suffix (`vg_dsa_parameter_search_1024_sha1_avx_bmi`), and a callee's variant in any part of a qualified suffix, not only the last. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHE2dqL6Q2PDogxfD5f --------- Co-authored-by: Claude <noreply@anthropic.com>
vg_dsa_generate_key checks the domain with vg_dsa_check_parameters, whose g^q mod p = 1 is a q-bit-exponent exponentiation modulo p, then derived the key with vg_dsa_derive_key, which repeated the domain's checks (Generate.parameters, that exponentiation included) before computing g^x: three such exponentiations where two suffice. Key generation now derives with Generate.deriveChecked, an internal function (vg_dsa_derive_key_checked): the derivation without the domain's checks, keeping x's and y's ranges. It is verified against the existing deriveKeyDomainCheckedContract (Spec/Dsa/DomainChecked.lean), whose precondition is that the exact domain bytes pass checkParametersBytes; key generation's proof establishes it from the domain check's result, which it already tracks (rChecked), and the unchanged domain bytes. vg_dsa_derive_key, which PrivateKey::from_private_components calls, is unchanged (its generated code is identical). The derivation's proofs are generic over its computation (deriveWith, ComputeOk, ComputeTrace), so both functions share them; deriveCompute is parameters followed by the new keyCompute. Part of #4141. Claude-Session: https://claude.ai/code/session_01TKUFHEAReVkeRSV5vyeuZJ Co-authored-by: Claude <noreply@anthropic.com>
vg_dsa_generate_key checked the domain with vg_dsa_check_parameters, whose g^q mod p = 1 is a modular exponentiation, then derived the key with vg_dsa_derive_key, which checked the whole domain again, g^q included. Generate.deriveChecked (vg_dsa_derive_key_checked, an internal function) is vg_dsa_derive_key for a domain that passes the checks: of them it keeps only the sizes, which give q's significant octets, and sets up the working spaces as the checks leave them (Prevalidated.setup, as prevalidated verification does); it checks x and y as Derive.body does. Key generation calls it once its domain check has returned 1. It is proven against the existing deriveKeyDomainCheckedContract (Spec/Dsa/DomainChecked.lean, deriveChecked_verified), and on the registers (dcContract: dContract and checkParametersBytes of the domain) for its call from key generation, whose proof establishes the precondition from the check's result and the unchanged domain bytes (derivec_pre). Its correctness is the derivation's (deriveWith_ok, DeriveFn.lean, now generic over the check of the domain), and its constant time composes derivation's levels with prevalidated verification's setup. vg_dsa_derive_key is unchanged. Claude-Session: https://claude.ai/code/session_01TKUFHGabzaozUPN18mLpEv Co-authored-by: Claude <noreply@anthropic.com>
vg_dsa_generate_key checks the domain with vg_dsa_check_parameters, whose g^q mod p = 1 is one exponentiation, and then derived the key with vg_dsa_derive_key, which repeated that same check after computing g^x. Port #4411 to AArch64: Generate.deriveChecked, an internal function, is deriveKey with the signer's cheap checks of g and y (Checks.publicPrefix) but without the g^q exponentiation, proven against the existing, reviewed deriveKeyDomainCheckedContract (Spec/Dsa/DomainChecked.lean). Key generation calls it as vg_dsa_derive_key_checked; its proof establishes the precondition from the domain check's result and the unchanged domain bytes. vg_dsa_derive_key itself is unchanged. ABIRegions no longer imports Mathlib.Algebra.Group.Nat.Defs, which it did not use: the new modules would otherwise make it a heavy-algebra hub of more than 40 importers (ci/check_lean_speed.py). No Spec/ or TCB/ change. Claude-Session: https://claude.ai/code/session_01TKUFHFhuWRWXNwncFAgx4q Co-authored-by: Claude <noreply@anthropic.com>
…ul_avx) (#4520) * GCM: 48 prepared powers on 128-bit registers (vg_aes_gcm_prepare_pclmul_avx) PrepareAvx.prepare runs the first three rounds of prepare16's plan (H'^2-H'^8), puts H'^9-H'^16 into eight registers keeping H'^8, and multiplies them by H'^8 four times, eight independent products a round, storing each power: vg_aes_gcm_prepare for CPUs with AVX and PCLMULQDQ. The plan's proof is generalized over the largest power computed (16 or 48); the new function is proven against prepareContract, and constant time by taint_decide. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHHDjuK1puxAcLZKKff * GCM: regenerate the x86-64 crate for vg_aes_gcm_prepare_pclmul_avx Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHHDjuK1puxAcLZKKff --------- Co-authored-by: Claude <noreply@anthropic.com>
This was referenced Nov 7, 2026
…end (#4533) RSAES-OAEP and RSASSA-PSS matched `rsa::Backend` in a per-architecture file each (`oaep_functions!`, `pss_functions!`) to name their encryption, decryption, signing and verification; they now call `vg_rsa_oaep_{encrypt_precomputed,decrypt}_auto` and `vg_rsa_pss_{sign,verify_precomputed}_auto`. The twelve per-architecture files, the two macros, the per-ABI function types and the backend's compile-time checks go, and with them `rsa::Backend`, its `select`, `REQUIRES` and their tests: nothing chooses an RSA implementation in Rust any more. Claude-Session: https://claude.ai/code/session_01TKUFHE2dqL6Q2PDogxfD5f Co-authored-by: Claude <noreply@anthropic.com>
…roduct (#4534) The sieve reduced the whole candidate once per prime of RSA's table: for each of a table word's four primes, its inverse and two 32-bit Montgomery steps per word of the candidate, 64 dependent steps per table word. It now multiplies the word's four primes into M (below 2^52), reduces the candidate once modulo M, one 64-bit Montgomery step per word (`productReduce`, `redc64`: acc 2^(64 w) = c mod M, acc < M + 2), and tests each prime on that acc as RSA's trial division does on the candidate (`accEntry`). Since each prime divides M, it divides c iff it divides acc (`acc_entry_math`, `trial_div`), so the flag, the early exit and `eeIter_ok`'s statement are unchanged. - `redc64_math`, `redc_bits`, `redc64_ok`, `prStep_ok`: the 64-bit step. - `prodBlock_ok`, `productHead_ok`, `productReduce_ok`: M, its inverse and the reduction. - `accEntry_ok`, `taEntry_ok`: each prime's test on acc. - The sieve's timing proofs are unchanged: the new code is taint-checked as the old was. Claude-Session: https://claude.ai/code/session_01TKUFHGjpPevDhRbNs9mJKT Co-authored-by: Claude <noreply@anthropic.com>
* Remove axiom audits of library constants from the Lean tests The emitter runs `#assert_standard_axioms all` over every artifact it emits (`TCB/Emit.lean`, `driver`), which audits the whole transitive closure of each artifact's proofs and contracts. An audit of a library theorem or spec definition in a test is therefore either already covered (the artifact depends on it) or irrelevant (nothing emitted does, and the rule only covers what an artifact depends on). `sorry` anywhere already fails `lake build` (warnings are errors). Delete the 18 test modules that held nothing but such audits, and the audits of library constants from 28 others, with their now-unused `TCB.Axioms` imports (and four modules that imported it without using it). Audits of theorems declared in the test files themselves stay, as do the tests of the emitter's driver text. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHGWcdWepar47ghKUMy * Remove the tests' other audits the emitter already runs `#assert_spec_origin` in a test module checks the `VG.Spec` names the test imports; the emitter's driver runs it over everything the registrations import (`TCB/Emit.lean`, `driver`), which is all the rule is about, and no test module declares a `VG.Spec` name but `Audit.lean`, which tests the audit itself and stays. `#assert_no_compiler_overrides` of DSA's `…Api` constants checks what the emitter's `#assert_no_compiler_overrides all …` already checks: each is registered. The audit of `Import.sizesValid` and `Import.lengthsValid`, propositions with no compiled code, checked nothing. The audits of the spec functions the known-answer tests evaluate stay: contracts are propositions, so the emitter's audit does not reach those through compiled code. Also drop the imports that only the removed audits used. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHGWcdWepar47ghKUMy --------- Co-authored-by: Claude <noreply@anthropic.com>
…ndent timing (#4157) * Spec: vg_dit_enter and vg_dit_clear, entering and leaving data independent timing Two functions with which the Rust code will run verified code with data independent timing on (on AArch64, PSTATE.DIT, which Arm requires for the timing guarantee the leakage model assumes): `vg_dit_enter() -> u32` returns 1 if the mode was on and 0 if it was off, and turns it on; `vg_dit_clear()` turns it off, for a caller to call only if `vg_dit_enter` returned 0. A contract in `Spec/` is one for every target, stated with `Sig.contract` on the arguments, the memory and the return value, which cannot name the mode, a part of one ISA's state. So these contracts say only that the functions take no argument and write no memory, with what every contract says (the calling convention's preserved state, constant time). What each does to the mode will be proven of its code against the same model, as a theorem of its proofs (`Proof/Dit/AArch64.lean`), which the summaries name. No `docs/algorithms/` entry: like `vg_ct_eq` and `vg_zeroize`, these are not an algorithm. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015ajQWyoNrCuvSgWWUoNG6S * Spec/Dit: vg_dit_enter's contract makes the mode public So that `vg_dit_enter` may branch on whether data independent timing was already on and not write PSTATE.DIT then. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015ajQWwnPmAfvKpXDUq9Tjq --------- Co-authored-by: Claude <noreply@anthropic.com>
…IT proven The code (`Impl/Dit/AArch64.lean`): * `vg_dit_enter`: `mrs x0, DIT; lsr x0, x0, #24; msr DIT, #1; ret` * `vg_dit_clear`: `msr DIT, #0; ret` The proofs (`Proof/Dit/AArch64.lean`): * `enter_verified`, `clear_verified`: the spec's contracts (no memory written, the calling convention's preserved state kept, constant time), like every artifact's. * `enter_dit`, `clear_dit`: what those contracts cannot name. Every run of `vg_dit_enter` in the model ends with PSTATE.DIT on and `x0` 1 if it was on and 0 if it was off; every run of `vg_dit_clear` ends with it off. They hold of every run (`Exec.det`), from any state. Registered with `features := ["dit"]` (`Artifacts/Dit/AArch64.lean`); the regenerated crate gains `dit.rs`, whose `VG_DIT_*_FEATURES` name the new `feature::DIT` (bit 21 of `verified-garbage-cpu`), which `src/cpu.rs` detects with `is_aarch64_feature_detected!("dit")` (or, without `std`, the target's `dit` feature, which `aarch64-apple-darwin` has) and `VG_CPU_FEATURES` can name. `src/dit.rs` holds, for now, only a test that runs the two functions on the CPU: entering reports the mode and turns it on, clearing turns it off. The `dit` group runs it on the AArch64 runner unrestricted (with FEAT_DIT) and under `none` (without it, where it calls neither). The guard that uses them comes with its callers, in the next PR. `RegUpd.dit_write` is the frame lemma of the new field. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015ajQWyoNrCuvSgWWUoNG6S
CI's coverage left the closing brace of `if was == 0` uncovered: every runner starts the test's thread with PSTATE.DIT off, so the branch's false side never ran. The test now ends with `vg_dit_clear` whatever the mode was, which needs no branch. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015ajQWyoNrCuvSgWWUoNG6S
…ions now do Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015ajQWwnPmAfvKpXDUq9Tjq
`mrs`, then `cbz` past the `msr` when data independent timing is already on. Its contract makes the mode public (`Spec/Dit.lean`), and the proof shows that it leaks only whether the mode was off (`enter_leak`). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015ajQWwnPmAfvKpXDUq9Tjq
This was referenced Nov 7, 2026
Every verified function, and every generated `_auto` dispatcher, takes a `Dit` token first (`TCB/Rust.lean`), which only `src/dit.rs` makes, so the compiler checks that every call of verified code comes from an operation that decided whether it needs data independent timing: * `dit::enter!`, for an operation that may process secrets (MACs, AEADs, ciphers, KDFs, key generation, signing, key agreement, KEMs, RSA's private key and encryption): turns PSTATE.DIT on for the current thread where the CPU has it (`vg_dit_enter`), and off again after if it was off (`vg_dit_clear`); * `dit::public(Why::…)`, for an operation on public data alone (hashing without a key, verifying a signature, checking or converting a public key, wiping), which leaves the mode as it is; * `dit::enter_if!`, for BLAKE2, keyed or not. A dispatcher passes its token on to the implementation it calls; the dispatchers of tables of functions, which Rust never calls, take none. `ci/check_dit.py` checks each module's reasons against its family (`docs/algorithms/`). In the tests, entering a guard inside another, or a public token inside a secret operation, panics, so each operation decides once and passes its token down (`update_with`, `digest_with`, …); the check keeps the threads holding a guard in a `Mutex<Vec<ThreadId>>`. `src/dit.rs` asks `verified_garbage_cpu::detect::dit()` whether the CPU has FEAT_DIT, whatever `VG_CPU_FEATURES` says, so tests run with the mode wherever the CPU has it while `none` still makes the dispatchers choose the base implementations. `Hmac::verify_mac` checks a MAC in one operation. Ported onto main's generated dispatchers. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015ajQWwnPmAfvKpXDUq9Tjq
`verified_garbage::dit::scope(f)` turns PSTATE.DIT on for the current thread around `f`, and restores it when `f` returns or unwinds. The operations inside find the mode on, so `vg_dit_enter` only reads it and their guards leave it on: one `mrs` per call instead of an `msr` pair. Guard and scope share one `Mode` value. The README's AArch64 caveat now says what the library does, and a benchmark feeds HMAC-SHA-256 64 bytes per update outside and inside a scope. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015ajQWwnPmAfvKpXDUq9Tjq
Apple's documentation asks for a speculation barrier after turning PSTATE.DIT on, "to ensure that subsequent instruction timing reflects the updated DIT processor state"; Arm specifies that a write of a PSTATE field takes effect for the instructions after it, and requires none. As Go's runtime does (golang/go#77776), the barrier is used on Apple's targets alone: SB where the CPU has FEAT_SB, else DSB SY and ISB, as Apple's corecrypto does. `Impl.Dit.AArch64.enterWith bars` is `vg_dit_enter` with the barriers `bars` after the MSR, on the path that turns the mode on only: a call that finds it on (inside `dit::scope`) pays nothing. The proofs cover any `bars` (the barriers change nothing in the model), and `enter`, `enterDsb` and `enterSb` are its instances, registered as `vg_dit_enter`, `vg_dit_enter_dsb` and `vg_dit_enter_sb` (`dit` and `sb`). Rust: `sb` is a detected feature (bit 22); `dit::aarch64::Enter` chooses among the three by the features and `cfg!(target_vendor = "apple")`, unit tested both ways, and the tests run each implementation the CPU can. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015ajQWwnPmAfvKpXDUq9Tjq
reaperhulk
force-pushed
the
claude/dit-scope
branch
from
November 7, 2026 20:58
f843e3a to
2944a26
Compare
Member
Author
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.
Stacked on #4328 (which is on #4327 → #4326 → #4210).
What
verified_garbage::dit::scope(f)runs a closure with data independent timing (PSTATE.DIT on AArch64) on for the current thread, and restores the mode after, whether the closure returns or unwinds:Each operation that may process secrets still turns DIT on itself (#4210), since it can't trust its caller to have done so. Inside a scope, it finds DIT already on. #4328's
vg_dit_enterthen only reads PSTATE.DIT, without writing it, and the guard does not clear it on drop. So each call costs onemrsand a branch instead of anmsrpair. That pair is the roughly 50–60 ns per call that doubled the time of short AES-GCM records and made streaming 3.2× slower on Apple silicon (#4210's table).Why a closure
Hmacand the AEAD states areSend, so the mode can't live in the objects. The scope holds a value that is neitherSendnorSync, on the stack of the thread it affects.The test-only checks (no guard inside another, no public token inside a secret operation) are unchanged. A scope belongs to the caller, not to an operation, so the operations inside it decide as usual.
Changes
src/dit.rs:scopeits only public item.Guardandscopeshare oneModevalue that turns DIT on and restores it on drop.scope. On AArch64 with FEAT_DIT, it checks that the mode is on inside, stays on after a guard and a nested scope inside, and is off after the scope returns or panics.README.md: the AArch64 caveat said "nothing in this library sets it", which has been out of date since Rust: every verified function takes a Dit token #4210. It now says what the library does, and mentionsscope.bench/benches/primitives/dit.rs: HMAC-SHA-256 fed 64 bytes perupdate, outside a scope (next to OpenSSL'sSigner::updatein the same pieces) and inside one (OpenSSL has no equivalent).No Lean, no generated code, no TCB or Spec change.
Making
dita public module changes howci/bench_arches.pyscopes a change tosrc/dit.rs. It used to count as a private helper, which reached every benchmark of code namingcrate::dit. Now it reaches only the benchmarks whoseUSESincludedit. A later change to how operations enter the mode should be measured on the modules it affects, as #4210 was.Benchmark
macOS AArch64 (
aarch64-apple, the one runner whose CPU reports FEAT_DIT), run 42276101848, this branch alone,modules=dit. Medians for HMAC-SHA-256 fed 64 bytes perupdate. "Per call" is the time saved, divided by the number of calls:new, n updates,finalize.With the SHA-2 instructions (the default), the per-call DIT cost of #4210 is about 34 ns. A scope removes it, and 16 KB in 64-byte pieces then takes about half of OpenSSL's time, where without one it was slower.
With
VG_CPU_FEATURES=none(scalar SHA-256), the scope is faster at 1 KB (1.32×) and 16 KB (1.58×), but slower at 64 B (1.27 → 1.59 µs). That single result is opposite to every other one. The scope does at most what the operations would do themselves (one enter and one restore), so it is most likely noise from 25 samples of 300 ms. I have not rerun it.Testing
cargo teston the host.cpu-features-env:-cpu max, which has FEAT_DIT: the full suite.-cpu cortex-a72, which lacks it: thedittests.cargo clippy --all-targets -D warnings, for the library and the benchmarks.RUSTDOCFLAGS=-D warnings cargo doc.check_dit.py,check_arch_gates.pyandcheck_variants.py.🤖 Generated with Claude Code
https://claude.ai/code/session_015ajQWwnPmAfvKpXDUq9Tjq