Repository navigation
ARMv7 SM4-CBC: batch decryption with reverse XOR - #3034
Merged
Merged
Conversation
This was referenced Oct 21, 2026
reaperhulk
changed the base branch from
codex/arm-sm4-batched-cfb-decrypt
to
main
October 21, 2026 17:50
reaperhulk
force-pushed
the
codex/arm-sm4-batched-cbc-decrypt
branch
from
October 21, 2026 17:50
6b9de4f to
074596f
Compare
reaperhulk
force-pushed
the
codex/arm-sm4-batched-cbc-decrypt
branch
from
October 21, 2026 18:46
074596f to
634f60a
Compare
reaperhulk
added this pull request to stack #3045
October 21, 2026 19:44
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.
ARMv7 SM4-CBC decryption called the full ECB entry point for every block, preparing the same round-key table repeatedly and using one of eight cipher lanes. Prepare the decryption keys once, decrypt up to eight ciphertext blocks independently, then XOR with preceding ciphertext in reverse order before it is overwritten. Save the last ciphertext for the continuation IV.
Enable the generated ARM/Thumb implementation with complete functional and constant-time proofs against the unchanged shared CBC decryption contract. The proofs cover arbitrary lengths, empty input, partial final batches, 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. Encryption retains its existing serial implementation. No specification or TCB changes.
The Thumb hot round loop is placed on a four-byte boundary with a self move whose identity is verified, following the measured placement improvement in #3033. Local disassembly confirms the aligned loop at function offset
0x76cin a section with four-byte alignment.Validation: full Lean build (22423 jobs), scoped emitter generation/audits and generated-code check; public-import checks on all 13 changed modules; static import/module/registration/proof-speed, algorithm-table, architecture/variant and MCDT checks; CBC integration tests, ARM/Thumb library compilation, ARM Clippy and Rustfmt. Existing tests compare to ECB, exercise the published vectors, chaining and invalid lengths. Full CI passed, including native ARM/Thumb tests, Lean, emitter audits and static checks.
Rebased onto main after #3033/#3036/#3037 merged. This diff contains only CBC decryption changes.
Native AArch32 benchmark, paired against the parent on Neoverse N2, OpenSSL enabled. Times in microseconds; lower is better:
Bulk decryption is approximately 9.3–9.7 times as fast as the parent and 11% faster than OpenSSL. The 64-byte case remains slower than OpenSSL. CBC encryption is unchanged and remains about 7.8 times slower at 16 KiB; this PR makes no encryption speed claim.
CI after rebasing onto main passed.
Rebased again after CBC encryption (#3040) merged, resolving the shared registration and documentation. Full Lean build (22449 jobs), emitter audits/check, public-import checks, ARM/Thumb compilation, Rustfmt and ARM Clippy pass. The generated decryption function is byte-for-byte identical to the benchmarked version; no unchanged-code benchmark rerun was needed.