Repository navigation
PPC64LE: SEED's serial modes on a verified single-block core - #4746
Merged
Merged
Conversation
PPC64LE Camellia's core (vg_camellia_crypt_prepared) enciphers the eight blocks of its tail buffer per call, but the modes used only the first, so every mode cost a whole batch per block. CBC and CFB decryption and CTR now take eight blocks a step while eight are left, then one a step. This ports RISC-V's framework for batched modes (#3978, #4012) to PPC64LE: Core.seq is now Core.seqWith (Core.steps m), the same code, and Core.seq2 runs the steps of a widened mode (Mode.widen) while r30 >> lg is not zero, then the narrow ones. The step proofs take the buffer's bytes a step uses, the regions the key is ready for and the count a step takes (Fixed, Inv), so one proof serves both loops; Proof/Modes/PPC64LE/ Wide.lean proves the loops of seq2 for CBC and CFB decryption and both counter modes from the architecture-independent Proof/Modes/Wide.lean and WideCtr.lean. No TCB or Spec change; the other modes' code is unchanged. Part of #4141. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHFCoYzWWszXpPsgsoT
…cks at a time PPC64LE SM4's core (vg_sm4_crypt_prepared) enciphers the sixteen blocks of its tail buffer per call, but the modes used only the first. CBC and CFB decryption, CTR and the counter mode with GCM's inc32 (vg_sm4_ctr32, which SM4-GCM inlines through its contract) now take sixteen blocks a step while sixteen are left, then one, with Core.seq2. The narrow counter modes step the counter block before the block cipher (Mode.ctrEarly, Mode.ctr32Early), as the wide ones do; Proof/Modes/PPC64LE/Ctr.lean and Ctr32.lean, the one-block counter modes, are no longer used and go. New tests check the API against itself at lengths around the groups: SM4-CBC decryption and SM4-CTR, and Camellia-CBC decryption, whole, a block at a time and in two pieces. Part of #4141. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHFCoYzWWszXpPsgsoT
SEED's blocks function computes the rounds of sixteen lanes whatever the number of blocks, so the modes, which called it on one block a step, paid a whole batch per block. The core is now parameterized by its buffer's number of blocks (core d g): the serial modes keep dirCore d = core d 1, the same code and 1184-byte frame, and CBC and CFB decryption use wideCore d = core d 16 with Core.seq2, sixteen blocks a step while sixteen are left, then one, in a 1424-byte frame (174 words of working space). modeContract and modeTaint take the working space's size, and τCallW adds the blocks functions' taint summaries at it. A new test checks SEED-CBC decryption against itself at lengths around the groups. Part of #4141. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHFCoYzWWszXpPsgsoT
…es with the full emitter EmitOne had placed the internal functions the modes share (vg_camellia_crypt_prepared, vg_seed_encrypt_blocks, ...) in each file it emitted; Emit.lean puts them back in their shared modules. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHFCoYzWWszXpPsgsoT
CBC and CFB encryption, OFB and the `_final` functions take one block a step, but ran the bitsliced core, which enciphers a batch of sixteen for each. `Impl/Sm4/PPC64LE/Serial.lean` is a single-block core: the standard's rounds a word at a time, the S-box as the AES S-box (`vsbox`) between two affine maps, each two nibble tables looked up by `vperm`. Its proofs (`Proof/Sm4/PPC64LE/SerialSbox.lean`, `SerialCore.lean`) give its `CoreSpec`, and the six functions are proven over it, constant time by the vector taint analysis. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHFCoYzWWszXpPsgsoT
#4671, which this branch was stacked on, merged as ef28190. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHFCoYzWWszXpPsgsoT
CBC and CFB encryption, OFB and the `_final` functions take one block a step, but ran the bitsliced core, which enciphers a batch of eight for each. `Impl/Camellia/PPC64LE/Serial.lean` is a single-block core: the standard's Feistel network on the halves in general-purpose registers, the eight S-boxes of a round on the vector unit as the AES S-box (`vsbox`) between nibble tables of affine maps (`vperm`, bit 4 of the index choosing `SBOX4`'s input map and `SBOX2`'s output map, `vsel` `SBOX3`'s), the P-function by rotations of the 32-bit halves, FL and FLINV, and a branch on the public number of rounds. Its proofs (`Proof/Camellia/PPC64LE/SerialSbox.lean`, `SerialCore.lean`) give its `CoreSpec`, and the six functions are proven over it, constant time by the vector taint analysis. The word-level F-function lemmas the AArch64 single-block core's proof had (`Pure.lean`, and `cryptWords_congr`) move to `Proof/Camellia/SerialPure.lean`, which both targets use, and the vector-byte lemmas of SM4's to `Proof/Framework/PPC64LE/VectorBytes.lean`. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHFCoYzWWszXpPsgsoT
The serial modes (CBC and CFB encryption, OFB) and the _final functions encipher one block per step, but the blocks function computes sixteen lanes whatever the number of blocks. Serial.core enciphers the one block of the buffer with RFC 4269's rounds in general-purpose registers, G's S-boxes on the vector unit through the AES S-box (each is affine- equivalent to it), with its proof (SerialSbox, SerialCore) and the modes' proofs over it; constant time by the vector taint analysis. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHFCoYzWWszXpPsgsoT
…ia-serial # Conflicts: # lean/VerifiedGarbage/Proof/Sm4/PPC64LE/SerialCore.lean
alex
marked this pull request as ready for review
November 8, 2026 22:18
This was referenced Nov 9, 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.
On PPC64LE, SEED's serial modes (CBC and CFB encryption, OFB) and the
_finalfunctions encipher one block per step. Until now each step called the blocks function on one block, and that function computes the rounds of sixteen lanes whatever the number of blocks. This PR adds a verified single-block core and runs those functions on it. It follows the SM4 (#4698) and Camellia (#4734) PRs and finding 5 of the ppc64le audit.vg_seed_cbc_encrypt_chained,vg_seed_cfb128_encrypt,vg_seed_ofbvg_seed_cfb128_encrypt_final,vg_seed_cfb128_decrypt_final,vg_seed_ofb_finalNo TCB or Spec change: each function meets the contract it met before.
How
Impl/Seed/PPC64LE/Serial.lean(new):Serial.core, aModes.PPC64LE.Corethat runs RFC 4269's sixteen rounds on one block. The halves are in general-purpose registers, and the rounds are unrolled, so the halves trade registers every round.S1andS2are each affine-equivalent to the AES S-box:S(x) = A_out(S_AES(A_in(x))), with the sameA_infor both.gFncomputesGon the vector unit:andandsrwiwith the mask0x0f0f0f0f);mtvsrd);A_inas two 16-byte nibble tables (vperm, XORed);vsboxapplies the AES S-box;A_outthe same way. A selector table sets bit 4 of the index for the bytesX1andX3, so thatvpermpicksS2's table for them.vpermbroadcasts each byte's image to a word,vandapplies G's masks, and twovsldoirotations with XORs sum the four words.mfvsrdmoves the word back.VG_SEED_PPC64LE_AFFINE), loaded withlxvd2xTbl.r3, soprepareis empty. The core's slots and buffer are those of the blocks function's core on one block, so every mode keeps its[u64; 144]scratch buffer.bufSlotmoves toSerial.lean, so thatModes.leancan import it.Proofs (
Proof/Seed/PPC64LE/SerialSbox.lean,SerialCore.lean):s0_affine,s1_affine: on all 256 bytes, the tables' affine maps around the AES S-box areS1andS2. The kernel evaluates the AES S-box ofA_in's images on truth tables (Proof.Aes.sboxT, materialized).lit_decidechecks them against the S-boxes' truth tables (Proof.Seed.tableT).gA_run,gB_run,gFn_run:G, againstSpec.Seed.g(throughProof.Seed.getLsbD_g).fRound_run,round_run,rounds_run:F, a round with the alternating registers (Spec.Seed.round), and the sixteen (Proof.Seed.roundsN).crypt_wp: the tables, the block's big-endian words (lwbrx), the rounds and the swapped store computeSpec.Seed.cipher(Proof.Seed.crypt_eq).coreSpec : CoreSpec Serial.core, with the blocks function's one-block core'sKeyArgsandReady.ModesVerified.leanandFbFinalVerified.leanprove the six functions from the modes' existing lemmas, overSerial.coreSpec.seqPre_ofandkeyArgs_ofnow take the core.vectorTaint,taint_decide) rather than the slot analysis with the blocks functions' summaries.Tests
The proofs cover correctness. The existing SEED CBC, CFB and OFB tests cover these functions, and they pass on ppc64le under
qemu-ppc64le. This PR adds no tests.Benchmarks
Benchmarks run 42525825207: POWER9,
arches=powerpc64, modulesseed_cbc seed_cfb seed_ofb, against #4734's head (c8c32ce, the codemainhas since #4734 merged). Medians, base → this PR:CBC and CFB decryption, whose code this PR does not change, stayed within 1% (0.99–1.00×).
Part of #4141.
🤖 Generated with Claude Code
https://claude.ai/code/session_01TKUFHFCoYzWWszXpPsgsoT