Table of Contents

Adler32Base Class

Definition

Namespace
Bodu.IO.Hashing.Checksums
Assembly
Bodu.IO.Hashing.dll
Package
Bodu.IO.Hashing 1.0.0
Source
Adler.Adler32Base.cs

Provides a reusable base class for Adler-32 style checksum algorithms using uint accumulators.

public abstract class Adler32Base : Adler<uint>, IResumableHashAlgorithm
Inheritance
Adler32Base
Implements
Derived
Inherited Members
Extension Methods

Examples

// Consume through a concrete derivative - the shared 32-bit finalization layout
// is identical across every Adler32Base subclass.
Adler32Base hash = new Adler32();                 // modulus 65521 (the canonical Adler-32)
hash.Append("Wikipedia"u8);
byte[] digest = hash.GetCurrentHash();            // 0x11E60398 in big-endian byte order

Remarks

Finalization combines the A and B accumulators into a 32-bit hash as (B << 16) | A, written in big-endian byte order.

Derived classes such as Adler32 and Adler32C supply different moduli (65521 or 65536) depending on performance or compatibility needs.

Constructors

Adler32Base(uint)

Initializes a new instance of the Adler32Base class with the specified modulus.

protected Adler32Base(uint modulo)

Parameters

modulo uint

The modulus applied to the accumulators after each reduction step.

Methods

GetCurrentHashCore(Span<byte>)

When overridden in a derived class, writes the computed hash value to destination without modifying accumulated state.

protected override void GetCurrentHashCore(Span<byte> destination)

Parameters

destination Span<byte>

The buffer that receives the computed hash value.

TryComputeHashFrom(ReadOnlySpan<byte>, ReadOnlySpan<byte>, Span<byte>, out int)

Resumes a hash computation from a previously finalized hash value, processes additional input, and writes the new finalized hash to the specified destination span.

public bool TryComputeHashFrom(ReadOnlySpan<byte> previousHash, ReadOnlySpan<byte> newData, Span<byte> destination, out int bytesWritten)

Parameters

previousHash ReadOnlySpan<byte>

The previously finalized hash value to resume from.

newData ReadOnlySpan<byte>

The additional input data to include in the resumed hash calculation.

destination Span<byte>

The destination buffer to write the finalized hash value to.

bytesWritten int

Outputs the number of bytes written to the destination buffer.

Returns

bool

true if the resumed and finalized hash was written successfully; otherwise, false if the destination span was too small.

Remarks

Adler digests carry the complete accumulator state ((B << 16) | A, big-endian), so resuming requires no finalization reversal: the halves seed the accumulators directly. The computation runs against saved-and-restored instance state, so any in-progress incremental state on the instance survives the call unchanged.

Exceptions

ArgumentException

Thrown if the previousHash length does not match HashLengthInBytes.

Explicit Interface Implementations

IResumableHashAlgorithm.get_HashLengthInBytes()

int IResumableHashAlgorithm.get_HashLengthInBytes()

Returns

int

Applies to

ProductVersions
.NET8, 10