silk.compress.checksum.

CRC-32, Adler-32, and CRC-64 checksums used by gzip, zlib, ZIP, and XZ containers.

When to use#

Use CompressionChecksum.crc32 for gzip and ZIP, CompressionChecksum.adler32 for zlib, and CompressionChecksum.crc64 for XZ. Use the Update functions to checksum data that arrives in parts.

Details#

No function allocates. CRC-32 folds 64 or 128 bytes per step with carry-less multiplication when the running CPU has it (pclmul on x86-64, aes on AArch64), and otherwise reads eight table entries per 8 bytes. Both paths return the same value.

Import as CompressionChecksum with import silk.compress.checksum { CompressionChecksum }.

Public declarations: 1.

CompressionChecksum#

silk
pub struct CompressionChecksum

Allocation-free container checksums.

Implementation CompressionChecksum#

silk
impl CompressionChecksum

Associated function crc32#

silk
pub fn crc32(bytes: &[u8]) -> u32

Returns the reflected IEEE CRC-32 of bytes, as gzip and ZIP store it.

Associated function crc32Update#

silk
pub fn crc32Update(crc: u32, bytes: &[u8]) -> u32

Returns the CRC-32 of the data that crc covers followed by bytes.

Details#

Pass 0 for the first part, then the result of the previous call. The result is the finished checksum of everything so far, as zlib's crc32 returns it, so crc32Update(crc32(a), b) equals the CRC-32 of a followed by b.

Associated function adler32#

silk
pub fn adler32(bytes: &[u8]) -> u32

Returns the Adler-32 of bytes, as zlib stores it.

Associated function adler32Update#

silk
pub fn adler32Update(adler: u32, bytes: &[u8]) -> u32

Returns the Adler-32 of the data that adler covers followed by bytes.

Details#

Pass 1 for the first part, then the result of the previous call, as with zlib's adler32. The sums are reduced once per 5552 bytes, the most that cannot overflow 32 bits.

Associated function crc64#

silk
pub fn crc64(bytes: &[u8]) -> u64

Returns the CRC-64/XZ checksum of the supplied bytes.

Category: Data formats.

Profiles: aarch64-apple-darwin, aarch64-unknown-linux-gnu, aarch64-unknown-linux-gnu-no-libc, x86_64-unknown-linux-gnu, x86_64-unknown-linux-gnu-no-libc, wasm32-unknown-unknown, wasm32-wasip1, wasm32-wasip2, x86_64-pc-windows-msvc, wasm64-unknown-unknown.

View the source of this page