Clarify CRC-24 C example implementation
The mismatch between the variable in the sample code defining CRC-24 and the definition of the generator in the paragraph above has been a source of confusion for over 20 years (see [0] for the first instance i could find in the wild). It has also been raised as an explicit erratum [1].
[0] https://mailarchive.ietf.org/arch/msg/openpgp/F29_03_iISnOS7DF0PUH-tVVKsI/ [1] https://www.rfc-editor.org/errata/eid5491
One option would be to change the CRC24_POLY variable in the code to
exactly match the generator described above. This allows the crc24
accumulator to overflow, which on most architectures has has no
practical functional change, because of the masking step at the end of
the function.
However, allowing the crc24
accumulator to overflow might cause
problems in some obscure architecture, as (a) crc24
is defined as
"long", which is typically a signed type, and (b) left-shift behavior
is undefined for overflowing signed values (and also for negative
signed values) [2].
[2] http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1570.pdf § 6.5.7(4)
So allowing the accumulator to overflow in the sample code seems ill-advised. This change clarifies both that the accumulator should be treated as unsigned, and aligns the variable with the textual description of the generator.