Bodu.IO.Hashing.Checksums Namespace
- Package
-
Bodu.IO.Hashing 1.0.0
Purpose
Bodu.IO.Hashing.Checksums ships the cyclic redundancy check (CRC) catalogue from the RevEng project - every variant from CRC-1 through CRC-64, addressable by name. The catalogue is auto-generated; the consumer-facing surface is the immutable CrcStandard parameter set, used as a parameter to Crc. The namespace also hosts the twin-accumulator checksums (Fletcher, Adler) and the CRC lookup-table machinery.
Key types
- Crc - the CRC engine, configured with a
CrcStandard. - CrcStandard - a sealed, immutable CRC parameter set:
Name,Size,Polynomial,InitialValue,ReflectIn,ReflectOut,XOrOut. Common standards are exposed as static properties (CRC32_ISOHDLC,CRC16_MODBUS, …); every catalogue entry is reachable throughGet(CrcStandards)andFromName/TryFromName; custom variants come from the public constructor. - CrcStandards - the enum naming every canonical catalogue entry.
- CrcLookupTableBuilder / CrcLookupTableCache - lookup-table construction and the process-wide cache shared by every
Crcwith the same (width, polynomial, reflect-in) triple. - Fletcher16 / Fletcher32 / Fletcher64 and Adler32 / Adler32C / Adler64 - the twin-accumulator checksums.
Example
using Bodu.IO.Hashing;
using Bodu.IO.Hashing.Checksums;
// CRC-32 (the standard variant used by Ethernet, ZIP, PNG).
var crc32 = new Crc(CrcStandard.CRC32_ISOHDLC);
ReadOnlySpan<byte> data = "123456789"u8;
crc32.Append(data);
byte[] digest = crc32.GetCurrentHash();
// 0xCBF43926 - the canonical CRC-32 check value
Notes
- Auto-generated catalogue. The standards are produced from the RevEng database; consumers reference them by name (
CrcStandard.CRC32_ISOHDLC,CrcStandard.CRC16_MODBUS, …) rather than constructing the configuration manually. - Resumable.
Crc, the Fletcher family, and the Adler family implement IResumableHashAlgorithm -ComputeHashFromreverse-finalizes a previously stored digest, appends more bytes, and finalizes again, without re-reading the original input. (Plain multi-Appendstreaming needs no special contract; every algorithm supports it.) - See also: the CRC guide, the CRC catalogue guide, and the parent Bodu.IO.Hashing landing page.
Classes
- Adler32
Computes the zlib-compatible
Adler-32checksum of the input data using the standard modulus 65521. This class cannot be inherited.
- Adler32Base
Provides a reusable base class for
Adler-32style checksum algorithms using uint accumulators.
- Adler32C
Computes a 32-bit Adler-style checksum using the power-of-two modulus 65536 for SIMD-friendly alignment. This class cannot be inherited.
- Adler64
Computes a 64-bit Adler-style checksum using the prime modulus 4294967291. This class cannot be inherited.
- Adler64Base
Provides a reusable base class for
Adler-64style checksum algorithms using ulong accumulators.
- Adler<T>
Provides a generic base class for Adler-style checksum algorithms parameterized by the accumulator type.
- Crc
General-purpose CRC (Cyclic Redundancy Check) engine driven by a CrcStandard parameter set - supports any catalogue width from 1 to 64 bits, snapshot-style intermediate digests, and resumption of a previous digest with additional input.
- CrcLookupTableBuilder
Generates the precomputed lookup tables that drive the byte-at-a-time inner loop of Crc, given the width, polynomial, and input-reflection mode of a CrcStandard.
- CrcLookupTableCache
Thread-safe cache of precomputed CRC lookup tables keyed by width, polynomial, and input reflection - amortizes the per-tuple build cost of BuildLookupTable(int, ulong, bool) across every Crc instance that uses the same CrcStandard.
- CrcStandard
Immutable parameter bundle that fully describes a CRC variant - width, polynomial, initial value, input/output bit reflection, and final XOR - and serves as the lookup key into the RevEng catalogue used by Crc.
- Fletcher
Provides a base class for the Fletcher checksum family (Fletcher-16, Fletcher-32, Fletcher-64).
- Fletcher16
Computes the hash for the input data using the
Fletcher-16hash algorithm. This variant performs a non-cryptographic checksum calculation using two 8-bit accumulators to detect errors in small byte sequences. This class cannot be inherited.
- Fletcher32
Computes the hash for the input data using the
Fletcher-32hash algorithm. This variant performs a non-cryptographic checksum calculation using two 16-bit accumulators to efficiently detect errors in byte sequences. This class cannot be inherited.
- Fletcher64
Computes the hash for the input data using the
Fletcher-64hash algorithm. This variant performs a non-cryptographic checksum calculation using two 32-bit accumulators to efficiently detect errors in byte sequences. This class cannot be inherited.
Enums
- CrcStandards
Identifies a CRC parameter set defined in the CRC RevEng catalogue. Pass to Get(CrcStandards) to materialise the corresponding CrcStandard on demand.