Skip to content

Run WinZip AES key derivation on the SHA-1 instructions on 64-bit ARM - #7

Merged
xbmc4lyfe merged 1 commit into
mainfrom
claude/sha1-hw
Nov 6, 2026
Merged

xbmc4lyfe merged 1 commit into
mainfrom
claude/sha1-hw

Conversation

@xbmc4lyfe

Copy link
Copy Markdown
Collaborator

What

WinZip AES derives its key and password verifier with PBKDF2-HMAC-SHA1: 999 chained HMACs per 20-byte block, two SHA-1 compressions each. On 64-bit ARM processors that have the SHA-1 instructions (checked at run time with is_aarch64_feature_detected!("sha2")), those iterations now run on them in accel::pbkdf2_sha1_rest:

  • Instructions. SHA1C, SHA1P and SHA1M each do four rounds with their round function. SHA1H gives the next e. SHA1SU0/SHA1SU1 extend the message schedule four words at a time.
  • Blocks built in registers. Each iteration's block is the previous digest, the padding bit, zeros and an 84-byte length. It is built in vector registers, so the 1000-iteration loop never touches memory.
  • Fallback. Without the instructions, the portable loop (HmacSha1::rest) runs as before.
  • x86-64 stays portable. It has SHA instructions too (SHA-NI), but none of the machines here has them: the i7-8700K lacks them, and this Mac has no Rosetta to emulate them. Without a machine to test on, that path isn't added. It's a candidate once there is one.

Measured (fastest round, examples/bench.rs)

case M4 Air M5 Air (load ~180) i7-8700K
aes256-accepts 149 → 41 µs 458 → 77 µs unchanged (~0.3 ms)
aes-derive-256 605 → 162 µs 2,112 → 304 µs unchanged
aes256-entry-1M (derive + decrypt) 534 → 194 µs 1,769 → 445 µs unchanged

Each compression now takes about 20 ns on the M4: the chain of twenty 4-round instructions, one after another.

Correctness

  • New pbkdf2_iterations_agree_with_and_without_sha1_instructions holds the instruction path to the portable loop. It uses 20 random keys of 0–89 bytes (crossing the 64-byte HMAC key-hashing boundary), random first MACs, and 1, 2, 3 and 1000 iterations.
  • The FIPS 180 SHA-1 vectors, the RFC 6070 PBKDF2 vectors and the reference aes_derive comparison all run through the fast path now.
  • Using SHA1M instead of SHA1P for one group of rounds on purpose fails four 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

PBKDF2's 999 chained HMACs per block now run on ARMv8's SHA-1 instructions
where the processor has them (checked at run time): SHA1C/SHA1P/SHA1M do
four rounds each, SHA1H gives the next e, and SHA1SU0/SHA1SU1 extend the
schedule, with each iteration's padded block built in registers from the
previous digest. Without them, and on x86-64 (none of the machines measured
has SHA-NI), the portable loop runs; a new test holds the two to the same
results over random keys and iteration counts, and the RFC 6070 and
reference tests now run through the fast path. AES-256 password check:
M4 149 -> 41 us, M5 458 -> 77 us; a whole 1 MiB AES-256 entry on the M4
534 -> 194 us.

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

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-06T19:56:30.769816Z e19b2e1 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 6c563d6 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