Boost C++ Libraries

...one of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

This is the documentation for an old version of Boost. Click here to view this page for the latest version.
PrevUpHomeNext

Function template augmented_crc

boost::augmented_crc — Compute the CRC of a memory block, with any augmentation provided by user.

Synopsis

// In header: <boost/crc.hpp>


template<std::size_t Bits, typename::boost::uint_t< Bits >::fast TruncPoly> 
  uint_t< Bits >::fast 
  augmented_crc(void const * buffer, std::size_t byte_count, 
                typename uint_t< Bits >::fast initial_remainder = 0u);

Description

Computes the polynomial remainder of a CRC run, assuming that buffer and byte_count describe a memory block representing the polynomial dividend. The first byte is considered the highest order, going down for subsequent bytes. Within a byte, the highest-order bit is read first (corresponding to RefIn = False in the RMCA). Check the other parts of this function's documentation to see how a checksum can be gained and/or used.

[Note] Note

Augmented-style CRC runs use straight-up modulo-2 polynomial division. Since data is being read byte-wise, a table of pre-computed remainder changes (as XOR masks) can be used to speed computation.

Reading just a memory block will yield an interim remainder, and not the final checksum. To get that checksum, allocate Bits / CHAR_BIT bytes directly after the block and fill them with zero values, then extend byte_count to include those extra bytes. A data block is corrupt if the return value doesn't equal your separately given checksum.

Another way to perform a check is use the zero-byte extension method, but replace the zero values with your separately-given checksum. The checksum must be loaded in big-endian order. Here corruption, in either the data block or the given checksum, is confirmed if the return value is not zero.

The two checksum techniques assume the CRC-run is performed bit-wise, while this function works byte-wise. That means that the techniques can be used only if CHAR_BIT divides Bits evenly!

Parameters:

buffer

The address where the memory block begins.

byte_count

The number of bytes in the memory block.

initial_remainder

The initial state of the polynomial remainder, defaulting to zero if omitted. If you are reading a memory block in multiple runs, put the return value of the previous run here. (Note that initial-remainders given by RMCA parameter lists, as Init, assume that the initial remainder is in its unaugmented state, so you would need to convert the value to make it suitable for this function. I currently don't provide a conversion routine.)

Template Parameters:

Bits

The order of the modulo-2 polynomial divisor. (Width from the RMCA)

TruncPoly

The lowest coefficients of the divisor polynomial. The highest-order coefficient is omitted and always assumed to be 1. (Poly from the RMCA)

Requires:

0 < Bits <= std::numeric_limit<uintmax_t>::digits

Returns:

The interim remainder, if no augmentation is used. A special value if augmentation is used (see the notes). No output processing is done on the value. (In RMCA terms, RefOut is False and XorOut is 0.)


PrevUpHomeNext