Imports #
"unsafe"
"internal/cpu"
"errors"
"hash"
"internal/byteorder"
"sync"
"sync/atomic"
"internal/byteorder"
"internal/cpu"
"unsafe"
"internal/cpu"
"internal/cpu"
"unsafe"
"internal/cpu"
"errors"
"hash"
"internal/byteorder"
"sync"
"sync/atomic"
"internal/byteorder"
"internal/cpu"
"unsafe"
"internal/cpu"
"internal/cpu"
Castagnoli's polynomial, used in iSCSI. Has better error detection characteristics than IEEE. https://dx.doi.org/10.1109/26.231911
const Castagnoli = 0x82f63b78IEEE is by far and away the most common CRC-32 polynomial. Used by ethernet (IEEE 802.3), v.42, fddi, gzip, zip, png, ...
const IEEE = 0xedb88320IEEETable is the table for the [IEEE] polynomial.
var IEEETable = *ast.CallExprKoopman's polynomial. Also has better error detection characteristics than IEEE. https://dx.doi.org/10.1109/DSN.2002.1028931
const Koopman = 0xeb31d82eThe size of a CRC-32 checksum in bytes.
const Size = 4var archCastagnoliTable8 *slicing8Tablevar archCastagnoliTable8 *slicing8Tablevar archIeeeTable8 *slicing8Tablevar archIeeeTable8 *slicing8Tablevar archIeeeTable8 *slicing8Tablevar castagnoliInitOnce = *ast.CallExprconst castagnoliK1 = 168const castagnoliK2 = 1344var castagnoliSSE42TableK1 *sse42Tablevar castagnoliSSE42TableK2 *sse42TablecastagnoliTable 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.
var castagnoliTable *Tablevar castagnoliTable8 *slicing8Tableconst crcCast = 2const crcIEEE = 1hasVX reports whether the machine has the z/Architecture vector facility installed and enabled.
var hasVX = cpu.S390X.HasVXvar haveCastagnoli atomic.Boolvar ieeeInitOnce = *ast.CallExprieeeTable8 is the slicing8Table for IEEE
var ieeeTable8 *slicing8Tableconst magic = "crc\x01"const marshaledSize = *ast.BinaryExprUse slicing-by-8 when payload >= this value.
const slicing8Cutoff = 16var updateCastagnoli func(crc uint32, p []byte) uint32var updateIEEE func(crc uint32, p []byte) uint32const vecAlignMask = 15const vecMinLen = 16const vxAlignMask = 15const vxMinLen = 64Table is a 256-word table representing the polynomial for efficient processing.
type Table [256]uint32slicing8Table is array of 8 Tables, used by the slicing-by-8 algorithm.
type slicing8Table [8]Tabletype sse42Table [4]Tabledigest represents the partial evaluation of a checksum.
type digest struct {
crc uint32
tab *Table
}func (d *digest) AppendBinary(b []byte) ([]byte, error)func (d *digest) BlockSize() intChecksum returns the CRC-32 checksum of data using the polynomial represented by the [Table].
func Checksum(data []byte, tab *Table) uint32ChecksumIEEE returns the CRC-32 checksum of data using the [IEEE] polynomial.
func ChecksumIEEE(data []byte) uint32MakeTable returns a [Table] constructed from the specified polynomial. The contents of this [Table] must not be modified.
func MakeTable(poly uint32) *Tablefunc (d *digest) MarshalBinary() ([]byte, error)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 New(tab *Table) hash.Hash32NewIEEE 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 NewIEEE() hash.Hash32func (d *digest) Reset()func (d *digest) Size() intfunc (d *digest) Sum(in []byte) []bytefunc (d *digest) Sum32() uint32func (d *digest) UnmarshalBinary(b []byte) errorUpdate returns the result of adding the bytes in p to the crc.
func Update(crc uint32, tab *Table, p []byte) uint32func (d *digest) Write(p []byte) (n int, err error)func archAvailableCastagnoli() boolfunc archAvailableCastagnoli() boolfunc archAvailableCastagnoli() boolfunc archAvailableCastagnoli() boolfunc archAvailableCastagnoli() boolfunc archAvailableCastagnoli() boolfunc archAvailableIEEE() boolfunc archAvailableIEEE() boolfunc archAvailableIEEE() boolfunc archAvailableIEEE() boolfunc archAvailableIEEE() boolfunc archAvailableIEEE() boolfunc archInitCastagnoli()func archInitCastagnoli()func archInitCastagnoli()func archInitCastagnoli()func archInitCastagnoli()func archInitCastagnoli()func archInitIEEE()func archInitIEEE()func archInitIEEE()func archInitIEEE()func archInitIEEE()func archInitIEEE()func archUpdateCastagnoli(crc uint32, p []byte) uint32func archUpdateCastagnoli(crc uint32, p []byte) uint32func archUpdateCastagnoli(crc uint32, p []byte) uint32archUpdateCastagnoli calculates the checksum of p using vectorizedCastagnoli.
func archUpdateCastagnoli(crc uint32, p []byte) uint32func archUpdateCastagnoli(crc uint32, p []byte) uint32func archUpdateCastagnoli(crc uint32, p []byte) uint32func archUpdateIEEE(crc uint32, p []byte) uint32archUpdateIEEE calculates the checksum of p using vectorizedIEEE.
func archUpdateIEEE(crc uint32, p []byte) uint32func archUpdateIEEE(crc uint32, p []byte) uint32archUpdateIEEE calculates the checksum of p using vectorizedIEEE.
func archUpdateIEEE(crc uint32, p []byte) uint32func archUpdateIEEE(crc uint32, p []byte) uint32func archUpdateIEEE(crc uint32, p []byte) uint32castagnoliSSE42 is defined in crc32_amd64.s and uses the SSE 4.2 CRC32 instruction. go:noescape
func castagnoliSSE42(crc uint32, p []byte) uint32castagnoliSSE42Triple is defined in crc32_amd64.s and uses the SSE 4.2 CRC32 instruction. go:noescape
func castagnoliSSE42Triple(crcA uint32, crcB uint32, crcC uint32, a []byte, b []byte, c []byte, rounds uint32) (retA uint32, retB uint32, retC uint32)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.
func castagnoliShift(table *sse42Table, crc uint32) uint32func castagnoliUpdate(crc uint32, p []byte) uint32func castagnoliUpdate(crc uint32, p []byte) uint32ieeeCLMUL is defined in crc_amd64.s and uses the PCLMULQDQ instruction as well as SSE 4.1. go:noescape
func ieeeCLMUL(crc uint32, p []byte) uint32func ieeeUpdate(crc uint32, p []byte) uint32func ieeeUpdate(crc uint32, p []byte) uint32go:noescape
func ppc64SlicingUpdateBy8(crc uint32, table8 *slicing8Table, p []byte) uint32simpleMakeTable allocates and constructs a Table for the specified polynomial. The table is suitable for use with the simple algorithm (simpleUpdate).
func simpleMakeTable(poly uint32) *TablesimplePopulateTable constructs a Table for the specified polynomial, suitable for use with simpleUpdate.
func simplePopulateTable(poly uint32, t *Table)simpleUpdate uses the simple algorithm to update the CRC, given a table that was previously computed using simpleMakeTable.
func simpleUpdate(crc uint32, tab *Table, p []byte) uint32slicingMakeTable constructs a slicing8Table for the specified polynomial. The table is suitable for use with the slicing-by-8 algorithm (slicingUpdate).
func slicingMakeTable(poly uint32) *slicing8TableslicingUpdate uses the slicing-by-8 algorithm to update the CRC, given a table that was previously computed using slicingMakeTable.
func slicingUpdate(crc uint32, tab *slicing8Table, p []byte) uint32tableSum returns the IEEE checksum of table t.
func tableSum(t *Table) uint32func update(crc uint32, tab *Table, p []byte, checkInitIEEE bool) uint32this function requires the buffer to be 16 byte aligned and > 16 bytes long. go:noescape
func vectorCrc32(crc uint32, poly uint32, p []byte) uint32vectorizedCastagnoli implements CRC32 using vector instructions. It is defined in crc32_s390x.s. go:noescape
func vectorizedCastagnoli(crc uint32, p []byte) uint32vectorizedIEEE implements CRC32 using vector instructions. It is defined in crc32_s390x.s. go:noescape
func vectorizedIEEE(crc uint32, p []byte) uint32Generated with Arrow