Class ChecksumAdler32
Adler-32 checksum algorithm implementation, compatible with the zlib standard (RFC 1950). Produces a 32-bit checksum by maintaining two running sums over the input bytes.
Implements
Inherited Members
Namespace: Scylla.Core.Util.Checksum
Assembly: ScyllaCore.dll
Syntax
public sealed class ChecksumAdler32 : IChecksum
Remarks
Adler-32 was designed by Mark Adler as part of the zlib compression library.
It operates on two 16-bit accumulators, s1 (initialized to 1) and
s2 (initialized to 0). For each input byte b:
s1 = (s1 + b) mod 65521s2 = (s2 + s1) mod 65521
The final checksum is the 32-bit value (s2 << 16) | s1, which is also
the value exposed via Value.
The modulus 65521 is the largest prime smaller than 2^16, chosen to maximize error-detection ability while keeping the accumulators within 32-bit arithmetic. Modulo reduction is deferred and applied once per block of up to 5552 bytes for maximum throughput.
Characteristics:
- Output width: 32 bits.
- Speed: faster than CRC-32 due to simple integer arithmetic with deferred modulo.
- Error detection: weaker than CRC-32 for short messages and certain error patterns such as transpositions of adjacent bytes or short zero-length messages.
- Standards: used in zlib (RFC 1950) and PNG image format headers.
When to use Adler-32 over CRC-32: prefer Adler-32 when you need zlib interoperability or slightly higher throughput on modern CPUs and error detection strength is not a primary concern. Use ChecksumCRC32 when maximum reliability or ZIP/GZip format compatibility is required.
Security note: Adler-32 is NOT cryptographically secure and must not be used for tamper detection or authentication. For security-sensitive hashing use the Scylla Crypto module instead.
Properties
Value
Gets the current Adler-32 checksum value as the standard 32-bit composite
(s2 << 16) | s1.
Declaration
public long Value { get; }
Property Value
| Type | Description |
|---|---|
| long | A non-negative |
Methods
Reset()
Resets the Adler-32 checksum to its zlib-standard initial state
(s1 = 1, s2 = 0), discarding any previously processed data.
Declaration
public void Reset()
Remarks
After calling Reset, Value returns 1 and subsequent
Update(byte[]) calls begin a fresh computation. This allows the same
ChecksumAdler32 instance to be reused across multiple independent
checksum operations without allocating a new object.
Update(byte[])
Updates the Adler-32 checksum by incorporating all bytes in buffer.
Declaration
public void Update(byte[] buffer)
Parameters
| Type | Name | Description |
|---|---|---|
| byte[] | buffer | The byte array to process. If |
Update(byte[], int, int)
Updates the Adler-32 checksum by incorporating count bytes
from buffer starting at offset.
Declaration
public void Update(byte[] buffer, int offset, int count)
Parameters
| Type | Name | Description |
|---|---|---|
| byte[] | buffer | The source byte array. If |
| int | offset | Zero-based index of the first byte to read in |
| int | count | Number of bytes to incorporate. Must not cause |
Remarks
Bytes are processed in blocks of up to NMAX (5552) bytes. Within each
block the accumulators are updated without a modulo operation; modulo reduction
is applied once per block boundary to maintain correctness while maximising
throughput. Multiple calls to this method produce the same final checksum as a
single call with the concatenated data.