GNU Radio's SATNOGS Package
CRC.h
Go to the documentation of this file.
1/**
2 @file CRC.h
3 @author Daniel Bahr
4 @version 1.2.0.0
5 @copyright
6 @parblock
7 CRC++
8 Copyright (c) 2022, Daniel Bahr
9 All rights reserved.
10
11 Redistribution and use in source and binary forms, with or without
12 modification, are permitted provided that the following conditions are met:
13
14 * Redistributions of source code must retain the above copyright notice, this
15 list of conditions and the following disclaimer.
16
17 * Redistributions in binary form must reproduce the above copyright notice,
18 this list of conditions and the following disclaimer in the documentation
19 and/or other materials provided with the distribution.
20
21 * Neither the name of CRC++ nor the names of its
22 contributors may be used to endorse or promote products derived from
23 this software without specific prior written permission.
24
25 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
26 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
28 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
29 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
31 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
32 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
33 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
34 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 @endparblock
36*/
37
38/*
39 CRC++ can be configured by setting various #defines before #including this header file:
40
41 #define crcpp_uint8 - Specifies the type used to store CRCs that have a width of 8 bits or less.
42 This type is not used in CRC calculations. Defaults to ::std::uint8_t.
43 #define crcpp_uint16 - Specifies the type used to store CRCs that have a width between 9 and 16 bits (inclusive).
44 This type is not used in CRC calculations. Defaults to ::std::uint16_t.
45 #define crcpp_uint32 - Specifies the type used to store CRCs that have a width between 17 and 32 bits (inclusive).
46 This type is not used in CRC calculations. Defaults to ::std::uint32_t.
47 #define crcpp_uint64 - Specifies the type used to store CRCs that have a width between 33 and 64 bits (inclusive).
48 This type is not used in CRC calculations. Defaults to ::std::uint64_t.
49 #define crcpp_size - This type is used for loop iteration and function signatures only. Defaults to ::std::size_t.
50 #define CRCPP_USE_NAMESPACE - Define to place all CRC++ code within the ::CRCPP namespace.
51 #define CRCPP_BRANCHLESS - Define to enable a branchless CRC implementation. The branchless implementation uses a single integer
52 multiplication in the bit-by-bit calculation instead of a small conditional. The branchless implementation
53 may be faster on processor architectures which support single-instruction integer multiplication.
54 #define CRCPP_USE_CPP11 - Define to enables C++11 features (move semantics, constexpr, static_assert, etc.).
55 #define CRCPP_INCLUDE_ESOTERIC_CRC_DEFINITIONS - Define to include definitions for little-used CRCs.
56*/
57
58#ifndef CRCPP_CRC_H_
59#define CRCPP_CRC_H_
60
61#include <climits> // Includes CHAR_BIT
62#ifdef CRCPP_USE_CPP11
63#include <cstddef> // Includes ::std::size_t
64#include <cstdint> // Includes ::std::uint8_t, ::std::uint16_t, ::std::uint32_t, ::std::uint64_t
65#else
66#include <stddef.h> // Includes size_t
67#include <stdint.h> // Includes uint8_t, uint16_t, uint32_t, uint64_t
68#endif
69#include <limits> // Includes ::std::numeric_limits
70#include <utility> // Includes ::std::move
71
72#ifndef crcpp_uint8
73# ifdef CRCPP_USE_CPP11
74 /// @brief Unsigned 8-bit integer definition, used primarily for parameter definitions.
75# define crcpp_uint8 ::std::uint8_t
76# else
77 /// @brief Unsigned 8-bit integer definition, used primarily for parameter definitions.
78# define crcpp_uint8 uint8_t
79# endif
80#endif
81
82#ifndef crcpp_uint16
83# ifdef CRCPP_USE_CPP11
84 /// @brief Unsigned 16-bit integer definition, used primarily for parameter definitions.
85# define crcpp_uint16 ::std::uint16_t
86# else
87 /// @brief Unsigned 16-bit integer definition, used primarily for parameter definitions.
88# define crcpp_uint16 uint16_t
89# endif
90#endif
91
92#ifndef crcpp_uint32
93# ifdef CRCPP_USE_CPP11
94 /// @brief Unsigned 32-bit integer definition, used primarily for parameter definitions.
95# define crcpp_uint32 ::std::uint32_t
96# else
97 /// @brief Unsigned 32-bit integer definition, used primarily for parameter definitions.
98# define crcpp_uint32 uint32_t
99# endif
100#endif
101
102#ifndef crcpp_uint64
103# ifdef CRCPP_USE_CPP11
104 /// @brief Unsigned 64-bit integer definition, used primarily for parameter definitions.
105# define crcpp_uint64 ::std::uint64_t
106# else
107 /// @brief Unsigned 64-bit integer definition, used primarily for parameter definitions.
108# define crcpp_uint64 uint64_t
109# endif
110#endif
111
112#ifndef crcpp_size
113# ifdef CRCPP_USE_CPP11
114 /// @brief Unsigned size definition, used for specifying data sizes.
115# define crcpp_size ::std::size_t
116# else
117 /// @brief Unsigned size definition, used for specifying data sizes.
118# define crcpp_size size_t
119# endif
120#endif
121
122#ifdef CRCPP_USE_CPP11
123 /// @brief Compile-time expression definition.
124# define crcpp_constexpr constexpr
125#else
126 /// @brief Compile-time expression definition.
127# define crcpp_constexpr const
128#endif
129
130#if defined(WIN32) || defined(_WIN32) || defined(WINCE)
131/* Disable warning C4127: conditional expression is constant. */
132#pragma warning(push)
133#pragma warning(disable : 4127)
134#endif
135
136#ifdef CRCPP_USE_NAMESPACE
137namespace CRCPP
138{
139#endif
140
141/**
142 @brief Static class for computing CRCs.
143 @note This class supports computation of full and multi-part CRCs, using a bit-by-bit algorithm or a
144 byte-by-byte lookup table. The CRCs are calculated using as many optimizations as is reasonable.
145 If compiling with C++11, the constexpr keyword is used liberally so that many calculations are
146 performed at compile-time instead of at runtime.
147*/
148class CRC
149{
150public:
151 // Forward declaration
152 template <typename CRCType, crcpp_uint16 CRCWidth>
153 struct Table;
154
155 /**
156 @brief CRC parameters.
157 */
158 template <typename CRCType, crcpp_uint16 CRCWidth>
160 {
161 CRCType polynomial; ///< CRC polynomial
162 CRCType initialValue; ///< Initial CRC value
163 CRCType finalXOR; ///< Value to XOR with the final CRC
164 bool reflectInput; ///< true to reflect all input bytes
165 bool reflectOutput; ///< true to reflect the output CRC (reflection occurs before the final XOR)
166
167 Table<CRCType, CRCWidth> MakeTable() const;
168 };
169
170 /**
171 @brief CRC lookup table. After construction, the CRC parameters are fixed.
172 @note A CRC table can be used for multiple CRC calculations.
173 */
174 template <typename CRCType, crcpp_uint16 CRCWidth>
175 struct Table
176 {
177 // Constructors are intentionally NOT marked explicit.
178 Table(const Parameters<CRCType, CRCWidth> & parameters);
179
180#ifdef CRCPP_USE_CPP11
182#endif
183
184 const Parameters<CRCType, CRCWidth> & GetParameters() const;
185
186 const CRCType * GetTable() const;
187
188 CRCType operator[](unsigned char index) const;
189
190 private:
191 void InitTable();
192
193 Parameters<CRCType, CRCWidth> parameters; ///< CRC parameters used to construct the table
194 CRCType table[1 << CHAR_BIT]; ///< CRC lookup table
195 };
196
197 // The number of bits in CRCType must be at least as large as CRCWidth.
198 // CRCType must be an unsigned integer type or a custom type with operator overloads.
199 template <typename CRCType, crcpp_uint16 CRCWidth>
200 static CRCType Calculate(const void * data, crcpp_size size, const Parameters<CRCType, CRCWidth> & parameters);
201
202 template <typename CRCType, crcpp_uint16 CRCWidth>
203 static CRCType Calculate(const void * data, crcpp_size size, const Parameters<CRCType, CRCWidth> & parameters, CRCType crc);
204
205 template <typename CRCType, crcpp_uint16 CRCWidth>
206 static CRCType Calculate(const void * data, crcpp_size size, const Table<CRCType, CRCWidth> & lookupTable);
207
208 template <typename CRCType, crcpp_uint16 CRCWidth>
209 static CRCType Calculate(const void * data, crcpp_size size, const Table<CRCType, CRCWidth> & lookupTable, CRCType crc);
210
211 template <typename CRCType, crcpp_uint16 CRCWidth>
212 static CRCType CalculateBits(const void * data, crcpp_size size, const Parameters<CRCType, CRCWidth> & parameters);
213
214 template <typename CRCType, crcpp_uint16 CRCWidth>
215 static CRCType CalculateBits(const void * data, crcpp_size size, const Parameters<CRCType, CRCWidth> & parameters, CRCType crc);
216
217 template <typename CRCType, crcpp_uint16 CRCWidth>
218 static CRCType CalculateBits(const void * data, crcpp_size size, const Table<CRCType, CRCWidth> & lookupTable);
219
220 template <typename CRCType, crcpp_uint16 CRCWidth>
221 static CRCType CalculateBits(const void * data, crcpp_size size, const Table<CRCType, CRCWidth> & lookupTable, CRCType crc);
222
223 // Common CRCs up to 64 bits.
224 // Note: Check values are the computed CRCs when given an ASCII input of "123456789" (without null terminator)
225#ifdef CRCPP_INCLUDE_ESOTERIC_CRC_DEFINITIONS
226 static const Parameters< crcpp_uint8, 4> & CRC_4_ITU();
227 static const Parameters< crcpp_uint8, 5> & CRC_5_EPC();
228 static const Parameters< crcpp_uint8, 5> & CRC_5_ITU();
229 static const Parameters< crcpp_uint8, 5> & CRC_5_USB();
230 static const Parameters< crcpp_uint8, 6> & CRC_6_CDMA2000A();
231 static const Parameters< crcpp_uint8, 6> & CRC_6_CDMA2000B();
232 static const Parameters< crcpp_uint8, 6> & CRC_6_ITU();
233 static const Parameters< crcpp_uint8, 6> & CRC_6_NR();
234 static const Parameters< crcpp_uint8, 7> & CRC_7();
235#endif
236 static const Parameters< crcpp_uint8, 8> & CRC_8();
237#ifdef CRCPP_INCLUDE_ESOTERIC_CRC_DEFINITIONS
238 static const Parameters< crcpp_uint8, 8> & CRC_8_EBU();
239 static const Parameters< crcpp_uint8, 8> & CRC_8_HDLC();
240 static const Parameters< crcpp_uint8, 8> & CRC_8_MAXIM();
241 static const Parameters< crcpp_uint8, 8> & CRC_8_WCDMA();
242 static const Parameters< crcpp_uint8, 8> & CRC_8_LTE();
243 static const Parameters<crcpp_uint16, 10> & CRC_10();
244 static const Parameters<crcpp_uint16, 10> & CRC_10_CDMA2000();
245 static const Parameters<crcpp_uint16, 11> & CRC_11();
246 static const Parameters<crcpp_uint16, 11> & CRC_11_NR();
247 static const Parameters<crcpp_uint16, 12> & CRC_12_CDMA2000();
248 static const Parameters<crcpp_uint16, 12> & CRC_12_DECT();
249 static const Parameters<crcpp_uint16, 12> & CRC_12_UMTS();
250 static const Parameters<crcpp_uint16, 13> & CRC_13_BBC();
251 static const Parameters<crcpp_uint16, 15> & CRC_15();
252 static const Parameters<crcpp_uint16, 15> & CRC_15_MPT1327();
253#endif
254 static const Parameters<crcpp_uint16, 16> & CRC_16_ARC();
255 static const Parameters<crcpp_uint16, 16> & CRC_16_BUYPASS();
256 static const Parameters<crcpp_uint16, 16> & CRC_16_CCITTFALSE();
257 static const Parameters<crcpp_uint16, 16> & CRC_16_MCRF4XX();
258#ifdef CRCPP_INCLUDE_ESOTERIC_CRC_DEFINITIONS
259 static const Parameters<crcpp_uint16, 16> & CRC_16_CDMA2000();
260 static const Parameters<crcpp_uint16, 16> & CRC_16_CMS();
261 static const Parameters<crcpp_uint16, 16> & CRC_16_DECTR();
262 static const Parameters<crcpp_uint16, 16> & CRC_16_DECTX();
263 static const Parameters<crcpp_uint16, 16> & CRC_16_DNP();
264#endif
265 static const Parameters<crcpp_uint16, 16> & CRC_16_GENIBUS();
266 static const Parameters<crcpp_uint16, 16> & CRC_16_KERMIT();
267#ifdef CRCPP_INCLUDE_ESOTERIC_CRC_DEFINITIONS
268 static const Parameters<crcpp_uint16, 16> & CRC_16_MAXIM();
269 static const Parameters<crcpp_uint16, 16> & CRC_16_MODBUS();
270 static const Parameters<crcpp_uint16, 16> & CRC_16_T10DIF();
271 static const Parameters<crcpp_uint16, 16> & CRC_16_USB();
272#endif
273 static const Parameters<crcpp_uint16, 16> & CRC_16_X25();
274 static const Parameters<crcpp_uint16, 16> & CRC_16_XMODEM();
275#ifdef CRCPP_INCLUDE_ESOTERIC_CRC_DEFINITIONS
276 static const Parameters<crcpp_uint32, 17> & CRC_17_CAN();
277 static const Parameters<crcpp_uint32, 21> & CRC_21_CAN();
278 static const Parameters<crcpp_uint32, 24> & CRC_24();
279 static const Parameters<crcpp_uint32, 24> & CRC_24_FLEXRAYA();
280 static const Parameters<crcpp_uint32, 24> & CRC_24_FLEXRAYB();
281 static const Parameters<crcpp_uint32, 24> & CRC_24_LTEA();
282 static const Parameters<crcpp_uint32, 24> & CRC_24_LTEB();
283 static const Parameters<crcpp_uint32, 24> & CRC_24_NRC();
284 static const Parameters<crcpp_uint32, 30> & CRC_30();
285#endif
286 static const Parameters<crcpp_uint32, 32> & CRC_32();
287 static const Parameters<crcpp_uint32, 32> & CRC_32_BZIP2();
288#ifdef CRCPP_INCLUDE_ESOTERIC_CRC_DEFINITIONS
289 static const Parameters<crcpp_uint32, 32> & CRC_32_C();
290#endif
291 static const Parameters<crcpp_uint32, 32> & CRC_32_MPEG2();
292 static const Parameters<crcpp_uint32, 32> & CRC_32_POSIX();
293#ifdef CRCPP_INCLUDE_ESOTERIC_CRC_DEFINITIONS
294 static const Parameters<crcpp_uint32, 32> & CRC_32_Q();
295 static const Parameters<crcpp_uint64, 40> & CRC_40_GSM();
296 static const Parameters<crcpp_uint64, 64> & CRC_64();
297#endif
298
299#ifdef CRCPP_USE_CPP11
300 CRC() = delete;
301 CRC(const CRC & other) = delete;
302 CRC & operator=(const CRC & other) = delete;
303 CRC(CRC && other) = delete;
304 CRC & operator=(CRC && other) = delete;
305#endif
306
307private:
308#ifndef CRCPP_USE_CPP11
309 CRC();
310 CRC(const CRC & other);
311 CRC & operator=(const CRC & other);
312#endif
313
314 template <typename IntegerType>
315 static IntegerType Reflect(IntegerType value, crcpp_uint16 numBits);
316
317 template <typename CRCType, crcpp_uint16 CRCWidth>
318 static CRCType Finalize(CRCType remainder, CRCType finalXOR, bool reflectOutput);
319
320 template <typename CRCType, crcpp_uint16 CRCWidth>
321 static CRCType UndoFinalize(CRCType remainder, CRCType finalXOR, bool reflectOutput);
322
323 template <typename CRCType, crcpp_uint16 CRCWidth>
324 static CRCType CalculateRemainder(const void * data, crcpp_size size, const Parameters<CRCType, CRCWidth> & parameters, CRCType remainder);
325
326 template <typename CRCType, crcpp_uint16 CRCWidth>
327 static CRCType CalculateRemainder(const void * data, crcpp_size size, const Table<CRCType, CRCWidth> & lookupTable, CRCType remainder);
328
329 template <typename CRCType, crcpp_uint16 CRCWidth>
330 static CRCType CalculateRemainderBits(unsigned char byte, crcpp_size numBits, const Parameters<CRCType, CRCWidth> & parameters, CRCType remainder);
331};
332
333/**
334 @brief Returns a CRC lookup table construct using these CRC parameters.
335 @note This function primarily exists to allow use of the auto keyword instead of instantiating
336 a table directly, since template parameters are not inferred in constructors.
337 @tparam CRCType Integer type for storing the CRC result
338 @tparam CRCWidth Number of bits in the CRC
339 @return CRC lookup table
340*/
341template <typename CRCType, crcpp_uint16 CRCWidth>
343{
344 // This should take advantage of RVO and optimize out the copy.
345 return CRC::Table<CRCType, CRCWidth>(*this);
346}
347
348/**
349 @brief Constructs a CRC table from a set of CRC parameters
350 @param[in] params CRC parameters
351 @tparam CRCType Integer type for storing the CRC result
352 @tparam CRCWidth Number of bits in the CRC
353*/
354template <typename CRCType, crcpp_uint16 CRCWidth>
356 parameters(params)
357{
358 InitTable();
359}
360
361#ifdef CRCPP_USE_CPP11
362/**
363 @brief Constructs a CRC table from a set of CRC parameters
364 @param[in] params CRC parameters
365 @tparam CRCType Integer type for storing the CRC result
366 @tparam CRCWidth Number of bits in the CRC
367*/
368template <typename CRCType, crcpp_uint16 CRCWidth>
370 parameters(::std::move(params))
371{
372 InitTable();
373}
374#endif
375
376/**
377 @brief Gets the CRC parameters used to construct the CRC table
378 @tparam CRCType Integer type for storing the CRC result
379 @tparam CRCWidth Number of bits in the CRC
380 @return CRC parameters
381*/
382template <typename CRCType, crcpp_uint16 CRCWidth>
384{
385 return parameters;
386}
387
388/**
389 @brief Gets the CRC table
390 @tparam CRCType Integer type for storing the CRC result
391 @tparam CRCWidth Number of bits in the CRC
392 @return CRC table
393*/
394template <typename CRCType, crcpp_uint16 CRCWidth>
395inline const CRCType * CRC::Table<CRCType, CRCWidth>::GetTable() const
396{
397 return table;
398}
399
400/**
401 @brief Gets an entry in the CRC table
402 @param[in] index Index into the CRC table
403 @tparam CRCType Integer type for storing the CRC result
404 @tparam CRCWidth Number of bits in the CRC
405 @return CRC table entry
406*/
407template <typename CRCType, crcpp_uint16 CRCWidth>
408inline CRCType CRC::Table<CRCType, CRCWidth>::operator[](unsigned char index) const
409{
410 return table[index];
411}
412
413/**
414 @brief Initializes a CRC table.
415 @tparam CRCType Integer type for storing the CRC result
416 @tparam CRCWidth Number of bits in the CRC
417*/
418template <typename CRCType, crcpp_uint16 CRCWidth>
420{
421 // For masking off the bits for the CRC (in the event that the number of bits in CRCType is larger than CRCWidth)
422 static crcpp_constexpr CRCType BIT_MASK((CRCType(1) << (CRCWidth - CRCType(1))) |
423 ((CRCType(1) << (CRCWidth - CRCType(1))) - CRCType(1)));
424
425 // The conditional expression is used to avoid a -Wshift-count-overflow warning.
426 static crcpp_constexpr CRCType SHIFT((CHAR_BIT >= CRCWidth) ? static_cast<CRCType>(CHAR_BIT - CRCWidth) : 0);
427
428 CRCType crc;
429 unsigned char byte = 0;
430
431 // Loop over each dividend (each possible number storable in an unsigned char)
432 do
433 {
434 crc = CRC::CalculateRemainder<CRCType, CRCWidth>(&byte, sizeof(byte), parameters, CRCType(0));
435
436 // This mask might not be necessary; all unit tests pass with this line commented out,
437 // but that might just be a coincidence based on the CRC parameters used for testing.
438 // In any case, this is harmless to leave in and only adds a single machine instruction per loop iteration.
439 crc &= BIT_MASK;
440
441 if (!parameters.reflectInput && CRCWidth < CHAR_BIT)
442 {
443 // Undo the special operation at the end of the CalculateRemainder()
444 // function for non-reflected CRCs < CHAR_BIT.
445 crc = static_cast<CRCType>(crc << SHIFT);
446 }
447
448 table[byte] = crc;
449 }
450 while (++byte);
451}
452
453/**
454 @brief Computes a CRC.
455 @param[in] data Data over which CRC will be computed
456 @param[in] size Size of the data, in bytes
457 @param[in] parameters CRC parameters
458 @tparam CRCType Integer type for storing the CRC result
459 @tparam CRCWidth Number of bits in the CRC
460 @return CRC
461*/
462template <typename CRCType, crcpp_uint16 CRCWidth>
463inline CRCType CRC::Calculate(const void * data, crcpp_size size, const Parameters<CRCType, CRCWidth> & parameters)
464{
465 CRCType remainder = CalculateRemainder(data, size, parameters, parameters.initialValue);
466
467 // No need to mask the remainder here; the mask will be applied in the Finalize() function.
468
469 return Finalize<CRCType, CRCWidth>(remainder, parameters.finalXOR, parameters.reflectInput != parameters.reflectOutput);
470}
471/**
472 @brief Appends additional data to a previous CRC calculation.
473 @note This function can be used to compute multi-part CRCs.
474 @param[in] data Data over which CRC will be computed
475 @param[in] size Size of the data, in bytes
476 @param[in] parameters CRC parameters
477 @param[in] crc CRC from a previous calculation
478 @tparam CRCType Integer type for storing the CRC result
479 @tparam CRCWidth Number of bits in the CRC
480 @return CRC
481*/
482template <typename CRCType, crcpp_uint16 CRCWidth>
483inline CRCType CRC::Calculate(const void * data, crcpp_size size, const Parameters<CRCType, CRCWidth> & parameters, CRCType crc)
484{
485 CRCType remainder = UndoFinalize<CRCType, CRCWidth>(crc, parameters.finalXOR, parameters.reflectInput != parameters.reflectOutput);
486
487 remainder = CalculateRemainder(data, size, parameters, remainder);
488
489 // No need to mask the remainder here; the mask will be applied in the Finalize() function.
490
491 return Finalize<CRCType, CRCWidth>(remainder, parameters.finalXOR, parameters.reflectInput != parameters.reflectOutput);
492}
493
494/**
495 @brief Computes a CRC via a lookup table.
496 @param[in] data Data over which CRC will be computed
497 @param[in] size Size of the data, in bytes
498 @param[in] lookupTable CRC lookup table
499 @tparam CRCType Integer type for storing the CRC result
500 @tparam CRCWidth Number of bits in the CRC
501 @return CRC
502*/
503template <typename CRCType, crcpp_uint16 CRCWidth>
504inline CRCType CRC::Calculate(const void * data, crcpp_size size, const Table<CRCType, CRCWidth> & lookupTable)
505{
506 const Parameters<CRCType, CRCWidth> & parameters = lookupTable.GetParameters();
507
508 CRCType remainder = CalculateRemainder(data, size, lookupTable, parameters.initialValue);
509
510 // No need to mask the remainder here; the mask will be applied in the Finalize() function.
511
512 return Finalize<CRCType, CRCWidth>(remainder, parameters.finalXOR, parameters.reflectInput != parameters.reflectOutput);
513}
514
515/**
516 @brief Appends additional data to a previous CRC calculation using a lookup table.
517 @note This function can be used to compute multi-part CRCs.
518 @param[in] data Data over which CRC will be computed
519 @param[in] size Size of the data, in bytes
520 @param[in] lookupTable CRC lookup table
521 @param[in] crc CRC from a previous calculation
522 @tparam CRCType Integer type for storing the CRC result
523 @tparam CRCWidth Number of bits in the CRC
524 @return CRC
525*/
526template <typename CRCType, crcpp_uint16 CRCWidth>
527inline CRCType CRC::Calculate(const void * data, crcpp_size size, const Table<CRCType, CRCWidth> & lookupTable, CRCType crc)
528{
529 const Parameters<CRCType, CRCWidth> & parameters = lookupTable.GetParameters();
530
531 CRCType remainder = UndoFinalize<CRCType, CRCWidth>(crc, parameters.finalXOR, parameters.reflectInput != parameters.reflectOutput);
532
533 remainder = CalculateRemainder(data, size, lookupTable, remainder);
534
535 // No need to mask the remainder here; the mask will be applied in the Finalize() function.
536
537 return Finalize<CRCType, CRCWidth>(remainder, parameters.finalXOR, parameters.reflectInput != parameters.reflectOutput);
538}
539
540/**
541 @brief Computes a CRC.
542 @param[in] data Data over which CRC will be computed
543 @param[in] size Size of the data, in bits
544 @param[in] parameters CRC parameters
545 @tparam CRCType Integer type for storing the CRC result
546 @tparam CRCWidth Number of bits in the CRC
547 @return CRC
548*/
549template <typename CRCType, crcpp_uint16 CRCWidth>
550inline CRCType CRC::CalculateBits(const void * data, crcpp_size size, const Parameters<CRCType, CRCWidth> & parameters)
551{
552 CRCType remainder = parameters.initialValue;
553
554 // Calculate the remainder on a whole number of bytes first, then call
555 // a special-case function for the remaining bits.
556 crcpp_size wholeNumberOfBytes = size / CHAR_BIT;
557 if (wholeNumberOfBytes > 0)
558 {
559 remainder = CalculateRemainder(data, wholeNumberOfBytes, parameters, remainder);
560 }
561
562 crcpp_size remainingNumberOfBits = size % CHAR_BIT;
563 if (remainingNumberOfBits != 0)
564 {
565 unsigned char lastByte = *(reinterpret_cast<const unsigned char *>(data) + wholeNumberOfBytes);
566 remainder = CalculateRemainderBits(lastByte, remainingNumberOfBits, parameters, remainder);
567 }
568
569 // No need to mask the remainder here; the mask will be applied in the Finalize() function.
570
571 return Finalize<CRCType, CRCWidth>(remainder, parameters.finalXOR, parameters.reflectInput != parameters.reflectOutput);
572}
573/**
574 @brief Appends additional data to a previous CRC calculation.
575 @note This function can be used to compute multi-part CRCs.
576 @param[in] data Data over which CRC will be computed
577 @param[in] size Size of the data, in bits
578 @param[in] parameters CRC parameters
579 @param[in] crc CRC from a previous calculation
580 @tparam CRCType Integer type for storing the CRC result
581 @tparam CRCWidth Number of bits in the CRC
582 @return CRC
583*/
584template <typename CRCType, crcpp_uint16 CRCWidth>
585inline CRCType CRC::CalculateBits(const void * data, crcpp_size size, const Parameters<CRCType, CRCWidth> & parameters, CRCType crc)
586{
587 CRCType remainder = UndoFinalize<CRCType, CRCWidth>(crc, parameters.finalXOR, parameters.reflectInput != parameters.reflectOutput);
588
589 // Calculate the remainder on a whole number of bytes first, then call
590 // a special-case function for the remaining bits.
591 crcpp_size wholeNumberOfBytes = size / CHAR_BIT;
592 if (wholeNumberOfBytes > 0)
593 {
594 remainder = CalculateRemainder(data, wholeNumberOfBytes, parameters, parameters.initialValue);
595 }
596
597 crcpp_size remainingNumberOfBits = size % CHAR_BIT;
598 if (remainingNumberOfBits != 0)
599 {
600 unsigned char lastByte = *(reinterpret_cast<const unsigned char *>(data) + wholeNumberOfBytes);
601 remainder = CalculateRemainderBits(lastByte, remainingNumberOfBits, parameters, remainder);
602 }
603
604 // No need to mask the remainder here; the mask will be applied in the Finalize() function.
605
606 return Finalize<CRCType, CRCWidth>(remainder, parameters.finalXOR, parameters.reflectInput != parameters.reflectOutput);
607}
608
609/**
610 @brief Computes a CRC via a lookup table.
611 @param[in] data Data over which CRC will be computed
612 @param[in] size Size of the data, in bits
613 @param[in] lookupTable CRC lookup table
614 @tparam CRCType Integer type for storing the CRC result
615 @tparam CRCWidth Number of bits in the CRC
616 @return CRC
617*/
618template <typename CRCType, crcpp_uint16 CRCWidth>
619inline CRCType CRC::CalculateBits(const void * data, crcpp_size size, const Table<CRCType, CRCWidth> & lookupTable)
620{
621 const Parameters<CRCType, CRCWidth> & parameters = lookupTable.GetParameters();
622
623 CRCType remainder = parameters.initialValue;
624
625 // Calculate the remainder on a whole number of bytes first, then call
626 // a special-case function for the remaining bits.
627 crcpp_size wholeNumberOfBytes = size / CHAR_BIT;
628 if (wholeNumberOfBytes > 0)
629 {
630 remainder = CalculateRemainder(data, wholeNumberOfBytes, lookupTable, remainder);
631 }
632
633 crcpp_size remainingNumberOfBits = size % CHAR_BIT;
634 if (remainingNumberOfBits != 0)
635 {
636 unsigned char lastByte = *(reinterpret_cast<const unsigned char *>(data) + wholeNumberOfBytes);
637 remainder = CalculateRemainderBits(lastByte, remainingNumberOfBits, parameters, remainder);
638 }
639
640 // No need to mask the remainder here; the mask will be applied in the Finalize() function.
641
642 return Finalize<CRCType, CRCWidth>(remainder, parameters.finalXOR, parameters.reflectInput != parameters.reflectOutput);
643}
644
645/**
646 @brief Appends additional data to a previous CRC calculation using a lookup table.
647 @note This function can be used to compute multi-part CRCs.
648 @param[in] data Data over which CRC will be computed
649 @param[in] size Size of the data, in bits
650 @param[in] lookupTable CRC lookup table
651 @param[in] crc CRC from a previous calculation
652 @tparam CRCType Integer type for storing the CRC result
653 @tparam CRCWidth Number of bits in the CRC
654 @return CRC
655*/
656template <typename CRCType, crcpp_uint16 CRCWidth>
657inline CRCType CRC::CalculateBits(const void * data, crcpp_size size, const Table<CRCType, CRCWidth> & lookupTable, CRCType crc)
658{
659 const Parameters<CRCType, CRCWidth> & parameters = lookupTable.GetParameters();
660
661 CRCType remainder = UndoFinalize<CRCType, CRCWidth>(crc, parameters.finalXOR, parameters.reflectInput != parameters.reflectOutput);
662
663 // Calculate the remainder on a whole number of bytes first, then call
664 // a special-case function for the remaining bits.
665 crcpp_size wholeNumberOfBytes = size / CHAR_BIT;
666 if (wholeNumberOfBytes > 0)
667 {
668 remainder = CalculateRemainder(data, wholeNumberOfBytes, lookupTable, parameters.initialValue);
669 }
670
671 crcpp_size remainingNumberOfBits = size % CHAR_BIT;
672 if (remainingNumberOfBits > 0)
673 {
674 unsigned char lastByte = *(reinterpret_cast<const unsigned char *>(data) + wholeNumberOfBytes);
675 remainder = CalculateRemainderBits(lastByte, remainingNumberOfBits, parameters, remainder);
676 }
677
678 // No need to mask the remainder here; the mask will be applied in the Finalize() function.
679
680 return Finalize<CRCType, CRCWidth>(remainder, parameters.finalXOR, parameters.reflectInput != parameters.reflectOutput);
681}
682
683/**
684 @brief Reflects (i.e. reverses the bits within) an integer value.
685 @param[in] value Value to reflect
686 @param[in] numBits Number of bits in the integer which will be reflected
687 @tparam IntegerType Integer type of the value being reflected
688 @return Reflected value
689*/
690template <typename IntegerType>
691inline IntegerType CRC::Reflect(IntegerType value, crcpp_uint16 numBits)
692{
693 IntegerType reversedValue(0);
694
695 for (crcpp_uint16 i = 0; i < numBits; ++i)
696 {
697 reversedValue = static_cast<IntegerType>((reversedValue << 1) | (value & 1));
698 value = static_cast<IntegerType>(value >> 1);
699 }
700
701 return reversedValue;
702}
703
704/**
705 @brief Computes the final reflection and XOR of a CRC remainder.
706 @param[in] remainder CRC remainder to reflect and XOR
707 @param[in] finalXOR Final value to XOR with the remainder
708 @param[in] reflectOutput true to reflect each byte of the remainder before the XOR
709 @tparam CRCType Integer type for storing the CRC result
710 @tparam CRCWidth Number of bits in the CRC
711 @return Final CRC
712*/
713template <typename CRCType, crcpp_uint16 CRCWidth>
714inline CRCType CRC::Finalize(CRCType remainder, CRCType finalXOR, bool reflectOutput)
715{
716 // For masking off the bits for the CRC (in the event that the number of bits in CRCType is larger than CRCWidth)
717 static crcpp_constexpr CRCType BIT_MASK = (CRCType(1) << (CRCWidth - CRCType(1))) |
718 ((CRCType(1) << (CRCWidth - CRCType(1))) - CRCType(1));
719
720 if (reflectOutput)
721 {
722 remainder = Reflect(remainder, CRCWidth);
723 }
724
725 return (remainder ^ finalXOR) & BIT_MASK;
726}
727
728/**
729 @brief Undoes the process of computing the final reflection and XOR of a CRC remainder.
730 @note This function allows for computation of multi-part CRCs
731 @note Calling UndoFinalize() followed by Finalize() (or vice versa) will always return the original remainder value:
732
733 CRCType x = ...;
734 CRCType y = Finalize(x, finalXOR, reflectOutput);
735 CRCType z = UndoFinalize(y, finalXOR, reflectOutput);
736 assert(x == z);
737
738 @param[in] crc Reflected and XORed CRC
739 @param[in] finalXOR Final value XORed with the remainder
740 @param[in] reflectOutput true if the remainder is to be reflected
741 @tparam CRCType Integer type for storing the CRC result
742 @tparam CRCWidth Number of bits in the CRC
743 @return Un-finalized CRC remainder
744*/
745template <typename CRCType, crcpp_uint16 CRCWidth>
746inline CRCType CRC::UndoFinalize(CRCType crc, CRCType finalXOR, bool reflectOutput)
747{
748 // For masking off the bits for the CRC (in the event that the number of bits in CRCType is larger than CRCWidth)
749 static crcpp_constexpr CRCType BIT_MASK = (CRCType(1) << (CRCWidth - CRCType(1))) |
750 ((CRCType(1) << (CRCWidth - CRCType(1))) - CRCType(1));
751
752 crc = (crc & BIT_MASK) ^ finalXOR;
753
754 if (reflectOutput)
755 {
756 crc = Reflect(crc, CRCWidth);
757 }
758
759 return crc;
760}
761
762/**
763 @brief Computes a CRC remainder.
764 @param[in] data Data over which the remainder will be computed
765 @param[in] size Size of the data, in bytes
766 @param[in] parameters CRC parameters
767 @param[in] remainder Running CRC remainder. Can be an initial value or the result of a previous CRC remainder calculation.
768 @tparam CRCType Integer type for storing the CRC result
769 @tparam CRCWidth Number of bits in the CRC
770 @return CRC remainder
771*/
772template <typename CRCType, crcpp_uint16 CRCWidth>
773inline CRCType CRC::CalculateRemainder(const void * data, crcpp_size size, const Parameters<CRCType, CRCWidth> & parameters, CRCType remainder)
774{
775#ifdef CRCPP_USE_CPP11
776 // This static_assert is put here because this function will always be compiled in no matter what
777 // the template parameters are and whether or not a table lookup or bit-by-bit algorithm is used.
778 static_assert(::std::numeric_limits<CRCType>::digits >= CRCWidth, "CRCType is too small to contain a CRC of width CRCWidth.");
779#else
780 // Catching this compile-time error is very important. Sadly, the compiler error will be very cryptic, but it's
781 // better than nothing.
782 enum { static_assert_failed_CRCType_is_too_small_to_contain_a_CRC_of_width_CRCWidth = 1 / (::std::numeric_limits<CRCType>::digits >= CRCWidth ? 1 : 0) };
783#endif
784
785 const unsigned char * current = reinterpret_cast<const unsigned char *>(data);
786
787 // Slightly different implementations based on the parameters. The current implementations try to eliminate as much
788 // computation from the inner loop (looping over each bit) as possible.
789 if (parameters.reflectInput)
790 {
791 CRCType polynomial = CRC::Reflect(parameters.polynomial, CRCWidth);
792 while (size--)
793 {
794 remainder = static_cast<CRCType>(remainder ^ *current++);
795
796 // An optimizing compiler might choose to unroll this loop.
797 for (crcpp_size i = 0; i < CHAR_BIT; ++i)
798 {
799#ifdef CRCPP_BRANCHLESS
800 // Clever way to avoid a branch at the expense of a multiplication. This code is equivalent to the following:
801 // if (remainder & 1)
802 // remainder = (remainder >> 1) ^ polynomial;
803 // else
804 // remainder >>= 1;
805 remainder = static_cast<CRCType>((remainder >> 1) ^ ((remainder & 1) * polynomial));
806#else
807 remainder = static_cast<CRCType>((remainder & 1) ? ((remainder >> 1) ^ polynomial) : (remainder >> 1));
808#endif
809 }
810 }
811 }
812 else if (CRCWidth >= CHAR_BIT)
813 {
814 static crcpp_constexpr CRCType CRC_WIDTH_MINUS_ONE(CRCWidth - CRCType(1));
815#ifndef CRCPP_BRANCHLESS
816 static crcpp_constexpr CRCType CRC_HIGHEST_BIT_MASK(CRCType(1) << CRC_WIDTH_MINUS_ONE);
817#endif
818 // The conditional expression is used to avoid a -Wshift-count-overflow warning.
819 static crcpp_constexpr CRCType SHIFT((CRCWidth >= CHAR_BIT) ? static_cast<CRCType>(CRCWidth - CHAR_BIT) : 0);
820
821 while (size--)
822 {
823 remainder = static_cast<CRCType>(remainder ^ (static_cast<CRCType>(*current++) << SHIFT));
824
825 // An optimizing compiler might choose to unroll this loop.
826 for (crcpp_size i = 0; i < CHAR_BIT; ++i)
827 {
828#ifdef CRCPP_BRANCHLESS
829 // Clever way to avoid a branch at the expense of a multiplication. This code is equivalent to the following:
830 // if (remainder & CRC_HIGHEST_BIT_MASK)
831 // remainder = (remainder << 1) ^ parameters.polynomial;
832 // else
833 // remainder <<= 1;
834 remainder = static_cast<CRCType>((remainder << 1) ^ (((remainder >> CRC_WIDTH_MINUS_ONE) & 1) * parameters.polynomial));
835#else
836 remainder = static_cast<CRCType>((remainder & CRC_HIGHEST_BIT_MASK) ? ((remainder << 1) ^ parameters.polynomial) : (remainder << 1));
837#endif
838 }
839 }
840 }
841 else
842 {
843 static crcpp_constexpr CRCType CHAR_BIT_MINUS_ONE(CHAR_BIT - 1);
844#ifndef CRCPP_BRANCHLESS
845 static crcpp_constexpr CRCType CHAR_BIT_HIGHEST_BIT_MASK(CRCType(1) << CHAR_BIT_MINUS_ONE);
846#endif
847 // The conditional expression is used to avoid a -Wshift-count-overflow warning.
848 static crcpp_constexpr CRCType SHIFT((CHAR_BIT >= CRCWidth) ? static_cast<CRCType>(CHAR_BIT - CRCWidth) : 0);
849
850 CRCType polynomial = static_cast<CRCType>(parameters.polynomial << SHIFT);
851 remainder = static_cast<CRCType>(remainder << SHIFT);
852
853 while (size--)
854 {
855 remainder = static_cast<CRCType>(remainder ^ *current++);
856
857 // An optimizing compiler might choose to unroll this loop.
858 for (crcpp_size i = 0; i < CHAR_BIT; ++i)
859 {
860#ifdef CRCPP_BRANCHLESS
861 // Clever way to avoid a branch at the expense of a multiplication. This code is equivalent to the following:
862 // if (remainder & CHAR_BIT_HIGHEST_BIT_MASK)
863 // remainder = (remainder << 1) ^ polynomial;
864 // else
865 // remainder <<= 1;
866 remainder = static_cast<CRCType>((remainder << 1) ^ (((remainder >> CHAR_BIT_MINUS_ONE) & 1) * polynomial));
867#else
868 remainder = static_cast<CRCType>((remainder & CHAR_BIT_HIGHEST_BIT_MASK) ? ((remainder << 1) ^ polynomial) : (remainder << 1));
869#endif
870 }
871 }
872
873 remainder = static_cast<CRCType>(remainder >> SHIFT);
874 }
875
876 return remainder;
877}
878
879/**
880 @brief Computes a CRC remainder using lookup table.
881 @param[in] data Data over which the remainder will be computed
882 @param[in] size Size of the data, in bytes
883 @param[in] lookupTable CRC lookup table
884 @param[in] remainder Running CRC remainder. Can be an initial value or the result of a previous CRC remainder calculation.
885 @tparam CRCType Integer type for storing the CRC result
886 @tparam CRCWidth Number of bits in the CRC
887 @return CRC remainder
888*/
889template <typename CRCType, crcpp_uint16 CRCWidth>
890inline CRCType CRC::CalculateRemainder(const void * data, crcpp_size size, const Table<CRCType, CRCWidth> & lookupTable, CRCType remainder)
891{
892 const unsigned char * current = reinterpret_cast<const unsigned char *>(data);
893
894 if (lookupTable.GetParameters().reflectInput)
895 {
896 while (size--)
897 {
898#if defined(WIN32) || defined(_WIN32) || defined(WINCE)
899 // Disable warning about data loss when doing (remainder >> CHAR_BIT) when
900 // remainder is one byte long. The algorithm is still correct in this case,
901 // though it's possible that one additional machine instruction will be executed.
902# pragma warning (push)
903# pragma warning (disable : 4333)
904#endif
905 remainder = static_cast<CRCType>((remainder >> CHAR_BIT) ^ lookupTable[static_cast<unsigned char>(remainder ^ *current++)]);
906#if defined(WIN32) || defined(_WIN32) || defined(WINCE)
907# pragma warning (pop)
908#endif
909 }
910 }
911 else if (CRCWidth >= CHAR_BIT)
912 {
913 // The conditional expression is used to avoid a -Wshift-count-overflow warning.
914 static crcpp_constexpr CRCType SHIFT((CRCWidth >= CHAR_BIT) ? static_cast<CRCType>(CRCWidth - CHAR_BIT) : 0);
915
916 while (size--)
917 {
918 remainder = static_cast<CRCType>((remainder << CHAR_BIT) ^ lookupTable[static_cast<unsigned char>((remainder >> SHIFT) ^ *current++)]);
919 }
920 }
921 else
922 {
923 // The conditional expression is used to avoid a -Wshift-count-overflow warning.
924 static crcpp_constexpr CRCType SHIFT((CHAR_BIT >= CRCWidth) ? static_cast<CRCType>(CHAR_BIT - CRCWidth) : 0);
925
926 remainder = static_cast<CRCType>(remainder << SHIFT);
927
928 while (size--)
929 {
930 // Note: no need to mask here since remainder is guaranteed to fit in a single byte.
931 remainder = lookupTable[static_cast<unsigned char>(remainder ^ *current++)];
932 }
933
934 remainder = static_cast<CRCType>(remainder >> SHIFT);
935 }
936
937 return remainder;
938}
939
940template <typename CRCType, crcpp_uint16 CRCWidth>
941inline CRCType CRC::CalculateRemainderBits(unsigned char byte, crcpp_size numBits, const Parameters<CRCType, CRCWidth> & parameters, CRCType remainder)
942{
943 // Slightly different implementations based on the parameters. The current implementations try to eliminate as much
944 // computation from the inner loop (looping over each bit) as possible.
945 if (parameters.reflectInput)
946 {
947 CRCType polynomial = CRC::Reflect(parameters.polynomial, CRCWidth);
948 remainder = static_cast<CRCType>(remainder ^ byte);
949
950 // An optimizing compiler might choose to unroll this loop.
951 for (crcpp_size i = 0; i < numBits; ++i)
952 {
953#ifdef CRCPP_BRANCHLESS
954 // Clever way to avoid a branch at the expense of a multiplication. This code is equivalent to the following:
955 // if (remainder & 1)
956 // remainder = (remainder >> 1) ^ polynomial;
957 // else
958 // remainder >>= 1;
959 remainder = static_cast<CRCType>((remainder >> 1) ^ ((remainder & 1) * polynomial));
960#else
961 remainder = static_cast<CRCType>((remainder & 1) ? ((remainder >> 1) ^ polynomial) : (remainder >> 1));
962#endif
963 }
964 }
965 else if (CRCWidth >= CHAR_BIT)
966 {
967 static crcpp_constexpr CRCType CRC_WIDTH_MINUS_ONE(CRCWidth - CRCType(1));
968#ifndef CRCPP_BRANCHLESS
969 static crcpp_constexpr CRCType CRC_HIGHEST_BIT_MASK(CRCType(1) << CRC_WIDTH_MINUS_ONE);
970#endif
971 // The conditional expression is used to avoid a -Wshift-count-overflow warning.
972 static crcpp_constexpr CRCType SHIFT((CRCWidth >= CHAR_BIT) ? static_cast<CRCType>(CRCWidth - CHAR_BIT) : 0);
973
974 remainder = static_cast<CRCType>(remainder ^ (static_cast<CRCType>(byte) << SHIFT));
975
976 // An optimizing compiler might choose to unroll this loop.
977 for (crcpp_size i = 0; i < numBits; ++i)
978 {
979#ifdef CRCPP_BRANCHLESS
980 // Clever way to avoid a branch at the expense of a multiplication. This code is equivalent to the following:
981 // if (remainder & CRC_HIGHEST_BIT_MASK)
982 // remainder = (remainder << 1) ^ parameters.polynomial;
983 // else
984 // remainder <<= 1;
985 remainder = static_cast<CRCType>((remainder << 1) ^ (((remainder >> CRC_WIDTH_MINUS_ONE) & 1) * parameters.polynomial));
986#else
987 remainder = static_cast<CRCType>((remainder & CRC_HIGHEST_BIT_MASK) ? ((remainder << 1) ^ parameters.polynomial) : (remainder << 1));
988#endif
989 }
990 }
991 else
992 {
993 static crcpp_constexpr CRCType CHAR_BIT_MINUS_ONE(CHAR_BIT - 1);
994#ifndef CRCPP_BRANCHLESS
995 static crcpp_constexpr CRCType CHAR_BIT_HIGHEST_BIT_MASK(CRCType(1) << CHAR_BIT_MINUS_ONE);
996#endif
997 // The conditional expression is used to avoid a -Wshift-count-overflow warning.
998 static crcpp_constexpr CRCType SHIFT((CHAR_BIT >= CRCWidth) ? static_cast<CRCType>(CHAR_BIT - CRCWidth) : 0);
999
1000 CRCType polynomial = static_cast<CRCType>(parameters.polynomial << SHIFT);
1001 remainder = static_cast<CRCType>((remainder << SHIFT) ^ byte);
1002
1003 // An optimizing compiler might choose to unroll this loop.
1004 for (crcpp_size i = 0; i < numBits; ++i)
1005 {
1006#ifdef CRCPP_BRANCHLESS
1007 // Clever way to avoid a branch at the expense of a multiplication. This code is equivalent to the following:
1008 // if (remainder & CHAR_BIT_HIGHEST_BIT_MASK)
1009 // remainder = (remainder << 1) ^ polynomial;
1010 // else
1011 // remainder <<= 1;
1012 remainder = static_cast<CRCType>((remainder << 1) ^ (((remainder >> CHAR_BIT_MINUS_ONE) & 1) * polynomial));
1013#else
1014 remainder = static_cast<CRCType>((remainder & CHAR_BIT_HIGHEST_BIT_MASK) ? ((remainder << 1) ^ polynomial) : (remainder << 1));
1015#endif
1016 }
1017
1018 remainder = static_cast<CRCType>(remainder >> SHIFT);
1019 }
1020
1021 return remainder;
1022}
1023
1024#ifdef CRCPP_INCLUDE_ESOTERIC_CRC_DEFINITIONS
1025/**
1026 @brief Returns a set of parameters for CRC-4 ITU.
1027 @note The parameters are static and are delayed-constructed to reduce memory footprint.
1028 @note CRC-4 ITU has the following parameters and check value:
1029 - polynomial = 0x3
1030 - initial value = 0x0
1031 - final XOR = 0x0
1032 - reflect input = true
1033 - reflect output = true
1034 - check value = 0x7
1035 @return CRC-4 ITU parameters
1036*/
1037inline const CRC::Parameters<crcpp_uint8, 4> & CRC::CRC_4_ITU()
1038{
1039 static const Parameters<crcpp_uint8, 4> parameters = { 0x3, 0x0, 0x0, true, true };
1040 return parameters;
1041}
1042
1043/**
1044 @brief Returns a set of parameters for CRC-5 EPC.
1045 @note The parameters are static and are delayed-constructed to reduce memory footprint.
1046 @note CRC-5 EPC has the following parameters and check value:
1047 - polynomial = 0x09
1048 - initial value = 0x09
1049 - final XOR = 0x00
1050 - reflect input = false
1051 - reflect output = false
1052 - check value = 0x00
1053 @return CRC-5 EPC parameters
1054*/
1055inline const CRC::Parameters<crcpp_uint8, 5> & CRC::CRC_5_EPC()
1056{
1057 static const Parameters<crcpp_uint8, 5> parameters = { 0x09, 0x09, 0x00, false, false };
1058 return parameters;
1059}
1060
1061/**
1062 @brief Returns a set of parameters for CRC-5 ITU.
1063 @note The parameters are static and are delayed-constructed to reduce memory footprint.
1064 @note CRC-5 ITU has the following parameters and check value:
1065 - polynomial = 0x15
1066 - initial value = 0x00
1067 - final XOR = 0x00
1068 - reflect input = true
1069 - reflect output = true
1070 - check value = 0x07
1071 @return CRC-5 ITU parameters
1072*/
1073inline const CRC::Parameters<crcpp_uint8, 5> & CRC::CRC_5_ITU()
1074{
1075 static const Parameters<crcpp_uint8, 5> parameters = { 0x15, 0x00, 0x00, true, true };
1076 return parameters;
1077}
1078
1079/**
1080 @brief Returns a set of parameters for CRC-5 USB.
1081 @note The parameters are static and are delayed-constructed to reduce memory footprint.
1082 @note CRC-5 USB has the following parameters and check value:
1083 - polynomial = 0x05
1084 - initial value = 0x1F
1085 - final XOR = 0x1F
1086 - reflect input = true
1087 - reflect output = true
1088 - check value = 0x19
1089 @return CRC-5 USB parameters
1090*/
1091inline const CRC::Parameters<crcpp_uint8, 5> & CRC::CRC_5_USB()
1092{
1093 static const Parameters<crcpp_uint8, 5> parameters = { 0x05, 0x1F, 0x1F, true, true };
1094 return parameters;
1095}
1096
1097/**
1098 @brief Returns a set of parameters for CRC-6 CDMA2000-A.
1099 @note The parameters are static and are delayed-constructed to reduce memory footprint.
1100 @note CRC-6 CDMA2000-A has the following parameters and check value:
1101 - polynomial = 0x27
1102 - initial value = 0x3F
1103 - final XOR = 0x00
1104 - reflect input = false
1105 - reflect output = false
1106 - check value = 0x0D
1107 @return CRC-6 CDMA2000-A parameters
1108*/
1109inline const CRC::Parameters<crcpp_uint8, 6> & CRC::CRC_6_CDMA2000A()
1110{
1111 static const Parameters<crcpp_uint8, 6> parameters = { 0x27, 0x3F, 0x00, false, false };
1112 return parameters;
1113}
1114
1115/**
1116 @brief Returns a set of parameters for CRC-6 CDMA2000-B.
1117 @note The parameters are static and are delayed-constructed to reduce memory footprint.
1118 @note CRC-6 CDMA2000-A has the following parameters and check value:
1119 - polynomial = 0x07
1120 - initial value = 0x3F
1121 - final XOR = 0x00
1122 - reflect input = false
1123 - reflect output = false
1124 - check value = 0x3B
1125 @return CRC-6 CDMA2000-B parameters
1126*/
1127inline const CRC::Parameters<crcpp_uint8, 6> & CRC::CRC_6_CDMA2000B()
1128{
1129 static const Parameters<crcpp_uint8, 6> parameters = { 0x07, 0x3F, 0x00, false, false };
1130 return parameters;
1131}
1132
1133/**
1134 @brief Returns a set of parameters for CRC-6 ITU.
1135 @note The parameters are static and are delayed-constructed to reduce memory footprint.
1136 @note CRC-6 ITU has the following parameters and check value:
1137 - polynomial = 0x03
1138 - initial value = 0x00
1139 - final XOR = 0x00
1140 - reflect input = true
1141 - reflect output = true
1142 - check value = 0x06
1143 @return CRC-6 ITU parameters
1144*/
1145inline const CRC::Parameters<crcpp_uint8, 6> & CRC::CRC_6_ITU()
1146{
1147 static const Parameters<crcpp_uint8, 6> parameters = { 0x03, 0x00, 0x00, true, true };
1148 return parameters;
1149}
1150
1151/**
1152 @brief Returns a set of parameters for CRC-6 NR.
1153 @note The parameters are static and are delayed-constructed to reduce memory
1154 footprint.
1155 @note CRC-6 NR has the following parameters and check value:
1156 - polynomial = 0x21
1157 - initial value = 0x00
1158 - final XOR = 0x00
1159 - reflect input = false
1160 - reflect output = false
1161 - check value = 0x15
1162 @return CRC-6 NR parameters
1163*/
1164inline const CRC::Parameters<crcpp_uint8, 6> & CRC::CRC_6_NR()
1165{
1166 static const Parameters<crcpp_uint8, 6> parameters = { 0x21, 0x00, 0x00, false, false };
1167 return parameters;
1168}
1169
1170/**
1171 @brief Returns a set of parameters for CRC-7 JEDEC.
1172 @note The parameters are static and are delayed-constructed to reduce memory footprint.
1173 @note CRC-7 JEDEC has the following parameters and check value:
1174 - polynomial = 0x09
1175 - initial value = 0x00
1176 - final XOR = 0x00
1177 - reflect input = false
1178 - reflect output = false
1179 - check value = 0x75
1180 @return CRC-7 JEDEC parameters
1181*/
1182inline const CRC::Parameters<crcpp_uint8, 7> & CRC::CRC_7()
1183{
1184 static const Parameters<crcpp_uint8, 7> parameters = { 0x09, 0x00, 0x00, false, false };
1185 return parameters;
1186}
1187#endif // CRCPP_INCLUDE_ESOTERIC_CRC_DEFINITIONS
1188
1189/**
1190 @brief Returns a set of parameters for CRC-8 SMBus.
1191 @note The parameters are static and are delayed-constructed to reduce memory footprint.
1192 @note CRC-8 SMBus has the following parameters and check value:
1193 - polynomial = 0x07
1194 - initial value = 0x00
1195 - final XOR = 0x00
1196 - reflect input = false
1197 - reflect output = false
1198 - check value = 0xF4
1199 @return CRC-8 SMBus parameters
1200*/
1202{
1203 static const Parameters<crcpp_uint8, 8> parameters = { 0x07, 0x00, 0x00, false, false };
1204 return parameters;
1205}
1206
1207#ifdef CRCPP_INCLUDE_ESOTERIC_CRC_DEFINITIONS
1208/**
1209 @brief Returns a set of parameters for CRC-8 EBU (aka CRC-8 AES).
1210 @note The parameters are static and are delayed-constructed to reduce memory footprint.
1211 @note CRC-8 EBU has the following parameters and check value:
1212 - polynomial = 0x1D
1213 - initial value = 0xFF
1214 - final XOR = 0x00
1215 - reflect input = true
1216 - reflect output = true
1217 - check value = 0x97
1218 @return CRC-8 EBU parameters
1219*/
1220inline const CRC::Parameters<crcpp_uint8, 8> & CRC::CRC_8_EBU()
1221{
1222 static const Parameters<crcpp_uint8, 8> parameters = { 0x1D, 0xFF, 0x00, true, true };
1223 return parameters;
1224}
1225
1226/**
1227 @brief Returns a set of parameters for CRC-8 HDLC (ISO/IEC 13239:2002).
1228 @note The parameters are static and are delayed-constructed to reduce memory footprint.
1229 @note CRC-8 HDLC has the following parameters and check value:
1230 - polynomial = 0x07
1231 - initial value = 0xFF
1232 - final XOR = 0xFF
1233 - reflect input = true
1234 - reflect output = true
1235 - check value = 0x2F
1236 @return CRC-8 HDLC parameters
1237*/
1238inline const CRC::Parameters<crcpp_uint8, 8> & CRC::CRC_8_HDLC()
1239{
1240 static const Parameters<crcpp_uint8, 8> parameters = { 0x07, 0xFF, 0xFF, true, true };
1241 return parameters;
1242}
1243
1244/**
1245 @brief Returns a set of parameters for CRC-8 MAXIM (aka CRC-8 DOW-CRC).
1246 @note The parameters are static and are delayed-constructed to reduce memory footprint.
1247 @note CRC-8 MAXIM has the following parameters and check value:
1248 - polynomial = 0x31
1249 - initial value = 0x00
1250 - final XOR = 0x00
1251 - reflect input = true
1252 - reflect output = true
1253 - check value = 0xA1
1254 @return CRC-8 MAXIM parameters
1255*/
1256inline const CRC::Parameters<crcpp_uint8, 8> & CRC::CRC_8_MAXIM()
1257{
1258 static const Parameters<crcpp_uint8, 8> parameters = { 0x31, 0x00, 0x00, true, true };
1259 return parameters;
1260}
1261
1262/**
1263 @brief Returns a set of parameters for CRC-8 WCDMA.
1264 @note The parameters are static and are delayed-constructed to reduce memory footprint.
1265 @note CRC-8 WCDMA has the following parameters and check value:
1266 - polynomial = 0x9B
1267 - initial value = 0x00
1268 - final XOR = 0x00
1269 - reflect input = true
1270 - reflect output = true
1271 - check value = 0x25
1272 @return CRC-8 WCDMA parameters
1273*/
1274inline const CRC::Parameters<crcpp_uint8, 8> & CRC::CRC_8_WCDMA()
1275{
1276 static const Parameters<crcpp_uint8, 8> parameters = { 0x9B, 0x00, 0x00, true, true };
1277 return parameters;
1278}
1279
1280/**
1281 @brief Returns a set of parameters for CRC-8 LTE.
1282 @note The parameters are static and are delayed-constructed to reduce memory footprint.
1283 @note CRC-8 LTE has the following parameters and check value:
1284 - polynomial = 0x9B
1285 - initial value = 0x00
1286 - final XOR = 0x00
1287 - reflect input = false
1288 - reflect output = false
1289 - check value = 0xEA
1290 @return CRC-8 LTE parameters
1291*/
1292inline const CRC::Parameters<crcpp_uint8, 8> & CRC::CRC_8_LTE()
1293{
1294 static const Parameters<crcpp_uint8, 8> parameters = { 0x9B, 0x00, 0x00, false, false };
1295 return parameters;
1296}
1297
1298/**
1299 @brief Returns a set of parameters for CRC-10 ITU.
1300 @note The parameters are static and are delayed-constructed to reduce memory footprint.
1301 @note CRC-10 ITU has the following parameters and check value:
1302 - polynomial = 0x233
1303 - initial value = 0x000
1304 - final XOR = 0x000
1305 - reflect input = false
1306 - reflect output = false
1307 - check value = 0x199
1308 @return CRC-10 ITU parameters
1309*/
1310inline const CRC::Parameters<crcpp_uint16, 10> & CRC::CRC_10()
1311{
1312 static const Parameters<crcpp_uint16, 10> parameters = { 0x233, 0x000, 0x000, false, false };
1313 return parameters;
1314}
1315
1316/**
1317 @brief Returns a set of parameters for CRC-10 CDMA2000.
1318 @note The parameters are static and are delayed-constructed to reduce memory footprint.
1319 @note CRC-10 CDMA2000 has the following parameters and check value:
1320 - polynomial = 0x3D9
1321 - initial value = 0x3FF
1322 - final XOR = 0x000
1323 - reflect input = false
1324 - reflect output = false
1325 - check value = 0x233
1326 @return CRC-10 CDMA2000 parameters
1327*/
1328inline const CRC::Parameters<crcpp_uint16, 10> & CRC::CRC_10_CDMA2000()
1329{
1330 static const Parameters<crcpp_uint16, 10> parameters = { 0x3D9, 0x3FF, 0x000, false, false };
1331 return parameters;
1332}
1333
1334/**
1335 @brief Returns a set of parameters for CRC-11 FlexRay.
1336 @note The parameters are static and are delayed-constructed to reduce memory footprint.
1337 @note CRC-11 FlexRay has the following parameters and check value:
1338 - polynomial = 0x385
1339 - initial value = 0x01A
1340 - final XOR = 0x000
1341 - reflect input = false
1342 - reflect output = false
1343 - check value = 0x5A3
1344 @return CRC-11 FlexRay parameters
1345*/
1346inline const CRC::Parameters<crcpp_uint16, 11> & CRC::CRC_11()
1347{
1348 static const Parameters<crcpp_uint16, 11> parameters = { 0x385, 0x01A, 0x000, false, false };
1349 return parameters;
1350}
1351
1352/**
1353 @brief Returns a set of parameters for CRC-11 NR.
1354 @note The parameters are static and are delayed-constructed to reduce memory
1355 footprint.
1356 @note CRC-11 NR has the following parameters and check value:
1357 - polynomial = 0x621
1358 - initial value = 0x000
1359 - final XOR = 0x000
1360 - reflect input = false
1361 - reflect output = false
1362 - check value = 0x5CA
1363 @return CRC-11 NR parameters
1364*/
1365inline const CRC::Parameters<crcpp_uint16, 11> & CRC::CRC_11_NR()
1366{
1367 static const Parameters<crcpp_uint16, 11> parameters = { 0x621, 0x000, 0x000, false, false };
1368 return parameters;
1369}
1370
1371/**
1372 @brief Returns a set of parameters for CRC-12 CDMA2000.
1373 @note The parameters are static and are delayed-constructed to reduce memory footprint.
1374 @note CRC-12 CDMA2000 has the following parameters and check value:
1375 - polynomial = 0xF13
1376 - initial value = 0xFFF
1377 - final XOR = 0x000
1378 - reflect input = false
1379 - reflect output = false
1380 - check value = 0xD4D
1381 @return CRC-12 CDMA2000 parameters
1382*/
1383inline const CRC::Parameters<crcpp_uint16, 12> & CRC::CRC_12_CDMA2000()
1384{
1385 static const Parameters<crcpp_uint16, 12> parameters = { 0xF13, 0xFFF, 0x000, false, false };
1386 return parameters;
1387}
1388
1389/**
1390 @brief Returns a set of parameters for CRC-12 DECT (aka CRC-12 X-CRC).
1391 @note The parameters are static and are delayed-constructed to reduce memory footprint.
1392 @note CRC-12 DECT has the following parameters and check value:
1393 - polynomial = 0x80F
1394 - initial value = 0x000
1395 - final XOR = 0x000
1396 - reflect input = false
1397 - reflect output = false
1398 - check value = 0xF5B
1399 @return CRC-12 DECT parameters
1400*/
1401inline const CRC::Parameters<crcpp_uint16, 12> & CRC::CRC_12_DECT()
1402{
1403 static const Parameters<crcpp_uint16, 12> parameters = { 0x80F, 0x000, 0x000, false, false };
1404 return parameters;
1405}
1406
1407/**
1408 @brief Returns a set of parameters for CRC-12 UMTS (aka CRC-12 3GPP).
1409 @note The parameters are static and are delayed-constructed to reduce memory footprint.
1410 @note CRC-12 UMTS has the following parameters and check value:
1411 - polynomial = 0x80F
1412 - initial value = 0x000
1413 - final XOR = 0x000
1414 - reflect input = false
1415 - reflect output = true
1416 - check value = 0xDAF
1417 @return CRC-12 UMTS parameters
1418*/
1419inline const CRC::Parameters<crcpp_uint16, 12> & CRC::CRC_12_UMTS()
1420{
1421 static const Parameters<crcpp_uint16, 12> parameters = { 0x80F, 0x000, 0x000, false, true };
1422 return parameters;
1423}
1424
1425/**
1426 @brief Returns a set of parameters for CRC-13 BBC.
1427 @note The parameters are static and are delayed-constructed to reduce memory footprint.
1428 @note CRC-13 BBC has the following parameters and check value:
1429 - polynomial = 0x1CF5
1430 - initial value = 0x0000
1431 - final XOR = 0x0000
1432 - reflect input = false
1433 - reflect output = false
1434 - check value = 0x04FA
1435 @return CRC-13 BBC parameters
1436*/
1437inline const CRC::Parameters<crcpp_uint16, 13> & CRC::CRC_13_BBC()
1438{
1439 static const Parameters<crcpp_uint16, 13> parameters = { 0x1CF5, 0x0000, 0x0000, false, false };
1440 return parameters;
1441}
1442
1443/**
1444 @brief Returns a set of parameters for CRC-15 CAN.
1445 @note The parameters are static and are delayed-constructed to reduce memory footprint.
1446 @note CRC-15 CAN has the following parameters and check value:
1447 - polynomial = 0x4599
1448 - initial value = 0x0000
1449 - final XOR = 0x0000
1450 - reflect input = false
1451 - reflect output = false
1452 - check value = 0x059E
1453 @return CRC-15 CAN parameters
1454*/
1455inline const CRC::Parameters<crcpp_uint16, 15> & CRC::CRC_15()
1456{
1457 static const Parameters<crcpp_uint16, 15> parameters = { 0x4599, 0x0000, 0x0000, false, false };
1458 return parameters;
1459}
1460
1461/**
1462 @brief Returns a set of parameters for CRC-15 MPT1327.
1463 @note The parameters are static and are delayed-constructed to reduce memory footprint.
1464 @note CRC-15 MPT1327 has the following parameters and check value:
1465 - polynomial = 0x6815
1466 - initial value = 0x0000
1467 - final XOR = 0x0001
1468 - reflect input = false
1469 - reflect output = false
1470 - check value = 0x2566
1471 @return CRC-15 MPT1327 parameters
1472*/
1473inline const CRC::Parameters<crcpp_uint16, 15> & CRC::CRC_15_MPT1327()
1474{
1475 static const Parameters<crcpp_uint16, 15> parameters = { 0x6815, 0x0000, 0x0001, false, false };
1476 return parameters;
1477}
1478#endif // CRCPP_INCLUDE_ESOTERIC_CRC_DEFINITIONS
1479
1480/**
1481 @brief Returns a set of parameters for CRC-16 ARC (aka CRC-16 IBM, CRC-16 LHA).
1482 @note The parameters are static and are delayed-constructed to reduce memory footprint.
1483 @note CRC-16 ARC has the following parameters and check value:
1484 - polynomial = 0x8005
1485 - initial value = 0x0000
1486 - final XOR = 0x0000
1487 - reflect input = true
1488 - reflect output = true
1489 - check value = 0xBB3D
1490 @return CRC-16 ARC parameters
1491*/
1493{
1494 static const Parameters<crcpp_uint16, 16> parameters = { 0x8005, 0x0000, 0x0000, true, true };
1495 return parameters;
1496}
1497
1498/**
1499 @brief Returns a set of parameters for CRC-16 BUYPASS (aka CRC-16 VERIFONE, CRC-16 UMTS).
1500 @note The parameters are static and are delayed-constructed to reduce memory footprint.
1501 @note CRC-16 BUYPASS has the following parameters and check value:
1502 - polynomial = 0x8005
1503 - initial value = 0x0000
1504 - final XOR = 0x0000
1505 - reflect input = false
1506 - reflect output = false
1507 - check value = 0xFEE8
1508 @return CRC-16 BUYPASS parameters
1509*/
1511{
1512 static const Parameters<crcpp_uint16, 16> parameters = { 0x8005, 0x0000, 0x0000, false, false };
1513 return parameters;
1514}
1515
1516/**
1517 @brief Returns a set of parameters for CRC-16 CCITT FALSE.
1518 @note The parameters are static and are delayed-constructed to reduce memory footprint.
1519 @note CRC-16 CCITT FALSE has the following parameters and check value:
1520 - polynomial = 0x1021
1521 - initial value = 0xFFFF
1522 - final XOR = 0x0000
1523 - reflect input = false
1524 - reflect output = false
1525 - check value = 0x29B1
1526 @return CRC-16 CCITT FALSE parameters
1527*/
1529{
1530 static const Parameters<crcpp_uint16, 16> parameters = { 0x1021, 0xFFFF, 0x0000, false, false };
1531 return parameters;
1532}
1533
1534/**
1535 @brief Returns a set of parameters for CRC-16 MCRF4XX.
1536 @note The parameters are static and are delayed-constructed to reduce memory footprint.
1537 @note CRC-16 MCRF4XX has the following parameters and check value:
1538 - polynomial = 0x1021
1539 - initial value = 0xFFFF
1540 - final XOR = 0x0000
1541 - reflect input = true
1542 - reflect output = true
1543 - check value = 0x6F91
1544 @return CRC-16 MCRF4XX parameters
1545*/
1547{
1548 static const Parameters<crcpp_uint16, 16> parameters = { 0x1021, 0xFFFF, 0x0000, true, true};
1549 return parameters;
1550}
1551
1552#ifdef CRCPP_INCLUDE_ESOTERIC_CRC_DEFINITIONS
1553/**
1554 @brief Returns a set of parameters for CRC-16 CDMA2000.
1555 @note The parameters are static and are delayed-constructed to reduce memory footprint.
1556 @note CRC-16 CDMA2000 has the following parameters and check value:
1557 - polynomial = 0xC867
1558 - initial value = 0xFFFF
1559 - final XOR = 0x0000
1560 - reflect input = false
1561 - reflect output = false
1562 - check value = 0x4C06
1563 @return CRC-16 CDMA2000 parameters
1564*/
1565inline const CRC::Parameters<crcpp_uint16, 16> & CRC::CRC_16_CDMA2000()
1566{
1567 static const Parameters<crcpp_uint16, 16> parameters = { 0xC867, 0xFFFF, 0x0000, false, false };
1568 return parameters;
1569}
1570
1571/**
1572 @brief Returns a set of parameters for CRC-16 CMS.
1573 @note The parameters are static and are delayed-constructed to reduce memory footprint.
1574 @note CRC-16 CMS has the following parameters and check value:
1575 - polynomial = 0x8005
1576 - initial value = 0xFFFF
1577 - final XOR = 0x0000
1578 - reflect input = false
1579 - reflect output = false
1580 - check value = 0xAEE7
1581 @return CRC-16 CMS parameters
1582*/
1583inline const CRC::Parameters<crcpp_uint16, 16> & CRC::CRC_16_CMS()
1584{
1585 static const Parameters<crcpp_uint16, 16> parameters = { 0x8005, 0xFFFF, 0x0000, false, false };
1586 return parameters;
1587}
1588
1589/**
1590 @brief Returns a set of parameters for CRC-16 DECT-R (aka CRC-16 R-CRC).
1591 @note The parameters are static and are delayed-constructed to reduce memory footprint.
1592 @note CRC-16 DECT-R has the following parameters and check value:
1593 - polynomial = 0x0589
1594 - initial value = 0x0000
1595 - final XOR = 0x0001
1596 - reflect input = false
1597 - reflect output = false
1598 - check value = 0x007E
1599 @return CRC-16 DECT-R parameters
1600*/
1601inline const CRC::Parameters<crcpp_uint16, 16> & CRC::CRC_16_DECTR()
1602{
1603 static const Parameters<crcpp_uint16, 16> parameters = { 0x0589, 0x0000, 0x0001, false, false };
1604 return parameters;
1605}
1606
1607/**
1608 @brief Returns a set of parameters for CRC-16 DECT-X (aka CRC-16 X-CRC).
1609 @note The parameters are static and are delayed-constructed to reduce memory footprint.
1610 @note CRC-16 DECT-X has the following parameters and check value:
1611 - polynomial = 0x0589
1612 - initial value = 0x0000
1613 - final XOR = 0x0000
1614 - reflect input = false
1615 - reflect output = false
1616 - check value = 0x007F
1617 @return CRC-16 DECT-X parameters
1618*/
1619inline const CRC::Parameters<crcpp_uint16, 16> & CRC::CRC_16_DECTX()
1620{
1621 static const Parameters<crcpp_uint16, 16> parameters = { 0x0589, 0x0000, 0x0000, false, false };
1622 return parameters;
1623}
1624
1625/**
1626 @brief Returns a set of parameters for CRC-16 DNP.
1627 @note The parameters are static and are delayed-constructed to reduce memory footprint.
1628 @note CRC-16 DNP has the following parameters and check value:
1629 - polynomial = 0x3D65
1630 - initial value = 0x0000
1631 - final XOR = 0xFFFF
1632 - reflect input = true
1633 - reflect output = true
1634 - check value = 0xEA82
1635 @return CRC-16 DNP parameters
1636*/
1637inline const CRC::Parameters<crcpp_uint16, 16> & CRC::CRC_16_DNP()
1638{
1639 static const Parameters<crcpp_uint16, 16> parameters = { 0x3D65, 0x0000, 0xFFFF, true, true };
1640 return parameters;
1641}
1642#endif // CRCPP_INCLUDE_ESOTERIC_CRC_DEFINITIONS
1643
1644/**
1645 @brief Returns a set of parameters for CRC-16 GENIBUS (aka CRC-16 EPC, CRC-16 I-CODE, CRC-16 DARC).
1646 @note The parameters are static and are delayed-constructed to reduce memory footprint.
1647 @note CRC-16 GENIBUS has the following parameters and check value:
1648 - polynomial = 0x1021
1649 - initial value = 0xFFFF
1650 - final XOR = 0xFFFF
1651 - reflect input = false
1652 - reflect output = false
1653 - check value = 0xD64E
1654 @return CRC-16 GENIBUS parameters
1655*/
1657{
1658 static const Parameters<crcpp_uint16, 16> parameters = { 0x1021, 0xFFFF, 0xFFFF, false, false };
1659 return parameters;
1660}
1661
1662/**
1663 @brief Returns a set of parameters for CRC-16 KERMIT (aka CRC-16 CCITT, CRC-16 CCITT-TRUE).
1664 @note The parameters are static and are delayed-constructed to reduce memory footprint.
1665 @note CRC-16 KERMIT has the following parameters and check value:
1666 - polynomial = 0x1021
1667 - initial value = 0x0000
1668 - final XOR = 0x0000
1669 - reflect input = true
1670 - reflect output = true
1671 - check value = 0x2189
1672 @return CRC-16 KERMIT parameters
1673*/
1675{
1676 static const Parameters<crcpp_uint16, 16> parameters = { 0x1021, 0x0000, 0x0000, true, true };
1677 return parameters;
1678}
1679
1680#ifdef CRCPP_INCLUDE_ESOTERIC_CRC_DEFINITIONS
1681/**
1682 @brief Returns a set of parameters for CRC-16 MAXIM.
1683 @note The parameters are static and are delayed-constructed to reduce memory footprint.
1684 @note CRC-16 MAXIM has the following parameters and check value:
1685 - polynomial = 0x8005
1686 - initial value = 0x0000
1687 - final XOR = 0xFFFF
1688 - reflect input = true
1689 - reflect output = true
1690 - check value = 0x44C2
1691 @return CRC-16 MAXIM parameters
1692*/
1693inline const CRC::Parameters<crcpp_uint16, 16> & CRC::CRC_16_MAXIM()
1694{
1695 static const Parameters<crcpp_uint16, 16> parameters = { 0x8005, 0x0000, 0xFFFF, true, true };
1696 return parameters;
1697}
1698
1699/**
1700 @brief Returns a set of parameters for CRC-16 MODBUS.
1701 @note The parameters are static and are delayed-constructed to reduce memory footprint.
1702 @note CRC-16 MODBUS has the following parameters and check value:
1703 - polynomial = 0x8005
1704 - initial value = 0xFFFF
1705 - final XOR = 0x0000
1706 - reflect input = true
1707 - reflect output = true
1708 - check value = 0x4B37
1709 @return CRC-16 MODBUS parameters
1710*/
1711inline const CRC::Parameters<crcpp_uint16, 16> & CRC::CRC_16_MODBUS()
1712{
1713 static const Parameters<crcpp_uint16, 16> parameters = { 0x8005, 0xFFFF, 0x0000, true, true };
1714 return parameters;
1715}
1716
1717/**
1718 @brief Returns a set of parameters for CRC-16 T10-DIF.
1719 @note The parameters are static and are delayed-constructed to reduce memory footprint.
1720 @note CRC-16 T10-DIF has the following parameters and check value:
1721 - polynomial = 0x8BB7
1722 - initial value = 0x0000
1723 - final XOR = 0x0000
1724 - reflect input = false
1725 - reflect output = false
1726 - check value = 0xD0DB
1727 @return CRC-16 T10-DIF parameters
1728*/
1729inline const CRC::Parameters<crcpp_uint16, 16> & CRC::CRC_16_T10DIF()
1730{
1731 static const Parameters<crcpp_uint16, 16> parameters = { 0x8BB7, 0x0000, 0x0000, false, false };
1732 return parameters;
1733}
1734
1735/**
1736 @brief Returns a set of parameters for CRC-16 USB.
1737 @note The parameters are static and are delayed-constructed to reduce memory footprint.
1738 @note CRC-16 USB has the following parameters and check value:
1739 - polynomial = 0x8005
1740 - initial value = 0xFFFF
1741 - final XOR = 0xFFFF
1742 - reflect input = true
1743 - reflect output = true
1744 - check value = 0xB4C8
1745 @return CRC-16 USB parameters
1746*/
1747inline const CRC::Parameters<crcpp_uint16, 16> & CRC::CRC_16_USB()
1748{
1749 static const Parameters<crcpp_uint16, 16> parameters = { 0x8005, 0xFFFF, 0xFFFF, true, true };
1750 return parameters;
1751}
1752
1753#endif // CRCPP_INCLUDE_ESOTERIC_CRC_DEFINITIONS
1754
1755/**
1756 @brief Returns a set of parameters for CRC-16 X-25 (aka CRC-16 IBM-SDLC, CRC-16 ISO-HDLC, CRC-16 B).
1757 @note The parameters are static and are delayed-constructed to reduce memory footprint.
1758 @note CRC-16 X-25 has the following parameters and check value:
1759 - polynomial = 0x1021
1760 - initial value = 0xFFFF
1761 - final XOR = 0xFFFF
1762 - reflect input = true
1763 - reflect output = true
1764 - check value = 0x906E
1765 @return CRC-16 X-25 parameters
1766*/
1768{
1769 static const Parameters<crcpp_uint16, 16> parameters = { 0x1021, 0xFFFF, 0xFFFF, true, true };
1770 return parameters;
1771}
1772
1773/**
1774 @brief Returns a set of parameters for CRC-16 XMODEM (aka CRC-16 ZMODEM, CRC-16 ACORN, CRC-16 LTE).
1775 @note The parameters are static and are delayed-constructed to reduce memory footprint.
1776 @note CRC-16 XMODEM has the following parameters and check value:
1777 - polynomial = 0x1021
1778 - initial value = 0x0000
1779 - final XOR = 0x0000
1780 - reflect input = false
1781 - reflect output = false
1782 - check value = 0x31C3
1783 @return CRC-16 XMODEM parameters
1784*/
1786{
1787 static const Parameters<crcpp_uint16, 16> parameters = { 0x1021, 0x0000, 0x0000, false, false };
1788 return parameters;
1789}
1790
1791#ifdef CRCPP_INCLUDE_ESOTERIC_CRC_DEFINITIONS
1792/**
1793 @brief Returns a set of parameters for CRC-17 CAN.
1794 @note The parameters are static and are delayed-constructed to reduce memory footprint.
1795 @note CRC-17 CAN has the following parameters and check value:
1796 - polynomial = 0x1685B
1797 - initial value = 0x00000
1798 - final XOR = 0x00000
1799 - reflect input = false
1800 - reflect output = false
1801 - check value = 0x04F03
1802 @return CRC-17 CAN parameters
1803*/
1804inline const CRC::Parameters<crcpp_uint32, 17> & CRC::CRC_17_CAN()
1805{
1806 static const Parameters<crcpp_uint32, 17> parameters = { 0x1685B, 0x00000, 0x00000, false, false };
1807 return parameters;
1808}
1809
1810/**
1811 @brief Returns a set of parameters for CRC-21 CAN.
1812 @note The parameters are static and are delayed-constructed to reduce memory footprint.
1813 @note CRC-21 CAN has the following parameters and check value:
1814 - polynomial = 0x102899
1815 - initial value = 0x000000
1816 - final XOR = 0x000000
1817 - reflect input = false
1818 - reflect output = false
1819 - check value = 0x0ED841
1820 @return CRC-21 CAN parameters
1821*/
1822inline const CRC::Parameters<crcpp_uint32, 21> & CRC::CRC_21_CAN()
1823{
1824 static const Parameters<crcpp_uint32, 21> parameters = { 0x102899, 0x000000, 0x000000, false, false };
1825 return parameters;
1826}
1827
1828/**
1829 @brief Returns a set of parameters for CRC-24 OPENPGP.
1830 @note The parameters are static and are delayed-constructed to reduce memory footprint.
1831 @note CRC-24 OPENPGP has the following parameters and check value:
1832 - polynomial = 0x864CFB
1833 - initial value = 0xB704CE
1834 - final XOR = 0x000000
1835 - reflect input = false
1836 - reflect output = false
1837 - check value = 0x21CF02
1838 @return CRC-24 OPENPGP parameters
1839*/
1840inline const CRC::Parameters<crcpp_uint32, 24> & CRC::CRC_24()
1841{
1842 static const Parameters<crcpp_uint32, 24> parameters = { 0x864CFB, 0xB704CE, 0x000000, false, false };
1843 return parameters;
1844}
1845
1846/**
1847 @brief Returns a set of parameters for CRC-24 FlexRay-A.
1848 @note The parameters are static and are delayed-constructed to reduce memory footprint.
1849 @note CRC-24 FlexRay-A has the following parameters and check value:
1850 - polynomial = 0x5D6DCB
1851 - initial value = 0xFEDCBA
1852 - final XOR = 0x000000
1853 - reflect input = false
1854 - reflect output = false
1855 - check value = 0x7979BD
1856 @return CRC-24 FlexRay-A parameters
1857*/
1858inline const CRC::Parameters<crcpp_uint32, 24> & CRC::CRC_24_FLEXRAYA()
1859{
1860 static const Parameters<crcpp_uint32, 24> parameters = { 0x5D6DCB, 0xFEDCBA, 0x000000, false, false };
1861 return parameters;
1862}
1863
1864/**
1865 @brief Returns a set of parameters for CRC-24 FlexRay-B.
1866 @note The parameters are static and are delayed-constructed to reduce memory footprint.
1867 @note CRC-24 FlexRay-B has the following parameters and check value:
1868 - polynomial = 0x5D6DCB
1869 - initial value = 0xABCDEF
1870 - final XOR = 0x000000
1871 - reflect input = false
1872 - reflect output = false
1873 - check value = 0x1F23B8
1874 @return CRC-24 FlexRay-B parameters
1875*/
1876inline const CRC::Parameters<crcpp_uint32, 24> & CRC::CRC_24_FLEXRAYB()
1877{
1878 static const Parameters<crcpp_uint32, 24> parameters = { 0x5D6DCB, 0xABCDEF, 0x000000, false, false };
1879 return parameters;
1880}
1881
1882/**
1883 @brief Returns a set of parameters for CRC-24 LTE-A/NR-A.
1884 @note The parameters are static and are delayed-constructed to reduce memory
1885 footprint.
1886 @note CRC-24 LTE-A has the following parameters and check value:
1887 - polynomial = 0x864CFB
1888 - initial value = 0x000000
1889 - final XOR = 0x000000
1890 - reflect input = false
1891 - reflect output = false
1892 - check value = 0xCDE703
1893 @return CRC-24 LTE-A parameters
1894*/
1895inline const CRC::Parameters<crcpp_uint32, 24> & CRC::CRC_24_LTEA()
1896{
1897 static const Parameters<crcpp_uint32, 24> parameters = { 0x864CFB, 0x000000, 0x000000, false, false };
1898 return parameters;
1899}
1900
1901/**
1902 @brief Returns a set of parameters for CRC-24 LTE-B/NR-B.
1903 @note The parameters are static and are delayed-constructed to reduce memory
1904 footprint.
1905 @note CRC-24 LTE-B has the following parameters and check value:
1906 - polynomial = 0x800063
1907 - initial value = 0x000000
1908 - final XOR = 0x000000
1909 - reflect input = false
1910 - reflect output = false
1911 - check value = 0x23EF52
1912 @return CRC-24 LTE-B parameters
1913*/
1914inline const CRC::Parameters<crcpp_uint32, 24> & CRC::CRC_24_LTEB()
1915{
1916 static const Parameters<crcpp_uint32, 24> parameters = { 0x800063, 0x000000, 0x000000, false, false };
1917 return parameters;
1918}
1919
1920/**
1921 @brief Returns a set of parameters for CRC-24 NR-C.
1922 @note The parameters are static and are delayed-constructed to reduce memory
1923 footprint.
1924 @note CRC-24 NR-C has the following parameters and check value:
1925 - polynomial = 0xB2B117
1926 - initial value = 0x000000
1927 - final XOR = 0x000000
1928 - reflect input = false
1929 - reflect output = false
1930 - check value = 0xF48279
1931 @return CRC-24 NR-C parameters
1932*/
1933inline const CRC::Parameters<crcpp_uint32, 24> & CRC::CRC_24_NRC()
1934{
1935 static const Parameters<crcpp_uint32, 24> parameters = { 0xB2B117, 0x000000, 0x000000, false, false };
1936 return parameters;
1937}
1938
1939/**
1940 @brief Returns a set of parameters for CRC-30 CDMA.
1941 @note The parameters are static and are delayed-constructed to reduce memory footprint.
1942 @note CRC-30 CDMA has the following parameters and check value:
1943 - polynomial = 0x2030B9C7
1944 - initial value = 0x3FFFFFFF
1945 - final XOR = 0x00000000
1946 - reflect input = false
1947 - reflect output = false
1948 - check value = 0x3B3CB540
1949 @return CRC-30 CDMA parameters
1950*/
1951inline const CRC::Parameters<crcpp_uint32, 30> & CRC::CRC_30()
1952{
1953 static const Parameters<crcpp_uint32, 30> parameters = { 0x2030B9C7, 0x3FFFFFFF, 0x00000000, false, false };
1954 return parameters;
1955}
1956#endif // CRCPP_INCLUDE_ESOTERIC_CRC_DEFINITIONS
1957
1958/**
1959 @brief Returns a set of parameters for CRC-32 (aka CRC-32 ADCCP, CRC-32 PKZip).
1960 @note The parameters are static and are delayed-constructed to reduce memory footprint.
1961 @note CRC-32 has the following parameters and check value:
1962 - polynomial = 0x04C11DB7
1963 - initial value = 0xFFFFFFFF
1964 - final XOR = 0xFFFFFFFF
1965 - reflect input = true
1966 - reflect output = true
1967 - check value = 0xCBF43926
1968 @return CRC-32 parameters
1969*/
1971{
1972 static const Parameters<crcpp_uint32, 32> parameters = { 0x04C11DB7, 0xFFFFFFFF, 0xFFFFFFFF, true, true };
1973 return parameters;
1974}
1975
1976/**
1977 @brief Returns a set of parameters for CRC-32 BZIP2 (aka CRC-32 AAL5, CRC-32 DECT-B, CRC-32 B-CRC).
1978 @note The parameters are static and are delayed-constructed to reduce memory footprint.
1979 @note CRC-32 BZIP2 has the following parameters and check value:
1980 - polynomial = 0x04C11DB7
1981 - initial value = 0xFFFFFFFF
1982 - final XOR = 0xFFFFFFFF
1983 - reflect input = false
1984 - reflect output = false
1985 - check value = 0xFC891918
1986 @return CRC-32 BZIP2 parameters
1987*/
1989{
1990 static const Parameters<crcpp_uint32, 32> parameters = { 0x04C11DB7, 0xFFFFFFFF, 0xFFFFFFFF, false, false };
1991 return parameters;
1992}
1993
1994#ifdef CRCPP_INCLUDE_ESOTERIC_CRC_DEFINITIONS
1995/**
1996 @brief Returns a set of parameters for CRC-32 C (aka CRC-32 ISCSI, CRC-32 Castagnoli, CRC-32 Interlaken).
1997 @note The parameters are static and are delayed-constructed to reduce memory footprint.
1998 @note CRC-32 C has the following parameters and check value:
1999 - polynomial = 0x1EDC6F41
2000 - initial value = 0xFFFFFFFF
2001 - final XOR = 0xFFFFFFFF
2002 - reflect input = true
2003 - reflect output = true
2004 - check value = 0xE3069283
2005 @return CRC-32 C parameters
2006*/
2007inline const CRC::Parameters<crcpp_uint32, 32> & CRC::CRC_32_C()
2008{
2009 static const Parameters<crcpp_uint32, 32> parameters = { 0x1EDC6F41, 0xFFFFFFFF, 0xFFFFFFFF, true, true };
2010 return parameters;
2011}
2012#endif
2013
2014/**
2015 @brief Returns a set of parameters for CRC-32 MPEG-2.
2016 @note The parameters are static and are delayed-constructed to reduce memory footprint.
2017 @note CRC-32 MPEG-2 has the following parameters and check value:
2018 - polynomial = 0x04C11DB7
2019 - initial value = 0xFFFFFFFF
2020 - final XOR = 0x00000000
2021 - reflect input = false
2022 - reflect output = false
2023 - check value = 0x0376E6E7
2024 @return CRC-32 MPEG-2 parameters
2025*/
2027{
2028 static const Parameters<crcpp_uint32, 32> parameters = { 0x04C11DB7, 0xFFFFFFFF, 0x00000000, false, false };
2029 return parameters;
2030}
2031
2032/**
2033 @brief Returns a set of parameters for CRC-32 POSIX.
2034 @note The parameters are static and are delayed-constructed to reduce memory footprint.
2035 @note CRC-32 POSIX has the following parameters and check value:
2036 - polynomial = 0x04C11DB7
2037 - initial value = 0x00000000
2038 - final XOR = 0xFFFFFFFF
2039 - reflect input = false
2040 - reflect output = false
2041 - check value = 0x765E7680
2042 @return CRC-32 POSIX parameters
2043*/
2045{
2046 static const Parameters<crcpp_uint32, 32> parameters = { 0x04C11DB7, 0x00000000, 0xFFFFFFFF, false, false };
2047 return parameters;
2048}
2049
2050#ifdef CRCPP_INCLUDE_ESOTERIC_CRC_DEFINITIONS
2051/**
2052 @brief Returns a set of parameters for CRC-32 Q.
2053 @note The parameters are static and are delayed-constructed to reduce memory footprint.
2054 @note CRC-32 Q has the following parameters and check value:
2055 - polynomial = 0x814141AB
2056 - initial value = 0x00000000
2057 - final XOR = 0x00000000
2058 - reflect input = false
2059 - reflect output = false
2060 - check value = 0x3010BF7F
2061 @return CRC-32 Q parameters
2062*/
2063inline const CRC::Parameters<crcpp_uint32, 32> & CRC::CRC_32_Q()
2064{
2065 static const Parameters<crcpp_uint32, 32> parameters = { 0x814141AB, 0x00000000, 0x00000000, false, false };
2066 return parameters;
2067}
2068
2069/**
2070 @brief Returns a set of parameters for CRC-40 GSM.
2071 @note The parameters are static and are delayed-constructed to reduce memory footprint.
2072 @note CRC-40 GSM has the following parameters and check value:
2073 - polynomial = 0x0004820009
2074 - initial value = 0x0000000000
2075 - final XOR = 0xFFFFFFFFFF
2076 - reflect input = false
2077 - reflect output = false
2078 - check value = 0xD4164FC646
2079 @return CRC-40 GSM parameters
2080*/
2081inline const CRC::Parameters<crcpp_uint64, 40> & CRC::CRC_40_GSM()
2082{
2083 static const Parameters<crcpp_uint64, 40> parameters = { 0x0004820009, 0x0000000000, 0xFFFFFFFFFF, false, false };
2084 return parameters;
2085}
2086
2087/**
2088 @brief Returns a set of parameters for CRC-64 ECMA.
2089 @note The parameters are static and are delayed-constructed to reduce memory footprint.
2090 @note CRC-64 ECMA has the following parameters and check value:
2091 - polynomial = 0x42F0E1EBA9EA3693
2092 - initial value = 0x0000000000000000
2093 - final XOR = 0x0000000000000000
2094 - reflect input = false
2095 - reflect output = false
2096 - check value = 0x6C40DF5F0B497347
2097 @return CRC-64 ECMA parameters
2098*/
2099inline const CRC::Parameters<crcpp_uint64, 64> & CRC::CRC_64()
2100{
2101 static const Parameters<crcpp_uint64, 64> parameters = { 0x42F0E1EBA9EA3693, 0x0000000000000000, 0x0000000000000000, false, false };
2102 return parameters;
2103}
2104#endif // CRCPP_INCLUDE_ESOTERIC_CRC_DEFINITIONS
2105
2106#ifdef CRCPP_USE_NAMESPACE
2107}
2108#endif
2109
2110#if defined(WIN32) || defined(_WIN32) || defined(WINCE)
2111#pragma warning(pop)
2112#endif
2113
2114#endif // CRCPP_CRC_H_
#define crcpp_constexpr
Compile-time expression definition.
Definition: CRC.h:127
#define crcpp_uint16
Unsigned 16-bit integer definition, used primarily for parameter definitions.
Definition: CRC.h:88
#define crcpp_size
Unsigned size definition, used for specifying data sizes.
Definition: CRC.h:118
Static class for computing CRCs.
Definition: CRC.h:149
static CRCType CalculateBits(const void *data, crcpp_size size, const Parameters< CRCType, CRCWidth > &parameters)
Computes a CRC.
Definition: CRC.h:550
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 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, 32 > & CRC_32_MPEG2()
Returns a set of parameters for CRC-32 MPEG-2.
Definition: CRC.h:2026
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 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, 16 > & CRC_16_MCRF4XX()
Returns a set of parameters for CRC-16 MCRF4XX.
Definition: CRC.h:1546
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 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_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, 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 CRCType Calculate(const void *data, crcpp_size size, const Parameters< CRCType, CRCWidth > &parameters)
Computes a CRC.
Definition: CRC.h:463
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
int i
Definition: decode_rs.h:73
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 > &parameters)
Constructs a CRC table from a set of CRC parameters.
Definition: CRC.h:355