Involved Source Files 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.gocrc32_generic.gocrc32_amd64.s
Code Examples
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 (total 4, in which 1 is exported)
Package-Level Functions (total 27, in which 6 are exported)
Checksum returns the CRC-32 checksum of data
using the polynomial represented by the Table.
ChecksumIEEE returns the CRC-32 checksum of data
using the IEEE polynomial.
MakeTable returns a Table constructed from the specified polynomial.
The contents of this Table must not be modified.
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.
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.
Update returns the result of adding the bytes in p to the crc.
castagnoliShift computes the CRC32-C of K1 or K2 zeroes (depending on the
table given) with the given initial crc value. This corresponds to
CRC(crc, O) in the description in updateCastagnoli.
castagnoliSSE42 is defined in crc32_amd64.s and uses the SSE 4.2 CRC32
instruction.
castagnoliSSE42Triple is defined in crc32_amd64.s and uses the SSE 4.2 CRC32
instruction.
ieeeCLMUL is defined in crc_amd64.s and uses the PCLMULQDQ
instruction as well as SSE 4.1.
simpleMakeTable allocates and constructs a Table for the specified
polynomial. The table is suitable for use with the simple algorithm
(simpleUpdate).
simplePopulateTable constructs a Table for the specified polynomial, suitable
for use with simpleUpdate.
simpleUpdate uses the simple algorithm to update the CRC, given a table that
was previously computed using simpleMakeTable.
slicingMakeTable constructs a slicing8Table for the specified polynomial. The
table is suitable for use with the slicing-by-8 algorithm (slicingUpdate).
slicingUpdate uses the slicing-by-8 algorithm to update the CRC, given a
table that was previously computed using slicingMakeTable.
castagnoliTable points to a lazily initialized Table for the Castagnoli
polynomial. MakeTable will always return this value when asked to make a
Castagnoli table so we can compare against it to find when the caller is
using this polynomial.
The pages are generated with Goldsv0.6.7. (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu.
PR and bug reports are welcome and can be submitted to the issue list.
Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds.