Repository navigation
PPC64LE: Camellia's serial modes on a verified single-block core - #4734
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
|
This pull request has conflicts with Posted by |
…ia-serial # Conflicts: # lean/VerifiedGarbage/Proof/Sm4/PPC64LE/SerialCore.lean
alex
marked this pull request as ready for review
November 8, 2026 21:42
alex
enabled auto-merge
November 8, 2026 21:45
6 tasks done
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, Camellia's serial modes (CBC and CFB encryption, OFB) and the
_finalfunctions encipher one block per step. Until now each step ran the bitsliced core, which costs a whole batch of eight blocks for that one block. This PR adds a verified single-block core and runs those functions on it (a follow-up to finding 5 of the ppc64le audit), as #4698 does for SM4.vg_camellia_cbc_encrypt_chained,vg_camellia_cfb128_encrypt,vg_camellia_ofbvg_camellia_cfb128_encrypt_final,vg_camellia_cfb128_decrypt_final,vg_camellia_ofb_finalNo TCB or Spec change: each function meets the contract it met before.
How
Impl/Camellia/PPC64LE/Serial.lean(new):Serial.coreruns RFC 3713's Feistel network with the halvesD1,D2inr6andr7.SBOX1is affine-equivalent to the AES S-box,SBOX1(x) = A_out(S_AES(A_in(x)))(Impl/Camellia/Circuit.lean).SBOX2,SBOX3andSBOX4rotate its output or input, which composes withA_outorA_in. An affine map on a byte is two 16-byte nibble tables, whichvpermlooks up for all eight bytes at once. Bit 4 of an index chooses between two tables. SosLayer:0x0f0f…inr12) and moves them to vector registers;A_in, orA_in ∘ rotl 1forSBOX4's bytes (selIn);vsbox;A_out, orrotl 1 ∘ A_outforSBOX2's bytes (selOut);rotl 7 ∘ A_out, and takes that forSBOX3's bytes withvsel(mask36).pFn). Rotations of the two 32-bit halves, as the AArch64 single-block core computes it.ldbrx) from the schedule atr3, in its stored order.r28).VG_CAMELLIA_PPC64LE_AFFINE), loaded withlxvd2xTbl. The core keeps the bitsliced core's slots and buffer, so the modes keep their[u64; 422]scratch buffer.Proofs (
Proof/Camellia/PPC64LE/SerialSbox.lean,SerialCore.lean):sbox1_affine…sbox4_affine: the composed maps areSBOX1…SBOX4on all 256 bytes. The kernel checks them on truth tables (Proof.Aes.sboxT, two materialized values,lit_decide).sLayer_run: the S layer issubstituted.pFn_run: the P-function islinearWord. Withf_eq, a round isSpec.Camellia.f.fl_run: FL and FLINV areSpec.Camellia.flandflinv.six_run,groupFl_run,prefix_run: the rounds areProof.Camellia.group.crypt_wp: both branches computecryptWords, soSpec.Camellia.cipher(cipher_bytes,cryptWords_congr).coreSpec : CoreSpec Serial.core.ModesVerified.leanandFbFinalVerified.leanprove the six functions over it.seqPre_of,keyArgs_ofandrun_wrappednow take the core.vectorTaint,taint_decide).Shared lemmas moved, not copied:
Proof/Camellia/AArch64/Serial/Pure.leanbecomes the architecture-independentProof/Camellia/SerialPure.lean(namespaceVG.Proof.Camellia.Serial), withcryptWords_congrfrom AArch64'sCipher.lean. The AArch64 filesopenit; their proofs are unchanged.Proof/Framework/PPC64LE/VectorBytes.lean, which both cores use.Tests
The proofs cover correctness, and the existing Camellia CBC, CFB and OFB vector tests cover these functions. I ran them on ppc64le under
qemu-ppc64le, and they pass. This PR adds no tests.Benchmarks
Benchmarks run 42523420396: POWER9,
arches=powerpc64, modulescamellia_cbc camellia_cfb camellia_ofb, against #4698's head (9e0890b, the codemainhas since #4698 merged). Medians, base → this PR:Camellia-192 matches Camellia-256 (2.4× at 64 B, 2.7× above). CBC and CFB decryption, whose code this PR does not change, are unchanged (1.00× at every size).
Part of #4141.
🤖 Generated with Claude Code
https://claude.ai/code/session_01TKUFHFCoYzWWszXpPsgsoT