Repository navigation
Derive WinZip AES keys with precomputed HMAC pads and only the blocks needed - #2
Merged
Merged
Conversation
… needed PBKDF2-HMAC-SHA1 hashed every iteration from scratch: four SHA-1 compressions and two allocations, for a key block and a 20-byte message that never change shape. HmacSha1 now compresses the key's two padded blocks once, so an iteration costs two compressions on fixed-layout blocks, with sha1_compress inlined there so the constant padding folds into the message schedule. PBKDF2's output blocks are independent: a password check computes only the block holding the verifier, and decryption checks the verifier before deriving the key and never derives the unused MAC key. AES-256 password check: 2.23 -> 0.16 ms on the M4, 2.37 -> 0.17 ms on the M5, 5.1 -> 0.27 ms on an i7-8700K. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
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.
What
WinZip AES derives its key and password verifier with PBKDF2-HMAC-SHA1 over 1000 iterations. Each iteration used to re-hash the HMAC key blocks: four SHA-1 compressions and two
Vecallocations.HmacSha1compresses the key's ipad and opad blocks once. An iteration is now two compressions over fixed-layout 20-byte-message blocks, with no allocation.sha1_compressis inlined into that path, so the constant padding words fold into the message schedule. The once-per-message paths call it out of line.pbkdf2_sha1computes just the blocks covering the requested range:PasswordCheck::acceptsderives only the block holding the verifier: 1 block instead of 2, 3 or 4.decrypt_winzip_aeschecks the verifier before deriving the key, and never derives the MAC key it doesn't use. A wrong password costs one block; AES-256 decryption costs 3 blocks instead of 4.aes_derivekeeps its output. Its length arithmetic is now checked, returningNoneinstead of overflowing.Measured (fastest of 11 rounds,
examples/bench.rs)The rest of a whole entry's time is AES-CTR itself.
Correctness
aes_deriveandaes_verifiermatch the old implementation, which is kept in the tests as the reference. Cases: empty, short, exactly 64-byte and 100-byte passwords; salts of 0–70 bytes; all three key lengths.cargo fmt --check,cargo clippy --all-targets -- -D warningsandcargo testpass on aarch64-apple-darwin and x86_64-linux.🤖 Generated with Claude Code