Skip to content

ARMv7 SM4-CBC: prepare encryption keys once per call - #3040

Merged
reaperhulk merged 1 commit into
mainfrom
codex/arm-sm4-prepared-cbc-encrypt
Oct 21, 2026
Merged

reaperhulk merged 1 commit into
mainfrom
codex/arm-sm4-prepared-cbc-encrypt

Conversation

@reaperhulk

@reaperhulk reaperhulk commented Oct 21, 2026 •

Copy link
Copy Markdown
Member

ARMv7 SM4-CBC encryption called the full ECB entry point for each feedback block, preparing the same round keys repeatedly. Prepare the bitsliced keys once per call, XOR each plaintext block with the preceding ciphertext (or IV), then encrypt and retain the result for the next feedback step.

Enable the generated ARM/Thumb implementation with complete functional and constant-time proofs against the unchanged shared CBC encryption contract. The proofs cover arbitrary lengths, empty input, continuation IVs, memory frames and ABI preservation. The verified stack wrapper wipes all 1512 bytes of working space; stack use falls from 1560 to 1520 bytes. No specification or TCB changes.

Validation: full Lean build (22437 jobs), scoped emitter generation/audits and generated-code checks, public-import checks on all 11 changed modules, static checks, CBC integration tests, ARM/Thumb assembly compilation, ARM Clippy and Rustfmt. Native ARM/Thumb benchmark passed; Full CI after rebasing passed, including native ARM/Thumb tests, Lean, emitter audits and static checks.

Rebased onto main after #3037/#3036 merged; this diff contains only CBC encryption changes. CBC decryption is unchanged in this diff; #3034 separately batches decryption. The serial core still computes eight lanes for each feedback block, so this change does not claim to close the entire OpenSSL gap.

Thumb disassembly confirms the hot round loop is word-aligned at function offset 0x578; the padding is a verified identity.

CBC encryption timings in microseconds, paired against the parent on Neoverse N2 (lower is better):

Bytes ARM parent ARM new OpenSSL Thumb parent Thumb new OpenSSL
64 4.96 4.44 1.43 4.99 4.48 1.45
1024 63.38 52.67 8.94 64.01 52.70 8.96
16384 997.98 824.06 129.27 ~1010 824.06 129.21

Bulk encryption improves by 17.4% on ARM and 18.3% on Thumb, but remains 6.4 times slower than OpenSSL. The rebase changes no CBC code, and the merged parent tree is byte-identical to the benchmark's parent. CBC decryption in this comparison uses main's serial implementation; #3034 independently replaces it with eight-block batches and beats OpenSSL at 1 KiB and 16 KiB.

@reaperhulk
reaperhulk changed the base branch from codex/arm-sm4-prepared-ofb to main October 21, 2026 17:50
@reaperhulk
reaperhulk force-pushed the codex/arm-sm4-prepared-cbc-encrypt branch from 818216b to 7ebc3db Compare October 21, 2026 17:50
@reaperhulk
reaperhulk added this pull request to the merge queue Oct 21, 2026
Merged via the queue into main with commit a366995 Oct 21, 2026
29 checks passed
@reaperhulk
reaperhulk deleted the codex/arm-sm4-prepared-cbc-encrypt branch October 21, 2026 18:10
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.

1 participant