crc

package
v0.511.0 Latest Latest
Warning

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

Go to latest
Published: Jun 4, 2026 License: AGPL-3.0 Imports: 1 Imported by: 0

Documentation

Overview

Package crc computes and identifies cyclic redundancy checks against the standard CRC catalogue (the parameters Greg Cook's reveng catalogue publishes). It is a protocol reverse-engineering aid: when a captured RF or wired frame ends in a checksum of an unknown algorithm — the constant case when bringing up a new decoder — this computes the CRC under each catalogue model, and the identify mode reports which model(s) reproduce an observed CRC over the data.

Wrap-vs-native judgement

Native. A CRC is a parameterised bit-walk — (width, polynomial, init, reflect-in, reflect-out, xor-out) — about thirty lines of shift/xor. There is nothing to wrap, and the project already computes specific CRCs inline across its decoders (canfd, adsb, pocsag); this generalises that into a reusable catalogue.

Verifiable / no confidently-wrong output

Every model in the catalogue carries its published "check" value — the CRC of the ASCII string "123456789", the universal CRC self-test vector. The unit tests assert that this package computes exactly that check value for every model, so a model only ships if its parameters reproduce the authoritative reference. The identify mode makes no guesses: it reports the models whose output equals the supplied CRC, and an empty result is an honest "no catalogue model matches".

Covered / deferred

Covered: the common CRC-8 / CRC-16 / CRC-32 models seen in embedded, RF, and fieldbus protocols, plus CRC-24 (OpenPGP, Bluetooth LE PDU, FlexRay) — each with a published check value. Rarer widths (CRC-5/USB, CRC-64) and the full reveng search (brute-forcing unknown polynomials) are deliberately out of scope here.

Index

Constants

This section is empty.

Variables

View Source
var Catalogue = []Model{
	{"CRC-8/SMBUS", 8, 0x07, 0x00, false, false, 0x00, 0xF4},
	{"CRC-8/MAXIM-DOW", 8, 0x31, 0x00, true, true, 0x00, 0xA1},
	{"CRC-16/ARC", 16, 0x8005, 0x0000, true, true, 0x0000, 0xBB3D},
	{"CRC-16/CCITT-FALSE", 16, 0x1021, 0xFFFF, false, false, 0x0000, 0x29B1},
	{"CRC-16/XMODEM", 16, 0x1021, 0x0000, false, false, 0x0000, 0x31C3},
	{"CRC-16/MODBUS", 16, 0x8005, 0xFFFF, true, true, 0x0000, 0x4B37},
	{"CRC-16/KERMIT", 16, 0x1021, 0x0000, true, true, 0x0000, 0x2189},
	{"CRC-24/OPENPGP", 24, 0x864CFB, 0xB704CE, false, false, 0x000000, 0x21CF02},
	{"CRC-24/BLE", 24, 0x00065B, 0x555555, true, true, 0x000000, 0xC25A56},
	{"CRC-24/FLEXRAY-A", 24, 0x5D6DCB, 0xFEDCBA, false, false, 0x000000, 0x7979BD},
	{"CRC-32/ISO-HDLC", 32, 0x04C11DB7, 0xFFFFFFFF, true, true, 0xFFFFFFFF, 0xCBF43926},
	{"CRC-32/BZIP2", 32, 0x04C11DB7, 0xFFFFFFFF, false, false, 0xFFFFFFFF, 0xFC891918},
	{"CRC-32/MPEG-2", 32, 0x04C11DB7, 0xFFFFFFFF, false, false, 0x00000000, 0x0376E6E7},
}

Catalogue is the set of supported CRC models. Each Check value is from the reveng catalogue and is asserted by the unit tests.

Functions

This section is empty.

Types

type Match

type Match struct {
	Model string `json:"model"`
	Width int    `json:"width"`
}

Match is one identify result.

func Identify

func Identify(data []byte, want uint32) []Match

Identify returns the catalogue models whose CRC of data equals want.

type Model

type Model struct {
	Name   string `json:"name"`
	Width  int    `json:"width"`
	Poly   uint32 `json:"poly"`
	Init   uint32 `json:"init"`
	RefIn  bool   `json:"ref_in"`
	RefOut bool   `json:"ref_out"`
	XorOut uint32 `json:"xor_out"`
	Check  uint32 `json:"check"` // CRC of "123456789"
}

Model is one parameterised CRC algorithm.

func Lookup

func Lookup(name string) (Model, bool)

Lookup returns the named model.

func (Model) Compute

func (m Model) Compute(data []byte) uint32

Compute returns the CRC of data under model m.

func (Model) Format

func (m Model) Format(v uint32) string

Format renders a CRC value as width-appropriate hex.

Jump to

Keyboard shortcuts

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