Skip to content

proposal: hash/crc32: Support both reverse and forward CRCs #60992

@onitake

Description

@onitake

There are many widely used CRC algorithms, but the Go standard library implementation only supports CRC32s with reversed polynomials.
There are various terms for these variants: In https://reveng.sourceforge.io/crc-catalogue/all.htm, they are called "reflected", but they could also be considered "little endian". Some algorithms use a "big endian" bit order, which is not compatible.

Unfortunately, it isn't trivial to use a forward polynomial in a reversed implementation or vice-versa.
It seems that reversing the bit order in various places (including table calculation) would enable this (the opposite way is described here: https://stackoverflow.com/questions/53812834/computing-crc16-with-reflected-bit-reversed-input-in-c), but I couldn't get it to work with the CRC32 used in MPEG-TS.

Furthermore, the inversion of the CRC at the beginning and end of the CRC calculation in crc32.simpleUpdate does not account for algorithms using a different value than 0xffffffff for the initial and final XOR, but this is less of a concern. Different values can be applied before/after calling crc32.Update.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    Status

    Incoming

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions