crc32

package
v0.1.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 15, 2024 License: Zlib Imports: 4 Imported by: 0

Documentation

Overview

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.

Checksums are layed out in big-endian byte order.

Index

Constants

View Source
const Size = 4

The size of a CRC-32 checksum in bytes.

Variables

This section is empty.

Functions

This section is empty.

Types

type Hash

Hash is a hash.Hash32 that also implements encoding.BinaryMarshaler and encoding.BinaryUnmarshaler to marshal and unmarshal the internal state of the hash. Its Sum methods will lay the value out in big-endian byte order.

func New

func New(p *Poly) Hash

New creates a new Hash computing the CRC-32 checksum using the polynomial represented by the Poly.

type Poly

type Poly struct {
	// contains filtered or unexported fields
}

Poly represents a 32-bit polynomial with tables for efficient processing.

func Castagnoli

func Castagnoli() *Poly

Castagnoli returns the Poly representing Castagnoli's polynomial, which is used in iSCSI. It has better error detection characteristics than IEEE. https://dx.doi.org/10.1109/26.231911

func IEEE

func IEEE() *Poly

IEEE returns the Poly representing the IEEE polynomial, which is by far and away the most common CRC-32 polynomial. It's used by ethernet (IEEE 802.3), v.42, fddi, gzip, zip, png, ...

func Koopman

func Koopman() *Poly

Koopman returns the Poly representing Koopman's polynomial. It has better error detection characteristics than IEEE. https://dx.doi.org/10.1109/DSN.2002.1028931

func MakePoly

func MakePoly(poly uint32) *Poly

MakePoly returns a Poly constructed from the specified polynomial given in LSB-first form, also known as reversed representation. The returned Poly may be shared and must not be modified.

func (*Poly) Checksum

func (p *Poly) Checksum(data []byte) uint32

Checksum returns the CRC-32 checksum of data in big-endian byte order.

func (*Poly) Combine

func (p *Poly) Combine(prev, next uint32, n int64) uint32

Combine returns the result of adding n bytes with the next sum to the prev sum.

func (*Poly) Polynomial

func (p *Poly) Polynomial() uint32

Polynomial returns the polynomial in LSB-first form, also known as reversed representation.

func (*Poly) Update

func (p *Poly) Update(sum uint32, data []byte) uint32

Update returns the result of adding the bytes in data to the sum.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL