d-bahr / CRCpp

Easy to use and fast C++ CRC library.
Other
337 stars 91 forks source link

can support crc32p4? #18

Closed fengmao31 closed 8 months ago

fengmao31 commented 8 months ago

I want to use crc32p4. But I cannot find the custom Polynomial parameter to input it.

d-bahr commented 8 months ago

CRC32P4 has the same parameters as CRC32 except it uses the polynomial 0xF4ACFB13.

Example:

const CRC::Parameters<crcpp_uint32, 32> crc32p4 = { 0xF4ACFB13, 0xFFFFFFFF, 0xFFFFFFFF, true, true };
std::vector<uint8_t> bytes = { 0x33, 0x22, 0x55, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF  };
crcpp_uint32 value = CRC::Calculate(bytes.data(), bytes.size(), crc32p4);
std::cout << value << std::endl;
// Prints "0xA65A343D"

Source for polynomial: https://www.autosar.org/fileadmin/standards/R22-11/CP/AUTOSAR_SWS_CRCLibrary.pdf