Skip to content

3DES PPC64LE: bitsliced ECB, 64 blocks at a time - #4666

Merged
alex merged 2 commits into
mainfrom
claude/ppc64le-3des
Nov 8, 2026
Merged

alex merged 2 commits into
mainfrom
claude/ppc64le-3des

Conversation

@alex

@alex alex commented Nov 8, 2026 •

Copy link
Copy Markdown
Member

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}crypt on 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):

  • Load and transpose. Up to 64 blocks are copied into the scratch buffer's state words, a doubleword at a time. The copy reuses the verified 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.
  • S-boxes. They are Rusakov's circuits (BitsliceCircuit). The new Impl/TripleDes/PPC64LE/BitsliceAlloc.lean allocates them to registers using only this model's and/or/xor. NOT and AND-NOT go through r11, which holds all ones.
  • Round keys. Each round loads its key straight from the caller's schedule and complements it. Key bit b becomes a mask as ((~k << (63-b)) >> 63) - 1.
  • Three passes. They are unrolled, and each is a loop over eight pairs of rounds. The state is then transposed back and copied out.

The functions keep the contract and frame they had: ecbScratchContract inside ecb_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 through Ecb.blockCall and Ecb/Call.lean.

Proofs

Proof/TripleDes/PPC64LE/Bitsliced/ mirrors RISC-V's proof and reuses the target-independent Proof/TripleDes/Bitslice/ lemmas. Each part is checked differently:

  • S-boxes: each allocated circuit is checked by evaluation over truth tables of all 64 inputs.
  • Output XORs and the half swap: evaluated over the variable domain.
  • Transposition: evaluated over the lane domain.
  • Constant time: taint_decide on the whole function.

ecb_wp needs 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 in r10 and r7, 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:

64 B 1 KiB 16 KiB
3DES-ECB encrypt (24-byte key) 5.80 µs 10.5 µs 149 µs
3DES-ECB decrypt (24-byte key) 5.82 µs 10.5 µs 148 µs

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

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants