Re: [CFRG] XChacha20 counter size

"D. J. Bernstein" <djb@cr.yp.to> Sat, 02 January 2021 18:20 UTC

Return-Path: <djb-dsn2-1406711340.7506@cr.yp.to>
X-Original-To: cfrg@ietfa.amsl.com
Delivered-To: cfrg@ietfa.amsl.com
Received: from localhost (localhost [127.0.0.1]) by ietfa.amsl.com (Postfix) with ESMTP id F05D73A0CC7 for <cfrg@ietfa.amsl.com>; Sat, 2 Jan 2021 10:20:22 -0800 (PST)
X-Virus-Scanned: amavisd-new at amsl.com
X-Spam-Flag: NO
X-Spam-Score: -1.898
X-Spam-Level:
X-Spam-Status: No, score=-1.898 tagged_above=-999 required=5 tests=[BAYES_00=-1.9, RCVD_IN_DNSWL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, UNPARSEABLE_RELAY=0.001] autolearn=ham autolearn_force=no
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 kkY-ESTrxiT1 for <cfrg@ietfa.amsl.com>; Sat, 2 Jan 2021 10:20:21 -0800 (PST)
Received: from salsa.cs.uic.edu (salsa.cs.uic.edu [131.193.32.108]) by ietfa.amsl.com (Postfix) with SMTP id 5E1693A0CC5 for <cfrg@irtf.org>; Sat, 2 Jan 2021 10:20:21 -0800 (PST)
Received: (qmail 29658 invoked by uid 1010); 2 Jan 2021 18:20:19 -0000
Received: from unknown (unknown) by unknown with QMTP; 2 Jan 2021 18:20:19 -0000
Received: (qmail 168396 invoked by uid 1000); 2 Jan 2021 18:20:10 -0000
Date: Sat, 02 Jan 2021 18:20:10 -0000
Message-ID: <20210102182010.168395.qmail@cr.yp.to>
From: "D. J. Bernstein" <djb@cr.yp.to>
To: cfrg@irtf.org
Mail-Followup-To: cfrg@irtf.org
In-Reply-To: <245e04ef3f689949b0cf8ac1b5ef40d760334794.camel@loup-vaillant.fr>
Archived-At: <https://mailarchive.ietf.org/arch/msg/cfrg/aSSYF0lxGtGJyNXTYSpz_0cs4Ns>
Subject: Re: [CFRG] XChacha20 counter size
X-BeenThere: cfrg@irtf.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Crypto Forum Research Group <cfrg.irtf.org>
List-Unsubscribe: <https://www.irtf.org/mailman/options/cfrg>, <mailto:cfrg-request@irtf.org?subject=unsubscribe>
List-Archive: <https://mailarchive.ietf.org/arch/browse/cfrg/>
List-Post: <mailto:cfrg@irtf.org>
List-Help: <mailto:cfrg-request@irtf.org?subject=help>
List-Subscribe: <https://www.irtf.org/mailman/listinfo/cfrg>, <mailto:cfrg-request@irtf.org?subject=subscribe>
X-List-Received-Date: Sat, 02 Jan 2021 18:20:23 -0000

A few comments.

1. For people designing high-level protocols, it's good to split
messages into separately authenticated limited-length packets, for
several reasons explained here:

   https://groups.google.com/forum/#!original/boring-crypto/BpUmNMXKMYQ/EEwAIeQdjacJ

One of the reasons is that the code handling packets is generally tested
only for limited lengths; testing many lengths is expensive.

2. For people designing low-level formats (network formats, C integer
sizes, etc.), upgrading 32-bit counters to 64-bit counters is good
practice, since 32-bit counters often overflow. Occasionally this can be
overridden by other considerations, but it's the safest default.

3. #2 doesn't mean that everything else will work with 64-bit counters;
it's just one step towards eliminating 32-bit limitations. (For example,
changing "int" to "long long" in the OpenSSL external APIs won't make
all sorts of internal 32-bit quantities turn into 64 bits.) Also, even
if everything is 64-bit clean, there are other reasons for #1.

4. Conversely, #1 doesn't remove the reasons for #2: one doesn't want
the #1 design decisions embedded into all the #2 pieces of the system.
This is a matter of information hiding.

---Dan