Adler<T> Class
Definition
Provides a generic base class for Adler-style checksum algorithms parameterized by the accumulator type.
public abstract class Adler<T> : NonCryptographicHashAlgorithm where T : unmanaged, INumber<T>
Type Parameters
- Inheritance
-
Adler<T>
- Derived
- Inherited Members
- Extension Methods
-
NonCryptographicHashAlgorithmExtensions.ComputeHash(NonCryptographicHashAlgorithm, byte[], int, int)NonCryptographicHashAlgorithmExtensions.TryVerifyHash(NonCryptographicHashAlgorithm, byte[], byte[])NonCryptographicHashAlgorithmExtensions.TryVerifyHash(NonCryptographicHashAlgorithm, byte[], string)NonCryptographicHashAlgorithmExtensions.TryVerifyHash(NonCryptographicHashAlgorithm, Stream, byte[])
Remarks
Adler checksums maintain two accumulators (A and B) and combine them to form the final checksum. Derived classes supply the modulus appropriate to the desired bit width (for example 65521 for Adler-32, or 4294967291 for Adler-64). The core hashing loop provides both a SIMD-accelerated path and a scalar fallback; the SIMD path applies the canonical positionally weighted block recurrence so that both paths produce identical digests for any input.
When to choose Adler. Adler-32 is the canonical checksum used by zlib (RFC 1950) - pick Adler32 any time interoperability with zlib, deflate, or PNG's chunk integrity is required. It is faster than CRC at the cost of weaker error-detection guarantees, and is therefore preferred where throughput matters more than rigorous coverage of burst errors. Adler64 generalizes the construction to 64 bits for very large inputs where the Adler-32 collision floor becomes a concern; Adler32C swaps the prime modulus 65521 for the power-of-two 65536 to enable cheaper modular reductions in vectorized paths - its outputs are not interchangeable with standard Adler-32. For stronger error detection prefer Crc; for hash-table keying prefer MurmurHash3 or CityHash .
Lifecycle and threading. Inherits the standard Append(ReadOnlySpan<byte>) / Reset() / GetCurrentHash() shape; snapshotting is non-destructive. Instances are not thread-safe; share behind explicit synchronization.
important
This algorithm is not cryptographically secure and should not be used for password hashing, digital signatures, or integrity validation in security-sensitive applications.
using Bodu.IO.Hashing.Checksums;
using Bodu.IO.Hashing.Extensions;
// zlib-compatible Adler-32 of a deflate payload.
var adler = new Adler32();
byte[] checksum = adler.ComputeHash(deflateBlock);
Constructors
Adler(int, T)
Initializes a new instance of the Adler<T> class with the specified hash length and modulus.
protected Adler(int hashLengthInBytes, T modulo)
Parameters
hashLengthInBytesintThe digest length, in bytes, produced by the derived algorithm.
moduloTThe modulus applied to the accumulators after each reduction step.
Fields
partA
The A accumulator, initialized to one and updated with each input byte.
protected T partA
Field Value
- T
partB
The B accumulator, which holds the running sum of partA across all processed bytes.
protected T partB
Field Value
- T
Methods
Append(ReadOnlySpan<byte>)
When overridden in a derived class, appends the contents of source to the data already processed for the current hash computation.
public override void Append(ReadOnlySpan<byte> source)
Parameters
sourceReadOnlySpan<byte>The data to process.
Reset()
When overridden in a derived class, resets the hash computation to the initial state.
public override void Reset()
Applies to
| Product | Versions |
|---|---|
| .NET | 8, 10 |