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

Daniel Kahn Gillmor <dkg@fifthhorseman.net> Fri, 19 March 2021 22:34 UTC

Return-Path: <dkg@fifthhorseman.net>
X-Original-To: openpgp@ietfa.amsl.com
Delivered-To: openpgp@ietfa.amsl.com
Received: from localhost (localhost [127.0.0.1]) by ietfa.amsl.com (Postfix) with ESMTP id 94E5A3A1275 for <openpgp@ietfa.amsl.com>; Fri, 19 Mar 2021 15:34:31 -0700 (PDT)
X-Virus-Scanned: amavisd-new at amsl.com
X-Spam-Flag: NO
X-Spam-Score: -0.507
X-Spam-Level:
X-Spam-Status: No, score=-0.507 tagged_above=-999 required=5 tests=[BAYES_00=-1.9, DATE_IN_PAST_03_06=1.592, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001] autolearn=no autolearn_force=no
Authentication-Results: ietfa.amsl.com (amavisd-new); dkim=neutral reason="invalid (unsupported algorithm ed25519-sha256)" header.d=fifthhorseman.net header.b=XHOLFC1K; dkim=pass (2048-bit key) header.d=fifthhorseman.net header.b=0QvPEkX3
Received: from mail.ietf.org ([4.31.198.44]) by localhost (ietfa.amsl.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 9UGUPg9DluXS for <openpgp@ietfa.amsl.com>; Fri, 19 Mar 2021 15:34:30 -0700 (PDT)
Received: from che.mayfirst.org (che.mayfirst.org [IPv6:2001:470:1:116::7]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ietfa.amsl.com (Postfix) with ESMTPS id 212143A1274 for <openpgp@ietf.org>; Fri, 19 Mar 2021 15:34:30 -0700 (PDT)
DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/simple; d=fifthhorseman.net; i=@fifthhorseman.net; q=dns/txt; s=2019; t=1616193267; h=from : to : subject : in-reply-to : references : date : message-id : mime-version : content-type : from; bh=BMCxGTMggr9gSMa3/+X5W+C7qPPvQ3WoIt1X7Mkenn4=; b=XHOLFC1KdSrnwhPQ7CryWcEIfVWmbwpbKbS99FKwg5xEETBDxI/+3NCYMxppZLTnWoelS kfJZoX0sXCWYAavAg==
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=fifthhorseman.net; i=@fifthhorseman.net; q=dns/txt; s=2019rsa; t=1616193267; h=from : to : subject : in-reply-to : references : date : message-id : mime-version : content-type : from; bh=BMCxGTMggr9gSMa3/+X5W+C7qPPvQ3WoIt1X7Mkenn4=; b=0QvPEkX3AzYs0RDHbUysJWW7/8nT+MSPD1rSB8Ia4y3MNrljXnEdGq3THopPcfhmCT0rA +RxNXUDziiqkqpHUTlcUSXBhAjTDJlN1aUfymogDgPX0F9+jPWVjI+q3d+naY3GbNflE/3p FfZ0ZwGOp4Q5Q6WT2JjFL6uwChCqSjV34Aj5/6heg5+mI1JsTYPT9yObBvx6BBz3iuk7RfE AtUnOR/m8sQ53Ckfwf8OlzFBbSMpplpsptmAk4tzo8LFzN/9x1J5X0EgSdlX/bkO8JhQlaw bXVbo3WtExouHXEnzC5untaZWgzOgV7kOCM3iM2qCDBosNyJyFfJQdzvbS5A==
Received: from fifthhorseman.net (lair.fifthhorseman.net [108.58.6.98]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by che.mayfirst.org (Postfix) with ESMTPSA id 49245F9A7; Fri, 19 Mar 2021 18:34:27 -0400 (EDT)
Received: by fifthhorseman.net (Postfix, from userid 1000) id F4217203F0; Fri, 19 Mar 2021 13:24:11 -0400 (EDT)
From: Daniel Kahn Gillmor <dkg@fifthhorseman.net>
To: Ángel <angel@16bits.net>, openpgp@ietf.org
In-Reply-To: <60773433fb4dfae65a59c089c22e24c37e7913cf.camel@16bits.net>
References: <20210317145508.136021-1-dkg@fifthhorseman.net> <871rcd7rdh.fsf@fifthhorseman.net> <25e8d5713bcccb7b86e0f9ce75dafba80fb41530.camel@16bits.net> <87sg4t5fz8.fsf@fifthhorseman.net> <87k0q4rgml.fsf@wheatstone.g10code.de> <60773433fb4dfae65a59c089c22e24c37e7913cf.camel@16bits.net>
Autocrypt: addr=dkg@fifthhorseman.net; prefer-encrypt=mutual; keydata= mDMEX+i03xYJKwYBBAHaRw8BAQdACA4xvL/xI5dHedcnkfViyq84doe8zFRid9jW7CC9XBiI0QQf FgoAgwWCX+i03wWJBZ+mAAMLCQcJEOCS6zpcoQ26RxQAAAAAAB4AIHNhbHRAbm90YXRpb25zLnNl cXVvaWEtcGdwLm9yZ/tr8E9NA10HvcAVlSxnox6z62KXCInWjZaiBIlgX6O5AxUKCAKbAQIeARYh BMKfigwB81402BaqXOCS6zpcoQ26AADZHQD/Zx9nc3N2kj13AUsKMr/7zekBtgfSIGB3hRCU74Su G44A/34Yp6IAkndewLxb1WdRSokycnaCVyrk0nb4imeAYyoPtBc8ZGtnQGZpZnRoaG9yc2VtYW4u bmV0PojRBBMWCgCDBYJf6LTfBYkFn6YAAwsJBwkQ4JLrOlyhDbpHFAAAAAAAHgAgc2FsdEBub3Rh dGlvbnMuc2VxdW9pYS1wZ3Aub3JnL0Gwxvypz2tu1IPG+yu1zPjkiZwpscsitwrVvzN3bbADFQoI ApsBAh4BFiEEwp+KDAHzXjTYFqpc4JLrOlyhDboAAPkXAP0Z29z7jW+YzLzPTQML4EQLMbkHOfU4 +s+ki81Czt0WqgD/SJ8RyrqDCtEP8+E4ZSR01ysKqh+MUAsTaJlzZjehiQ24MwRf6LTfFgkrBgEE AdpHDwEBB0DkKHOW2kmqfAK461+acQ49gc2Z6VoXMChRqobGP0ubb4kBiAQYFgoBOgWCX+i03wWJ BZ+mAAkQ4JLrOlyhDbpHFAAAAAAAHgAgc2FsdEBub3RhdGlvbnMuc2VxdW9pYS1wZ3Aub3Jnfvo+ nHoxDwaLaJD8XZuXiaqBNZtIGXIypF1udBBRoc0CmwICHgG+oAQZFgoAbwWCX+i03wkQPp1xc3He VlxHFAAAAAAAHgAgc2FsdEBub3RhdGlvbnMuc2VxdW9pYS1wZ3Aub3JnaheiqE7Pfi3Atb3GGTw+ jFcBGOaobgzEJrhEuFpXREEWIQQttUkcnfDcj0MoY88+nXFzcd5WXAAAvrsBAIJ5sBg8Udocv25N stN/zWOiYpnjjvOjVMLH4fV3pWE1AP9T6hzHz7hRnAA8d01vqoxOlQ3O6cb/kFYAjqx3oMXSBhYh BMKfigwB81402BaqXOCS6zpcoQ26AADX7gD/b83VObe14xrNP8xcltRrBZF5OE1rQSPkMNy+eWpk eCwA/1hxiS8ZxL5/elNjXiWuHXEvUGnRoVj745Vl48sZPVYMuDgEX+i03xIKKwYBBAGXVQEFAQEH QIGex1WZbH6xhUBve5mblScGYU+Y8QJOomXH+rr5tMsMAwEICYjJBBgWCgB7BYJf6LTfBYkFn6YA CRDgkus6XKENukcUAAAAAAAeACBzYWx0QG5vdGF0aW9ucy5zZXF1b2lhLXBncC5vcmcEAx9vTD3b J0SXkhvcRcCr6uIDJwic3KFKxkH1m4QW0QKbDAIeARYhBMKfigwB81402BaqXOCS6zpcoQ26AAAX mwD8CWmukxwskU82RZLMk5fm1wCgMB5z8dA50KLw3rgsCykBAKg1w/Y7XpBS3SlXEegIg1K1e6dR fRxL7Z37WZXoH8AH
Date: Fri, 19 Mar 2021 13:24:11 -0400
Message-ID: <87blbf5a6c.fsf@fifthhorseman.net>
MIME-Version: 1.0
Content-Type: multipart/signed; boundary="=-=-="; micalg="pgp-sha256"; protocol="application/pgp-signature"
Archived-At: <https://mailarchive.ietf.org/arch/msg/openpgp/lYyOm2QVuqUIWrygvWIxcUlTS74>
Subject: Re: [openpgp] [RFC4880bis PATCH] Clarify CRC-24 C example implementation
X-BeenThere: openpgp@ietf.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Ongoing discussion of OpenPGP issues." <openpgp.ietf.org>
List-Unsubscribe: <https://www.ietf.org/mailman/options/openpgp>, <mailto:openpgp-request@ietf.org?subject=unsubscribe>
List-Archive: <https://mailarchive.ietf.org/arch/browse/openpgp/>
List-Post: <mailto:openpgp@ietf.org>
List-Help: <mailto:openpgp-request@ietf.org?subject=help>
List-Subscribe: <https://www.ietf.org/mailman/listinfo/openpgp>, <mailto:openpgp-request@ietf.org?subject=subscribe>
X-List-Received-Date: Fri, 19 Mar 2021 22:34:32 -0000

On Fri 2021-03-19 00:08:02 +0100, Ángel wrote:
> 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;
>                    }

fwiw, i'm fine with either of these.  I note that the change i'd
originally proposed renamed the constant to CRC24_GENERATOR, to align it
with the term in the text ("poly" doesn't appear anywhere in the text,
but "generator" does).

That said, we are pretty clearly in bike-shedding territory here.

I have heard no one advocate for leaving the text unchanged, and i have
heard no one advocate for just silently amending the code to drop bit 25
from the constant.

All of the other variants proposed in this thread seem to have people
expressing various degrees of mild preference, so long as:

 - bit 25 should be cleared during accumulation
 - the accumulator type is explicitly and clearly unsigned
 - the variable definition matches the constant in the text

i observe that the first two points are mutually redundant -- when the
accumulator is unsigned, then overflow doesn't hit undefined behavior,
if i'm reading the C spec correctly.  But it still seems cleaner and
easier to understand if the sample code includes both belt and
suspenders.

<chair hat on>
I think the editors should pick one particular color of bike shed that
satisfies the conditions above and include it in the next revision.
If a member of the WG strongly objects to the revision, we can have more
discussion, but otherwise, i think the WG should focus on more pressing
topics.
</chair hat off>

        --dkg