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#
pub struct CompressionChecksumAllocation-free container checksums.
Implementation CompressionChecksum#
impl CompressionChecksumAssociated function crc32#
pub fn crc32(bytes: &[u8]) -> u32Returns the reflected IEEE CRC-32 of bytes, as gzip and ZIP store it.
Associated function crc32Update#
pub fn crc32Update(crc: u32, bytes: &[u8]) -> u32Returns 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#
pub fn adler32(bytes: &[u8]) -> u32Returns the Adler-32 of bytes, as zlib stores it.
Associated function adler32Update#
pub fn adler32Update(adler: u32, bytes: &[u8]) -> u32Returns 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#
pub fn crc64(bytes: &[u8]) -> u64Returns 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.