Repository navigation
Conversation
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
… full emitter `lake env lean --run Emit.lean --check` found these files out of date: the internal functions' modules are declared where the full emitter puts them. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHFbSpgWBYWAsEnfUks
…to claude/ppc64le-3des-cbc-cfb
This was referenced Nov 8, 2026
Member
Author
|
Superseded by #4694: the same change, with the same tree as this PR's head, but as a linear stack on #4671's head ( 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, from the Camellia/SEED/SM4 work). This PR's base is #4671's branch, and it stays a draft until #4671 merges; then I'll restack it ontomain.It also builds on #4666 (the bitsliced ECB), now merged. It carries #4666's two commits until the base branch takes
main's squash of them.Finding 4 of the PPC64LE audit (#4141 (comment)): 3DES CBC and CFB64 decryption call the block function once per block, at about 5.6 µs a 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, as for SM4's modes. The variable-length copy loops ofecbwould make it forget them.Cost of the tail. A batch costs the same however many blocks it holds, so each block left after the last group of 64 costs a whole batch. That is about 4.8 µs, slightly less than the block function's 5.8 µs for one block.
Stack. The working space grows from 72 to 200 words, so CBC and CFB64 decryption take a 1632-byte frame instead of 608. The generated dispatchers' safety comments say so; the Rust is unchanged. The decryption block function
vg_triple_des_decrypt_blockis now unused (CMAC and the serial modes encrypt), and the emitter dropped it.Proofs
Proof/TripleDes/PPC64LE/Bitsliced/Ecb64.lean:ecb64_wpreuses 3DES PPC64LE: bitsliced ECB, 64 blocks at a time #4666's setup, transposition, passes and restore. The unrolled copies are checked by evaluation over the variable domain.Proof/TripleDes/PPC64LE/ModeCoreWide.lean:wideCoreSpec, theCoreSpecfor the 64-block core.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,
triple_desCBC and CFB64 groups; base9de9b1b9, which is #4671's branch plus #4666): https://github.com/pyca/verified-garbage/actions/runs/42513716834, on POWER9.triple-des-cbc-decrypt/64triple-des-cbc-decrypt/1024triple-des-cbc-decrypt/16384triple-des-cfb64-decrypt/64triple-des-cfb64-decrypt/1024triple-des-cfb64-decrypt/16384triple-des-cbc-encrypt/*,triple-des-cfb64-encrypt/*At 16 KiB both are about 73× faster. The audit measured OpenSSL's CBC and CFB64 decryption at about 11.4 ms / 14×, i.e. about 800 µs, so these are now about 0.2× OpenSSL, as ECB is.
🤖 Generated with Claude Code
https://claude.ai/code/session_01TKUFHFbSpgWBYWAsEnfUks