Search code examples
c++boostrfidcrc

Calculate CRC-5 using boost


I need to calculate a CRC-5 checksum as specified in the EPC passive RFID protocol standard (UHF Class 1 Gen 2 Standard). I intend to use the optimized crc computer from Boost for the calculations, but I'm having a difficult time mapping the information from the EPC specification to the crc computer template parameters:

template < std::size_t Bits, impl_def TruncPoly,
           impl_def InitRem, impl_def FinalXor,
           bool ReflectIn, bool ReflectRem >

The CRC 5 definition from the EPC standard can be found in table 6.12: enter image description here

Annex F contains this additional information: enter image description here

The first template parameter (Bits) is obviously 5, and I suppose that TruncPoly should be 0x09 (from wikipedia), but I could really use some advice for the rest.


Solution

  • After a bit more searching I found this: http://reveng.sourceforge.net/crc-catalogue/1-15.htm#crc.cat-bits.5

    It provides the following information (copied to ensure that it doesn't disappear): enter image description here

    In case it is not clearly visible, the relevant information is:

    width=5 poly=0x09 init=0x09 refin=false refout=false xorout=0x00 check=0x00 name="CRC-5/EPC"

    As you can see, they don't just give the information needed, they also thoroughly reference their sources, so I can recommend to follow the link if you're working with this.

    To answer my own question, the boost crc-5-epc definition then becomes:

    boost::crc_optimal<5, 0x09, 0x09, 0x00, false, false>  crc_5_epc;