GithubHelp home page GithubHelp logo

werekraken / libcrc32trim Goto Github PK

View Code? Open in Web Editor NEW
3.0 3.0 2.0 39 KB

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: zlib License

Makefile 1.97% C 95.68% Shell 2.26% Ruby 0.08%

libcrc32trim's Introduction

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.

libcrc32trim's People

Contributors

werekraken avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

andrewlixin zu3st

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.