Class ChecksumCRC16
CRC-16-CCITT checksum algorithm implementation using the generator polynomial
x^16 + x^12 + x^5 + 1 (hex: 0x1021). Produces a 16-bit cyclic
redundancy check value suitable for protocol and packet integrity verification.
Implements
Inherited Members
Namespace: Scylla.Core.Util.Checksum
Assembly: ScyllaCore.dll
Syntax
public sealed class ChecksumCRC16 : IChecksum
Remarks
Algorithm details:
- Polynomial (normal representation):
0x1021- the CCITT / CRC-CCITT polynomial. - Initial value:
0xFFFF(all ones), matching the XMODEM and CRC-B variants. - Input / output reflection: none (non-reflected, big-endian bit order).
- Final XOR: none; the accumulated CRC register is returned as-is.
- Output width: 16 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:
- Serial communication protocols: HDLC, X.25, XMODEM.
- Wireless and embedded protocols: Bluetooth, SD card, DNP3.
- Small data packet integrity checks where a 16-bit result is sufficient.
Comparison with CRC-32: CRC-16 produces a 16-bit result (65,536 possible values) versus CRC-32's 32-bit result (~4 billion values). It is faster and more compact but has a higher probability of undetected errors for large messages. For file integrity or application data checksums, prefer ChecksumCRC32.
Security note: CRC-16 is NOT cryptographically secure. For security-sensitive hashing use the Scylla Crypto module instead.
Properties
Value
Gets the current CRC-16-CCITT checksum value.
Declaration
public long Value { get; }
Property Value
| Type | Description |
|---|---|
| long | A non-negative |
Methods
Reset()
Resets the CRC-16-CCITT checksum to its initial state (0xFFFF),
discarding any previously processed data.
Declaration
public void Reset()
Remarks
After calling Reset, Value returns 0xFFFF. 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-16-CCITT 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-16-CCITT 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 using a single table lookup into the precomputed
_table array: crc = table[(crc >> 8) ^ byte] ^ (crc << 8).
Multiple calls accumulate into the same CRC register and produce the same final
result as a single call with the concatenated input.