crc16

package module
v0.0.0-...-ab1acd0 Latest Latest
Warning

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

Go to latest
Published: Jul 21, 2021 License: MIT Imports: 1 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// IBM is used by Bisync, Modbus, USB, ANSI X3.28, SIA DC-07, ...
	IBM        = 0xA001
	IBM_NORMAL = 0x8005

	// CCITT is used by X.25, V.41, HDLC FCS, XMODEM, Bluetooth, PACTOR, SD, ...
	// CCITT forward is 0x8408. Reverse is 0x1021.
	CCITT      = 0x8408
	CCITTFalse = 0x1021

	// SCSI is used by SCSI
	SCSI = 0xEDD1

	MBUS = 0x3D65

	XMODEM = 0x1021
)

Predefined polynomials.

Variables

View Source
var CCITTFalseTable = makeBitsReversedTable(CCITTFalse)

CCITTFalseTable is the table for CCITT-FALSE.

View Source
var CCITTTable = makeTable(CCITT)

CCITTTable is the table for the CCITT polynomial.

View Source
var IBMTable = makeTable(IBM)

IBMTable is the table for the IBM polynomial.

View Source
var MBusTable = makeBitsReversedTable(MBUS)
View Source
var SCSITable = makeTable(SCSI)

SCSITable is the table for the SCSI polynomial.

View Source
var XModemTable = makeBitsReversedTable(XMODEM)

Functions

func Checksum

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

Checksum returns the CRC-16 checksum of data using the polynomial represented by the Table.

func ChecksumCCITT

func ChecksumCCITT(data []byte) uint16

ChecksumCCITT returns the CRC-16 checksum of data using the CCITT polynomial.

func ChecksumCCITTFalse

func ChecksumCCITTFalse(data []byte) uint16

ChecksumCCITTFalse returns the CRC-16 checksum using what some call the CCITT-False polynomial, which matches what is used by Perl Digest/CRC and Boost for example.

func ChecksumIBM

func ChecksumIBM(data []byte) uint16

ChecksumIBM returns the CRC-16 checksum of data using the IBM polynomial.

func ChecksumInverted

func ChecksumInverted(data []byte, tab *Table) uint16

ChecksumInverted returns the CRC-16 checksum of data where each byte gets inverted before lookup using the polynomial represented by the Table.

func ChecksumMBus

func ChecksumMBus(data []byte) uint16

ChecksumMBus returns the CRC-16 checksum of data using the MBus polynomial. Final result is inverted

func ChecksumSCSI

func ChecksumSCSI(data []byte) uint16

ChecksumSCSI returns the CRC-16 checksum of data using the SCSI polynomial.

func ChecksumXModem

func ChecksumXModem(data []byte) uint16

ChecksumXModem returns the CRC-16 checksum of data using the XMODEM polynomial.

func Update

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

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

func UpdateInverted

func UpdateInverted(crc uint16, tab *Table, p []byte) uint16

Types

type Hash16

type Hash16 interface {
	hash.Hash
	Sum16() uint16
}

Hash16 is the common interface implemented by all 16-bit hash functions.

func New

func New(tab *Table) Hash16

New creates a new Hash16 computing the CRC-16 checksum using the polynomial represented by the Table.

type Table

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

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

func MakeBitsReversedTable

func MakeBitsReversedTable(poly uint16) *Table

MakeTable returns the Table constructed from the specified polynomial.

func MakeTable

func MakeTable(poly uint16) *Table

MakeTable returns the Table constructed from the specified polynomial.

func (*Table) Entries

func (t *Table) Entries() [256]uint16

Jump to

Keyboard shortcuts

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