LDMX Software
CRC.cxx
1#include "Packing/Utility/CRC.h"
2
3#include <algorithm>
4#include <boost/crc.hpp>
5#include <boost/endian/conversion.hpp> // IWYU pragma: keep
6#include <vector>
7
8namespace packing::utility {
9
10uint32_t crc32(std::span<const uint32_t> data) {
15 std::vector<uint32_t> words{data.begin(), data.end()};
16 std::transform(words.begin(), words.end(), words.begin(),
17 [](uint32_t w) { return boost::endian::endian_reverse(w); });
18 auto input_ptr = reinterpret_cast<const unsigned char*>(words.data());
23 return boost::crc<32, 0x04c11db7, 0x0, 0x0, false, false>(input_ptr,
24 words.size() * 4);
25}
26
27uint8_t econdCrc8(uint64_t data) {
32 uint64_t w = boost::endian::endian_reverse(data);
33 auto input_ptr = reinterpret_cast<const unsigned char*>(&w);
42 /*
43 * for future reference:
44 * boost::crc<Bits, Poly, Init, XorOut, RefIn, RefOut>
45 */
46 return boost::crc<8, 0xa7, 0x00, 0x00, false, false>(input_ptr, 8);
47}
48
49} // namespace packing::utility