hash/crc32

Guided tour · Hashing · pkg.go.dev →

CRC-32 checksums. Fast, 32-bit, great for integrity checks — not a secure hash.

Compute a CRC-32

ChecksumIEEE — the common polynomial

sum := crc32.ChecksumIEEE([]byte("hello"))
fmt.Printf("%08x\n", sum)

Streaming via Hash32

h := crc32.NewIEEE()
io.Copy(h, f)
fmt.Printf("%08x\n", h.Sum32())

Other polynomials

Castagnoli (used by iSCSI and ext4) is faster on modern CPUs thanks to hardware support.

t := crc32.MakeTable(crc32.Castagnoli)
sum := crc32.Checksum(data, t)