#include "utilities.hpp" #include namespace dusk::utils { constexpr std::array generate_crc32_table() { std::array table{}; for (uint32_t i = 0; i < 256; ++i) { uint32_t ch = i; for (size_t j = 0; j < 8; ++j) { ch = (ch & 1) != 0 ? 0xEDB88320 ^ ch >> 1 : ch >> 1; } table[i] = ch; } return table; } constexpr std::array kCrc32Table = generate_crc32_table(); // CRC-32 (IEEE, reflected) uint32_t CRC32(const void* data, size_t size) { const auto* bytes = static_cast(data); uint32_t crc = ~0u; for (size_t i = 0; i < size; ++i) { crc = crc >> 8 ^ kCrc32Table[static_cast(crc ^ bytes[i])]; } return ~crc; } }