Repository navigation
3DES PPC64LE: the round function as a 64-lane table lookup - #4693
Merged
Merged
Conversation
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
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)), 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 asImpl/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:
andi. A group's mask below2 ^ 15comes fromli, and only six masks are words of constants.((y >>> a) &&& keep) <<< (a + s).Proofs
kExt,linearK_ok). The tree is checked over the position-table domain.feistel_okcomposes them, androundBody_okadds the half swap.Readycarries the constants (ConstsAt). The rounds' frame is now the two unused slots (spillRegion). The head proves the constants' stores (storeConsts_wp).Impl/TripleDes/PPC64LE/Sbox.leanandProof/…/{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_ofbandcmac_triple_des; base9d4f8cd4, this PR's base): https://github.com/pyca/verified-garbage/actions/runs/42516327193Every 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.
tdes-cmac/64tdes-cmac/1024tdes-cmac/16384tdes-cmac-verify/64tdes-cmac-verify/1024tdes-cmac-verify/16384triple-des-cbc-decrypt/64triple-des-cbc-decrypt/1024triple-des-cbc-decrypt/16384triple-des-cbc-encrypt/64triple-des-cbc-encrypt/1024triple-des-cbc-encrypt/16384triple-des-cfb64-decrypt/64triple-des-cfb64-decrypt/1024triple-des-cfb64-decrypt/16384triple-des-cfb64-encrypt/64triple-des-cfb64-encrypt/1024triple-des-cfb64-encrypt/16384triple-des-cfb8-decrypt/64triple-des-cfb8-decrypt/1024triple-des-cfb8-decrypt/16384triple-des-cfb8-encrypt/64triple-des-cfb8-encrypt/1024triple-des-cfb8-encrypt/16384triple-des-ofb/64triple-des-ofb/1024triple-des-ofb/16384🤖 Generated with Claude Code
https://claude.ai/code/session_01TKUFHFbSpgWBYWAsEnfUks