modulepackage
0.0.0-20171223171357-2b2a61e366a6
Repository: https://github.com/howeyc/crc16.git
Documentation: pkg.go.dev
# README
CRC16
A Go package implementing the 16-bit Cyclic Redundancy Check, or CRC-16, checksum.
Usage
To generate the hash of a byte slice, use the crc16.Checksum()
function:
import "github.com/howeyc/crc16"
data := byte("test")
checksum := crc16.Checksum(data, crc16.IBMTable)
The package provides the following hashing tables. For each of these tables, a shorthand can be used.
// This is the same as crc16.Checksum(data, crc16.IBMTable)
checksum := crc16.ChecksumIBM(data)
Using the hash.Hash interface also works.
h := crc16.New(crc16.IBMTable)
data := byte("test")
data2 := byte("data")
h.Write(data)
h.Write(data2)
checksum := h.Sum(nil)
Changelog
- 2017.03.27 - Added MBus checksum
- 2017.05.27 - Added checksum function without XOR
- 2017.12.08 - Implement encoding.BinaryMarshaler and encoding.BinaryUnmarshaler to allow saving and recreating their internal state.
# Functions
Checksum returns the CRC-16 checksum of data using the polynomial represented by the Table.
ChecksumCCITT returns the CRC-16 checksum of data using the CCITT polynomial.
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.
ChecksumIBM returns the CRC-16 checksum of data using the IBM polynomial.
ChecksumMBus returns the CRC-16 checksum of data using the MBus polynomial.
ChecksumSCSI returns the CRC-16 checksum of data using the SCSI polynomial.
MakeBitsReversedTable returns the Table constructed from the specified polynomial.
MakeTable returns the Table constructed from the specified polynomial.
MakeTableNoXOR returns the Table constructed from the specified polynomial.
New creates a new Hash16 computing the CRC-16 checksum using the polynomial represented by the Table.
NewCCITT creates a new hash.Hash16 computing the CRC-16 checksum using the CCITT polynomial.
NewIBM creates a new Hash16 computing the CRC-16 checksum using the IBM polynomial.
NewSCSI creates a new Hash16 computing the CRC-16 checksum using the SCSI polynomial.
Update returns the result of adding the bytes in p to the crc.
# Constants
CCITT is used by X.25, V.41, HDLC FCS, XMODEM, Bluetooth, PACTOR, SD, ..
Predefined polynomials.
IBM is used by Bisync, Modbus, USB, ANSI X3.28, SIA DC-07, ...
MBUS is used by Meter-Bus, DNP, ...
SCSI is used by SCSI.
# Variables
CCITTFalseTable is the table for CCITT-FALSE.
CCITTTable is the table for the CCITT polynomial.
IBMTable is the table for the IBM polynomial.
MBusTable is the tabe used for Meter-Bus polynomial.
SCSITable is the table for the SCSI polynomial.
# Interfaces
Hash16 is the common interface implemented by all 16-bit hash functions.