7#include "libxr_def.hpp"
22 static const uint8_t
INIT = 0xFF;
25 static inline uint8_t
tab_[256];
38 for (
int i = 0; i < 256; i++)
43 for (
int i = 0; i < 256; i++)
45 for (
int j = 7; j >= 0; j--)
69 LIBXR_FORCE_OPTIMIZE_O3
static uint8_t
Calculate(
const void* raw,
size_t len)
71 const uint8_t* buf =
reinterpret_cast<const uint8_t*
>(raw);
81 crc =
tab_[(crc ^ *buf++) & 0xff];
94 static bool Verify(
const void* raw,
size_t len)
96 const uint8_t* buf =
reinterpret_cast<const uint8_t*
>(raw);
106 uint8_t expected =
Calculate(buf, len -
sizeof(uint8_t));
107 return expected == buf[len -
sizeof(uint8_t)];
122 static const uint16_t
INIT = 0xFFFF;
125 static inline uint16_t
tab_[256];
136 for (
int i = 0; i < 256; ++i)
139 for (
int j = 0; j < 8; ++j)
143 crc = (crc >> 1) ^ 0x8408;
161 LIBXR_FORCE_OPTIMIZE_O3
static uint16_t
Calculate(
const void* raw,
size_t len)
163 const uint8_t* buf =
reinterpret_cast<const uint8_t*
>(raw);
172 crc =
tab_[(crc ^ *buf++) & 0xff] ^ (crc >> 8);
184 static bool Verify(
const void* raw,
size_t len)
186 const uint8_t* buf =
reinterpret_cast<const uint8_t*
>(raw);
198 std::memcpy(&actual, buf + len -
sizeof(actual),
sizeof(actual));
200 uint16_t expected =
Calculate(buf, len -
sizeof(uint16_t));
201 return expected == actual;
216 static const uint32_t
INIT = 0xFFFFFFFF;
219 static inline uint32_t
tab_[256];
231 for (
int i = 0; i < 256; ++i)
234 for (
int j = 0; j < 8; ++j)
238 crc = (crc >> 1) ^ 0xEDB88320;
256 LIBXR_FORCE_OPTIMIZE_O3
static uint32_t
Calculate(
const void* raw,
size_t len)
258 const uint8_t* buf =
reinterpret_cast<const uint8_t*
>(raw);
267 crc =
tab_[(crc ^ *buf++) & 0xff] ^ (crc >> 8);
279 static bool Verify(
const void* raw,
size_t len)
281 const uint8_t* buf =
reinterpret_cast<const uint8_t*
>(raw);
293 std::memcpy(&actual, buf + len -
sizeof(actual),
sizeof(actual));
295 uint32_t expected =
Calculate(buf, len -
sizeof(uint32_t));
296 return expected == actual;
312 0xFFFFFFFFFFFFFFFFULL;
315 static inline uint64_t
tab_[256];
327 for (
int i = 0; i < 256; ++i)
329 crc =
static_cast<uint64_t
>(i);
330 for (
int j = 0; j < 8; ++j)
334 crc = (crc >> 1U) ^ 0xC96C5795D7870F42ULL;
352 LIBXR_FORCE_OPTIMIZE_O3
static uint64_t
Calculate(
const void* raw,
size_t len)
354 const uint8_t* buf =
reinterpret_cast<const uint8_t*
>(raw);
363 crc =
tab_[(crc ^ *buf++) & 0xff] ^ (crc >> 8U);
16 位循环冗余校验(CRC-16)计算类 / CRC-16 checksum computation class
static bool Verify(const void *raw, size_t len)
验证数据的 CRC16 校验码 / Verifies the CRC16 checksum of the given data
static LIBXR_FORCE_OPTIMIZE_O3 uint16_t Calculate(const void *raw, size_t len)
计算数据的 CRC16 校验码 / Computes the CRC16 checksum for the given data
static bool inited_
查找表是否已初始化 / Whether the lookup table is initialized
static void GenerateTable()
生成 CRC16 查找表 / Generates the CRC16 lookup table
static uint16_t tab_[256]
CRC16 查找表 / CRC16 lookup table.
static const uint16_t INIT
CRC16 初始值 / CRC16 initial value.
32 位循环冗余校验(CRC-32)计算类 / CRC-32 checksum computation class
static LIBXR_FORCE_OPTIMIZE_O3 uint32_t Calculate(const void *raw, size_t len)
计算数据的 CRC32 校验码 / Computes the CRC32 checksum for the given data
static bool inited_
查找表是否已初始化 / Whether the lookup table is initialized
static const uint32_t INIT
CRC32 初始值 / CRC32 initial value.
static uint32_t tab_[256]
CRC32 查找表 / CRC32 lookup table.
static bool Verify(const void *raw, size_t len)
验证数据的 CRC32 校验码 / Verifies the CRC32 checksum of the given data
static void GenerateTable()
生成 CRC32 查找表 / Generates the CRC32 lookup table
64 位循环冗余校验(CRC-64)计算类 / CRC-64 checksum computation class
static const uint64_t INIT
CRC64 初始值 / CRC64 initial value.
static LIBXR_FORCE_OPTIMIZE_O3 uint64_t Calculate(const void *raw, size_t len)
计算数据的 CRC64 校验码 / Computes the CRC64 checksum for the given data
static bool inited_
查找表是否已初始化 / Whether the lookup table is initialized
static void GenerateTable()
生成 CRC64 查找表 / Generates the CRC64 lookup table
static uint64_t tab_[256]
CRC64 查找表 / CRC64 lookup table.
8 位循环冗余校验(CRC-8)计算类 / CRC-8 checksum computation class
static const uint8_t INIT
CRC8 初始值 / CRC8 initial value.
static void GenerateTable()
生成 CRC8 查找表 / Generates the CRC8 lookup table
static LIBXR_FORCE_OPTIMIZE_O3 uint8_t Calculate(const void *raw, size_t len)
计算数据的 CRC8 校验码 / Computes the CRC8 checksum for the given data
static bool inited_
查找表是否已初始化 / Whether the lookup table is initialized
static uint8_t tab_[256]
CRC8 查找表 / CRC8 lookup table.
static bool Verify(const void *raw, size_t len)
验证数据的 CRC8 校验码 / Verifies the CRC8 checksum of the given data