Table of Contents

Bodu.IO.Hashing Namespace

Package

Bodu.IO.Hashing

Purpose

Bodu.IO.Hashing is a focused library of non-cryptographic hashes, checksums, and check digits built on the BCL NonCryptographicHashAlgorithm contract. It covers three subfamilies: fingerprints (FNV, CityHash, MurmurHash3, Pearson, classic string hashes), checksums (the full CRC RevEng catalogue at widths 1-64 bits, Fletcher 16/32/64, Adler 32/32C/64), and check digits (Luhn, Damm, Verhoeff, EAN/GTIN/UPC, ISIN, ABA routing, plus the alphanumeric and multi-character identifier schemes such as ISBN, IBAN, LEI, SEDOL, and CUSIP).

Reach for this library when you need a fast, deterministic checksum for error detection, file integrity, framing, fingerprinting, or human-typed identifier validation - and when you want the result to drop straight into any API that accepts NonCryptographicHashAlgorithm. If you need cryptographic integrity (against an active attacker, not just noise on the wire), see Bodu.Security.Cryptography instead.

BCL note. XxHash32, XxHash64, XxHash3, and XxHash128 already ship in System.IO.Hashing from .NET 6 onwards - Bodu does not duplicate them. Use the BCL types directly when you want xxHash.

Static documentation

Key types

Fingerprints - Bodu.IO.Hashing

Checksums - Bodu.IO.Hashing.Checksums

  • Crc - the single CRC engine. Configured with a CrcStandard, it handles widths from 1 to 64 bits, honors polynomial, initial value, input / output reflection, and final XOR, and ships with a shared lookup-table cache.
  • CrcStandard - an immutable parameter set: name, width, polynomial, initial value, reflect-in, reflect-out, XOR-out. Exposes common standards as named properties (CRC32_ISOHDLC, CRC32_ISCSI, CRC16_MODBUS, CRC64_XZ, …) and provides FromName / TryFromName over canonical names and published aliases.
  • CrcStandards - an enum covering every canonical CRC RevEng entry (112 standards as of the last catalogue fetch).
  • CrcLookupTableCache - thread-safe cache of 256-entry lookup tables, keyed by (width, polynomial, reflect-in), shared process-wide through GlobalCache.
  • CrcLookupTableBuilder - builds a lookup table from parameters; used by the cache on first miss.
  • Fletcher16 / Fletcher32 / Fletcher64 - twin-accumulator position-dependent checksums.
  • Adler32 / Adler32C / Adler64 - Adler-32 (canonical zlib), Adler-32C (SIMD), Adler-64; over the shared Adler32Base / Adler64Base abstract bases.

Check digits - Bodu.IO.Hashing.CheckDigits

Extensions - Bodu.IO.Hashing.Extensions

Example

using System.Text;
using Bodu.IO.Hashing;
using Bodu.IO.Hashing.Checksums;

byte[] data = Encoding.UTF8.GetBytes("the quick brown fox");

// CRC-32/ISO-HDLC - the canonical zlib / PNG / Ethernet CRC.
using var crc = new Crc(CrcStandard.CRC32_ISOHDLC);
crc.Append(data);
string crc32 = Convert.ToHexString(crc.GetCurrentHash());

// Fletcher-32 - position-dependent, drops into anything that takes a NonCryptographicHashAlgorithm.
using var fletcher = new Fletcher32();
fletcher.Append(data);
string fl32 = Convert.ToHexString(fletcher.GetCurrentHash());

// Resume a CRC from a previously stored digest and keep hashing.
byte[] previous = crc.GetCurrentHash();
byte[] combined = crc.ComputeHashFrom(previous, Encoding.UTF8.GetBytes(" jumps over"));

Notes

  • Not cryptographically secure. Every algorithm here is designed for error detection and hash-table distribution, not authentication. An attacker who can choose the input can trivially forge the output. Pair with a MAC or signature if integrity against an adversary matters - see SipHash64 for a keyed short-input hash, or System.Security.Cryptography.SHA256 for a full cryptographic digest.
  • Shared lookup tables. Crc instances with identical (width, polynomial, reflect-in) triples share a single 256-entry lookup table through GlobalCache. Constructing a hundred Crc(CrcStandard.CRC32_ISOHDLC) instances allocates one table, not a hundred.
  • Non-destructive GetCurrentHash. Calling NonCryptographicHashAlgorithm.GetCurrentHash snapshots the accumulator and applies the final reflect / XOR / width-mask on the copy, so in-progress hashing is not disturbed. Call it as many times as you like.
  • Resumable. Crc, the FNV family, the Fletcher family, and the Adler family implement IResumableHashAlgorithm - reverse-finalize a stored digest, append further data, re-finalize. Handy for chunked streams where re-reading earlier bytes is expensive.
  • Determinism and portability. All algorithms produce identical byte-for-byte output across platforms and architectures for the same input and configuration.
  • See also: the Using CRC and Using Fletcher guides, the full CRC catalogue, and the Bodu.IO.Hashing introduction.

Namespaces

Bodu.IO.Hashing.CheckDigits
Bodu.IO.Hashing.Checksums
Bodu.IO.Hashing.Extensions

Classes

ApHash

Computes a 32-bit non-cryptographic hash using Arash Partow's APHash algorithm, which alternates XOR mixing patterns based on input byte-index parity. This class cannot be inherited.

BKDR

Computes a 32-bit non-cryptographic hash using the BKDR polynomial rolling algorithm from Kernighan and Ritchie's "The C Programming Language". This class cannot be inherited.

Bernstein

Computes a 32-bit non-cryptographic hash using Daniel J. Bernstein's djb2 algorithm, optionally using the XOR-modified variant. This class cannot be inherited.

BlockNonCryptographicHashAlgorithm

Base class for non-cryptographic hash algorithms whose internal state advances one fixed-size block at a time - handles residual buffering, block alignment, total-length tracking, snapshot-based GetCurrentHash, and optional final-block padding so that derived implementations only need to express the per-block compression step.

CityHash

Base class for the CityHash family of non-cryptographic hash algorithms developed by Google. See the CityHash reference repository for the specification.

CityHash128

Computes a 128-bit (16-byte) non-cryptographic hash using the CityHash128 variant by Google. This class cannot be inherited.

CityHash32

Computes a 32-bit (4-byte) non-cryptographic hash using the CityHash32 variant by Google. This class cannot be inherited.

CityHash64

Computes a 64-bit (8-byte) non-cryptographic hash using the CityHash64 variant by Google. This class cannot be inherited.

Elf64

Computes a 64-bit non-cryptographic hash using the ELF (Executable and Linkable Format) hash algorithm originally used in UNIX System V object files. This class cannot be inherited.

Fnv

Provides a base class for the Fowler-Noll-Vo (FNV) hash family, supporting both the FNV-1 and FNV-1a variants at 32-bit and 64-bit widths.

Fnv132

Computes the hash for the input data using the FNV-1 32-bit hash algorithm. This class cannot be inherited.

Fnv164

Computes the hash for the input data using the FNV-1 64-bit hash algorithm. This class cannot be inherited.

Fnv1a32

Computes the hash for the input data using the FNV-1a 32-bit hash algorithm. This class cannot be inherited.

Fnv1a64

Computes the hash for the input data using the FNV-1a 64-bit hash algorithm. This class cannot be inherited.

HashingStream

Provides a pass-through Stream that feeds every byte read from or written to an inner stream into a NonCryptographicHashAlgorithm, so a digest can be computed while data is being transferred.

JSHash

Computes a 32-bit non-cryptographic hash using Justin Sobel's JSHash bitwise mixing function. This class cannot be inherited.

MurmurHash3

Base class for the MurmurHash3 family of non-cryptographic hash algorithms by Austin Appleby. See the SMHasher reference repository for the specification.

MurmurHash3_128

Computes a 128-bit (16-byte) non-cryptographic hash using the MurmurHash3_x64_128 variant by Austin Appleby, optimized for 64-bit platforms. This class cannot be inherited.

MurmurHash3_32

Computes a 32-bit (4-byte) non-cryptographic hash using the MurmurHash3_x86_32 variant by Austin Appleby. This class cannot be inherited.

Pearson

Computes the hash for the input data using the Pearson hash algorithm. This variant applies a non-cryptographic permutation-based transformation using a 256-byte lookup table to produce compact hash values. This class cannot be inherited.

Pjw32

Computes a 32-bit non-cryptographic hash using Peter J. Weinberger's PJW shift-and-fold algorithm (as described in the "Dragon Book"). This class cannot be inherited.

SDBM

Computes a 32-bit non-cryptographic hash using the SDBM algorithm popularized by the public-domain NDBM database library. This class cannot be inherited.

SuperFastHash

Computes a 32-bit non-cryptographic hash using Paul Hsieh's SuperFastHash algorithm, intended for hash-table keying. This class cannot be inherited.

Interfaces

IResumableHashAlgorithm

Marks a non-cryptographic hash algorithm whose internal state can be reconstructed from a previously emitted digest, so additional input can be folded into an existing hash without re-reading the bytes that produced it.

Enums

Pearson.PearsonTableType

Defines the available permutation table presets that can be used with the Pearson hashing algorithm.