ietf-openpgp
[Top] [All Lists]

Re: [openpgp] [RFC4880bis PATCH] Clarify CRC-24 C example implementation

2021-03-18 18:08:18
(technically the CRC-24 accumulator just needs 25 bits -- one to test
for overflow -- but we don't need to cut it so fine :P)

I don't think you would find many platforms with a uint_least25_t type. ;-)
I generally prefer explicit sizes when the number of bits matter, but
you are right: a long is more idiomatic. I don't mind either way.


On 2021-03-18 at 09:49 +0100, Werner Koch wrote:
Anyway, I am in favor of applying Hal Finney's old suggestion (patch
39, attached).


As the goal is to provide clear code, that ORed 0x1000000 may still be
a bit surprising (albeit less than when it was included in the
constant). I think it would be clearer to use

                   if (crc & 0x1000000) {
                       crc = (crc ^ CRC24_POLY) & 0xffffff;
                   }


or, following more closely hal's second suggestion:
                   if (crc & 0x1000000) {
                       crc &= 0xffffff; /* Clear bit 25 to avoid overflow */
                       crc ^= CRC24_POLY;
                   }




Best regards


_______________________________________________
openpgp mailing list
openpgp(_at_)ietf(_dot_)org
https://www.ietf.org/mailman/listinfo/openpgp