Table of Contents

Adler64Base Class

Definition

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

Provides a reusable base class for Adler-64 style checksum algorithms using ulong accumulators.

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

Examples

// Consume through a concrete derivative - the shared 64-bit finalization layout
// is identical across every Adler64Base subclass.
Adler64Base hash = new Adler64();
hash.Append("Wikipedia"u8);
byte[] digest = hash.GetCurrentHash();   // big-endian (B << 32) | A

Remarks

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

Constructors

Adler64Base(ulong)

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

protected Adler64Base(ulong modulo)

Parameters

modulo ulong

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 << 32) | 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