Re: [Cfrg] ChaCha20 and Poly1305 for IPsec

Yoav Nir <ynir@checkpoint.com> Thu, 09 January 2014 07:17 UTC

Return-Path: <ynir@checkpoint.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 CF3221AE08C for <cfrg@ietfa.amsl.com>; Wed, 8 Jan 2014 23:17:19 -0800 (PST)
X-Virus-Scanned: amavisd-new at amsl.com
X-Spam-Flag: NO
X-Spam-Score: -7.439
X-Spam-Level:
X-Spam-Status: No, score=-7.439 tagged_above=-999 required=5 tests=[BAYES_00=-1.9, RCVD_IN_DNSWL_HI=-5, RP_MATCHES_RCVD=-0.538, 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 4i7u0DoquCdf for <cfrg@ietfa.amsl.com>; Wed, 8 Jan 2014 23:17:17 -0800 (PST)
Received: from smtp.checkpoint.com (smtp.checkpoint.com [194.29.34.68]) by ietfa.amsl.com (Postfix) with ESMTP id 5F1021AC8F5 for <cfrg@irtf.org>; Wed, 8 Jan 2014 23:17:17 -0800 (PST)
Received: from IL-EX10.ad.checkpoint.com ([194.29.34.147]) by smtp.checkpoint.com (8.13.8/8.13.8) with ESMTP id s097H0Cj026150; Thu, 9 Jan 2014 09:17:00 +0200
X-CheckPoint: {52CE47AA-0-1B221DC2-1FFFF}
Received: from DAG-EX10.ad.checkpoint.com ([169.254.3.110]) by IL-EX10.ad.checkpoint.com ([169.254.2.120]) with mapi id 14.03.0123.003; Thu, 9 Jan 2014 09:17:00 +0200
From: Yoav Nir <ynir@checkpoint.com>
To: David McGrew <mcgrew@cisco.com>
Thread-Topic: [Cfrg] ChaCha20 and Poly1305 for IPsec
Thread-Index: AQHPCjHEk17DdD0mQkqxUhltboUzx5p33c2AgABIH4CAAApZgIAADBaAgAAKHoCAA5kvAA==
Date: Thu, 9 Jan 2014 07:16:59 +0000
Message-ID: <09031D92-9A14-4CF0-A000-123E71D4F784@checkpoint.com>
References: <180998C7-B6E5-489E-9C79-80D9CAC0DE68@checkpoint.com> <CAL9PXLy9hrq+i_neP96FbTJRvRLbLEXnMYdBdwSeHunFAwF+jQ@mail.gmail.com> <A867BB8E-4556-44B1-A0AF-16771626BF5C@checkpoint.com> <52CB358D.3050603@cisco.com> <A6BDE08D-1F7D-4813-A9C4-61AF8C14412B@checkpoint.com> <52CB482D.6090807@cisco.com>
In-Reply-To: <52CB482D.6090807@cisco.com>
Accept-Language: en-US
Content-Language: en-US
X-MS-Has-Attach:
X-MS-TNEF-Correlator:
x-originating-ip: [172.31.21.3]
x-kse-antivirus-interceptor-info: protection disabled
Content-Type: text/plain; charset="iso-8859-1"
Content-ID: <BAF21ECA3DA326469C1717653D88F511@ad.checkpoint.com>
Content-Transfer-Encoding: quoted-printable
MIME-Version: 1.0
Cc: "cfrg@irtf.org" <cfrg@irtf.org>, Adam Langley <agl@google.com>
Subject: Re: [Cfrg] ChaCha20 and Poly1305 for IPsec
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, 09 Jan 2014 07:17:20 -0000

On Jan 7, 2014, at 2:19 AM, David McGrew <mcgrew@cisco.com> wrote:

> Hi Yoav,
> 
> On 01/06/2014 06:43 PM, Yoav Nir wrote:
>> On Jan 7, 2014, at 1:00 AM, David McGrew <mcgrew@cisco.com>
>> wrote:
>> 
>>> Hi Yoav,
>>> 
>>> On 01/06/2014 05:23 PM, Yoav Nir wrote:
>>>> Thanks. Proposing this seems so obvious, that I thought I must be missing something that makes it unsuitable.
>>>> 
>>>> On Jan 6, 2014, at 8:05 PM, Adam Langley <agl@google.com> wrote:
>>>> 
>>>>> On Sun, Jan 5, 2014 at 11:18 AM, Yoav Nir <ynir@checkpoint.com> wrote:
>>>>>> Unlike RC4, ChaCha20 has a 64-bit nonce, so different packets could use different keystreams, much like block ciphers in counter mode. Unlike 3DES, ChaCha20 has performance that is close to that of AES.
>>>>>> 
>>>>>> So my question is whether there is any reason not to use ChaCha20 (with or without the AEAD construction from Adam's draft) for IKE and/or IPsec. Could this be the standby algorithm that we have been looking for?
>>>>> I don't know of any problems with this. If IPsec has the concept of a
>>>>> counter than can be used as an nonce then I think the AEAD
>>>>> construction would be fine, as is.
>>>> IPsec has a 32- or 64-bit packet counter, but for some reason it has never been used as a nonce. Both AES-CTR and AES-GCM have explicit 64-bit IVs in IPsec, so I think a ChaCha implementation should do the same - have an explicit IV that's used as a nonce, with a MUST requirement for uniqueness of IV/key combination.
>>> the reason that the ESP sequence number isn't used as a cryptographic nonce is that it was not regarded as reliable enough.   That is, the ESP standard does not insist that the sequence number never wrap, and many implementations are not careful about maintaining the uniqueness of the sequence number.  This situation is not ideal, but it does seem to be the case.
>> I agree that the text could use some more RFC2119 language, but allowing the sequence to wrap is not allowed:
>> 
>>                                              If anti-replay is enabled
>>   (the default), the transmitted Sequence Number must never be allowed
>>   to cycle.  Thus, the sender's counter and the receiver's counter MUST
>>   be reset (by establishing a new SA and thus a new key) prior to the
>>   transmission of the 2^32nd packet on an SA.
>> 
>>>>> If one needs to pick the nonces
>>>>> randomly, however, then a 64-bit space is too small and XChaCha (which
>>>>> has a 192-bit nonce) would be more suitable.
>>>> It would work, but IPsec requires re-keying when the 32-bit or 64-bit counter reaches 2^n-1, so that seems like overkill.
>>> Agreed that a 192-bit nonce sounds a bit big.
>>> 
>>> ESP supports multipoint security associations, in which case it is essential to coordinate nonces across all of the encrypters, to make sure that they are all distinct.   The requirements and a simple approach is outlined in rfc6054, and those requirements are followed in the latest version of the Group Domain of Interpretation rfc6407.  The nonce management is a bit ugly, but there is precedent for it.
>>> 
>>> We could do a lot worse than ChaCha as a cipher.   An AEAD construction could be used in a way that mirrors GCM/CCM, though if I recall right, Adam defined an 8-byte nonce rather than a 12-byte nonce for the ChaCha AEAD algorithm, which makes it incompatible with almost all of the other AEAD algorithms (see Table 1 of draft-mcgrew-iv-gen-02).   A 12-byte nonce would enable ESP implementations to use the same nonce generation techniques, including rfc6407 ones.
>> An 8-byte nonce is part of ChaCha.
> 
> - faceplam -  Yes, of course.
> 
>> This is different from counter mode where the initial counter could be anything up to block size. I don't claim to understand why ChaCha has a 64-bit nonce and a 64-bit block counter instead of, say, a 96-bit nonce and a 32-bit block counter (good for 256 GB - plenty for an IP packet). Would ChaCha modified like that retain its security properties?
> 
> I think so - I would be surprised if it didn't retain its security properties.   But it might be best to avoid tweaking the design.

Thinking it over, I think so too. While ChaCha20 can handle 64 TB messages, 256 GB is more than good enough for an IPsec packet (currently limited to 64KB). So we could reduce the block counter to 10 bits, but since everything else id ChaCha is 32-bit, I'll leave it at 32-bit. So the nonce could be expanded to 96-bit, but as long as an implementation makes sure that it *is* a nonce (only used once), 64-bit is plenty for a single SA. I will use the extra 32-bit word as sender-id. So it can be set to zero for regular ESP, and set to non-zero for GDOI with multiple senders.

Yoav