Skip to main content

Module checksum

Module checksum 

Source
Expand description

Checksums for the delta engine.

Two layers, exactly as in the rsync algorithm:

  • a weak rolling checksum (RollingChecksum) that is cheap to compute and O(1) to slide one byte along a buffer, used to cheaply reject non-matching windows; and
  • a strong hash (strong_hash) — the first 16 bytes of a BLAKE3 digest — used to confirm a candidate match found via the weak checksum.

§Rolling checksum definition

With modulus M = 65536 and a window of length L:

a = (Σ_k          bytes[k]) mod M
b = (Σ_k (L - k) * bytes[k]) mod M       // position-weighted, k = 0..L
checksum = a + b * M

Because M = 2^16, reducing modulo M is the same as masking the low 16 bits, and ordinary wrapping (mod 2^32) arithmetic is congruent modulo M. We therefore accumulate with wrapping u32 ops and mask only when reading the value out — this keeps rolling branch-free and exact.

Structs§

RollingChecksum
Rolling weak checksum over a fixed-length window.

Constants§

STRONG_LEN
Length of the strong hash prefix kept per block, in bytes.

Functions§

strong_hash
Strong hash of data: the first STRONG_LEN bytes of its BLAKE3 digest.

Type Aliases§

StrongHash
A 16-byte strong hash (BLAKE3 prefix).