
/* boost-crc-bug-demo.cpp Written by U.Mutlu on 2015-07-09-Th Compile: g++ -O2 -Wall -std=gnu++11 boost-crc-bug-demo.cpp Run: ./a.out Output: crc("The quick brown fox jumps over the lazy dog")=414fa339 crc("The quick brown fox ")=88b075e2 crc("The quick brown fox jumps over the lazy dog")=4ac56d0f ERROR See also: http://www.boost.org/doc/libs/1_58_0/libs/crc/crc.html#usage Conclusion: It doesn't do what it should and also advertises; ie. there's a bug */ #include <boost/crc.hpp> #include <boost/cstdint.hpp> #include <iostream> int main() { uint32_t expected; { const std::string sTxt = "The quick brown fox jumps over the lazy dog"; boost::crc_optimal<32, 0x04C11DB7, 0xFFFFFFFF, 0xFFFFFFFF, true, true> crc; crc.process_bytes(sTxt.data(), sTxt.size()); std::cout << "crc(\"" << sTxt << "\")=" << std::hex << crc.checksum() << std::endl; // save the result for the following test expected = crc.checksum(); } // test: doing the same as above, but now in 2 steps, ie. chunk- or blockwise: std::string sTxt; uint32_t result = 0xFFFFFFFF; for (size_t i = 0; i <= 1; ++i) { sTxt += !i ? "The quick brown fox " : "jumps over the lazy dog"; // using the special ctor for initial remainder stored in "result" boost::crc_optimal<32, 0x04C11DB7, 0xFFFFFFFF, 0xFFFFFFFF, true, true> crc(result); crc.process_bytes(sTxt.data(), sTxt.size()); std::cout << "crc(\"" << sTxt << "\")=" << std::hex << crc.checksum() << std::endl; result = crc.checksum(); } // eval: const std::string sRes = result == expected ? "SUCCESS" : "ERROR"; std::cout << sRes << std::endl; return 0; }