Hi,

I have reported this upstream with a full analysis:

  https://github.com/MacPaw/XADMaster/issues/202
  "[LSAR/UNAR] WinZip-AES encrypted zips always fail with 'Missing or
   wrong password', even with the correct password (SHA-1 miscompiled
   at -O2 by strict-aliasing UB in Crypto/sha.c)"

Short version of the root cause: XADMaster/Crypto/sha.c type-puns
uint8_t
buffers through uint32_t*/uint64_t* pointers (strict-aliasing UB). With
GCC 14.2 at -O2 (trixie's default, and what Makefile.linux uses), the
generated SHA-1 code computes wrong hashes. The WinZip-AES KDF is
PBKDF2-HMAC-SHA1, so the 2-byte password verification value never
matches and unar raises "Missing or wrong password" for EVERY password,
including the correct one.

Proof with unmodified upstream sources, gcc 14.2:

  gcc -O2:  SHA1("abc") = 7f9f882da937eb765c197e9edb3f73aad3243060
            (expected a9993e364706816aba3e25717850c26c9cd0d89d)
            HMAC-SHA1 RFC 2202 TC2 also wrong
  gcc -O0 / -O1 / -O2 -fno-strict-aliasing: all correct

So this affects every WinZip-AES zip on trixie builds (7z -mem=AES128/
AES192/AES256, WinZip's AES defaults, pyzipper, ...), not just archives
created by 7z; ZipCrypto zips and RAR5 archives are unaffected (RAR5's
KDF is PBKDF2-HMAC-SHA256 and SHA-256 still compiles correctly with
this GCC). Encrypted pre-RAR5 RARs use the same broken SHA-1 code and
are presumably affected too.

Until upstream fixes it, a stopgap for the Debian build would be
compiling Crypto/ with -fno-strict-aliasing; there is also a proper
patch attached to the upstream issue that removes the type-punning
from the SHA-1 paths (verified against the SHA-1/HMAC test vectors and
against a WinZip-AES password verification value).

Given that this breaks extraction of all WinZip-AES zips with any
password, you may want to reconsider the severity.

Thanks.

Reply via email to