crc32

Imports

Imports #

"unsafe"
"internal/cpu"
"errors"
"hash"
"internal/byteorder"
"sync"
"sync/atomic"
"internal/byteorder"
"internal/cpu"
"unsafe"
"internal/cpu"
"internal/cpu"

Constants & Variables

Castagnoli const #

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

const Castagnoli = 0x82f63b78

IEEE const #

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 IEEE = 0xedb88320

IEEETable var #

IEEETable is the table for the [IEEE] polynomial.

var IEEETable = *ast.CallExpr

Koopman const #

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

const Koopman = 0xeb31d82e

Size const #

The size of a CRC-32 checksum in bytes.

const Size = 4

archCastagnoliTable8 var #

var archCastagnoliTable8 *slicing8Table

archCastagnoliTable8 var #

var archCastagnoliTable8 *slicing8Table

archIeeeTable8 var #

var archIeeeTable8 *slicing8Table

archIeeeTable8 var #

var archIeeeTable8 *slicing8Table

archIeeeTable8 var #

var archIeeeTable8 *slicing8Table

castagnoliInitOnce var #

var castagnoliInitOnce = *ast.CallExpr

castagnoliK1 const #

const castagnoliK1 = 168

castagnoliK2 const #

const castagnoliK2 = 1344

castagnoliSSE42TableK1 var #

var castagnoliSSE42TableK1 *sse42Table

castagnoliSSE42TableK2 var #

var castagnoliSSE42TableK2 *sse42Table

castagnoliTable var #

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.

var castagnoliTable *Table

castagnoliTable8 var #

var castagnoliTable8 *slicing8Table

crcCast const #

const crcCast = 2

crcIEEE const #

const crcIEEE = 1

hasVX var #

hasVX reports whether the machine has the z/Architecture vector facility installed and enabled.

var hasVX = cpu.S390X.HasVX

haveCastagnoli var #

var haveCastagnoli atomic.Bool

ieeeInitOnce var #

var ieeeInitOnce = *ast.CallExpr

ieeeTable8 var #

ieeeTable8 is the slicing8Table for IEEE

var ieeeTable8 *slicing8Table

magic const #

const magic = "crc\x01"

marshaledSize const #

const marshaledSize = *ast.BinaryExpr

slicing8Cutoff const #

Use slicing-by-8 when payload >= this value.

const slicing8Cutoff = 16

updateCastagnoli var #

var updateCastagnoli func(crc uint32, p []byte) uint32

updateIEEE var #

var updateIEEE func(crc uint32, p []byte) uint32

vecAlignMask const #

const vecAlignMask = 15

vecMinLen const #

const vecMinLen = 16

vxAlignMask const #

const vxAlignMask = 15

vxMinLen const #

const vxMinLen = 64

Type Aliases

Table type #

Table is a 256-word table representing the polynomial for efficient processing.

type Table [256]uint32

slicing8Table type #

slicing8Table is array of 8 Tables, used by the slicing-by-8 algorithm.

type slicing8Table [8]Table

sse42Table type #

type sse42Table [4]Table

Structs

digest struct #

digest represents the partial evaluation of a checksum.

type digest struct {
crc uint32
tab *Table
}

Functions

AppendBinary method #

func (d *digest) AppendBinary(b []byte) ([]byte, error)

BlockSize method #

func (d *digest) BlockSize() int

Checksum function #

Checksum returns the CRC-32 checksum of data using the polynomial represented by the [Table].

func Checksum(data []byte, tab *Table) uint32

ChecksumIEEE function #

ChecksumIEEE returns the CRC-32 checksum of data using the [IEEE] polynomial.

func ChecksumIEEE(data []byte) uint32

MakeTable function #

MakeTable returns a [Table] constructed from the specified polynomial. The contents of this [Table] must not be modified.

func MakeTable(poly uint32) *Table

MarshalBinary method #

func (d *digest) MarshalBinary() ([]byte, error)

New function #

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.Hash32

NewIEEE function #

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 NewIEEE() hash.Hash32

Reset method #

func (d *digest) Reset()

Size method #

func (d *digest) Size() int

Sum method #

func (d *digest) Sum(in []byte) []byte

Sum32 method #

func (d *digest) Sum32() uint32

UnmarshalBinary method #

func (d *digest) UnmarshalBinary(b []byte) error

Update function #

Update returns the result of adding the bytes in p to the crc.

func Update(crc uint32, tab *Table, p []byte) uint32

Write method #

func (d *digest) Write(p []byte) (n int, err error)

archAvailableCastagnoli function #

func archAvailableCastagnoli() bool

archAvailableCastagnoli function #

func archAvailableCastagnoli() bool

archAvailableCastagnoli function #

func archAvailableCastagnoli() bool

archAvailableCastagnoli function #

func archAvailableCastagnoli() bool

archAvailableCastagnoli function #

func archAvailableCastagnoli() bool

archAvailableCastagnoli function #

func archAvailableCastagnoli() bool

archAvailableIEEE function #

func archAvailableIEEE() bool

archAvailableIEEE function #

func archAvailableIEEE() bool

archAvailableIEEE function #

func archAvailableIEEE() bool

archAvailableIEEE function #

func archAvailableIEEE() bool

archAvailableIEEE function #

func archAvailableIEEE() bool

archAvailableIEEE function #

func archAvailableIEEE() bool

archInitCastagnoli function #

func archInitCastagnoli()

archInitCastagnoli function #

func archInitCastagnoli()

archInitCastagnoli function #

func archInitCastagnoli()

archInitCastagnoli function #

func archInitCastagnoli()

archInitCastagnoli function #

func archInitCastagnoli()

archInitCastagnoli function #

func archInitCastagnoli()

archInitIEEE function #

func archInitIEEE()

archInitIEEE function #

func archInitIEEE()

archInitIEEE function #

func archInitIEEE()

archInitIEEE function #

func archInitIEEE()

archInitIEEE function #

func archInitIEEE()

archInitIEEE function #

func archInitIEEE()

archUpdateCastagnoli function #

func archUpdateCastagnoli(crc uint32, p []byte) uint32

archUpdateCastagnoli function #

func archUpdateCastagnoli(crc uint32, p []byte) uint32

archUpdateCastagnoli function #

func archUpdateCastagnoli(crc uint32, p []byte) uint32

archUpdateCastagnoli function #

archUpdateCastagnoli calculates the checksum of p using vectorizedCastagnoli.

func archUpdateCastagnoli(crc uint32, p []byte) uint32

archUpdateCastagnoli function #

func archUpdateCastagnoli(crc uint32, p []byte) uint32

archUpdateCastagnoli function #

func archUpdateCastagnoli(crc uint32, p []byte) uint32

archUpdateIEEE function #

func archUpdateIEEE(crc uint32, p []byte) uint32

archUpdateIEEE function #

archUpdateIEEE calculates the checksum of p using vectorizedIEEE.

func archUpdateIEEE(crc uint32, p []byte) uint32

archUpdateIEEE function #

func archUpdateIEEE(crc uint32, p []byte) uint32

archUpdateIEEE function #

archUpdateIEEE calculates the checksum of p using vectorizedIEEE.

func archUpdateIEEE(crc uint32, p []byte) uint32

archUpdateIEEE function #

func archUpdateIEEE(crc uint32, p []byte) uint32

archUpdateIEEE function #

func archUpdateIEEE(crc uint32, p []byte) uint32

castagnoliSSE42 function #

castagnoliSSE42 is defined in crc32_amd64.s and uses the SSE 4.2 CRC32 instruction. go:noescape

func castagnoliSSE42(crc uint32, p []byte) uint32

castagnoliSSE42Triple function #

castagnoliSSE42Triple 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 function #

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) uint32

castagnoliUpdate function #

func castagnoliUpdate(crc uint32, p []byte) uint32

castagnoliUpdate function #

func castagnoliUpdate(crc uint32, p []byte) uint32

ieeeCLMUL function #

ieeeCLMUL 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) uint32

ieeeUpdate function #

func ieeeUpdate(crc uint32, p []byte) uint32

ieeeUpdate function #

func ieeeUpdate(crc uint32, p []byte) uint32

ppc64SlicingUpdateBy8 function #

go:noescape

func ppc64SlicingUpdateBy8(crc uint32, table8 *slicing8Table, p []byte) uint32

simpleMakeTable function #

simpleMakeTable allocates and constructs a Table for the specified polynomial. The table is suitable for use with the simple algorithm (simpleUpdate).

func simpleMakeTable(poly uint32) *Table

simplePopulateTable function #

simplePopulateTable constructs a Table for the specified polynomial, suitable for use with simpleUpdate.

func simplePopulateTable(poly uint32, t *Table)

simpleUpdate function #

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) uint32

slicingMakeTable function #

slicingMakeTable constructs a slicing8Table for the specified polynomial. The table is suitable for use with the slicing-by-8 algorithm (slicingUpdate).

func slicingMakeTable(poly uint32) *slicing8Table

slicingUpdate function #

slicingUpdate 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) uint32

tableSum function #

tableSum returns the IEEE checksum of table t.

func tableSum(t *Table) uint32

update function #

func update(crc uint32, tab *Table, p []byte, checkInitIEEE bool) uint32

vectorCrc32 function #

this function requires the buffer to be 16 byte aligned and > 16 bytes long. go:noescape

func vectorCrc32(crc uint32, poly uint32, p []byte) uint32

vectorizedCastagnoli function #

vectorizedCastagnoli implements CRC32 using vector instructions. It is defined in crc32_s390x.s. go:noescape

func vectorizedCastagnoli(crc uint32, p []byte) uint32

vectorizedIEEE function #

vectorizedIEEE implements CRC32 using vector instructions. It is defined in crc32_s390x.s. go:noescape

func vectorizedIEEE(crc uint32, p []byte) uint32

Generated with Arrow