crc

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2026 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Overview

Package crc provides parameterized CRC computation and recovery of CRC parameters from sample (data, crc) frames — the kind of task that comes up identifying the framing/FEC check on an unfamiliar RF protocol. It generalizes the fixed CRC-16/GSM already used by the P25 alias framing.

Index

Constants

This section is empty.

Variables

View Source
var CRC16GSM = Params{Width: 16, Poly: 0x1021, Init: 0x0000, RefIn: false, RefOut: false, XorOut: 0xFFFF}

CRC16GSM is the catalogued CRC used by the P25 alias framing, provided so recovery tests and callers have a known reference.

Functions

This section is empty.

Types

type Params

type Params struct {
	Width  int    // 1..64
	Poly   uint64 // generator polynomial (normal form, MSB-first)
	Init   uint64 // register initial value
	RefIn  bool   // reflect each input byte
	RefOut bool   // reflect the final register before XorOut
	XorOut uint64 // final XOR
}

Params is a fully-specified Rocksoft/RevEng-model CRC.

func Recover

func Recover(samples []Sample, widths []int) ([]Params, error)

Recover searches for CRC parameters consistent with every sample. It brute-forces the polynomial and the two reflect flags for each candidate width, using an init/xorout-invariant equal-length test to cull polynomials cheaply, then resolves Init/XorOut and verifies the full model against all samples.

Init recovery is exact when the corpus mixes message lengths; for a single length, Init and XorOut are mathematically entangled, so the canonical solution Init=0 with the implied XorOut is returned (it reproduces every sample of that length). widths defaults to {16} and recovery brute-forces only widths ≤ 24 (a 2^24 poly sweep) — wider CRCs need a supplied poly.

func (Params) Compute

func (p Params) Compute(data []byte) uint64

Compute returns the CRC of data under p.

type Sample

type Sample struct {
	Data []byte
	CRC  uint64
}

Sample is one observed (message, crc) pair.

Jump to

Keyboard shortcuts

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