Skip to content

Trim crcs of streams (e.g. padding, headers, footers) from the front, end, or both of a combined crc when the lengths of all streams, but the first, are known.

License

Notifications You must be signed in to change notification settings

werekraken/libcrc32trim

Repository files navigation

libcrc32trim

libcrc32trim exposes a number of functions which perform combine and trim operations for several CRC-32 implementations.

crc32_combine_nz(), crc32c_combine(), and crc32posix_combine() all perform a combine operation like zlib's crc32_combine().

crcAB = crc32_combine_nz(crcA, crcB, lenB);
crcAB = crc32c_combine(crcA, crcB, lenB);
crcAB = crc32posix_combine(crcA, crcB, lenB);

crc32_trim_leading(), crc32c_trim_leading(), and crc32posix_trim_leading() all perform a leading trim.

crcB = crc32_trim_leading(crcAB, crcA, lenB);
crcB = crc32c_trim_leading(crcAB, crcA, lenB);
crcB = crc32posix_trim_leading(crcAB, crcA, lenB);

crc32_trim_trailing(), crc32c_trim_trailing(), and crc32posix_trim_trailing() all perform a trailing trim.

crcA = crc32_trim_trailing(crcAB, crcB, lenB);
crcA = crc32c_trim_trailing(crcAB, crcB, lenB);
crcA = crc32posix_trim_trailing(crcAB, crcB, lenB);

The initial motivation for crc32_trim_trailing() was to compute the crc32 of a stream trimmed of padding of a known length and value without needing the original stream. crc32_trim_leading() can do the same for leading padding, but the length of the stream without leading padding must be known.

These functions can also be used to compute the crc32 of a body trimmed of a known header and footer, when lengths of the body and footer are known, without needing the original stream.

Installation

libcrc32trim has build time dependencies on gcc and make. These package names may vary slightly between distros.

Install build time dependencies on CentOS.

sudo yum install gcc make

Build.

make

Install.

sudo make install

The vagrant environment can also be used to build an rpm.

To spin up the CentOS 7 environment and build an rpm use the following. This will clean up the vm.

./runner.sh buildrpm

Usage

crc32_trim_leading()

unsigned long crcA;
unsigned long crcAB;
unsigned long crcB;
long lenB;

crcAB = 0xedffc49cUL; // crc32 for 'thisthat'
crcA  = 0xfeee8227UL; // crc32 for 'this'
lenB  = 4L;

crcB = crc32_trim_leading(crcAB, crcA, lenB);
// crcB contains 0xa8539d8cUL, the crc32 for 'that'

crc32_trim_trailing()

unsigned long crcA;
unsigned long crcAB;
unsigned long crcB;
long lenB;

crcAB = 0xedffc49cUL; // crc32 for 'thisthat'
crcB  = 0xa8539d8cUL; // crc32 for 'that'
lenB  = 4L;

crcA = crc32_trim_trailing(crcAB, crcB, lenB);
// crcA contains 0xfeee8227UL, the crc32 for 'this'

Testing

Vagrant is used for consistent test environments.

To spin up the CentOS 7 enviroment, build, and run the tests use the following. This will clean up the vm.

./runner.sh

If developing new tests, it can be convenient to keep the environment around for several runs. This will leave the vm in place.

RUNNER_VAGRANT_DESTROY=false ./runner.sh

Versioning

This project adheres to Semantic Versioning.

License

libcrc32trim is available as open source under the terms of the zlib license.

Compatibility

libcrc32trim is actively tested on CentOS 7, but is likely to work on other distros and Unix-like systems.

About

Trim crcs of streams (e.g. padding, headers, footers) from the front, end, or both of a combined crc when the lengths of all streams, but the first, are known.

Resources

License

Stars

Watchers

Forks

Packages

No packages published