Il campo CRC (Cyclic Redundancy Check) viene utilizzato per determinare se il file viene decrittografato correttamente. Citato dalla specifica del formato ZIP originale:
After the header is decrypted, the last 1 or 2 bytes in Buffer SHOULD be the high-order word/byte of the CRC for the file being decrypted, stored in Intel low-byte/high-byte order. Versions of PKZIP prior to 2.0 used a 2 byte CRC check; a 1 byte CRC check is used on versions after 2.0. This can be used to test if the password supplied is correct or not.
Aggiornamento: come si può vedere dal % codice sorgente% di Info-ZIP Info-ZIP , il valore CRC viene utilizzato per verificare se la password è corretta:
link
#ifdef ZIP10 /* check two bytes */
c = hh[RAND_HEAD_LEN-2], b = hh[RAND_HEAD_LEN-1];
Trace((stdout,
" (c | (b<<8)) = %04x (crc >> 16) = %04x lrec.time = %04x\n",
(ush)(c | (b<<8)), (ush)(GLOBAL(lrec.crc32) >> 16),
((ush)GLOBAL(lrec.last_mod_dos_datetime) & 0xffff))));
if ((ush)(c | (b<<8)) != (GLOBAL(pInfo->ExtLocHdr) ?
((ush)GLOBAL(lrec.last_mod_dos_datetime) & 0xffff) :
(ush)(GLOBAL(lrec.crc32) >> 16)))
return -1; /* bad */
#else
b = hh[RAND_HEAD_LEN-1];
Trace((stdout, " b = %02x (crc >> 24) = %02x (lrec.time >> 8) = %02x\n",
b, (ush)(GLOBAL(lrec.crc32) >> 24),
((ush)GLOBAL(lrec.last_mod_dos_datetime) >> 8) & 0xff));
if (b != (GLOBAL(pInfo->ExtLocHdr) ?
((ush)GLOBAL(lrec.last_mod_dos_datetime) >> 8) & 0xff :
(ush)(GLOBAL(lrec.crc32) >> 24)))
return -1; /* bad */
#endif
/* password OK: decrypt current buffer contents before leaving */
for (n = (long)GLOBAL(incnt) > GLOBAL(csize) ?
(int)GLOBAL(csize) : GLOBAL(incnt),
p = GLOBAL(inptr); n--; p++)
zdecode(*p);
return 0; /* OK */