Skip to content

hash/crc32: wrong hash code for CRC32-Q in documented example #65200

@larschri

Description

@larschri

Go version

not relevant

Output of go env in your module/workspace:

not relevant

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    DocumentationIssues describing a change to documentation.NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions