hash/crc32: wrong hash code for CRC32-Q in documented example #65200
Labels
Documentation
NeedsInvestigation
Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone
Go version
not relevant
Output of
go env
in your module/workspace:What did you do?
The example on https://pkg.go.dev/hash/crc32#example-MakeTable uses the polynomial for CRC32-Q when producing a checksum, so it looks like it should be producing the correct CRC32-Q checksum.
What did you see happen?
The produced checksum value - 2964d064 - is not correct.
The reason is that hash/crc32 only support some specific variations of crc32 algorithms, and CRC32-Q requires other settings than those implemented in hash/crc32. There is a proposal to support other variants in #60992 .
What did you expect to see?
The expected output when computing the CRC32-Q checksum for "Hello world" is "0xA790E213", as here: https://crccalc.com/?crc=Hello+world&method=CRC-32Q&datatype=ascii&outtype=0
The simplest fix here is to remove the example, and I think that would be an improvement. It is better to not provide a wrong example.
It would be more helpful to give some hints about the pitfalls, though.
I have attempted to fix the example on https://go.dev/play/p/_avQEOSV2uJ, but maybe this is too complicated to put in the standard documentation.
The text was updated successfully, but these errors were encountered: