[quicwg/base-drafts] ChaCha inputs (#2171)

ekr <notifications@github.com> Fri, 14 December 2018 00:15 UTC

Return-Path: <noreply@github.com>
X-Original-To: quic-issues@ietfa.amsl.com
Delivered-To: quic-issues@ietfa.amsl.com
Received: from localhost (localhost []) by ietfa.amsl.com (Postfix) with ESMTP id E4CA012E036 for <quic-issues@ietfa.amsl.com>; Thu, 13 Dec 2018 16:15:49 -0800 (PST)
X-Virus-Scanned: amavisd-new at amsl.com
X-Spam-Flag: NO
X-Spam-Score: -9.46
X-Spam-Status: No, score=-9.46 tagged_above=-999 required=5 tests=[BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.46, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, HTML_MESSAGE=0.001, MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_HI=-5, SPF_PASS=-0.001] autolearn=ham autolearn_force=no
Authentication-Results: ietfa.amsl.com (amavisd-new); dkim=pass (1024-bit key) header.d=github.com
Received: from mail.ietf.org ([]) by localhost (ietfa.amsl.com []) (amavisd-new, port 10024) with ESMTP id MQlwGJmGxiry for <quic-issues@ietfa.amsl.com>; Thu, 13 Dec 2018 16:15:47 -0800 (PST)
Received: from out-5.smtp.github.com (out-5.smtp.github.com []) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ietfa.amsl.com (Postfix) with ESMTPS id 9997A1286E7 for <quic-issues@ietf.org>; Thu, 13 Dec 2018 16:15:47 -0800 (PST)
Date: Thu, 13 Dec 2018 16:15:45 -0800
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=github.com; s=pf2014; t=1544746545; bh=FWT9k8uxDWSZaTE0AwnjsDI4S52Tuf3RXnfDx3xjcBQ=; h=Date:From:Reply-To:To:Cc:Subject:List-ID:List-Archive:List-Post: List-Unsubscribe:From; b=GBKmC1dfALqV7RE5HhHC1tke1K5GdJmy4HpNDs0pg8u7YqS2pfriQsbG8xxGvjYcv h5dc/3JWOgblxPBycYgoxTJtPaGdqgWglpSdrM9vFZE4Eg24etkoB+CstwoOpw5pWH BIhM1YDBK0kSdJtyuKRd0kbRsPkfHL84A06dR6y8=
From: ekr <notifications@github.com>
Reply-To: quicwg/base-drafts <reply+0166e4abe51f8bf0fa040849f392b72e635d3b6bc09c50b592cf00000001182ab83192a169ce174ce37a@reply.github.com>
To: quicwg/base-drafts <base-drafts@noreply.github.com>
Cc: Subscribed <subscribed@noreply.github.com>
Message-ID: <quicwg/base-drafts/issues/2171@github.com>
Subject: [quicwg/base-drafts] ChaCha inputs (#2171)
Mime-Version: 1.0
Content-Type: multipart/alternative; boundary="--==_mimepart_5c12f631b8630_785f3fcdf5ed45c42068b3"; charset="UTF-8"
Content-Transfer-Encoding: 7bit
Precedence: list
X-GitHub-Sender: ekr
X-GitHub-Recipient: quic-issues
X-GitHub-Reason: subscribed
X-Auto-Response-Suppress: All
X-GitHub-Recipient-Address: quic-issues@ietf.org
Archived-At: <https://mailarchive.ietf.org/arch/msg/quic-issues/e30SUJZ5kJVl05P7506oPQIkqAI>
X-BeenThere: quic-issues@ietf.org
X-Mailman-Version: 2.1.29
List-Id: Notification list for GitHub issues related to the QUIC WG <quic-issues.ietf.org>
List-Unsubscribe: <https://www.ietf.org/mailman/options/quic-issues>, <mailto:quic-issues-request@ietf.org?subject=unsubscribe>
List-Archive: <https://mailarchive.ietf.org/arch/browse/quic-issues/>
List-Post: <mailto:quic-issues@ietf.org>
List-Help: <mailto:quic-issues-request@ietf.org?subject=help>
List-Subscribe: <https://www.ietf.org/mailman/listinfo/quic-issues>, <mailto:quic-issues-request@ietf.org?subject=subscribe>
X-List-Received-Date: Fri, 14 Dec 2018 00:15:50 -0000

Here's what 5.4.4 says

```The first 4 bytes of the sampled ciphertext are interpreted as a 32-bit number
in little-endian order and are used as the block count.  The remaining 12 bytes
are interpreted as three concatenated 32-bit numbers in little-endian order and
used as the nonce.```

However, RFC 8439 says:

   o  A 96-bit nonce, treated as a concatenation of three 32-bit little-
      endian integers.

   o  A 32-bit block count parameter, treated as a 32-bit little-endian
This is a little confusing, but I think the correct way to read this is that the ChaCha function takes the nonce as a 96-bit opaque quantity, and the fact that it's little-endian is an internal detail irrelevant to our purposes, so we should just replace the second sentence with "The remaining 12 bytes are used as the 96-bit ChaCha nonce". This is reinforced by the fact that the test vectors have the nonce as a byte block.

The situation with the counter is more complicated because we are told it is both a counter and 32-bits (which might make you think it's an integer parameter), but it is also treated as a little-endian integer, which makes one think it's a bitstring. And then the test vectors treat it as a value, rather than as a bitstring. If you look at code it typically thinks of this as an integer:

See, for instance:

So, I think the right answer here is to think of ChaCha as having the following API:

ChaCha20(k [32]byte{}, nonce [12]byte{}, nonce uint32, []byte{})

Note that because the value on the wire is in big-endian format, this would invert the nonce, but I think it's the right answer anyway. Otherwise, you're having to pass in the counter in the wrong format on big-endian platforms.

You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub: