Skip to content

Triple DES CBC and CFB64 decryption on AArch64: 128 blocks at a time, bitsliced - #5114

Merged
alex merged 3 commits into
mainfrom
claude/aarch64-3des-decrypt-batched
Nov 15, 2026
Merged

alex merged 3 commits into
mainfrom
claude/aarch64-3des-decrypt-batched

Conversation

@alex

@alex alex commented Nov 15, 2026

Copy link
Copy Markdown
Member

Triple DES CBC and CFB64 decryption on AArch64 are 81 times as fast at 16 KiB. This is the decryption half of finding 2 of the ARM64 audit (and finding 1 of the Apple M5 audit), which x86-64 fixed in #4416.

Cause

Both called the scalar block function once per block, 3.77 µs each on a Neoverse N2, though they are as parallel as ECB, whose bitsliced code does 128 blocks in about 6 µs.

Change

  • Impl/TripleDes/AArch64/Cbc.lean: batchCore d, a core for the shared AArch64 modes over the ECB functions' BitsliceNeon.batch d on a buffer of 128 blocks, as Blowfish's core is over its batch of sixteen. cbcDecryptChained is the modes' CBC decryption over batchCore .decrypt.
  • Impl/TripleDes/AArch64/Fb.lean: cfbDecrypt is the modes' cfbDecryptBatched over batchCore .encrypt.
  • Shared code: cfbDecryptBatched (Impl/Modes/AArch64/CfbDec.lean, Proof/Modes/AArch64/CfbDec/Whole.lean) only took 16-byte blocks; it now takes blocks of one or two words. For two-word blocks the code is the same: the emitter changed no Camellia, SEED or SM4 file. Their FbVerified.lean each lose one argument at a call site.
  • CBC encryption, CFB64 encryption, OFB, CFB8 and the _final functions are unchanged. CFB64 encryption, OFB and CFB8 follow in a PR stacked on this one.
  • vg_triple_des_decrypt_block has no caller left, so the emitter no longer writes it. Its Lean code and proofs are still built; removing them is left for a follow-up.

No change to Spec/ or TCB/.

What it costs

  • One block is slower. A group costs a whole batch whatever its size: about 6.8 µs (the 64-byte row below), against 3.77 µs for one scalar block. So a call that decrypts a single 8-byte block is about 1.8× slower, and every call of two or more blocks is faster. The modes' framework has no path for a short remainder, and this PR does not add one.
  • Stack: both functions use 1120 bytes rather than 1008.
  • Code size: each function has its own inlined copy of the batch, as the two ECB functions do.

Measurement

Benchmarks run 43731654884, against 831067d (this branch's base), on the Neoverse N2 runner:

Benchmark Base Head Change
triple-des-cbc-decrypt/64 31.24 µs 6.83 µs 78.1% faster
triple-des-cbc-decrypt/1024 483.02 µs 6.99 µs 98.6% faster
triple-des-cbc-decrypt/16384 7.71 ms 95.13 µs 98.8% faster
triple-des-cfb64-decrypt/64 31.26 µs 6.83 µs 78.2% faster
triple-des-cfb64-decrypt/1024 483.29 µs 6.95 µs 98.6% faster
triple-des-cfb64-decrypt/16384 7.72 ms 94.55 µs 98.8% faster

The encryption rows of the two modules are unchanged (within 0.1%). In the audit OpenSSL took 472 µs and 506 µs for these at 16 KiB, so they go from 16× and 15× of it to 0.2×. The benchmarks have no one-block size, so the cost above is not in this table.

Tests

  • tests/cavp/triple_des_{cbc,cfb}.rs: the long_messages tests already decrypted 1,000 blocks whole and in pieces of 255, 256 and 257 blocks; they now also take pieces of 127, 128 and 129, around a group's size. They check decryption against encryption; no vector was typed.
  • The fifteen Triple DES CAVP tests pass for aarch64-unknown-linux-gnu under qemu-user, the MMT vectors among them. That is emulation; CI is the first run on an ARM64 CPU.

Generated by Claude Code

The batched core (batchCore: the ECB functions' batch on a buffer of 128
blocks) and CBC decryption over it build, with the registration. Not yet
done: CFB64 decryption, the regenerated crate, the checks.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TKUFHFQ9fhoiRgxoBRku5u
The modes' batched CFB decryption takes blocks of one or two words, and
Triple DES-CFB64 decryption runs it over the batched core. The Triple DES
registrations build. Not yet done: the full build (the other ciphers' users
of the modes' CFB decryption), the regenerated crate, the checks.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TKUFHFQ9fhoiRgxoBRku5u
…tsliced batch

Both called the scalar block function once for each block, 3.77 µs a block
on a Neoverse N2, though their blocks need no block's result for the next:
83 times as long as ECB, whose bitsliced batch deciphers 128 blocks at once.

batchCore (Impl/TripleDes/AArch64/Cbc.lean) is a core for the modes over that
batch, BitsliceNeon.batch, on a buffer of 128 blocks, with the schedule read
where the caller passed it. vg_triple_des_cbc_decrypt_chained is the modes'
CBC decryption over it, and vg_triple_des_cfb64_decrypt their batched CFB
decryption, which now takes blocks of one word as well as two (cfbDecGather
and the XOR of the group, xorBlocksW, by the block's words; for two-word
blocks the code is what it was, so Camellia's, SEED's and SM4's is
unchanged). A group costs one batch whatever its number of blocks, so one
block alone takes about a batch (5.8 µs) rather than 3.77 µs; two or more are
faster than before.

The working space, on the stack, is 1120 bytes (140 words: the buffer and
the modes' twelve) rather than 1008. The scalar vg_triple_des_decrypt_block
has no caller left and is no longer emitted. CBC encryption, CFB64
encryption, OFB, CFB8 and the functions of a message's last piece are
unchanged.

The long-message tests split at 127, 128 and 129 blocks too, around this
group's size.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TKUFHFQ9fhoiRgxoBRku5u
@alex
alex added this pull request to the merge queue Nov 15, 2026
Merged via the queue into main with commit 06ed677 Nov 15, 2026
44 checks passed
@alex
alex deleted the claude/aarch64-3des-decrypt-batched branch November 15, 2026 16:35
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.

2 participants