32 lines
565 B
C++
Raw Normal View History

2011-09-12 11:49:42 +01:00
#include "checksum.h"
2011-09-16 10:06:37 +01:00
#include <boost/crc.hpp>
2011-09-12 11:49:42 +01:00
using namespace base;
//----------------------------------------------------------------
2011-09-16 10:06:37 +01:00
crc32c::crc32c(uint32_t xor_value)
: xor_value_(xor_value),
sum_(0)
{
2011-09-12 11:49:42 +01:00
}
void
2011-09-16 10:06:37 +01:00
crc32c::append(void const *buffer, unsigned len)
2011-09-12 11:49:42 +01:00
{
2011-09-16 10:06:37 +01:00
uint32_t const powers = 0x1EDC6F41;
boost::crc_basic<32> crc(powers, 0xffffffff, 0, true, true);
crc.process_bytes(buffer, len);
sum_ = crc.checksum();
2011-09-12 11:49:42 +01:00
}
uint32_t
2011-09-16 10:06:37 +01:00
crc32c::get_sum() const
2011-09-12 11:49:42 +01:00
{
2011-09-16 10:06:37 +01:00
return sum_ ^ xor_value_;
2011-09-12 11:49:42 +01:00
}
//----------------------------------------------------------------