zlib-ng / minizip-ng

Fork of the popular zip manipulation library found in the zlib distribution.
Other
1.23k stars 432 forks source link

Please explain crc_for_crypting #109

Closed gianlucabertani closed 7 years ago

gianlucabertani commented 7 years ago

Hello Nathan.

When creating a zip file protected with password, MiniZip APIs (e.g. zipOpenNewFileInZip3_64) require this perplexing crc_for_crypting parameter. The zip.h file just says: "needed for crypting". Following its use in the code provides no particular clues, beside that it's being actively used during encryption.

Could you explain:

As you are aware of, MiniZip is used extensively in Objective-Zip, and I would like to provide a better explanation for this parameter than a simple "needed for crypting".

Thanks in advance. Keep up the great job!

nmoinvaz commented 7 years ago

This value is used when zipping with a password using Traditional PKWARE Encryption. The CRC is supplied so that it "can be used to test if the password supplied is correct or not" during decryption.

https://pkware.cachefly.net/webdocs/casestudies/APPNOTE.TXT

gianlucabertani commented 7 years ago

So it's actually a fundamental parameter, if you pass it wrong you can't decrypt the zip even if the password is correct.

Why don't you compute it autonomously while encrypting? It would be safer to compute it with the same function, instead of relying on a user-supplied CRC.

nmoinvaz commented 7 years ago

The answer on this StackOverflow question might provide more insight: http://stackoverflow.com/questions/30876659/zip-file-encryption-readable-by-some-zip-clients-not-others

gianlucabertani commented 7 years ago

Thanks Nathan, that clears up the question.

nmoinvaz commented 7 years ago

It looks like InfoZIP added a modification to the ZIP format that makes it so that the crc_for_crypting is not necessary. See issue #123 for more info.

sashazxtt commented 2 months ago

It appears that the crc_for_crypting parameter is ignored in the mz_compat.c sources. The calls end up in zipOpenNewFileInZip5, which doesn't make use of the parameter. How to interpret that? And yes, I want to password-protect files in my .zip and data is arriving as a stream. My attempts so far resulted in the files that cannot be extracted, with the 'password is invalid' message.