salt the pkware encryption header per entry in _zip_entry_open#444
Merged
kuba-- merged 2 commits intoJul 18, 2026
Conversation
kuba--
reviewed
Jul 17, 2026
| (mz_uint8)((mz_crc32(MZ_CRC32_INIT, enc_header, i) ^ salt) >> | ||
| (i & 7)); | ||
| enc_header[i] = zip_pkware_encrypt_byte(&zip->entry.enc_keys, rnd); | ||
| salt = salt * 1103515245u + 12345u; |
Owner
There was a problem hiding this comment.
- Comment + #define naming the LCG.
- Simpler mix:
salt = (salt << 5) ^ (salt >> 7) ^ (mz_uint32)i
— also fine for uniqueness.
True random for the 11 bytes — better hygiene, more platform work.
- (Optionally): True random for the 11 bytes — better hygiene, more platform work.
Contributor
Author
There was a problem hiding this comment.
switched to your shift/xor mix, so the lcg constants are gone and the comment now describes the stir instead. left true random out for now to keep it portable, happy to follow up with it if you want. full suite still passes, including the determinism test.
kuba--
approved these changes
Jul 18, 2026
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.
encryption header is identical for every entry under the same password
The header's first 11 bytes came from a crc of the bytes written so far, which depends only on the password, so identical plaintext encrypted to identical ciphertext and entries reused the keystream. Salted the derivation with the entry's own local-header offset and time so each entry gets a distinct header; encrypt and decrypt stay symmetric so existing archives still read back.