Repository navigation
3DES PPC64LE: bitsliced ECB, 64 blocks at a time - #4666
Merged
Merged
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
This was referenced Nov 8, 2026
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.
Finding 4 of the PPC64LE audit (#4141 (comment)): 3DES-ECB on ppc64le called the block function once per block, about 5.6 µs a block, 9–15× OpenSSL.
What changes
vg_triple_des_ecb_{en,de}crypton ppc64le now work on 64 blocks at a time, bitsliced in 64-bit GPRs. This is a port of RISC-V's design (Impl/TripleDes/RISCV64/Bitsliced.lean):Gather.PPC64LE.copyWords; the model's doubleword accesses need no alignment. The words are then transposed in place. The transpose's left shifts are rotations, because the bits moved up are zero at the top.BitsliceCircuit). The newImpl/TripleDes/PPC64LE/BitsliceAlloc.leanallocates them to registers using only this model'sand/or/xor. NOT and AND-NOT go throughr11, which holds all ones.bbecomes a mask as((~k << (63-b)) >> 63) - 1.The functions keep the contract and frame they had:
ecbScratchContractinsideecb_framed, so the 1056-byte frame wipes the scratch buffer. The Rust code is unchanged.Removed: the block-at-a-time ECB loop and its proofs (
Proof/TripleDes/PPC64LE/Ecb/{Loop,Verified,ConstantTime}.lean). The modes and CMAC still call the block functions throughEcb.blockCallandEcb/Call.lean.Proofs
Proof/TripleDes/PPC64LE/Bitsliced/mirrors RISC-V's proof and reuses the target-independentProof/TripleDes/Bitslice/lemmas. Each part is checked differently:taint_decideon the whole function.ecb_wpneeds only the schedule readable and the blocks and scratch buffer writable, not the contract's exact region lists. It also returns the regions it writes, and the scratch buffer's and schedule's addresses inr10andr7, so the modes can run the same code on their own buffer.No TCB or Spec changes.
Not in this PR
CBC and CFB64 decryption still go one block at a time. A follow-up will batch them over this kernel, as x86-64's #4416 did. That follow-up is stacked on the PPC64LE batched-modes framework from the Camellia/SEED/SM4 work.
Benchmarks
Scoped run (powerpc64,
triple_des, base = this PR's base): https://github.com/pyca/verified-garbage/actions/runs/42511583010, on POWER9.This branch's ECB, median:
At 16 KiB the audit measured 11.4 ms for ECB on
main, and 750 µs for OpenSSL. This branch is 77× faster than that and about 0.2× OpenSSL. A 64-block batch costs about 4.6 µs, about as much as one block of the old code. The serial modes (CBC encryption, OFB, CFB, CFB8, CMAC) don't use ECB and are unchanged.🤖 Generated with Claude Code
https://claude.ai/code/session_01TKUFHFbSpgWBYWAsEnfUks