CRC-32
CRC-32
The checksum in every ZIP, PNG, gzip and bzip2.
- Digest
- 32-bit · 4 bytes
- HMAC
- no key mode
- Security
- NOT for security: error-detection checksum only
- Family
- 4 in CRC
Sample
- hex
- 0d4a1185
- base64
- DUoRhQ==
Options
Access
- Create
create("crc32") - CLI
hashes crc32 'hello world' - Tryplayground with the sample above
- Kincrc64, crc24, crc16-xmodem
The IEEE CRC-32, the one in ZIP, PNG, gzip and Ethernet. It catches accidental bit flips and nothing else. Anyone can forge a CRC-32 in microseconds, since it's linear.
create("crc32").hash("123456789").digest; // "cbf43926", the standard check value
create("crc32").hash("The quick brown fox jumps over the lazy dog").digest; // "414fa339"
create("crc32").hash("123456789", { variant: "bzip2" }).digest; // "fc891918"
The avalanche panel on the landing makes the linearity visible. Flip one input bit and the CRC changes by a pattern that depends only on where that bit sat, not on the rest of the input. A real hash moves a random half. Printed big-endian, as crc32 tools write it.
Variants
variant picks which CRC-32. The names come from the CRC catalogue.
variant | Who uses it |
|---|---|
iso-hdlc (default) | zlib, gzip, ZIP, PNG, Ethernet |
bzip2 | bzip2, after every block and once more for the stream |
Same polynomial, same all-ones start and finish. bzip2 just reads the bits the other way round, so the answer is different. A checksum from a .bz2 file that matches neither is usually the stream CRC, which rotates the running value left by one bit before each block's CRC goes in. One block and the two agree.