Repository navigation
Run WinZip AES key derivation on the x86 SHA extensions - #8
Merged
Merged
Conversation
PBKDF2's 999 chained HMACs per block now run on the x86 SHA extensions (SHA-NI) where the processor has them, checked at run time, as they already do on ARMv8: SHA1RNDS4 does four rounds, SHA1NEXTE gives the next e from the a before them, and SHA1MSG1, a XOR and SHA1MSG2 extend the schedule, with each iteration's padded block built in registers from the previous digest. Without them the portable loop runs, as before. No machine here has SHA-NI, so this was tested under Intel's Software Development Emulator (Ice Lake and Goldmont models) on an i7-8700K: the whole suite passes there and natively, and a wrong round function in the last group fails four tests under the emulator. Its speed is not measured. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codex Review Summary: ✅ CompletedThis 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: 999 chained HMACs per 20-byte block, two SHA-1 compressions each. #7 runs those on ARMv8's SHA-1 instructions. This does the same on x86-64 processors with the SHA extensions (SHA-NI), checked at run time with
is_x86_feature_detected!("sha"), inaccel::pbkdf2_sha1_rest.SHA1RNDS4does four rounds; its immediate picks the round function and constant. It takeseadded to the first of its four words.SHA1NEXTEsupplies that: theefour rounds on is theafrom before them, rotated.SHA1MSG1, a XOR andSHA1MSG2extend the message schedule four words at a time.evector is its fifth word with zeros below. So each iteration's block is the previous digest's two vectors, with the padding bit ORed into the second, then zeros and the 84-byte length. The 1000-iteration loop never touches memory, as on ARM.HmacSha1::rest) runs as before. That includes the i7-8700K and every Intel desktop core before Ice Lake.Testing without the hardware
No machine here has SHA-NI: the i7-8700K lacks it, and Rosetta on the Mac doesn't report it. So the new path was run under Intel's Software Development Emulator (10.13.1) on the 8700K.
cargo test --releasepasses undersde64 -icl(Ice Lake). It also passes natively, where the portable path runs.sde64 -glm(Goldmont, an Atom core with SHA-NI but no AVX).pbkdf2_iterations_agree_with_and_without_sha1_instructionsholds this path to the portable loop. It uses random keys of 0–89 bytes and 1, 2, 3 and 1000 iterations. The RFC 6070 and referenceaes_derivetests run through it too.objdumpshows the 40sha1rnds4(20 per compression, inlined twice) in the release test binary.cargo fmt --check,cargo clippy --all-targets -- -D warningsandcargo testpass on aarch64-apple-darwin and x86_64-linux.Speed
Not measured: the emulator's timings mean nothing. The structure is the one that gave ARM 3.7× in #7: twenty 4-round instructions per compression, with no loads or stores in the loop. Many of GitHub's x86 runners (AMD EPYC, Ice Lake Xeon) have SHA-NI, so CI may well run this path on real hardware, though nothing here confirms it. Timings will come once there is a machine with SHA-NI to bench on.
🤖 Generated with Claude Code