Skip to content

Decrypt ZipCrypto with the CRC-32 instructions on 64-bit ARM - #9

Merged
xbmc4lyfe merged 1 commit into
mainfrom
claude/zipcrypto-crc
Nov 6, 2026
Merged

xbmc4lyfe merged 1 commit into
mainfrom
claude/zipcrypto-crc

Conversation

@xbmc4lyfe

Copy link
Copy Markdown
Collaborator

What

Each byte of ZipCrypto updates its three keys with two steps of ZIP's CRC-32 (on key0 with the plain byte, on key2 with the top byte of key1). The next byte's keystream comes from key2, so decryption is one long chain: about 27 cycles a byte on an M4, roughly 160 MB/s.

ARMv8's CRC32B is one byte of the reflected CRC-32 that ZIP uses, without the inversions at either end, which is exactly ZipCrypto's key update. It takes about three cycles. The table lookup LLVM builds from the bitwise loop takes an XOR, an AND, a load and a shifted XOR. Two of those come off the chain on every byte.

  • accel::zipcrypto_decrypt decrypts the payload with CRC32B when the processor has it (is_aarch64_feature_detected!("crc"), true on every Apple core). It appends to the output and leaves the keys where the data ends.
  • Fallback. Without it, and on x86-64, the portable loop runs as before. x86's CRC32 instruction computes CRC-32C, a different polynomial.
  • The 12-byte header check (password check) stays on the portable code: twelve bytes don't make a difference.

Measured (fastest round, examples/bench.rs)

case M4 Air M5 Air (load ~180) i7-8700K
zipcrypto-8M 162 → 232 MB/s 123 → 159 MB/s unchanged (160 / 158)
zipcrypto-accepts unchanged unchanged unchanged

On the M4 that's about 19 cycles a byte, down from 27. What's left of the chain is the keystream multiply, the key1 multiply-add and the two CRC32Bs.

Correctness

  • New zipcrypto_decryption_agrees_with_and_without_crc_instructions holds the instruction path to the portable crypto_step loop. It covers random keys and 0–4099 bytes, plus the final keys and appending after existing output.
  • The existing ZipCrypto archive test now decrypts through the fast path.
  • Feeding key1 >> 16 instead of key1 >> 24 to the second CRC on purpose fails both tests.
  • cargo fmt --check, cargo clippy --all-targets -- -D warnings and cargo test pass on aarch64-apple-darwin and x86_64-linux.

🤖 Generated with Claude Code

Each byte of ZipCrypto updates its keys with two steps of ZIP's CRC-32,
and the next byte's keystream depends on them, so decryption is one long
chain. ARMv8's CRC32B is exactly that step, and takes about three cycles
where the table lookup takes a load and three ALU operations. Where the
processor has it (checked at run time), the payload now decrypts through
it; elsewhere the portable loop runs as before (x86's CRC32 instruction is
CRC-32C, a different polynomial). A new test holds the two to the same
plain bytes and final keys. 8 MiB ZipCrypto entry: M4 162 -> 232 MB/s;
i7-8700K unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 6, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-06T23:54:03.191180Z 72798fe PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@xbmc4lyfe
xbmc4lyfe merged commit e994bfc into main Nov 6, 2026
3 checks passed
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