-
Notifications
You must be signed in to change notification settings - Fork 36
Description
The "normal" crc32 (in python available in zlib or binascii) can do continuation of a crc, i.e. (python3):
>>> from zlib import crc32
>>> crc32(b'12345678')
2598427311
>>> crc32(b'12345678', 2598427311)
1808553911
>>> crc32(b'1234567812345678')
1808553911
pycrc doesn't seem to get this right (I've installed the pycrc.py as pycrc in my path, the prompt is designed to allow cutting/pasting the whole line):
: %; pycrc --version
pycrc v0.9.2
: %; pycrc --width=32 --poly=0x04c11db7 --xor-in=0 --xor-out=0 \
--reflect-in=1 --reflect-out=1 --check-hexstring 12345678
0x6b4dd184
: %; pycrc --width=32 --poly=0x04c11db7 --xor-in=0x6b4dd184 --xor-out=0 \
--reflect-in=1 --reflect-out=1 --check-hexstring 12345678
0x3ab64c61
: %; pycrc --width=32 --poly=0x04c11db7 --xor-in=0 --xor-out=0
--reflect-in=1 --reflect-out=1 --check-hexstring 1234567812345678
0x1a8a2677
If I reverse the output value 0x6b4dd184 before using it in the second call above it works:
: %; ./rev 0x6b4dd184
0x218bb2d6
: %; pycrc --width=32 --poly=0x04c11db7 --xor-in=0x218bb2d6 --xor-out=0 \
--reflect-in=1 --reflect-out=1 --check-hexstring 12345678
0x1a8a2677
So it looks like pycrc should reflect the xor-in value before xoring it into the register for reflected algos.
Note that I'm not sure why pycrc gets it wrong for 32 bit but seems to get it right for crc16, there is the 16-bit model 'crc-16-ccitt' which has an asymmetric xor-in value of 0x1d0f. This produces a check-value consistent with other crc implementation of the same algo (e.g. reveng which names it CRC-16/SPI-FUJITSU). And continuation works, too (the algo has a zero xor-out, so we don't need to compensate):
: %; pycrc --width=16 --poly=0x1021 --xor-in=0x1d0f --xor-out=0 \
--reflect-in=0 --reflect-out=0 --check-string=1234567812345678
0x5b57
: %; pycrc --width=16 --poly=0x1021 --xor-in=0x1d0f --xor-out=0 \
--reflect-in=0 --reflect-out=0 --check-string=12345678
0x712c
: %; pycrc --width=16 --poly=0x1021 --xor-in=0x712c --xor-out=0 \
--reflect-in=0 --reflect-out=0 --check-string=12345678
0x5b57
Any ideas?