Class ChecksumCRC32
CRC-32 checksum algorithm implementation using the standard IEEE 802.3 generator polynomial. Produces the same 32-bit result as the CRC used in Ethernet, GZip, ZIP, PNG, and many other widespread formats.
Implements
Inherited Members
Namespace: Scylla.Core.Util.Checksum
Assembly: ScyllaCore.dll
Syntax
public sealed class ChecksumCRC32 : IChecksum
Remarks
Algorithm details:
- Polynomial (reflected representation):
0xEDB88320, which is the bit-reversal of the normal form0x04C11DB7(IEEE 802.3). - Initial value:
0xFFFFFFFF(all ones). - Input / output reflection: reflected (least-significant bit first).
- Final XOR:
0xFFFFFFFF, applied automatically in Value. - Output width: 32 bits.
Lookup-table acceleration is used: the 256-entry table is computed once at class initialisation and shared across all instances via a static field.
Common use cases:
- File integrity verification (ZIP, GZip, PNG checksums).
- Data transmission and networking error detection (Ethernet IEEE 802.3).
- Save game and asset cache validation.
- Any situation requiring a well-known, interoperable 32-bit checksum.
Comparison with other algorithms: CRC-32 offers strong error detection for all single-bit, double-bit, odd-count bit errors, and burst errors up to 32 bits. It is somewhat slower than ChecksumAdler32 but more reliable for short messages. For very high throughput requirements on 64-bit platforms, consider ChecksumXXHash64.
Security note: CRC-32 is NOT cryptographically secure. For security-sensitive hashing use the Scylla Crypto module instead.
Properties
Value
Gets the current CRC-32 checksum value with the standard final XOR applied.
Declaration
public long Value { get; }
Property Value
| Type | Description |
|---|---|
| long | A non-negative |
Methods
Reset()
Resets the CRC-32 checksum to its standard initial state
(internal register = 0xFFFFFFFF), discarding any previously processed data.
Declaration
public void Reset()
Remarks
After calling Reset, Value returns 0 (the result of
0xFFFFFFFF ^ 0xFFFFFFFF). Subsequent Update(byte[]) calls begin a
fresh CRC computation. Use this to reuse the same instance for multiple independent
checksums without allocating a new object.
Update(byte[])
Updates the CRC-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 CRC-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 process. Must not cause |
Remarks
Each byte is processed with a single table lookup:
_crc = table[(_crc ^ byte) & 0xFF] ^ (_crc >> 8). Multiple calls
accumulate into the same CRC register; the final result is equivalent to processing
the entire concatenated input in a single call.