``````package crc32

Import Path
hash/crc32 (on golang.org and go.dev)

Dependency Relation
imports 6 packages, and imported by 3 packages

Involved Source Files

d➜ crc32.go
Package crc32 implements the 32-bit cyclic redundancy check, or CRC-32,
checksum. See https://en.wikipedia.org/wiki/Cyclic_redundancy_check for
information.

Polynomials are represented in LSB-first form also known as reversed representation.

See https://en.wikipedia.org/wiki/Mathematics_of_cyclic_redundancy_checks#Reversed_representations_and_reciprocal_polynomials
for information.

crc32_amd64.go
crc32_generic.go
crc32_amd64.s
Code Examples

MakeTable
package main

import (
"fmt"
"hash/crc32"
)

func main() {
// In this package, the CRC polynomial is represented in reversed notation,
// or LSB-first representation.
//
// LSB-first representation is a hexadecimal number with n bits, in which the
// most significant bit represents the coefficient of x⁰ and the least significant
// bit represents the coefficient of xⁿ⁻¹ (the coefficient for xⁿ is implicit).
//
// For example, CRC32-Q, as defined by the following polynomial,
//	x³²+ x³¹+ x²⁴+ x²²+ x¹⁶+ x¹⁴+ x⁸+ x⁷+ x⁵+ x³+ x¹+ x⁰
// has the reversed notation 0b11010101100000101000001010000001, so the value
// that should be passed to MakeTable is 0xD5828281.
crc32q := crc32.MakeTable(0xD5828281)
fmt.Printf("%08x\n", crc32.Checksum([]byte("Hello world"), crc32q))
}

Package-Level Type Names (only one)

/* sort by: alphabet | popularity */	 type Table ([...]T)
Table is a 256-word table representing the polynomial for efficient processing.

As Outputs Of (at least one exported)
func MakeTable(poly uint32) *Table
As Inputs Of (at least 3)
func Checksum(data []byte, tab *Table) uint32
func New(tab *Table) hash.Hash32
func Update(crc uint32, tab *Table, p []byte) uint32
As Types Of (only one)
var IEEETable *Table

Package-Level Functions (total 6)

func Checksum(data []byte, tab *Table) uint32
Checksum returns the CRC-32 checksum of data
using the polynomial represented by the Table.

func ChecksumIEEE(data []byte) uint32
ChecksumIEEE returns the CRC-32 checksum of data
using the IEEE polynomial.

func MakeTable(poly uint32) *Table
MakeTable returns a Table constructed from the specified polynomial.
The contents of this Table must not be modified.

func New(tab *Table) hash.Hash32
New creates a new hash.Hash32 computing the CRC-32 checksum using the
polynomial represented by the Table. Its Sum method will lay the
value out in big-endian byte order. The returned Hash32 also
implements encoding.BinaryMarshaler and encoding.BinaryUnmarshaler to
marshal and unmarshal the internal state of the hash.

func NewIEEE() hash.Hash32
NewIEEE creates a new hash.Hash32 computing the CRC-32 checksum using
the IEEE polynomial. Its Sum method will lay the value out in
big-endian byte order. The returned Hash32 also implements
encoding.BinaryMarshaler and encoding.BinaryUnmarshaler to marshal
and unmarshal the internal state of the hash.

func Update(crc uint32, tab *Table, p []byte) uint32
Update returns the result of adding the bytes in p to the crc.

Package-Level Variables (only one)

var IEEETable *Table
IEEETable is the table for the IEEE polynomial.

Package-Level Constants (total 4)

const Castagnoli = 2197175160
Castagnoli's polynomial, used in iSCSI.
Has better error detection characteristics than IEEE.
https://dx.doi.org/10.1109/26.231911

const IEEE = 3988292384
IEEE is by far and away the most common CRC-32 polynomial.
Used by ethernet (IEEE 802.3), v.42, fddi, gzip, zip, png, ...

const Koopman = 3945912366
Koopman's polynomial.
Also has better error detection characteristics than IEEE.
https://dx.doi.org/10.1109/DSN.2002.1028931

const Size = 4
The size of a CRC-32 checksum in bytes.

``````