I have a crc32 polynomial:
poly=0xF4ACFB13
seed=0
xorout=0
refin=no
refout=no
check=0x6c9f84a8
I cannot get golang builtin crc32 package to give me the correct checksums.
This website https://www.lddgo.net/en/encrypt/crc yields the correct sums. (sum for string "0" should be 0xC45441EB)
This website https://simplycalc.com/crc32-text.php yields the same as go (if I reverse poly). (sum for string "0" shows 0x1D62A0AB instead same as go)
Can someone help me understand why a function with such basic parameters isn't matching?
Using https://www.lddgo.net/en/encrypt/crc, the following parameters produce a result which matches the Go
hash/crc32implementation and the Javascript implementation at https://simplycalc.com/crc32-source.php:32F4ACFB13FFFFFFFFFFFFFFFFThis answers the initial question, "what parameters are being used?"
If you're open to considering an alternative implementation, you might use one that's designed to be more flexible. See https://github.com/snksoft/crc.
Note that With
hash/crc32, you can use an alternative initial value via the first argument offunc Update(crc uint32, tab *Table, p []byte) uint32. Otherwise, the parameters are hardcoded. Note that these hardcoded parameters are shared between the predefined polynomials (i.e. IEEE, Castagnoli, and Koopman). Adding support for more parameters tohash/crc32doesn't look straightforward, as it would require modifying the binary marshaling/unmarshaling functionality, which is subject to the backwards compatibility guarantee (see the last paragraph in https://pkg.go.dev/hash#Hash).Here's an example comparing usage of
hash/crc32andgithub.com/snksoft/crc:Output:
Go Playground