Skip to content

Add parallel AES-NI CBC-decrypt kernel (single fused pass)#144

Merged
Xor-el merged 1 commit into
masterfrom
feat/cbc-decrypt-kernel
Jul 10, 2026
Merged

Add parallel AES-NI CBC-decrypt kernel (single fused pass)#144
Xor-el merged 1 commit into
masterfrom
feat/cbc-decrypt-kernel

Conversation

@Xor-el

@Xor-el Xor-el commented Jul 10, 2026

Copy link
Copy Markdown
Owner

CBC decrypt is P[i] = DEC(C[i]) xor C[i-1]: the inverse transforms are independent, so decrypt the run 8-wide (x86_64) / 4-wide (i386) and fold the chain XOR into that same pass. This replaces the mode's two passes over memory (bulk aesdec write, then a separate XOR re-read) with one, which lifts the DRAM-bandwidth ceiling that bounded large buffers.

TAesNiCbcKernel now serves both directions (branch on FDirection, as the CCM kernel does); the factory probes TryGetDecKeysPtr for the inverse- MixColumns schedule. New AesNiCbcDecryptWide_{x86_64,i386}.inc are kept separate from the serial encrypt include -- the two share no structure (serial 1-wide leaf vs parallel wide with an xmm save frame), only the shared round chains. In-place safe with no stack spill: every input read completes before the first output store. A 1-wide tail drains the 1..7 (1..3 on i386) residual blocks, so the kernel takes any block count.

TCbcBlockCipher resolves a direction-matched kernel at Init and routes CbcDecryptBulk through it, falling back to the existing path when nil.

CBC decrypt is P[i] = DEC(C[i]) xor C[i-1]: the inverse transforms are
independent, so decrypt the run 8-wide (x86_64) / 4-wide (i386) and fold
the chain XOR into that same pass. This replaces the mode's two passes
over memory (bulk aesdec write, then a separate XOR re-read) with one,
which lifts the DRAM-bandwidth ceiling that bounded large buffers.

TAesNiCbcKernel now serves both directions (branch on FDirection, as the
CCM kernel does); the factory probes TryGetDecKeysPtr for the inverse-
MixColumns schedule. New AesNiCbcDecryptWide_{x86_64,i386}.inc are kept
separate from the serial encrypt include -- the two share no structure
(serial 1-wide leaf vs parallel wide with an xmm save frame), only the
shared round chains. In-place safe with no stack spill: every input read
completes before the first output store. A 1-wide tail drains the 1..7
(1..3 on i386) residual blocks, so the kernel takes any block count.

TCbcBlockCipher resolves a direction-matched kernel at Init and routes
CbcDecryptBulk through it, falling back to the existing path when nil.
@Xor-el Xor-el merged commit fe2e511 into master Jul 10, 2026
24 checks passed
@Xor-el Xor-el deleted the feat/cbc-decrypt-kernel branch July 10, 2026 22:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant