CUBRID Engine  latest
CRC Class Reference

Static class for computing CRCs. More...

#include <CRC.h>

Collaboration diagram for CRC:
Collaboration graph

Classes

struct  Parameters
 CRC parameters. More...
 
struct  Table
 CRC lookup table. After construction, the CRC parameters are fixed. More...
 

Static Public Member Functions

template<typename CRCType , crcpp_uint16 CRCWidth>
static CRCType Calculate (const void *data, crcpp_size size, const Parameters< CRCType, CRCWidth > &parameters)
 Computes a CRC. More...
 
template<typename CRCType , crcpp_uint16 CRCWidth>
static CRCType Calculate (const void *data, crcpp_size size, const Parameters< CRCType, CRCWidth > &parameters, CRCType crc)
 Appends additional data to a previous CRC calculation. More...
 
template<typename CRCType , crcpp_uint16 CRCWidth>
static CRCType Calculate (const void *data, crcpp_size size, const Table< CRCType, CRCWidth > &lookupTable)
 Computes a CRC via a lookup table. More...
 
template<typename CRCType , crcpp_uint16 CRCWidth>
static CRCType Calculate (const void *data, crcpp_size size, const Table< CRCType, CRCWidth > &lookupTable, CRCType crc)
 Appends additional data to a previous CRC calculation using a lookup table. More...
 
static const Parameters< crcpp_uint8, 8 > & CRC_8 ()
 Returns a set of parameters for CRC-8 SMBus. More...
 
static const Parameters< crcpp_uint16, 16 > & CRC_16_ARC ()
 Returns a set of parameters for CRC-16 ARC (aka CRC-16 IBM, CRC-16 LHA). More...
 
static const Parameters< crcpp_uint16, 16 > & CRC_16_BUYPASS ()
 Returns a set of parameters for CRC-16 BUYPASS (aka CRC-16 VERIFONE, CRC-16 UMTS). More...
 
static const Parameters< crcpp_uint16, 16 > & CRC_16_CCITTFALSE ()
 Returns a set of parameters for CRC-16 CCITT FALSE. More...
 
static const Parameters< crcpp_uint16, 16 > & CRC_16_GENIBUS ()
 Returns a set of parameters for CRC-16 GENIBUS (aka CRC-16 EPC, CRC-16 I-CODE, CRC-16 DARC). More...
 
static const Parameters< crcpp_uint16, 16 > & CRC_16_KERMIT ()
 Returns a set of parameters for CRC-16 KERMIT (aka CRC-16 CCITT, CRC-16 CCITT-TRUE). More...
 
static const Parameters< crcpp_uint16, 16 > & CRC_16_X25 ()
 Returns a set of parameters for CRC-16 X-25 (aka CRC-16 IBM-SDLC, CRC-16 ISO-HDLC, CRC-16 B). More...
 
static const Parameters< crcpp_uint16, 16 > & CRC_16_XMODEM ()
 Returns a set of parameters for CRC-16 XMODEM (aka CRC-16 ZMODEM, CRC-16 ACORN, CRC-16 LTE). More...
 
static const Parameters< crcpp_uint32, 32 > & CRC_32 ()
 Returns a set of parameters for CRC-32 (aka CRC-32 ADCCP, CRC-32 PKZip). More...
 
static const Parameters< crcpp_uint32, 32 > & CRC_32_BZIP2 ()
 Returns a set of parameters for CRC-32 BZIP2 (aka CRC-32 AAL5, CRC-32 DECT-B, CRC-32 B-CRC). More...
 
static const Parameters< crcpp_uint32, 32 > & CRC_32_MPEG2 ()
 Returns a set of parameters for CRC-32 MPEG-2. More...
 
static const Parameters< crcpp_uint32, 32 > & CRC_32_POSIX ()
 Returns a set of parameters for CRC-32 POSIX. More...
 

Private Member Functions

 CRC ()
 
 CRC (const CRC &other)
 
CRCoperator= (const CRC &other)
 

Static Private Member Functions

template<typename IntegerType >
static IntegerType Reflect (IntegerType value, crcpp_uint16 numBits)
 Reflects (i.e. reverses the bits within) an integer value. More...
 
template<typename CRCType , crcpp_uint16 CRCWidth>
static CRCType Finalize (CRCType remainder, CRCType finalXOR, bool reflectOutput)
 Computes the final reflection and XOR of a CRC remainder. More...
 
template<typename CRCType , crcpp_uint16 CRCWidth>
static CRCType UndoFinalize (CRCType remainder, CRCType finalXOR, bool reflectOutput)
 Undoes the process of computing the final reflection and XOR of a CRC remainder. More...
 
template<typename CRCType , crcpp_uint16 CRCWidth>
static CRCType CalculateRemainder (const void *data, crcpp_size size, const Parameters< CRCType, CRCWidth > &parameters, CRCType remainder)
 Computes a CRC remainder. More...
 
template<typename CRCType , crcpp_uint16 CRCWidth>
static CRCType CalculateRemainder (const void *data, crcpp_size size, const Table< CRCType, CRCWidth > &lookupTable, CRCType remainder)
 Computes a CRC remainder using lookup table. More...
 

Detailed Description

Static class for computing CRCs.

Note
This class supports computation of full and multi-part CRCs, using a bit-by-bit algorithm or a byte-by-byte lookup table. The CRCs are calculated using as many optimizations as is reasonable. If compiling with C++11, the constexpr keyword is used liberally so that many calculations are performed at compile-time instead of at runtime.

Definition at line 144 of file CRC.h.

Constructor & Destructor Documentation

CRC::CRC ( )
private
CRC::CRC ( const CRC other)
private

Member Function Documentation

template<typename CRCType , crcpp_uint16 CRCWidth>
CRCType CRC::Calculate ( const void *  data,
crcpp_size  size,
const Parameters< CRCType, CRCWidth > &  parameters 
)
inlinestatic

Computes a CRC.

Parameters
[in]dataData over which CRC will be computed
[in]sizeSize of the data
[in]parametersCRC parameters
Template Parameters
CRCTypeInteger type for storing the CRC result
CRCWidthNumber of bits in the CRC
Returns
CRC

Definition at line 436 of file CRC.h.

References CalculateRemainder(), CRC::Parameters< CRCType, CRCWidth >::finalXOR, CRC::Parameters< CRCType, CRCWidth >::initialValue, CRC::Parameters< CRCType, CRCWidth >::reflectInput, and CRC::Parameters< CRCType, CRCWidth >::reflectOutput.

Referenced by crypt_crc32().

Here is the caller graph for this function:

template<typename CRCType , crcpp_uint16 CRCWidth>
CRCType CRC::Calculate ( const void *  data,
crcpp_size  size,
const Parameters< CRCType, CRCWidth > &  parameters,
CRCType  crc 
)
inlinestatic

Appends additional data to a previous CRC calculation.

Note
This function can be used to compute multi-part CRCs.
Parameters
[in]dataData over which CRC will be computed
[in]sizeSize of the data
[in]parametersCRC parameters
[in]crcCRC from a previous calculation
Template Parameters
CRCTypeInteger type for storing the CRC result
CRCWidthNumber of bits in the CRC
Returns
CRC

Definition at line 456 of file CRC.h.

References CalculateRemainder(), CRC::Parameters< CRCType, CRCWidth >::finalXOR, CRC::Parameters< CRCType, CRCWidth >::reflectInput, and CRC::Parameters< CRCType, CRCWidth >::reflectOutput.

template<typename CRCType , crcpp_uint16 CRCWidth>
CRCType CRC::Calculate ( const void *  data,
crcpp_size  size,
const Table< CRCType, CRCWidth > &  lookupTable 
)
inlinestatic

Computes a CRC via a lookup table.

Parameters
[in]dataData over which CRC will be computed
[in]sizeSize of the data
[in]lookupTableCRC lookup table
Template Parameters
CRCTypeInteger type for storing the CRC result
CRCWidthNumber of bits in the CRC
Returns
CRC

Definition at line 477 of file CRC.h.

References CalculateRemainder(), CRC::Parameters< CRCType, CRCWidth >::finalXOR, CRC::Table< CRCType, CRCWidth >::GetParameters(), CRC::Parameters< CRCType, CRCWidth >::initialValue, CRC::Table< CRCType, CRCWidth >::parameters, CRC::Parameters< CRCType, CRCWidth >::reflectInput, and CRC::Parameters< CRCType, CRCWidth >::reflectOutput.

template<typename CRCType , crcpp_uint16 CRCWidth>
CRCType CRC::Calculate ( const void *  data,
crcpp_size  size,
const Table< CRCType, CRCWidth > &  lookupTable,
CRCType  crc 
)
inlinestatic

Appends additional data to a previous CRC calculation using a lookup table.

Note
This function can be used to compute multi-part CRCs.
Parameters
[in]dataData over which CRC will be computed
[in]sizeSize of the data
[in]lookupTableCRC lookup table
[in]crcCRC from a previous calculation
Template Parameters
CRCTypeInteger type for storing the CRC result
CRCWidthNumber of bits in the CRC
Returns
CRC

Definition at line 500 of file CRC.h.

References CalculateRemainder(), CRC::Parameters< CRCType, CRCWidth >::finalXOR, CRC::Table< CRCType, CRCWidth >::GetParameters(), CRC::Table< CRCType, CRCWidth >::parameters, CRC::Parameters< CRCType, CRCWidth >::reflectInput, and CRC::Parameters< CRCType, CRCWidth >::reflectOutput.

template<typename CRCType , crcpp_uint16 CRCWidth>
CRCType CRC::CalculateRemainder ( const void *  data,
crcpp_size  size,
const Parameters< CRCType, CRCWidth > &  parameters,
CRCType  remainder 
)
inlinestaticprivate

Computes a CRC remainder.

Parameters
[in]dataData over which the remainder will be computed
[in]sizeSize of the data
[in]parametersCRC parameters
[in]remainderRunning CRC remainder. Can be an initial value or the result of a previous CRC remainder calculation.
Template Parameters
CRCTypeInteger type for storing the CRC result
CRCWidthNumber of bits in the CRC
Returns
CRC remainder

Definition at line 603 of file CRC.h.

References crcpp_constexpr, crcpp_size, i, CRC::Parameters< CRCType, CRCWidth >::polynomial, Reflect(), and CRC::Parameters< CRCType, CRCWidth >::reflectInput.

Referenced by Calculate().

Here is the caller graph for this function:

template<typename CRCType , crcpp_uint16 CRCWidth>
CRCType CRC::CalculateRemainder ( const void *  data,
crcpp_size  size,
const Table< CRCType, CRCWidth > &  lookupTable,
CRCType  remainder 
)
inlinestaticprivate

Computes a CRC remainder using lookup table.

Parameters
[in]dataData over which the remainder will be computed
[in]sizeSize of the data
[in]lookupTableCRC lookup table
[in]remainderRunning CRC remainder. Can be an initial value or the result of a previous CRC remainder calculation.
Template Parameters
CRCTypeInteger type for storing the CRC result
CRCWidthNumber of bits in the CRC
Returns
CRC remainder

Definition at line 720 of file CRC.h.

References crcpp_constexpr, CRC::Table< CRCType, CRCWidth >::GetParameters(), and CRC::Table< CRCType, CRCWidth >::parameters.

const CRC::Parameters< crcpp_uint16, 16 > & CRC::CRC_16_ARC ( )
inlinestatic

Returns a set of parameters for CRC-16 ARC (aka CRC-16 IBM, CRC-16 LHA).

Note
The parameters are static and are delayed-constructed to reduce memory footprint.
CRC-16 ARC has the following parameters and check value:
  • polynomial = 0x8005
  • initial value = 0x0000
  • final XOR = 0x0000
  • reflect input = true
  • reflect output = true
  • check value = 0xBB3D
Returns
CRC-16 ARC parameters

Definition at line 1164 of file CRC.h.

References CRC::Table< CRCType, CRCWidth >::parameters.

const CRC::Parameters< crcpp_uint16, 16 > & CRC::CRC_16_BUYPASS ( )
inlinestatic

Returns a set of parameters for CRC-16 BUYPASS (aka CRC-16 VERIFONE, CRC-16 UMTS).

Note
The parameters are static and are delayed-constructed to reduce memory footprint.
CRC-16 BUYPASS has the following parameters and check value:
  • polynomial = 0x8005
  • initial value = 0x0000
  • final XOR = 0x0000
  • reflect input = false
  • reflect output = false
  • check value = 0xFEE8
Returns
CRC-16 BUYPASS parameters

Definition at line 1182 of file CRC.h.

References CRC::Table< CRCType, CRCWidth >::parameters.

const CRC::Parameters< crcpp_uint16, 16 > & CRC::CRC_16_CCITTFALSE ( )
inlinestatic

Returns a set of parameters for CRC-16 CCITT FALSE.

Note
The parameters are static and are delayed-constructed to reduce memory footprint.
CRC-16 CCITT FALSE has the following parameters and check value:
  • polynomial = 0x1021
  • initial value = 0xFFFF
  • final XOR = 0x0000
  • reflect input = false
  • reflect output = false
  • check value = 0x29B1
Returns
CRC-16 CCITT FALSE parameters

Definition at line 1200 of file CRC.h.

References CRC::Table< CRCType, CRCWidth >::parameters.

const CRC::Parameters< crcpp_uint16, 16 > & CRC::CRC_16_GENIBUS ( )
inlinestatic

Returns a set of parameters for CRC-16 GENIBUS (aka CRC-16 EPC, CRC-16 I-CODE, CRC-16 DARC).

Note
The parameters are static and are delayed-constructed to reduce memory footprint.
CRC-16 GENIBUS has the following parameters and check value:
  • polynomial = 0x1021
  • initial value = 0xFFFF
  • final XOR = 0xFFFF
  • reflect input = false
  • reflect output = false
  • check value = 0xD64E
Returns
CRC-16 GENIBUS parameters

Definition at line 1310 of file CRC.h.

References CRC::Table< CRCType, CRCWidth >::parameters.

const CRC::Parameters< crcpp_uint16, 16 > & CRC::CRC_16_KERMIT ( )
inlinestatic

Returns a set of parameters for CRC-16 KERMIT (aka CRC-16 CCITT, CRC-16 CCITT-TRUE).

Note
The parameters are static and are delayed-constructed to reduce memory footprint.
CRC-16 KERMIT has the following parameters and check value:
  • polynomial = 0x1021
  • initial value = 0x0000
  • final XOR = 0x0000
  • reflect input = true
  • reflect output = true
  • check value = 0x2189
Returns
CRC-16 KERMIT parameters

Definition at line 1328 of file CRC.h.

References CRC::Table< CRCType, CRCWidth >::parameters.

const CRC::Parameters< crcpp_uint16, 16 > & CRC::CRC_16_X25 ( )
inlinestatic

Returns a set of parameters for CRC-16 X-25 (aka CRC-16 IBM-SDLC, CRC-16 ISO-HDLC, CRC-16 B).

Note
The parameters are static and are delayed-constructed to reduce memory footprint.
CRC-16 X-25 has the following parameters and check value:
  • polynomial = 0x1021
  • initial value = 0xFFFF
  • final XOR = 0xFFFF
  • reflect input = true
  • reflect output = true
  • check value = 0x906E
Returns
CRC-16 X-25 parameters

Definition at line 1421 of file CRC.h.

References CRC::Table< CRCType, CRCWidth >::parameters.

const CRC::Parameters< crcpp_uint16, 16 > & CRC::CRC_16_XMODEM ( )
inlinestatic

Returns a set of parameters for CRC-16 XMODEM (aka CRC-16 ZMODEM, CRC-16 ACORN, CRC-16 LTE).

Note
The parameters are static and are delayed-constructed to reduce memory footprint.
CRC-16 XMODEM has the following parameters and check value:
  • polynomial = 0x1021
  • initial value = 0x0000
  • final XOR = 0x0000
  • reflect input = false
  • reflect output = false
  • check value = 0x31C3
Returns
CRC-16 XMODEM parameters

Definition at line 1439 of file CRC.h.

References CRC::Table< CRCType, CRCWidth >::parameters.

const CRC::Parameters< crcpp_uint32, 32 > & CRC::CRC_32 ( )
inlinestatic

Returns a set of parameters for CRC-32 (aka CRC-32 ADCCP, CRC-32 PKZip).

Note
The parameters are static and are delayed-constructed to reduce memory footprint.
CRC-32 has the following parameters and check value:
  • polynomial = 0x04C11DB7
  • initial value = 0xFFFFFFFF
  • final XOR = 0xFFFFFFFF
  • reflect input = true
  • reflect output = true
  • check value = 0xCBF43926
Returns
CRC-32 parameters

Definition at line 1567 of file CRC.h.

References CRC::Table< CRCType, CRCWidth >::parameters.

Referenced by crypt_crc32().

Here is the caller graph for this function:

const CRC::Parameters< crcpp_uint32, 32 > & CRC::CRC_32_BZIP2 ( )
inlinestatic

Returns a set of parameters for CRC-32 BZIP2 (aka CRC-32 AAL5, CRC-32 DECT-B, CRC-32 B-CRC).

Note
The parameters are static and are delayed-constructed to reduce memory footprint.
CRC-32 BZIP2 has the following parameters and check value:
  • polynomial = 0x04C11DB7
  • initial value = 0xFFFFFFFF
  • final XOR = 0xFFFFFFFF
  • reflect input = false
  • reflect output = false
  • check value = 0xFC891918
Returns
CRC-32 BZIP2 parameters

Definition at line 1585 of file CRC.h.

References CRC::Table< CRCType, CRCWidth >::parameters.

const CRC::Parameters< crcpp_uint32, 32 > & CRC::CRC_32_MPEG2 ( )
inlinestatic

Returns a set of parameters for CRC-32 MPEG-2.

Note
The parameters are static and are delayed-constructed to reduce memory footprint.
CRC-32 MPEG-2 has the following parameters and check value:
  • polynomial = 0x04C11DB7
  • initial value = 0xFFFFFFFF
  • final XOR = 0x00000000
  • reflect input = false
  • reflect output = false
  • check value = 0x0376E6E7
Returns
CRC-32 MPEG-2 parameters

Definition at line 1623 of file CRC.h.

References CRC::Table< CRCType, CRCWidth >::parameters.

const CRC::Parameters< crcpp_uint32, 32 > & CRC::CRC_32_POSIX ( )
inlinestatic

Returns a set of parameters for CRC-32 POSIX.

Note
The parameters are static and are delayed-constructed to reduce memory footprint.
CRC-32 POSIX has the following parameters and check value:
  • polynomial = 0x04C11DB7
  • initial value = 0x00000000
  • final XOR = 0xFFFFFFFF
  • reflect input = false
  • reflect output = false
  • check value = 0x765E7680
Returns
CRC-32 POSIX parameters

Definition at line 1641 of file CRC.h.

References CRC::Table< CRCType, CRCWidth >::parameters.

const CRC::Parameters< crcpp_uint8, 8 > & CRC::CRC_8 ( )
inlinestatic

Returns a set of parameters for CRC-8 SMBus.

Note
The parameters are static and are delayed-constructed to reduce memory footprint.
CRC-8 SMBus has the following parameters and check value:
  • polynomial = 0x07
  • initial value = 0x00
  • final XOR = 0x00
  • reflect input = false
  • reflect output = false
  • check value = 0xF4
Returns
CRC-8 SMBus parameters

Definition at line 928 of file CRC.h.

References CRC::Table< CRCType, CRCWidth >::parameters.

template<typename CRCType , crcpp_uint16 CRCWidth>
CRCType CRC::Finalize ( CRCType  remainder,
CRCType  finalXOR,
bool  reflectOutput 
)
inlinestaticprivate

Computes the final reflection and XOR of a CRC remainder.

Parameters
[in]remainderCRC remainder to reflect and XOR
[in]finalXORFinal value to XOR with the remainder
[in]reflectOutputtrue to reflect each byte of the remainder before the XOR
Template Parameters
CRCTypeInteger type for storing the CRC result
CRCWidthNumber of bits in the CRC
Returns
Final CRC

Definition at line 544 of file CRC.h.

References crcpp_constexpr, and Reflect().

CRC& CRC::operator= ( const CRC other)
private
template<typename IntegerType >
IntegerType CRC::Reflect ( IntegerType  value,
crcpp_uint16  numBits 
)
inlinestaticprivate

Reflects (i.e. reverses the bits within) an integer value.

Parameters
[in]valueValue to reflect
[in]numBitsNumber of bits in the integer which will be reflected
Template Parameters
IntegerTypeInteger type of the value being reflected
Returns
Reflected value

Definition at line 521 of file CRC.h.

References crcpp_uint16, and i.

Referenced by CalculateRemainder(), Finalize(), and UndoFinalize().

Here is the caller graph for this function:

template<typename CRCType , crcpp_uint16 CRCWidth>
CRCType CRC::UndoFinalize ( CRCType  crc,
CRCType  finalXOR,
bool  reflectOutput 
)
inlinestaticprivate

Undoes the process of computing the final reflection and XOR of a CRC remainder.

Note
This function allows for computation of multi-part CRCs
Calling UndoFinalize() followed by Finalize() (or vice versa) will always return the original remainder value:
CRCType x = ...;
CRCType y = Finalize(x, finalXOR, reflectOutput);
CRCType z = UndoFinalize(y, finalXOR, reflectOutput);
assert(x == z);
Parameters
[in]crcReflected and XORed CRC
[in]finalXORFinal value XORed with the remainder
[in]reflectOutputtrue if the remainder is to be reflected
Template Parameters
CRCTypeInteger type for storing the CRC result
CRCWidthNumber of bits in the CRC
Returns
Un-finalized CRC remainder

Definition at line 576 of file CRC.h.

References crcpp_constexpr, and Reflect().


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