pabigot  0.1.1
C++ support classes
Public Types | Static Public Member Functions | Static Public Attributes | Protected Types
pabigot::crc::crc< W, Poly, Rin, Rout, Init, XorOut > Class Template Reference

CRC calculation using Rocksoft^tm Model characteristics. More...

#include </mnt/devel/pabigot-cxx/include/pabigot/crc.hpp>

Inheritance diagram for pabigot::crc::crc< W, Poly, Rin, Rout, Init, XorOut >:
pabigot::crc::details::base_crc< W, Rin >

Public Types

using tabler_type = Tabler< this_type >
 The Tabler associated with this CRC type.
 
using fast_type = typename support_traits::fast_type
 A fast native unsigned integral type capable of holding width-bit CRC values. More...
 
using least_type = typename support_traits::least_type
 A small native unsigned integral type capable of holding width-bit CRC values. More...
 
- Public Types inherited from pabigot::crc::details::base_crc< W, Rin >
using uint_traits = typename support_traits::uint_traits
 
using fast_type = typename support_traits::fast_type
 A fast native unsigned integral type capable of holding width-bit CRC values. More...
 
using least_type = typename support_traits::least_type
 A small native unsigned integral type capable of holding width-bit CRC values. More...
 

Static Public Member Functions

static constexpr least_type residue ()
 Value expected for CRC(x || XE(CRC(x))). More...
 
template<typename InputIterator >
static constexpr fast_type append (InputIterator first, InputIterator last, const fast_type &crc=init)
 Augment a checksum with additional data. More...
 
static constexpr least_type lookup_for_byte (std::uint_fast8_t byte)
 Delegate to super_::lookup_for_byte.
 
static constexpr least_type finalize (fast_type crc)
 Calculate the final CRC value for a sequence. More...
 
static constexpr tabler_type instantiate_tabler ()
 Construct an object that does table-driven CRC calculations for this algorithm.
 
static constexpr uint8_t * store (fast_type crc, uint8_t *bp)
 Store a finalized CRC into a buffer in a way that enables crc::residue(). More...
 
- Static Public Member Functions inherited from pabigot::crc::details::base_crc< W, Rin >
static constexpr fast_type reflect (const fast_type &v)
 Delegate to support_traits::reflect.
 
static constexpr uint8_t * store (fast_type crc, uint8_t *bp)
 Store a finalized CRC into a buffer in a way that enables crc::residue(). More...
 

Static Public Attributes

static constexpr bool refout = Rout
 true iff the output CRC is to be reflected.
 
static constexpr fast_type poly = super_::mask & Poly
 The CRC polynomial in normal form (all bits except bit width which is known to be 1 are provided).
 
static constexpr least_type init = super_::mask & Init
 The initial value of the CRC register before any message bits have been processed.
 
static constexpr least_type xorout = super_::mask & XorOut
 A value subtracted (xor'd) from the calculated result prior to returning it.
 
- Static Public Attributes inherited from pabigot::crc::details::base_crc< W, Rin >
static constexpr unsigned int width = W
 The width of the CRC in bits.
 
static constexpr unsigned int size = (7 + width) / 8
 The width of the CRC in bytes.
 
static constexpr fast_type mask = support_traits::mask
 The mask that discards bits of a fast_type that would be outside the width limit.
 
static constexpr bool refin = Rin
 true iff the input message bit stream is reflected. More...
 

Protected Types

using support_traits = details::uint_support< width >
 Traits class providing native integral types and parameter-independent values supporting width-bit operations.
 
- Protected Types inherited from pabigot::crc::details::base_crc< W, Rin >
using support_traits = details::uint_support< width >
 Traits class providing native integral types and parameter-independent values supporting width-bit operations.
 

Additional Inherited Members

- Static Protected Member Functions inherited from pabigot::crc::details::base_crc< W, Rin >
static constexpr least_type lookup_for_byte (const fast_type &poly, std::uint_fast8_t byte)
 Calculate a single lookup table entry using the given polynomial. More...
 
static constexpr fast_type crc_apply (const fast_type &poly, const fast_type &crc, fast_type msg, unsigned int n)
 Apply message bits into a CRC. More...
 

Detailed Description

template<unsigned int W, uintmax_t Poly, bool Rin = false, bool Rout = false, uintmax_t Init = 0, uintmax_t XorOut = 0>
class pabigot::crc::crc< W, Poly, Rin, Rout, Init, XorOut >

CRC calculation using Rocksoft^tm Model characteristics.

Template Parameters
Wthe width of the CRC in bits.
Polythe CRC polynomial in normal form.
Rinwhether the input bit stream is reflected.
Routwhether the output bit stream is reflected.
Initthe initial value of the CRC register before any bits have been processed. A value of -1 may be used to start with all bits set. XorOut the value xorout subtracted from the calculated result prior to returning it. A value of -1 may be used to bitwise invert the value.
See also
http://www.ross.net/crc/download/crc_v3.txt
http://reveng.sourceforge.net/crc-catalogue/
http://users.ece.cmu.edu/~koopman/crc/index.html
https://en.wikipedia.org/wiki/Mathematics_of_cyclic_redundancy_checks especially the Koopman references

Member Typedef Documentation

◆ fast_type

template<unsigned int W, uintmax_t Poly, bool Rin = false, bool Rout = false, uintmax_t Init = 0, uintmax_t XorOut = 0>
using pabigot::crc::details::base_crc< W, Rin >::fast_type = typename support_traits::fast_type

A fast native unsigned integral type capable of holding width-bit CRC values.

Warning
This value may have more octets or bits than are required to store the CRC.

◆ least_type

template<unsigned int W, uintmax_t Poly, bool Rin = false, bool Rout = false, uintmax_t Init = 0, uintmax_t XorOut = 0>
using pabigot::crc::details::base_crc< W, Rin >::least_type = typename support_traits::least_type

A small native unsigned integral type capable of holding width-bit CRC values.

Warning
This value may have more octets or bits than are required to store the CRC.

Member Function Documentation

◆ append()

template<unsigned int W, uintmax_t Poly, bool Rin = false, bool Rout = false, uintmax_t Init = 0, uintmax_t XorOut = 0>
template<typename InputIterator >
static constexpr fast_type pabigot::crc::crc< W, Poly, Rin, Rout, Init, XorOut >::append ( InputIterator  first,
InputIterator  last,
const fast_type crc = init 
)
inlinestaticconstexpr

Augment a checksum with additional data.

Template Parameters
InputIteratoriterator over inputs. InputIterator::value_type must be convertible to an unsigned 8-bit value without changing the value content.
Parameters
firstbeginning of the range over which CRCs will be calculated.
lastbeginning of the range over which CRCs will be calculated.
crcthe CRC value calculated over all previous message bits. Start with init, which is the defaulted value.
Returns
the unreflected CRC value over all message bits through this invocation. This may be passed as crc to process more message content.
See also
finalize()

◆ finalize()

template<unsigned int W, uintmax_t Poly, bool Rin = false, bool Rout = false, uintmax_t Init = 0, uintmax_t XorOut = 0>
static constexpr least_type pabigot::crc::crc< W, Poly, Rin, Rout, Init, XorOut >::finalize ( fast_type  crc)
inlinestaticconstexpr

Calculate the final CRC value for a sequence.

refout and xorout are applied to the final register value and the result returned.

Note
A common operation on CRCs is to store them into a buffer for transfer to another system, particularly to enable use of residue(). Be aware that if width is not a power of 2 then least_type is likely to have padding bits in it, for which a basic byte-swap for endianness will produce anomalous results. See store() for a partial solution.
Parameters
crcthe CRC resulting after all message bits have been calculated.
Returns
the CRC of the message in smallest type capable of holding it.

◆ residue()

template<unsigned int W, uintmax_t Poly, bool Rin = false, bool Rout = false, uintmax_t Init = 0, uintmax_t XorOut = 0>
static constexpr least_type pabigot::crc::crc< W, Poly, Rin, Rout, Init, XorOut >::residue ( )
inlinestaticconstexpr

Value expected for CRC(x || XE(CRC(x))).

When the checksum of the message is stored at the end of the message a receiver can calculate the finalized checksum of the message plus the stored checksum. This value will be equal to the residue() if no errors are discovered.

Note
The residues produced by this function may not match those specified by the reveng catalog because the classic check algorithm used for residues does not apply crc::xorout to the final value. See, for example, this code for the classic CRC-32 algorithm. The value here is correct when compared with a finalized checksum.
Warning
This library does not properly handle residue calculation for messages that are not an integral number of bytes, or CRCs with a width that is not a multiple of 8 bits.

◆ store()

template<unsigned int W, uintmax_t Poly, bool Rin = false, bool Rout = false, uintmax_t Init = 0, uintmax_t XorOut = 0>
static constexpr uint8_t* pabigot::crc::details::base_crc< W, Rin >::store
inlinestaticconstexpr

Store a finalized CRC into a buffer in a way that enables crc::residue().

Warning
If the CRC width is not a multiple of 8 the stored value will not be correct, as this namespace provides no API to operate on messages that are not an integral number of octets.
Parameters
crcthe finalized CRC of a message.
bppointer to space of size bytes immediately following the message, into which the CRC can be stored.
Returns
pointer into the region identified by bp immediately following the stored CRC.

The documentation for this class was generated from the following file: