// vdm/util/crc32.hpp โ€” CRC-32 (IEEE 802.3 / zlib polynomial), header-only. // // Used to integrity-check the .veloxpart.meta resume sidecar (docs/04 ยง5). Standard // reflected CRC-32 with 0xEDB88320, init/xorout 0xFFFFFFFF โ€” byte-compatible with // zlib's crc32() and `cksum -o3` โ€” so the value is reproducible outside this codebase. // // This header compiles standalone. #ifndef VDM_UTIL_CRC32_HPP #define VDM_UTIL_CRC32_HPP #include #include #include #include "vdm/util/bytes.hpp" namespace vdm { namespace detail { inline constexpr std::array make_crc32_table() { std::array t{}; for (std::uint32_t i = 0; i < 256; ++i) { std::uint32_t c = i; for (int k = 0; k < 8; ++k) c = (c & 1u) ? (0xEDB88320u ^ (c >> 1)) : (c >> 1); t[i] = c; } return t; } inline constexpr std::array kCrc32Table = make_crc32_table(); } // namespace detail // Incremental: pass the previous result back as `seed` to continue over split buffers. [[nodiscard]] inline std::uint32_t crc32_update(std::uint32_t seed, ConstByteSpan data) noexcept { std::uint32_t c = seed ^ 0xFFFFFFFFu; for (std::byte b : data) c = detail::kCrc32Table[(c ^ std::to_integer(b)) & 0xFFu] ^ (c >> 8); return c ^ 0xFFFFFFFFu; } [[nodiscard]] inline std::uint32_t crc32(ConstByteSpan data) noexcept { return crc32_update(0u, data); } } // namespace vdm #endif // VDM_UTIL_CRC32_HPP