Module crc

Source
Expand description

Public because a checksum is a checksum. copy verifies a file it has just written with the same CRC-32 routine Ogg pages are checked with, rather than growing a second implementation of the same polynomial next door. The three cyclic redundancy checks the audio containers carry.

Each is defined by its polynomial and by whether the bits are reflected, and the three used here disagree on both counts — so they are written out rather than derived from one another.

WhereWidthPolynomialCovers
FLAC frame header80x07the header, up to the byte before the CRC
FLAC frame160x8005the whole frame, up to the two bytes before the CRC
Ogg page320x04C11DB7the page, its own CRC field read as zero

Tables are built at first use rather than written out: 256 entries computed in a few microseconds are easier to trust than 256 constants copied by hand.

Functions§

crc8
CRC-8 as FLAC uses it: polynomial 0x07, no reflection, zero seed.
crc16
CRC-16 as FLAC uses it: polynomial 0x8005, no reflection, zero seed.
crc32_ogg
CRC-32 as Ogg uses it: polynomial 0x04C11DB7, no reflection and no final inversion — which is what sets it apart from the CRC-32 of zip and PNG, and why a general-purpose implementation cannot be reused here.