Skip to content

3DES PPC64LE: the round function as a 64-lane table lookup - #4693

Merged
alex merged 1 commit into
mainfrom
claude/ppc64le-3des-block
Nov 8, 2026
Merged

alex merged 1 commit into
mainfrom
claude/ppc64le-3des-block

Conversation

@alex

@alex alex commented Nov 8, 2026 •

Copy link
Copy Markdown
Member

Finding 4 of the PPC64LE audit (#4141 (comment)), the serial paths. Every 3DES function that encrypts one block at a time runs the single-block function: CBC encryption, OFB, CFB8, CFB64 encryption, CMAC, and today also CBC and CFB64 decryption (#4694 batches those).

That function ran the eight S-boxes' Boolean circuits one after another, each on one bit, with spills: about 1,700 instructions a round.

What changes

The block now uses RISC-V's round function (Impl/TripleDes/RISCV64/Feistel.lean), ported as Impl/TripleDes/PPC64LE/Feistel.lean. It looks up all eight S-boxes at once, in the 64 lanes of a word, with a multiplexer tree on words of constants. The round is now 282 instructions with no spills, and each block function shrinks from 1,876 to 1,164 instructions.

What differs from RISC-V:

  • Shift left. The proofs' evaluators follow no left shift of an unknown word. A shift left is therefore a rotation of a word whose top bits are zero. Each such rotation is exact, and the checks confirm it.
  • One-bit groups of P. A group of P's outputs that is one bit is rotated to the top, shifted to bit 0, then shifted to its place.
  • Small groups of P. The model has no andi. A group's mask below 2 ^ 15 comes from li, and only six masks are words of constants.
  • The doubling steps keep one mask each: ((y >>> a) &&& keep) <<< (a + s).
  • Where the constants live. The block stores its 47 words of constants in slots 15–61 of its 512-byte scratch buffer, after the saved registers. These are the slots the S-boxes' spills used. The function's interface, contract and stack use are unchanged.

Proofs

  • The checks are RISC-V's. The two linear parts are checked over the lane domain, with the constants as constant external words (kExt, linearK_ok). The tree is checked over the position-table domain. feistel_ok composes them, and roundBody_ok adds the half swap.
  • No memory writes in the rounds. Ready carries the constants (ConstsAt). The rounds' frame is now the two unused slots (spillRegion). The head proves the constants' stores (storeConsts_wp).
  • Deleted: the old S-box modules, Impl/TripleDes/PPC64LE/Sbox.lean and Proof/…/{Round,RoundFunction,Box,Sbox,SboxTable}.lean.

No TCB, Spec or Rust changes. Only the two internal block functions' generated code changes.

Benchmarks

Scoped run (powerpc64; triple_des_cbc, triple_des_cfb, triple_des_cfb8, triple_des_ofb and cmac_triple_des; base 9d4f8cd4, this PR's base): https://github.com/pyca/verified-garbage/actions/runs/42516327193

Every group that uses the single block is about 2.7× faster (61–64% less time), less than the 6× fewer instructions would suggest. CBC and CFB64 decryption also improve here, until #4694 batches them.

Benchmark Base Head Change
tdes-cmac/64 52.24 µs 20.19 µs 61.4% faster
tdes-cmac/1024 726.94 µs 266.07 µs 63.4% faster
tdes-cmac/16384 11.54 ms 4.22 ms 63.5% faster
tdes-cmac-verify/64 52.50 µs 20.11 µs 61.7% faster
tdes-cmac-verify/1024 728.39 µs 266.41 µs 63.4% faster
tdes-cmac-verify/16384 11.54 ms 4.20 ms 63.6% faster
triple-des-cbc-decrypt/64 46.58 µs 17.98 µs 61.4% faster
triple-des-cbc-decrypt/1024 723.09 µs 264.65 µs 63.4% faster
triple-des-cbc-decrypt/16384 11.57 ms 4.21 ms 63.6% faster
triple-des-cbc-encrypt/64 46.43 µs 17.93 µs 61.4% faster
triple-des-cbc-encrypt/1024 720.96 µs 264.16 µs 63.4% faster
triple-des-cbc-encrypt/16384 11.53 ms 4.21 ms 63.5% faster
triple-des-cfb64-decrypt/64 46.56 µs 17.97 µs 61.4% faster
triple-des-cfb64-decrypt/1024 722.85 µs 264.22 µs 63.4% faster
triple-des-cfb64-decrypt/16384 11.52 ms 4.21 ms 63.5% faster
triple-des-cfb64-encrypt/64 46.59 µs 18.03 µs 61.3% faster
triple-des-cfb64-encrypt/1024 724.15 µs 265.47 µs 63.3% faster
triple-des-cfb64-encrypt/16384 11.58 ms 4.22 ms 63.5% faster
triple-des-cfb8-decrypt/64 361.49 µs 133.20 µs 63.2% faster
triple-des-cfb8-decrypt/1024 5.76 ms 2.11 ms 63.4% faster
triple-des-cfb8-decrypt/16384 92.38 ms 33.70 ms 63.5% faster
triple-des-cfb8-encrypt/64 362.08 µs 134.01 µs 63.0% faster
triple-des-cfb8-encrypt/1024 5.77 ms 2.12 ms 63.3% faster
triple-des-cfb8-encrypt/16384 92.39 ms 33.83 ms 63.4% faster
triple-des-ofb/64 46.62 µs 18.03 µs 61.3% faster
triple-des-ofb/1024 721.31 µs 264.19 µs 63.4% faster
triple-des-ofb/16384 11.52 ms 4.21 ms 63.4% faster

🤖 Generated with Claude Code

https://claude.ai/code/session_01TKUFHFbSpgWBYWAsEnfUks

The single block function (CBC encryption, OFB, CFB8, CFB64 encryption,
CMAC and the batched modes' tails) ran the eight S-boxes' Boolean circuits
one after the other, on one bit each, with spills: about 1,700
instructions a round. It now uses RISC-V's round function
(Impl/TripleDes/RISCV64/Feistel.lean), which looks the eight S-boxes up at
once in the 64 lanes of a word with a multiplexer tree on words of
constants: 282 instructions a round, with no spills.

On PPC64LE a shift left is a rotation of a word whose top bits are zero
(the evaluators follow no left shift of an unknown word), a group of P's
outputs of one bit is rotated to the top, shifted to bit 0 and then to its
place, and a small group's mask comes from `li`. The block stores the 47
words of constants in slots 15-61 of its scratch buffer first.

The proofs are RISC-V's: the two linear parts over the lane domain, with
the constants as constant external words, and the tree over the
position-table domain. The rounds now write no memory; Ready carries the
constants, and the head proves their stores.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TKUFHFbSpgWBYWAsEnfUks
@github-actions github-actions Bot added the untrusted-only This changes exclusively implementations and proofs, and thus is entirely formally verified. label Nov 8, 2026
@alex
alex added this pull request to the merge queue Nov 8, 2026
Merged via the queue into main with commit ba43c22 Nov 8, 2026
24 checks passed
@alex
alex deleted the claude/ppc64le-3des-block branch November 8, 2026 20:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

untrusted-only This changes exclusively implementations and proofs, and thus is entirely formally verified.

Development

Successfully merging this pull request may close these issues.

2 participants