Re: [Cfrg] I-D Action: draft-nir-cfrg-chacha20-poly1305-01.txt

Yoav Nir <ynir.ietf@gmail.com> Thu, 13 March 2014 14:46 UTC

Return-Path: <ynir.ietf@gmail.com>
X-Original-To: cfrg@ietfa.amsl.com
Delivered-To: cfrg@ietfa.amsl.com
Received: from localhost (ietfa.amsl.com [127.0.0.1]) by ietfa.amsl.com (Postfix) with ESMTP id 758341A09F6 for <cfrg@ietfa.amsl.com>; Thu, 13 Mar 2014 07:46:06 -0700 (PDT)
X-Virus-Scanned: amavisd-new at amsl.com
X-Spam-Flag: NO
X-Spam-Score: -2
X-Spam-Level:
X-Spam-Status: No, score=-2 tagged_above=-999 required=5 tests=[BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, FREEMAIL_FROM=0.001, SPF_PASS=-0.001] autolearn=ham
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 GlB4ulBb_hqN for <cfrg@ietfa.amsl.com>; Thu, 13 Mar 2014 07:46:02 -0700 (PDT)
Received: from mail-ee0-x232.google.com (mail-ee0-x232.google.com [IPv6:2a00:1450:4013:c00::232]) by ietfa.amsl.com (Postfix) with ESMTP id 698291A09EE for <cfrg@irtf.org>; Thu, 13 Mar 2014 07:46:02 -0700 (PDT)
Received: by mail-ee0-f50.google.com with SMTP id c13so475810eek.9 for <cfrg@irtf.org>; Thu, 13 Mar 2014 07:45:55 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=content-type:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=XkZj8CuopJ9vEsCz1Zuxtu1hvpln3ThYn8Us1Zk/6rs=; b=L8gX5UkRpZ8c90N+3AKuZfblFxS9v/8AkW9ViJBkezw/2J5p/Bwx1/aeIWgSeS0S9B vkxSwwDn/pMNxOrwRomo9FGPDW7M/ZR23vdL4Ae0ETZZPbsCoQ2YPxeYXqqB3R9BNhiM axxqYb6wUyYRSMmoKqv7Z/YMmm33hTfQmZENhXrYRQE+OBa3N8D2aIM/NkpKD95gel48 xXi4fj9Vktf5hgENqKE8rBxbUmxkHhbRseIC36pIIV0aSDZMwLFUPCzXEZ/e4AlWOLum ez3UJe83IKPywla15A41/P/cqVEJU8ayvYwpELIjNvPWGt7i8xJXXD8wUaiKDMSg9VYh xj9Q==
X-Received: by 10.15.56.130 with SMTP id y2mr2673258eew.17.1394721955484; Thu, 13 Mar 2014 07:45:55 -0700 (PDT)
Received: from [172.24.250.117] (dyn32-131.checkpoint.com. [194.29.32.131]) by mx.google.com with ESMTPSA id o5sm8936883eeg.8.2014.03.13.07.45.54 for <multiple recipients> (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 13 Mar 2014 07:45:54 -0700 (PDT)
Content-Type: text/plain; charset="windows-1252"
Mime-Version: 1.0 (Mac OS X Mail 7.2 \(1874\))
From: Yoav Nir <ynir.ietf@gmail.com>
In-Reply-To: <1AC3290E-64A3-4D74-AE2B-C578236E60EA@krovetz.net>
Date: Thu, 13 Mar 2014 16:45:55 +0200
Content-Transfer-Encoding: quoted-printable
Message-Id: <411966EE-1A23-4B38-8A50-E479832CC13B@gmail.com>
References: <20140228121448.1c123bab@chromobil.localdomain> <1AC3290E-64A3-4D74-AE2B-C578236E60EA@krovetz.net>
To: Ted Krovetz <ted@krovetz.net>
X-Mailer: Apple Mail (2.1874)
Archived-At: http://mailarchive.ietf.org/arch/msg/cfrg/Qkp9vKFTyj5qDwj3wXAI36kC5Pk
Cc: cfrg@irtf.org
Subject: Re: [Cfrg] I-D Action: draft-nir-cfrg-chacha20-poly1305-01.txt
X-BeenThere: cfrg@irtf.org
X-Mailman-Version: 2.1.15
Precedence: list
List-Id: Crypto Forum Research Group <cfrg.irtf.org>
List-Unsubscribe: <http://www.irtf.org/mailman/options/cfrg>, <mailto:cfrg-request@irtf.org?subject=unsubscribe>
List-Archive: <http://www.irtf.org/mail-archive/web/cfrg/>
List-Post: <mailto:cfrg@irtf.org>
List-Help: <mailto:cfrg-request@irtf.org?subject=help>
List-Subscribe: <http://www.irtf.org/mailman/listinfo/cfrg>, <mailto:cfrg-request@irtf.org?subject=subscribe>
X-List-Received-Date: Thu, 13 Mar 2014 14:46:06 -0000

On Mar 12, 2014, at 4:57 AM, Ted Krovetz <ted@krovetz.net> wrote:

> Hello Yoav,
> 
> Nice work on draft-nir-cfrg-chacha20-poly1305-01.txt. It's a useful document. I wonder, though, if endian conventions are clear enough. What exactly is a little-endian integer? (I thought there was only one kind of integer.)

I don’t know what a 32-bit integer is, either. I thought the list of integers extended to infinity. I guess I should change the text to say that it’s a little-endian representation of integers limited to 32 bits.

> I think you mean that keys, etc, residing in memory are read little-endian, 32-bits at a time. But, what if these quantities do not come from memory? What if the nonce, or key, or counter happens to be a computed value and resides in registers?

That is exactly what happens in both ESP and TLS (and I assume SSH). Some KDF churns out an octet string, and that has to be used as keys. So if my draft says that the key to ChaCha is 8 little-endian 32-bit integers, what I mean is that the 32 octets (or 256 bits) are taken 4 (or 32) at a time, and taken to be a 32-bit little-endian representation of an integer. This produces that 8 integers that are the input to ChaCha.

> When exactly do these need byte reversal? As an example, when you talk about the counter being 1, is that 00:00:00:01 in memory, which then becomes 01:00:00:00 in a register, or vice-versa? I was able to figure it out by looking at your examples, but it might be better if it were made clearer and didn't *need* looking at examples.

I’m guessing you didn’t attend the JSON meeting on Friday, where someone (I don’t remember who) said something to the effect that real developers look first at the examples rather than read ABNF. Some cheered (I know I did)

Anyway, the block counter is internally generated, so it’s simply a number regardless of the internal architecture of the machine. The nonce in ChaCha, however, and the blocks in Poly1305 are read from an octet string as if they were a 32-bit little-endian representation of integers.

> One approach you might consider is defining the interfaces as taking plain old integers, but then writing a note that explains how big-endian and little-endian systems would interact with such an interface to get standard behavior.

It could be a good idea. I’ll see if it fits for the next revision.

> Damn Intel for making the world primarily little-endian! It's such a pain.

I don’t know. This is pretty nifty:

int main(int argc, char** argv)
{
    long long int num;
    long long int* llp;
    long int* lp;
    int* p;
    short* sp;
    char* cp;

    num = 7;
    llp = &num;
    lp = (long*) llp;
    p = (int*) llp;
    sp = (short*) llp;
    cp = (char*) llp;

    printf(“%lld %ld %d %hd %hhd\n”, 
        *llp, *lp, *p, *sp, *cp); 
}

Yoav