Repository navigation
Conversation
PPC64LE Camellia's core (vg_camellia_crypt_prepared) enciphers the eight blocks of its tail buffer per call, but the modes used only the first, so every mode cost a whole batch per block. CBC and CFB decryption and CTR now take eight blocks a step while eight are left, then one a step. This ports RISC-V's framework for batched modes (#3978, #4012) to PPC64LE: Core.seq is now Core.seqWith (Core.steps m), the same code, and Core.seq2 runs the steps of a widened mode (Mode.widen) while r30 >> lg is not zero, then the narrow ones. The step proofs take the buffer's bytes a step uses, the regions the key is ready for and the count a step takes (Fixed, Inv), so one proof serves both loops; Proof/Modes/PPC64LE/ Wide.lean proves the loops of seq2 for CBC and CFB decryption and both counter modes from the architecture-independent Proof/Modes/Wide.lean and WideCtr.lean. No TCB or Spec change; the other modes' code is unchanged. Part of #4141. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHFCoYzWWszXpPsgsoT
…cks at a time PPC64LE SM4's core (vg_sm4_crypt_prepared) enciphers the sixteen blocks of its tail buffer per call, but the modes used only the first. CBC and CFB decryption, CTR and the counter mode with GCM's inc32 (vg_sm4_ctr32, which SM4-GCM inlines through its contract) now take sixteen blocks a step while sixteen are left, then one, with Core.seq2. The narrow counter modes step the counter block before the block cipher (Mode.ctrEarly, Mode.ctr32Early), as the wide ones do; Proof/Modes/PPC64LE/Ctr.lean and Ctr32.lean, the one-block counter modes, are no longer used and go. New tests check the API against itself at lengths around the groups: SM4-CBC decryption and SM4-CTR, and Camellia-CBC decryption, whole, a block at a time and in two pieces. Part of #4141. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHFCoYzWWszXpPsgsoT
SEED's blocks function computes the rounds of sixteen lanes whatever the number of blocks, so the modes, which called it on one block a step, paid a whole batch per block. The core is now parameterized by its buffer's number of blocks (core d g): the serial modes keep dirCore d = core d 1, the same code and 1184-byte frame, and CBC and CFB decryption use wideCore d = core d 16 with Core.seq2, sixteen blocks a step while sixteen are left, then one, in a 1424-byte frame (174 words of working space). modeContract and modeTaint take the working space's size, and τCallW adds the blocks functions' taint summaries at it. A new test checks SEED-CBC decryption against itself at lengths around the groups. Part of #4141. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHFCoYzWWszXpPsgsoT
…es with the full emitter EmitOne had placed the internal functions the modes share (vg_camellia_crypt_prepared, vg_seed_encrypt_blocks, ...) in each file it emitted; Emit.lean puts them back in their shared modules. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHFCoYzWWszXpPsgsoT
ECB on ppc64le called the block function once per block (about 5.6 µs a block, 9-15x OpenSSL; finding 4 of the PPC64LE audit in #4141). It now encrypts and decrypts 64 blocks at a time, bitsliced in 64-bit GPRs, as on RISC-V: the blocks are copied into the scratch buffer's state words and transposed, the S-boxes run as Rusakov's circuits (`BitsliceCircuit`), allocated to registers for this model's and/or/xor (NOT and AND-NOT through a register of all ones), and the state is transposed back. The functions keep the contract and the frame they had (`ecbScratchContract`, `ecb_framed`), so the Rust code is unchanged. The block-at-a-time ECB loop and its proofs are gone; the modes and CMAC still call the block functions. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHFbSpgWBYWAsEnfUks
`ecb_wp` assumed the contract's exact lists of readable and writable regions. It now needs only the schedule readable and the blocks and the scratch buffer writable, and also gives the regions it writes and, when there are blocks, the scratch buffer and the schedule's addresses left in `r10` and `r7`, so that the modes can run the same code on their buffer. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHFbSpgWBYWAsEnfUks
…es regenerating) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHFbSpgWBYWAsEnfUks
…its own module Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHFbSpgWBYWAsEnfUks
This was referenced Nov 8, 2026
|
This pull request has conflicts with Posted by |
Member
Author
|
Superseded by #4738: the same change, restacked onto 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.
Depends on #4671 (the PPC64LE batched-modes framework,
Impl/Modes/PPC64LE/Wide.lean). This PR's base is #4671's branch. It stays a draft until #4671 merges, and will then be restacked ontomain. It replaces #4679, whose stack was not linear: the same change, with the same tree as #4679's last head (f8cb6ceb, CI green), as four commits on #4671's headad3b520b. The first two are #4666 (bitsliced ECB, merged tomainas9d4f8cd4), and they drop out at the restack.Finding 4 of the PPC64LE audit (#4141 (comment)): 3DES CBC and CFB64 decryption call the block function once per block. x86-64 batched them in #4416.
What changes
vg_triple_des_cbc_decrypt_chainedandvg_triple_des_cfb_decrypton ppc64le now take 64 blocks a step while at least 64 are left, then one block a step (Core.seq2, withMode.cbcDecWideandcfbDecWide).The core.
wideCore dhas a 64-block buffer. Its block cipher is a call of the new internal functionsvg_triple_des_ecb64_{en,de}crypt(Bitslice.ecb64): #4666's bitsliced ECB on exactly 64 blocks, as one batch with the copies unrolled. ECB leaves the scratch buffer's and the schedule's addresses inr10andr7, and the core restoressbandr3from there.Why a call, and why unrolled:
blreaches.r29–r31(the modes' state) in the scratch buffer and restores them. With every store at a fixed offset,slotTaintsees those slots come back public.Stack. The working space grows from 72 to 200 words, so CBC and CFB64 decryption take a 1632-byte frame instead of 608. The decryption block function
vg_triple_des_decrypt_blockis now unused, and the emitter dropped it.Proofs
Proof/TripleDes/PPC64LE/Bitsliced/Ecb64.lean:ecb64_wp.Proof/TripleDes/PPC64LE/ModeCoreWide.lean:wideCoreSpec.ModesVerified.lean,ModesFrame.lean: the 200-word contracts and frames. Correctness comes fromcbcDecWide_wpandcfbDecWide_wp.ModesConstantTime.lean:slotTaintfor the two functions.No TCB or Spec changes.
Benchmarks
Scoped run (powerpc64; base
9de9b1b9, #4671's branch plus #4666), on POWER9: https://github.com/pyca/verified-garbage/actions/runs/42513716834triple-des-cbc-decrypt/64triple-des-cbc-decrypt/1024triple-des-cbc-decrypt/16384triple-des-cfb64-decrypt/64triple-des-cfb64-decrypt/1024triple-des-cfb64-decrypt/16384Generated by Claude Code