thin-provisioning-tools/checksum.cc

32 lines
565 B
C++
Raw Normal View History

2011-09-12 16:19:42 +05:30
#include "checksum.h"
2011-09-16 14:36:37 +05:30
#include <boost/crc.hpp>
2011-09-12 16:19:42 +05:30
using namespace base;
//----------------------------------------------------------------
2011-09-16 14:36:37 +05:30
crc32c::crc32c(uint32_t xor_value)
: xor_value_(xor_value),
sum_(0)
{
2011-09-12 16:19:42 +05:30
}
void
2011-09-16 14:36:37 +05:30
crc32c::append(void const *buffer, unsigned len)
2011-09-12 16:19:42 +05:30
{
2011-09-16 14:36:37 +05:30
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 16:19:42 +05:30
}
uint32_t
2011-09-16 14:36:37 +05:30
crc32c::get_sum() const
2011-09-12 16:19:42 +05:30
{
2011-09-16 14:36:37 +05:30
return sum_ ^ xor_value_;
2011-09-12 16:19:42 +05:30
}
//----------------------------------------------------------------