crc32 computes the non-reflected (big-endian) CRC-32
(data []byte, seed uint32)
| 10 | |
| 11 | // crc32 computes the non-reflected (big-endian) CRC-32 |
| 12 | func crc32(data []byte, seed uint32) int32 { |
| 13 | const poly = uint32(0x04C11DB7) |
| 14 | crc := seed ^ 0xFFFF_FFFF |
| 15 | for _, b := range data { |
| 16 | crc ^= uint32(b) << 24 |
| 17 | for range 8 { |
| 18 | if crc&0x8000_0000 != 0 { |
| 19 | crc = (crc << 1) ^ poly |
| 20 | } else { |
| 21 | crc <<= 1 |
| 22 | } |
| 23 | } |
| 24 | } |
| 25 | return int32(crc ^ 0xFFFF_FFFF) |
| 26 | } |