crc.bend checks
raw source on the hub · import bend-osdev-crc@0.1.0.0/crc.bend as Crc
bend-osdev-crc: cyclic redundancy checks, in the Rocksoft parameter model (Ross Williams, "A Painless Guide to CRC Error Detection Algorithms", 1993; the catalogue of parameters at reveng.sourceforge.io).
A CRC is fixed by its width, polynomial (in normal, most-significant-first form), initial register value, bit order, and final XOR. Crc32Spec covers widths 1 to 32 on U32 (below 8, most-significant-first CRCs take their input a bit at a time); Crc64Spec covers width 64 on W64. Every CRC here reads its input bytes in the same order it writes its result (refin = refout), as all the CRCs below do.
The kernel's CRCs as named variants: crc32c (iSCSI, ext4, btrfs), crc16 (the ARC variant: ext4's group descriptors), crc_t10dif (SCSI data integrity), crc64_ecma, crc64_xz and crc64_nvme. crc32 (ISO-HDLC) is here as a cross-check against implementations outside this repository.
3 imports
import Base import bend-osdev-word64@0.1.0.0/word64.bend as W import bend-osdev-bytes@0.1.0.0/bytes.bend as B
Types
type Crc32Spec source · line 20 · raw
Data
Crc32Spec@width:Nat -> @poly:U32 -> @init:U32 -> @reflected:Bool -> @xorout:U32 -> Crc32Spec
type Crc64Spec source · line 23 · raw
Data
Crc64Spec@poly:0x44cf1401f78136bfc15c4c5be1cd20f0/word64.W64 -> @init:0x44cf1401f78136bfc15c4c5be1cd20f0/word64.W64 -> @reflected:Bool -> @xorout:0x44cf1401f78136bfc15c4c5be1cd20f0/word64.W64 -> Crc64Spec
Definitions
def reflect32.go source · line 28 · raw
@n:Nat -> @+x:U32 -> @r:U32 -> U32
def reflect32 source · line 35 · raw
@x:U32 -> @n:Nat -> U32
def reflect64.go source · line 38 · raw
@n:Nat -> @+x:0x44cf1401f78136bfc15c4c5be1cd20f0/word64.W64 -> @r:0x44cf1401f78136bfc15c4c5be1cd20f0/word64.W64 -> 0x44cf1401f78136bfc15c4c5be1cd20f0/word64.W64
def reflect64 source · line 45 · raw
@x:0x44cf1401f78136bfc15c4c5be1cd20f0/word64.W64 -> 0x44cf1401f78136bfc15c4c5be1cd20f0/word64.W64
def r32.pick source · line 50 · raw
@odd:Bool -> @+poly:U32 -> @c:U32 -> U32
def r32.bits source · line 57 · raw
@n:Nat -> @+poly:U32 -> @+c:U32 -> U32
def r32.raw source · line 65 · raw
@xs:List<&2, U32> -> @+poly:U32 -> @c:U32 -> U32
the register after the bytes xs, from register c (poly reflected)
def n32.pick source · line 74 · raw
@top:Bool -> @+poly:U32 -> @+mask:U32 -> @c:U32 -> U32
def n32.bits source · line 81 · raw
@n:Nat -> @+poly:U32 -> @+topbit:U32 -> @+mask:U32 -> @+c:U32 -> U32
def n32.raw source · line 89 · raw
@xs:List<&2, U32> -> @+poly:U32 -> @+shift:Nat -> @+topbit:U32 -> @+mask:U32 -> @c:U32 -> U32
the register after the bytes xs, from register c; shift is width - 8
def s32.pick source · line 100 · raw
@top:Bool -> @+poly:U32 -> @+mask:U32 -> @c:U32 -> U32
def s32.bits source · line 108 · raw
@+n:Nat -> @+poly:U32 -> @+topsh:Nat -> @+mask:U32 -> @+h:U32 -> @+c:U32 -> U32
the bits p - 1 down to 0 of h, into register c
def s32.raw source · line 115 · raw
@xs:List<&2, U32> -> @+poly:U32 -> @+topsh:Nat -> @+mask:U32 -> @c:U32 -> U32
def r64.pick source · line 124 · raw
@odd:Bool -> @+poly:0x44cf1401f78136bfc15c4c5be1cd20f0/word64.W64 -> @c:0x44cf1401f78136bfc15c4c5be1cd20f0/word64.W64 -> 0x44cf1401f78136bfc15c4c5be1cd20f0/word64.W64
def r64.bits source · line 131 · raw
@n:Nat -> @+poly:0x44cf1401f78136bfc15c4c5be1cd20f0/word64.W64 -> @+c:0x44cf1401f78136bfc15c4c5be1cd20f0/word64.W64 -> 0x44cf1401f78136bfc15c4c5be1cd20f0/word64.W64
def r64.raw source · line 138 · raw
@xs:List<&2, U32> -> @+poly:0x44cf1401f78136bfc15c4c5be1cd20f0/word64.W64 -> @c:0x44cf1401f78136bfc15c4c5be1cd20f0/word64.W64 -> 0x44cf1401f78136bfc15c4c5be1cd20f0/word64.W64
def n64.pick source · line 145 · raw
@top:Bool -> @+poly:0x44cf1401f78136bfc15c4c5be1cd20f0/word64.W64 -> @c:0x44cf1401f78136bfc15c4c5be1cd20f0/word64.W64 -> 0x44cf1401f78136bfc15c4c5be1cd20f0/word64.W64
def n64.bits source · line 152 · raw
@n:Nat -> @+poly:0x44cf1401f78136bfc15c4c5be1cd20f0/word64.W64 -> @+c:0x44cf1401f78136bfc15c4c5be1cd20f0/word64.W64 -> 0x44cf1401f78136bfc15c4c5be1cd20f0/word64.W64
def n64.raw source · line 159 · raw
@xs:List<&2, U32> -> @+poly:0x44cf1401f78136bfc15c4c5be1cd20f0/word64.W64 -> @c:0x44cf1401f78136bfc15c4c5be1cd20f0/word64.W64 -> 0x44cf1401f78136bfc15c4c5be1cd20f0/word64.W64
def Crc32Spec.update.msb source · line 170 · raw
@small:Bool -> @+width:Nat -> @poly:U32 -> @c:U32 -> @xs:List<&2, U32> -> U32
most significant bit first: the byte engine for widths of 8 and up, the bit engine below
def Crc32Spec.update.go source · line 180 · raw
@reflected:Bool -> @+width:Nat -> @poly:U32 -> @c:U32 -> @xs:List<&2, U32> -> U32
the register after the bytes xs, from register c, without the final XOR: what a caller that computes a CRC in pieces passes from one piece to the next
def Crc32Spec.update source · line 187 · raw
@spec:Crc32Spec -> @c:U32 -> @o:0x9df7f91779a4a1c215bfa96cd0864601/bytes.Octets -> U32
def Crc32Spec.start.go source · line 193 · raw
@reflected:Bool -> @init:U32 -> @width:Nat -> U32
the register a CRC starts from
def Crc32Spec.start source · line 200 · raw
@spec:Crc32Spec -> U32
def Crc32Spec.finish source · line 205 · raw
@spec:Crc32Spec -> @c:U32 -> U32
def Crc32Spec.compute source · line 210 · raw
@+spec:Crc32Spec -> @xs:0x9df7f91779a4a1c215bfa96cd0864601/bytes.Octets -> U32
def Crc64Spec.update.go source · line 213 · raw
@reflected:Bool -> @poly:0x44cf1401f78136bfc15c4c5be1cd20f0/word64.W64 -> @c:0x44cf1401f78136bfc15c4c5be1cd20f0/word64.W64 -> @xs:List<&2, U32> -> 0x44cf1401f78136bfc15c4c5be1cd20f0/word64.W64
def Crc64Spec.update source · line 220 · raw
@spec:Crc64Spec -> @c:0x44cf1401f78136bfc15c4c5be1cd20f0/word64.W64 -> @o:0x9df7f91779a4a1c215bfa96cd0864601/bytes.Octets -> 0x44cf1401f78136bfc15c4c5be1cd20f0/word64.W64
def Crc64Spec.start.go source · line 225 · raw
@reflected:Bool -> @init:0x44cf1401f78136bfc15c4c5be1cd20f0/word64.W64 -> 0x44cf1401f78136bfc15c4c5be1cd20f0/word64.W64
def Crc64Spec.start source · line 232 · raw
@spec:Crc64Spec -> 0x44cf1401f78136bfc15c4c5be1cd20f0/word64.W64
def Crc64Spec.finish source · line 237 · raw
@spec:Crc64Spec -> @c:0x44cf1401f78136bfc15c4c5be1cd20f0/word64.W64 -> 0x44cf1401f78136bfc15c4c5be1cd20f0/word64.W64
def Crc64Spec.compute source · line 242 · raw
@+spec:Crc64Spec -> @xs:0x9df7f91779a4a1c215bfa96cd0864601/bytes.Octets -> 0x44cf1401f78136bfc15c4c5be1cd20f0/word64.W64
def crc32c.spec source · line 248 · raw
Crc32Spec
CRC-32C (Castagnoli): poly 0x1EDC6F41
def crc32.spec source · line 252 · raw
Crc32Spec
CRC-32 (ISO-HDLC, as zlib and Ethernet): poly 0x04C11DB7
def crc16.spec source · line 256 · raw
Crc32Spec
CRC-16/ARC (the kernel's crc16): poly 0x8005
def crc_t10dif.spec source · line 260 · raw
Crc32Spec
CRC-16/T10-DIF: poly 0x8BB7
def crc64_ecma.spec source · line 264 · raw
Crc64Spec
CRC-64/ECMA-182: poly 0x42F0E1EBA9EA3693, most significant bit first
def crc64_xz.spec source · line 268 · raw
Crc64Spec
CRC-64/XZ: the same polynomial, reflected, as the XZ format's check
def crc64_nvme.spec source · line 272 · raw
Crc64Spec
CRC-64/NVME: poly 0xAD93D23594C93659
def crc4_itu.spec source · line 276 · raw
Crc32Spec
CRC-4/G-704 (CRC-4/ITU): poly 0x3, reflected
def crc7_mmc.spec source · line 280 · raw
Crc32Spec
CRC-7/MMC (SD/MMC commands): poly 0x09
def crc8_smbus.spec source · line 284 · raw
Crc32Spec
CRC-8/SMBUS: poly 0x07
def crc8_itu.spec source · line 288 · raw
Crc32Spec
CRC-8/I-432-1 (CRC-8/ITU, ATM HEC): poly 0x07, xorout 0x55
def crc8_maxim.spec source · line 292 · raw
Crc32Spec
CRC-8/MAXIM-DOW (Dallas/Maxim 1-Wire): poly 0x31, reflected
def crc8_dvb_s2.spec source · line 296 · raw
Crc32Spec
CRC-8/DVB-S2: poly 0xD5
def crc8_autosar.spec source · line 300 · raw
Crc32Spec
CRC-8/AUTOSAR: poly 0x2F, init 0xFF, xorout 0xFF
def crc16_kermit.spec source · line 304 · raw
Crc32Spec
CRC-16/KERMIT (CRC-16/CCITT, the kernel's crc_ccitt): poly 0x1021, reflected
def crc16_ccitt_false.spec source · line 308 · raw
Crc32Spec
CRC-16/IBM-3740 (CRC-16/CCITT-FALSE): poly 0x1021, init 0xFFFF
def crc16_xmodem.spec source · line 312 · raw
Crc32Spec
CRC-16/XMODEM (CRC-16/ITU-T, the kernel's crc_itu_t): poly 0x1021
def crc32c source · line 315 · raw
@xs:0x9df7f91779a4a1c215bfa96cd0864601/bytes.Octets -> U32
def crc32 source · line 318 · raw
@xs:0x9df7f91779a4a1c215bfa96cd0864601/bytes.Octets -> U32
def crc16 source · line 321 · raw
@xs:0x9df7f91779a4a1c215bfa96cd0864601/bytes.Octets -> U32
def crc_t10dif source · line 324 · raw
@xs:0x9df7f91779a4a1c215bfa96cd0864601/bytes.Octets -> U32
def crc64_ecma source · line 327 · raw
@xs:0x9df7f91779a4a1c215bfa96cd0864601/bytes.Octets -> 0x44cf1401f78136bfc15c4c5be1cd20f0/word64.W64
def crc64_xz source · line 330 · raw
@xs:0x9df7f91779a4a1c215bfa96cd0864601/bytes.Octets -> 0x44cf1401f78136bfc15c4c5be1cd20f0/word64.W64
def crc64_nvme source · line 333 · raw
@xs:0x9df7f91779a4a1c215bfa96cd0864601/bytes.Octets -> 0x44cf1401f78136bfc15c4c5be1cd20f0/word64.W64
def crc4_itu source · line 336 · raw
@xs:0x9df7f91779a4a1c215bfa96cd0864601/bytes.Octets -> U32
def crc7_mmc source · line 339 · raw
@xs:0x9df7f91779a4a1c215bfa96cd0864601/bytes.Octets -> U32
def crc8_smbus source · line 342 · raw
@xs:0x9df7f91779a4a1c215bfa96cd0864601/bytes.Octets -> U32
def crc8_itu source · line 345 · raw
@xs:0x9df7f91779a4a1c215bfa96cd0864601/bytes.Octets -> U32
def crc8_maxim source · line 348 · raw
@xs:0x9df7f91779a4a1c215bfa96cd0864601/bytes.Octets -> U32
def crc8_dvb_s2 source · line 351 · raw
@xs:0x9df7f91779a4a1c215bfa96cd0864601/bytes.Octets -> U32
def crc8_autosar source · line 354 · raw
@xs:0x9df7f91779a4a1c215bfa96cd0864601/bytes.Octets -> U32
def crc16_kermit source · line 357 · raw
@xs:0x9df7f91779a4a1c215bfa96cd0864601/bytes.Octets -> U32
def crc16_ccitt_false source · line 360 · raw
@xs:0x9df7f91779a4a1c215bfa96cd0864601/bytes.Octets -> U32
def crc16_xmodem source · line 363 · raw
@xs:0x9df7f91779a4a1c215bfa96cd0864601/bytes.Octets -> U32