37 #ifndef COMMON_CRC_SLOW_H 38 #define COMMON_CRC_SLOW_H 40 #include "common/system.h" 47 CRCSlow(T poly, T init_remainder, T final_xor,
bool need_reflect);
48 T crcSlow(byte
const message[],
int nBytes)
const;
52 const T _init_remainder;
61 static R reflect(R data);
63 byte reflectData(byte x)
const {
return _reflect ? reflect<byte>(x) : x; }
64 T reflectRemainder(T x)
const {
return _reflect ? reflect<T>(x) : x; }
79 template<
typename T>
template<
typename R>
86 for (byte bit = 0; bit <
sizeof(R) * 8; ++bit) {
91 reflection |= (1 << ((
sizeof(R) * 8 - 1) - bit));
114 T remainder = _init_remainder;
119 for (
int b = 0; b < nBytes; ++b) {
123 remainder ^= reflectData(message[b]) << (_width - 8);
128 for (byte bit = 8; bit > 0; --bit) {
132 if (remainder & _topbit) {
133 remainder = (remainder << 1) ^ _poly;
135 remainder = (remainder << 1);
143 return reflectRemainder(remainder) ^ _final_xor;
149 _poly(poly), _init_remainder(init_remainder), _final_xor(final_xor), _width(8 *
sizeof(T)), _topbit(1 << (8 *
sizeof(T) - 1)), _reflect(need_reflect) {}
Definition: crc_slow.h:161
Definition: crc_slow.h:166
Definition: algorithm.h:29
Definition: crc_slow.h:151
Definition: crc_slow.h:156
Definition: crc_slow.h:45