73# ifdef CRCPP_USE_CPP11
75# define crcpp_uint8 ::std::uint8_t
78# define crcpp_uint8 uint8_t
83# ifdef CRCPP_USE_CPP11
85# define crcpp_uint16 ::std::uint16_t
88# define crcpp_uint16 uint16_t
93# ifdef CRCPP_USE_CPP11
95# define crcpp_uint32 ::std::uint32_t
98# define crcpp_uint32 uint32_t
103# ifdef CRCPP_USE_CPP11
105# define crcpp_uint64 ::std::uint64_t
108# define crcpp_uint64 uint64_t
113# ifdef CRCPP_USE_CPP11
115# define crcpp_size ::std::size_t
118# define crcpp_size size_t
122#ifdef CRCPP_USE_CPP11
124# define crcpp_constexpr constexpr
127# define crcpp_constexpr const
130#if defined(_MSC_VER) && !defined(__clang__) && !defined(__INTEL_COMPILER)
133#pragma warning(disable : 4127)
136#ifdef CRCPP_USE_NAMESPACE
152 template <
typename CRCType, crcpp_u
int16 CRCW
idth>
158 template <
typename CRCType, crcpp_u
int16 CRCW
idth>
174 template <
typename CRCType, crcpp_u
int16 CRCW
idth>
180#ifdef CRCPP_USE_CPP11
186 const CRCType * GetTable()
const;
188 CRCType operator[](
unsigned char index)
const;
194 CRCType table[1 << CHAR_BIT];
199 template <
typename CRCType, crcpp_u
int16 CRCW
idth>
202 template <
typename CRCType, crcpp_u
int16 CRCW
idth>
205 template <
typename CRCType, crcpp_u
int16 CRCW
idth>
208 template <
typename CRCType, crcpp_u
int16 CRCW
idth>
211 template <
typename CRCType, crcpp_u
int16 CRCW
idth>
214 template <
typename CRCType, crcpp_u
int16 CRCW
idth>
217 template <
typename CRCType, crcpp_u
int16 CRCW
idth>
220 template <
typename CRCType, crcpp_u
int16 CRCW
idth>
225#ifdef CRCPP_INCLUDE_ESOTERIC_CRC_DEFINITIONS
237#ifdef CRCPP_INCLUDE_ESOTERIC_CRC_DEFINITIONS
258#ifdef CRCPP_INCLUDE_ESOTERIC_CRC_DEFINITIONS
267#ifdef CRCPP_INCLUDE_ESOTERIC_CRC_DEFINITIONS
275#ifdef CRCPP_INCLUDE_ESOTERIC_CRC_DEFINITIONS
288#ifdef CRCPP_INCLUDE_ESOTERIC_CRC_DEFINITIONS
293#ifdef CRCPP_INCLUDE_ESOTERIC_CRC_DEFINITIONS
299#ifdef CRCPP_USE_CPP11
308#ifndef CRCPP_USE_CPP11
311 CRC & operator=(
const CRC & other);
314 template <
typename IntegerType>
315 static IntegerType Reflect(IntegerType value,
crcpp_uint16 numBits);
317 template <
typename CRCType, crcpp_u
int16 CRCW
idth>
318 static CRCType Finalize(CRCType remainder, CRCType finalXOR,
bool reflectOutput);
320 template <
typename CRCType, crcpp_u
int16 CRCW
idth>
321 static CRCType UndoFinalize(CRCType remainder, CRCType finalXOR,
bool reflectOutput);
323 template <
typename CRCType, crcpp_u
int16 CRCW
idth>
326 template <
typename CRCType, crcpp_u
int16 CRCW
idth>
329 template <
typename CRCType, crcpp_u
int16 CRCW
idth>
341template <
typename CRCType, crcpp_u
int16 CRCW
idth>
354template <
typename CRCType, crcpp_u
int16 CRCW
idth>
361#ifdef CRCPP_USE_CPP11
368template <
typename CRCType, crcpp_u
int16 CRCW
idth>
382template <
typename CRCType, crcpp_u
int16 CRCW
idth>
394template <
typename CRCType, crcpp_u
int16 CRCW
idth>
407template <
typename CRCType, crcpp_u
int16 CRCW
idth>
418template <
typename CRCType, crcpp_u
int16 CRCW
idth>
429 unsigned char byte = 0;
462template <
typename CRCType, crcpp_u
int16 CRCW
idth>
482template <
typename CRCType, crcpp_u
int16 CRCW
idth>
503template <
typename CRCType, crcpp_u
int16 CRCW
idth>
526template <
typename CRCType, crcpp_u
int16 CRCW
idth>
549template <
typename CRCType, crcpp_u
int16 CRCW
idth>
584template <
typename CRCType, crcpp_u
int16 CRCW
idth>
618template <
typename CRCType, crcpp_u
int16 CRCW
idth>
656template <
typename CRCType, crcpp_u
int16 CRCW
idth>
690template <
typename IntegerType>
713template <
typename CRCType, crcpp_u
int16 CRCW
idth>
745template <
typename CRCType, crcpp_u
int16 CRCW
idth>
772template <
typename CRCType, crcpp_u
int16 CRCW
idth>
775#ifdef CRCPP_USE_CPP11
778 static_assert(::std::numeric_limits<CRCType>::digits >=
CRCWidth,
"CRCType is too small to contain a CRC of width CRCWidth.");
785 const unsigned char *
current =
reinterpret_cast<const unsigned char *
>(
data);
789 if (parameters.reflectInput)
799#ifdef CRCPP_BRANCHLESS
815#ifndef CRCPP_BRANCHLESS
828#ifdef CRCPP_BRANCHLESS
844#ifndef CRCPP_BRANCHLESS
860#ifdef CRCPP_BRANCHLESS
889template <
typename CRCType, crcpp_u
int16 CRCW
idth>
892 const unsigned char *
current =
reinterpret_cast<const unsigned char *
>(
data);
898#if defined(_MSC_VER) && !defined(__clang__) && !defined(__INTEL_COMPILER)
902# pragma warning (push)
903# pragma warning (disable : 4333)
906#if defined(_MSC_VER) && !defined(__clang__) && !defined(__INTEL_COMPILER)
907# pragma warning (pop)
940template <
typename CRCType, crcpp_u
int16 CRCW
idth>
945 if (parameters.reflectInput)
953#ifdef CRCPP_BRANCHLESS
968#ifndef CRCPP_BRANCHLESS
979#ifdef CRCPP_BRANCHLESS
994#ifndef CRCPP_BRANCHLESS
1006#ifdef CRCPP_BRANCHLESS
1024#ifdef CRCPP_INCLUDE_ESOTERIC_CRC_DEFINITIONS
1207#ifdef CRCPP_INCLUDE_ESOTERIC_CRC_DEFINITIONS
1552#ifdef CRCPP_INCLUDE_ESOTERIC_CRC_DEFINITIONS
1680#ifdef CRCPP_INCLUDE_ESOTERIC_CRC_DEFINITIONS
1791#ifdef CRCPP_INCLUDE_ESOTERIC_CRC_DEFINITIONS
1994#ifdef CRCPP_INCLUDE_ESOTERIC_CRC_DEFINITIONS
2050#ifdef CRCPP_INCLUDE_ESOTERIC_CRC_DEFINITIONS
2106#ifdef CRCPP_USE_NAMESPACE
2110#if defined(_MSC_VER) && !defined(__clang__) && !defined(__INTEL_COMPILER)
#define crcpp_constexpr
Compile-time expression definition.
Definition CRC.h:124
#define crcpp_uint16
Unsigned 16-bit integer definition, used primarily for parameter definitions.
Definition CRC.h:85
#define crcpp_size
Unsigned size definition, used for specifying data sizes.
Definition CRC.h:115
Static class for computing CRCs.
Definition CRC.h:149
static CRCType CalculateBits(const void *data, crcpp_size size, const Parameters< CRCType, CRCWidth > ¶meters)
Computes a CRC.
Definition CRC.h:550
CRC(const CRC &other)=delete
static const Parameters< crcpp_uint16, 12 > & CRC_12_DECT()
Returns a set of parameters for CRC-12 DECT (aka CRC-12 X-CRC).
Definition CRC.h:1401
static const Parameters< crcpp_uint32, 24 > & CRC_24_NRC()
Returns a set of parameters for CRC-24 NR-C.
Definition CRC.h:1933
static const Parameters< crcpp_uint32, 24 > & CRC_24_FLEXRAYB()
Returns a set of parameters for CRC-24 FlexRay-B.
Definition CRC.h:1876
static const Parameters< crcpp_uint32, 24 > & CRC_24_LTEB()
Returns a set of parameters for CRC-24 LTE-B/NR-B.
Definition CRC.h:1914
static const Parameters< crcpp_uint16, 10 > & CRC_10()
Returns a set of parameters for CRC-10 ITU.
Definition CRC.h:1310
static const Parameters< crcpp_uint8, 6 > & CRC_6_ITU()
Returns a set of parameters for CRC-6 ITU.
Definition CRC.h:1145
static const Parameters< crcpp_uint8, 7 > & CRC_7()
Returns a set of parameters for CRC-7 JEDEC.
Definition CRC.h:1182
static const Parameters< crcpp_uint8, 4 > & CRC_4_ITU()
Returns a set of parameters for CRC-4 ITU.
Definition CRC.h:1037
CRC & operator=(const CRC &other)=delete
static const Parameters< crcpp_uint8, 5 > & CRC_5_EPC()
Returns a set of parameters for CRC-5 EPC.
Definition CRC.h:1055
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).
Definition CRC.h:1785
static CRCType CalculateRemainderBits(unsigned char byte, crcpp_size numBits, const Parameters< CRCType, CRCWidth > ¶meters, CRCType remainder)
Definition CRC.h:941
static const Parameters< crcpp_uint32, 30 > & CRC_30()
Returns a set of parameters for CRC-30 CDMA.
Definition CRC.h:1951
static const Parameters< crcpp_uint16, 16 > & CRC_16_DECTR()
Returns a set of parameters for CRC-16 DECT-R (aka CRC-16 R-CRC).
Definition CRC.h:1601
static const Parameters< crcpp_uint32, 17 > & CRC_17_CAN()
Returns a set of parameters for CRC-17 CAN.
Definition CRC.h:1804
static const Parameters< crcpp_uint8, 8 > & CRC_8()
Returns a set of parameters for CRC-8 SMBus.
Definition CRC.h:1201
static const Parameters< crcpp_uint32, 24 > & CRC_24()
Returns a set of parameters for CRC-24 OPENPGP.
Definition CRC.h:1840
static const Parameters< crcpp_uint16, 15 > & CRC_15_MPT1327()
Returns a set of parameters for CRC-15 MPT1327.
Definition CRC.h:1473
static const Parameters< crcpp_uint32, 32 > & CRC_32_MPEG2()
Returns a set of parameters for CRC-32 MPEG-2.
Definition CRC.h:2026
static CRCType UndoFinalize(CRCType remainder, CRCType finalXOR, bool reflectOutput)
Undoes the process of computing the final reflection and XOR of a CRC remainder.
Definition CRC.h:746
static const Parameters< crcpp_uint32, 24 > & CRC_24_FLEXRAYA()
Returns a set of parameters for CRC-24 FlexRay-A.
Definition CRC.h:1858
static const Parameters< crcpp_uint16, 16 > & CRC_16_MAXIM()
Returns a set of parameters for CRC-16 MAXIM.
Definition CRC.h:1693
static const Parameters< crcpp_uint32, 32 > & CRC_32_C()
Returns a set of parameters for CRC-32 C (aka CRC-32 ISCSI, CRC-32 Castagnoli, CRC-32 Interlaken).
Definition CRC.h:2007
static const Parameters< crcpp_uint16, 13 > & CRC_13_BBC()
Returns a set of parameters for CRC-13 BBC.
Definition CRC.h:1437
static const Parameters< crcpp_uint8, 8 > & CRC_8_MAXIM()
Returns a set of parameters for CRC-8 MAXIM (aka CRC-8 DOW-CRC).
Definition CRC.h:1256
static const Parameters< crcpp_uint8, 8 > & CRC_8_HDLC()
Returns a set of parameters for CRC-8 HDLC (ISO/IEC 13239:2002).
Definition CRC.h:1238
static const Parameters< crcpp_uint8, 8 > & CRC_8_WCDMA()
Returns a set of parameters for CRC-8 WCDMA.
Definition CRC.h:1274
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).
Definition CRC.h:1510
static CRCType CalculateRemainder(const void *data, crcpp_size size, const Parameters< CRCType, CRCWidth > ¶meters, CRCType remainder)
Computes a CRC remainder.
Definition CRC.h:773
static const Parameters< crcpp_uint8, 6 > & CRC_6_NR()
Returns a set of parameters for CRC-6 NR.
Definition CRC.h:1164
static const Parameters< crcpp_uint32, 24 > & CRC_24_LTEA()
Returns a set of parameters for CRC-24 LTE-A/NR-A.
Definition CRC.h:1895
static const Parameters< crcpp_uint16, 15 > & CRC_15()
Returns a set of parameters for CRC-15 CAN.
Definition CRC.h:1455
static const Parameters< crcpp_uint16, 16 > & CRC_16_DECTX()
Returns a set of parameters for CRC-16 DECT-X (aka CRC-16 X-CRC).
Definition CRC.h:1619
static const Parameters< crcpp_uint32, 21 > & CRC_21_CAN()
Returns a set of parameters for CRC-21 CAN.
Definition CRC.h:1822
static const Parameters< crcpp_uint16, 12 > & CRC_12_UMTS()
Returns a set of parameters for CRC-12 UMTS (aka CRC-12 3GPP).
Definition CRC.h:1419
static const Parameters< crcpp_uint16, 16 > & CRC_16_CMS()
Returns a set of parameters for CRC-16 CMS.
Definition CRC.h:1583
static const Parameters< crcpp_uint16, 10 > & CRC_10_CDMA2000()
Returns a set of parameters for CRC-10 CDMA2000.
Definition CRC.h:1328
CRC & operator=(CRC &&other)=delete
static const Parameters< crcpp_uint8, 6 > & CRC_6_CDMA2000B()
Returns a set of parameters for CRC-6 CDMA2000-B.
Definition CRC.h:1127
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).
Definition CRC.h:1674
static const Parameters< crcpp_uint16, 11 > & CRC_11()
Returns a set of parameters for CRC-11 FlexRay.
Definition CRC.h:1346
static const Parameters< crcpp_uint32, 32 > & CRC_32_Q()
Returns a set of parameters for CRC-32 Q.
Definition CRC.h:2063
static const Parameters< crcpp_uint16, 16 > & CRC_16_T10DIF()
Returns a set of parameters for CRC-16 T10-DIF.
Definition CRC.h:1729
static const Parameters< crcpp_uint16, 16 > & CRC_16_MCRF4XX()
Returns a set of parameters for CRC-16 MCRF4XX.
Definition CRC.h:1546
static const Parameters< crcpp_uint16, 12 > & CRC_12_CDMA2000()
Returns a set of parameters for CRC-12 CDMA2000.
Definition CRC.h:1383
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).
Definition CRC.h:1656
static IntegerType Reflect(IntegerType value, crcpp_uint16 numBits)
Reflects (i.e. reverses the bits within) an integer value.
Definition CRC.h:691
static const Parameters< crcpp_uint8, 8 > & CRC_8_EBU()
Returns a set of parameters for CRC-8 EBU (aka CRC-8 AES).
Definition CRC.h:1220
static const Parameters< crcpp_uint8, 5 > & CRC_5_USB()
Returns a set of parameters for CRC-5 USB.
Definition CRC.h:1091
static const Parameters< crcpp_uint16, 16 > & CRC_16_USB()
Returns a set of parameters for CRC-16 USB.
Definition CRC.h:1747
static const Parameters< crcpp_uint16, 16 > & CRC_16_MODBUS()
Returns a set of parameters for CRC-16 MODBUS.
Definition CRC.h:1711
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).
Definition CRC.h:1988
static const Parameters< crcpp_uint16, 16 > & CRC_16_CDMA2000()
Returns a set of parameters for CRC-16 CDMA2000.
Definition CRC.h:1565
static const Parameters< crcpp_uint16, 16 > & CRC_16_CCITTFALSE()
Returns a set of parameters for CRC-16 CCITT FALSE.
Definition CRC.h:1528
static const Parameters< crcpp_uint32, 32 > & CRC_32_POSIX()
Returns a set of parameters for CRC-32 POSIX.
Definition CRC.h:2044
static const Parameters< crcpp_uint16, 11 > & CRC_11_NR()
Returns a set of parameters for CRC-11 NR.
Definition CRC.h:1365
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,...
Definition CRC.h:1767
static const Parameters< crcpp_uint8, 6 > & CRC_6_CDMA2000A()
Returns a set of parameters for CRC-6 CDMA2000-A.
Definition CRC.h:1109
static const Parameters< crcpp_uint8, 5 > & CRC_5_ITU()
Returns a set of parameters for CRC-5 ITU.
Definition CRC.h:1073
static const Parameters< crcpp_uint8, 8 > & CRC_8_LTE()
Returns a set of parameters for CRC-8 LTE.
Definition CRC.h:1292
static CRCType Calculate(const void *data, crcpp_size size, const Parameters< CRCType, CRCWidth > ¶meters)
Computes a CRC.
Definition CRC.h:463
static const Parameters< crcpp_uint16, 16 > & CRC_16_DNP()
Returns a set of parameters for CRC-16 DNP.
Definition CRC.h:1637
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).
Definition CRC.h:1492
static const Parameters< crcpp_uint32, 32 > & CRC_32()
Returns a set of parameters for CRC-32 (aka CRC-32 ADCCP, CRC-32 PKZip).
Definition CRC.h:1970
static const Parameters< crcpp_uint64, 64 > & CRC_64()
Returns a set of parameters for CRC-64 ECMA.
Definition CRC.h:2099
static CRCType Finalize(CRCType remainder, CRCType finalXOR, bool reflectOutput)
Computes the final reflection and XOR of a CRC remainder.
Definition CRC.h:714
static const Parameters< crcpp_uint64, 40 > & CRC_40_GSM()
Returns a set of parameters for CRC-40 GSM.
Definition CRC.h:2081
CRC parameters.
Definition CRC.h:160
Table< CRCType, CRCWidth > MakeTable() const
Returns a CRC lookup table construct using these CRC parameters.
Definition CRC.h:342
CRCType initialValue
Initial CRC value.
Definition CRC.h:162
CRCType polynomial
CRC polynomial.
Definition CRC.h:161
CRCType finalXOR
Value to XOR with the final CRC.
Definition CRC.h:163
bool reflectInput
true to reflect all input bytes
Definition CRC.h:164
bool reflectOutput
true to reflect the output CRC (reflection occurs before the final XOR)
Definition CRC.h:165
CRC lookup table. After construction, the CRC parameters are fixed.
Definition CRC.h:176
const CRCType * GetTable() const
Gets the CRC table.
Definition CRC.h:395
const Parameters< CRCType, CRCWidth > & GetParameters() const
Gets the CRC parameters used to construct the CRC table.
Definition CRC.h:383
CRCType operator[](unsigned char index) const
Gets an entry in the CRC table.
Definition CRC.h:408
Table(const Parameters< CRCType, CRCWidth > ¶meters)
Constructs a CRC table from a set of CRC parameters.
Definition CRC.h:355
void InitTable()
Initializes a CRC table.
Definition CRC.h:419
Parameters< CRCType, CRCWidth > parameters
CRC parameters used to construct the table.
Definition CRC.h:193