ietf-openpgp
[Top] [All Lists]

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

2021-04-29 11:16:16
On Thu 2021-04-29 00:01:08 -0400, Paul Wouters wrote:
On Sat, 20 Mar 2021, Ángel wrote:

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

This issue was also left with multiple competing texts, and so I would
like the WG to come up with 1 change for me to apply :)

The version that you've committed to gitlab's main branch looks good to
me:

------
## An Implementation of the CRC-24 in "C"

    #define CRC24_INIT 0xB704CEL
    #define CRC24_GENERATOR 0x864CFBL

    typedef unsigned long crc24;
    crc24 crc_octets(unsigned char *octets, size_t len)
    {
        crc24 crc = CRC24_INIT;
        int i;
        while (len--) {
            crc ^= (*octets++) << 16;
            for (i = 0; i < 8; i++) {
                crc <<= 1;
                if (crc & 0x1000000) {
                    crc &= 0xffffff; /* Clear bit 25 to avoid overflow */
                    crc ^= CRC24_GENERATOR;
                }
            }
        }
        return crc & 0xFFFFFFL;
    }
------

It's a little bit weird that one constant is written as 0xFFFFFFL and
the other is written as 0xffffff -- maybe we want to align the
orthography (and should 0x1000000 also have an L suffix)?  But even
without those little tweaks, this is strictly better than the earlier
version.

If anyone has any objections to this, please speak up!

   --dkg

Attachment: signature.asc
Description: PGP signature

_______________________________________________
openpgp mailing list
openpgp(_at_)ietf(_dot_)org
https://www.ietf.org/mailman/listinfo/openpgp
<Prev in Thread] Current Thread [Next in Thread>