Boost logo

Boost :

Subject: Re: [boost] crc // wrong poly for crc_xmodem_type
From: Sergei Nikulov (sergey.nikulov_at_[hidden])
Date: 2017-05-16 07:35:58


Hi Pavel,

2017-05-15 19:40 GMT+03:00 Pavel Kretov <firegurafiku_at_[hidden]>:
> Hi Sergei.
>
>> I've discovered that current typedef crc_xmodem_type uses wrong poly.
>
> I'm not an expert in CRCs and I have no idea whether Boost's implementation is
> wrong, but it's interesting that:
>
> bin(0x8408) = reverse(bin(0x1021))
>
> Maybe this isn't a real problem, but simply someone decided to intentionally
> flip the poly in the CRC implementation, and the computation still leads to
> correct results?
>
> ——— Pavel K.

I believe this is real problem

CRC16 calculator from here
https://www.lammertbies.nl/comm/info/crc-calculation.html

XMODEM for string "123456789" gives 0x31C3

Test case

>>>>>>>>>>>>>> cut here <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
#define CATCH_CONFIG_MAIN
// This tells Catch to provide a main() - only do this in one cpp file
#include "catch.hpp"

#include <boost/crc.hpp>

TEST_CASE("boost_checksum_crc16", "[checksum]")
{

    std::string xmt{"123456789"};

    boost::crc_xmodem_type bxmt;
    bxmt.process_bytes(xmt.c_str(), xmt.length());
    unsigned xmv = bxmt.checksum();
    CHECK(xmv == 0x31C3);

    boost::crc_optimal<16, 0x1021, 0, 0, false, false> crc_xmt;
    crc_xmt.process_bytes(xmt.c_str(), xmt.length());
    unsigned xmvr = crc_xmt.checksum();
    CHECK(xmvr == 0x31C3);
}
>>>>>>>>>>>>>> cut here <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

First one check fails with

../test/test_3.cpp:136: FAILED:
  CHECK( xmv == 0x31C3 )
with expansion:
  3187 (0xc73) == 12739 (0x31c3)

The second one is passed.

-- 
Best Regards,
Sergei Nikulov

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk