Reputation: 1538
I am using the C zlib API because it has the crc32_combine
function to concatenate checksums together, whereas the Boost one does not.
However, I need to implement the CRC32-C (Castagnoli) checksum, with polynomial 0x1EDC6F41
, instead of the standard CRC32 checksum.
With Boost I can apparently use:
#include <boost/crc.hpp>
using crc_32c_type = boost::crc_optimal<32, 0x1EDC6F41, 0xFFFFFFFF, 0xFFFFFFFF, true, true>;
crc_32c_type result;
result.process_bytes(reinterpret_cast<const char*>(&buffer), len);
return result.checksum();
Which can use the 0x1EDC6F41
polynomial.
Is there a similar way for me to do this with zlib?
Upvotes: 1
Views: 3742
Reputation: 1144
For Objective C
Took me a while to find one that worked.
//------------------------------------------------------------------------------------
// crc32c
// Calculate crc32c (Castagnoli) Checksum
//------------------------------------------------------------------------------------
+ (uint32_t) crc32c:(NSData *)data {
/* CRC-32C (iSCSI) polynomial in reversed bit order. */
int k;
const unsigned char *buf = [data bytes];
unsigned long len = [data length];
uint32_t crc = 0xFFFFFFFF;
while (len--) {
crc ^= *buf++;
for (k = 0; k < 8; k++)
//CRC-32C polynomial 0x1EDC6F41 in reversed bit order.
crc = crc & 1 ? (crc >> 1) ^ 0x82f63b78 : crc >> 1;
}
return ~crc;
}
Upvotes: 0
Reputation: 112547
zlib is open source. You can simply take the source and modify for your own needs. You can change the line: odd[0] = 0xedb88320UL;
to the reflection of the Castagnoli polynomial.
Upvotes: 6