<?xml version="1.0"?>
<?xml-stylesheet type='text/xsl' href='./rfc2629.xslt' ?>

<?rfc toc="yes"?>
<?rfc symrefs="no"?>
<?rfc compact="yes" ?>
<?rfc sortrefs="yes" ?>
<?rfc strict="yes" ?>
<?rfc linkmailto="yes" ?>
<!DOCTYPE rfc SYSTEM "rfc2629.dtd" >
    

<?xml-stylesheet type='text/xsl' href='./rfc2629.xslt' ?>

<?rfc symrefs="yes"?>
<?rfc compact="yes" ?>
<?rfc subcompact="yes" ?>
<?rfc sortrefs="yes" ?>
<rfc ipr="trust200902" docName="draft-nir-ipsecme-chacha20-poly1305-01" category="std">
  <front>
    <title abbrev="ChaCha20 & Poly1305 for IPsec">ChaCha20 and Poly1305 and their use in IPsec</title>
    <author initials="Y." surname="Nir" fullname="Yoav Nir">
      <organization abbrev="Check Point">Check Point Software Technologies Ltd.</organization>
      <address>
        <postal>
          <street>5 Hasolelim st.</street>
          <city>Tel Aviv</city>
          <code>6789735</code>
          <country>Israel</country>
        </postal>
        <email>ynir@checkpoint.com</email>
      </address>
    </author>
    <date year="2014"/>
    <area>Security Area</area>
    <keyword>Internet-Draft</keyword>
    <abstract>
      <t> This document describes the use of the ChaCha20 stream cipher in IPsec, as well as the use of the Poly1305 authenticator, both as stand-alone algorithms, and as a combined mode AEAD algorithm.</t>
    </abstract>
  </front>
  <middle>
    <!-- ====================================================================== -->
    <section anchor="introduction" title="Introduction">
      <t> The Advanced Encryption Standard (AES - <xref target="FIPS-197"/>) has become the gold standard in encryption. Its efficient design, wide implementation, and hardware support allow for high performance in many areas, including IPsec VPNs. On most modern platforms, AES is anywhere from 4x to 10x as fast as the previous most-used cipher, 3-key Data Encryption Standard (3DES - <xref target="FIPS-46"/>), which makes it not only the best choice, but the only choice.</t>
      <t> The problem is that if future advances in cryptanalysis reveal a weakness in AES, VPN users will be in an unenviable position. With the only other widely supported cipher being the much slower 3DES, it is not feasible to re-configure IPsec implementations to use 3DES. <xref target="standby-cipher"/> describes this issue and the need for a standby cipher in greater detail.</t>
      <t> This document proposes the ChaCha20 stream cipher as such a standby cipher with or without the Poly1305 authenticator. These algorithms are described in a separate document (<xref target="chacha_poly"/>). This document only describes the IPsec-specific things.</t> 
      <section anchor="mustshouldmay" title="Conventions Used in This Document">
        <t>The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT",
          "RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be interpreted as described
          in <xref target="RFC2119"/>.</t>
      </section>
    </section>
    <section anchor="foripsec" title="Algorithms for ESP & AH">
      <t> This document defines three algorithms for use with the Encapsulated Security Protocol (ESP - <xref target="RFC4303"/>) and Authentication Header (AH - <xref target="RFC4302"/>):<list style="symbols">
        <t> ChaCha20 for use as an encryption algorithms for ESP.</t>
        <t> Poly1305-MAC for use as a message authentication algorithm for ESP and AH.</t>
        <t> ChaCha20-Poly1305-ESP as an AEAD algorithm for ESP.</t></list></t>
      <section anchor="esp_chacha" title="ENCR_ChaCha20 for ESP">
        <t> The algorithm for ChaCha20 is described in section 2.4 of <xref target="chacha_poly"/>. In ESP the following parameters are used:<list style="symbols">
          <t> The IV is 64-bit. Since this is used for the nonce in the ChaCha20 function, this IV MUST NOT repeat. The most natural way to implement this is with a counter, but anything that guarantees uniqueness can be used, such as a linear feedback shift register (LFSR).  Note that the encrypter can use any IV generation method that meets the uniqueness requirement, without coordinating with the decrypter.</t>
          <t> The Internet Key Exchange protocol (IKE - <xref target="RFC5996"/>) generates a bitstring called KEYMAT that is generated from a PRF. That KEYMAT is divided into keys for encryption, message authentication and whatever else is needed. For the ChaCha20 algorithm, 256 bits are used for the key. TBD: do we want an extra 32 bits as salt for the nonce like in GCM?</t>
          <t> The ChaCha20 encryption algorithm is called with the 256-bit key, one (1) for the initial counter. The packet IV is prepended by a 32-bit sender ID value to form the 96-bit nonce. For regular IPsec, the Sender ID is set to zero. For multi-sender SAs, such as described in <xref target="RFC6054"/>, there sender ID can be set to a different value for each sender. The reason that one (1) is used for the initial counter rather than zero is that one is used for encryption in the AEAD algorithm (because zero is reserved for generating the one-time Poly1305 key), so one was used here for consistency.</t>
          <t> As ChaCha20 is not a block cipher, no padding should be necessary. However, in keeping with the specification in RFC 4303, the ESP does have padding, so as to align the buffer to an integral multiple of 4 octets.</t></list></t>
        <t> The encryption algorithm transform ID for negotiating this algorithm in IKE is TBA by IANA.</t> 
      </section>  
      <section anchor="esp_ah_poly1305" title="AUTH_Poly1305 for ESP and AH">
        <t> You cannot use a part of the keying material directly, because Poly1305 requires an unpredictable and non-repeating key for each authenticated message. So the Poly1305 key for each message is generated as in section 2.6 of <xref target="chacha_poly"/>:<list style="symbols">
          <t> The key for AUTH_Poly1305 is 256-bits.</t>
          <t> To determine the per-packet Poly1305 key, the ChaCha20 block function is called with the following parameters:<list style="symbols">
            <t> The AUTH_Poly1305 256-bit key is used as the key.</t>
            <t> The nonce is set from the sequence number (in the order as it appears in the packet). 32 or 64 zero bits are prepended depending on whether ESN is enabled or not, forming a 96-bit nonce.</t>
            <t> Zero is used for the block counter.</t></list></t>
          <t> The 512-bit result is then truncated. The top 256 bits are used as the one-time key for Poly1305 to calculate the message authentication code (MAC).</t>
          <t> The 128-bit output serves as the MAC for the packet. All 16 bytes are included in the packet.</t></list></t>
        <t> The integrity algorithm transform ID for negotiating this algorithm in IKE is TBA by IANA.</t> 
        <section anchor="esp_ah_example" title="Example One-Time Key Derivation">
          <t> Suppose our 256-bit MAC key and sequence number are as follows:<figure>
          	<artwork><![CDATA[
AUTH_Poly1305 Key:
000  7b ac 2b 25 2d b4 47 af 09 b6 7a 55 a4 e9 55 84|{.+%-.G...zU..U.
016  0a e1 d6 73 10 75 d9 eb 2a 93 75 78 3e d5 53 ff|...s.u..*.ux>.S.

ESN: off
Sequence Number: 40 (represented on the packet as 00:00:00:28)
]]></artwork></figure></t>
        <t> So the ChaCha20 block function (section 2.3 of <xref target="chacha_poly"/>) is called with the following parameters:<list style="symbols">
          <t> The AUTH_Poly1305 key.</t>
          <t> The 96-bit nonce 00:00:00:00:00:00:00:00:00:00:00:28.</t>
          <t> The block count parameter set to zero (0).</t></list></t>
        <t> Note in the following ChaCha20 block, that the sequence number (bottom right) is reversed. This is because the sequence number is big-endian in the ESP packet, but is treated as a sequence of 32-bit little-endian numbers in ChaCha20.<figure>
          	<artwork><![CDATA[
Set up ChaCha20 block:
    61707865  3320646e  79622d32  6b206574
    252bac7b  af47b42d  557ab609  8455e9a4
    73d6e10a  ebd97510  7875932a  ff53d53e
    00000000  00000000  00000000  28000000
]]></artwork></figure><figure>
          	<artwork><![CDATA[
After running the ChaCha20 block operation:
    0c15e292  6e2fe7cc  dcd9bd92  f60a30b3
    4094c018  b0ba041d  88ed8acf  09f9bba5
    a29dbf3d  e1a6acdc  011e3fe8  d953dff5
    32989c29  12be0248  0c267749  e55f2037
]]></artwork></figure><figure>
          	<artwork><![CDATA[
The Poly1305 one-time key (256 bits):
000  92 e2 15 0c cc e7 2f 6e 92 bd d9 dc b3 30 0a f6  ....../n.....0..
016  18 c0 94 40 1d 04 ba b0 cf 8a ed 88 a5 bb f9 09  ...@............
]]></artwork></figure></t>
        </section>
      </section>  
      <section anchor="esp_chacha_poly" title="ESP_ChaCha20-Poly1305 for ESP">
        <t> ESP_ChaCha20-Poly1305 is a combined mode algorithm, or AEAD. The construction follows the AEAD construction in section 2.7 of <xref target="chacha_poly"/>:<list style="symbols"> 
          <t> As in <xref target="esp_chacha"/>, the IV is 64-bit, and is used as part of the nonce. </t>
          <t> Also as in <xref target="esp_chacha"/>, a 32-bit sender ID (zero for regular IPsec) is prepended to the 64-bit IV to form the nonce.</t>
          <t> Also as in <xref target="esp_chacha"/>, the encryption key is 256-bit.</t>
          <t> As in <xref target="esp_ah_poly1305"/>, the nonce, along with a block counter of zero is passed to the ChaCha20 block function, and the top part of the result used as the Poly1305 key. However, unlike AUTH_Poly1305, the nonce passed to the block function here does not depend on the ESP sequence number, but is the same nonce that is used in ChaCha20, including the 32-bit Sender ID bits, and the key passed is the same as the encryption key.</t>
          <t> The ChaCha20 encryption function is then called with the nonce, the key, and an initial counter of zero.</t>
          <t> Finally, the Poly1305 function is run on the data to be authenticated, which is, as specified in section 2.7 of <xref target="chacha_poly"/> a concatenation of the following:<list style="symbols">
            <t> The Authenticated Additional Data (AAD) - see <xref target="aad"/>.</t>
            <t> The AAD length in bytes as a 32-bit network order quantity.</t>
            <t> The ciphertext</t>
            <t> The length of the ciphertext as a 32-bit network order quantity.</t></list></t>
          <t> The 128-bit output of Poly1305 is used as the tag. All 16 bytes are included in the packet.</t></list></t>
        <t> The encryption algorithm transform ID for negotiating this algorithm in IKE is TBA by IANA.</t> 
        <section anchor="aad" title="AAD Construction">
          <t> The construction of the Additional Authenticated Data (AAD) is similar to the one in <xref target="RFC4106"/>. For security associations (SAs) with 32-bit sequence numbers the AAD is 8 bytes: 4-byte SPI followed by 4-byte sequence number ordered exactly as it is in the packet. For SAs with ESN the AAD is 12 bytes: 4-byte SPI followed by an 8-byte sequence number as a 64-bit network order integer.</t>
        </section>
      </section>  
    </section>
      <section anchor="security" title="Security Considerations">
        <t> The ChaCha20 cipher is designed to provide 256-bit security.</t>
        <t> The Poly1305 authenticator is designed to ensure that forged messages are rejected with a probability of 1-(n/(2^102)) for a 16n-byte message, even after sending 2^64 legitimate messages, so it is SUF-CMA in the terminology of <xref target="AE"/>.</t>
        <t> The most important security consideration in implementing this draft is the uniqueness of the nonce used in ChaCha20. This is trivial in AUTH_Poly1305, because the packet sequence number is used as a nonce, but is required for ChaCha20 as well. As said in <xref target="esp_chacha"/>, the nonce should be selected uniquely for a particular key. counters and LFSRs are both acceptable ways of generating unique nonces, as is encrypting a counter using a 64-bit cipher such as DES. Note that it is not acceptable to use a truncation of a counter encrypted with a 128-bit or 256-bit cipher, because such a truncation may repeat after a short time.</t>
      </section>
      <section anchor="iana" title="IANA Considerations">
        <t> IANA is requested to assign two values from the IKEv2 "Transform Type 1 - Encryption Algorithm Transform IDs" registry, as follows:<list style="symbols">
          <t>ENCR_ChaCha20</t>
          <t>ESP_ChaCha20-Poly1305</t></list></t>
        <t> IANA is also requested to assign one value from the IKEv2 "Transform Type 3 - Integrity Algorithm Transform IDs" registry with name "AUTH_Poly1305".</t>
      </section>  
      <section anchor="ack" title="Acknowledgements">
        <t> All of the algorithms in this document were designed by D. J. Bernstein. The AEAD construction was designed by Adam Langley. The author would also like to thank Adam for helpful comments, as well as Yaron Sheffer for telling me to write the algorithms draft.</t>
      </section>    
  </middle>
  <!-- ====================================================================== -->
  <back>
    <references title="Normative References"> 
      <reference anchor='RFC2119'>
        <front>
          <title abbrev='RFC Key Words'>Key words for use in RFCs to Indicate Requirement Levels</title>
          <author initials='S.' surname='Bradner' fullname='Scott Bradner'>
            <organization>Harvard University</organization>
            <address>
              <postal>
                <street>1350 Mass. Ave.</street>
                <street>Cambridge</street>
                <street>MA 02138</street>
              </postal>
              <phone>- +1 617 495 3864</phone>
              <email>sob@harvard.edu</email>
            </address>
          </author>
          <date year='1997' month='March' />
          <area>General</area>
          <keyword>keyword</keyword>
        </front>
        <seriesInfo name='BCP' value='14' />
        <seriesInfo name='RFC' value='2119' />
        <format type='TXT' octets='4723' target='ftp://ftp.isi.edu/in-notes/rfc2119.txt' />
        <format type='HTML' octets='16553' target='http://tools.ietf.org/html/rfc2119' />
      </reference>
      <reference anchor="RFC5996">
        <front>
          <title>Internet Key Exchange Protocol Version 2 (IKEv2)</title>
          <author initials="C." surname="Kaufman" fullname="C. Kaufman">
            <organization/>
          </author>
          <author initials="P." surname="Hoffman" fullname="P. Hoffman">
            <organization/>
          </author>
          <author initials="Y." surname="Nir" fullname="Y. Nir">
            <organization/>
          </author>
          <author initials="P." surname="Eronen" fullname="P. Eronen">
            <organization/>
          </author>
          <date year="2010" month="September"/>
        </front>
        <seriesInfo name="RFC" value="5996"/>
        <format type="TXT" octets="346466" target="http://www.rfc-editor.org/rfc/rfc5996.txt"/>
      </reference>
      <reference anchor="RFC4302">
        <front>
          <title>IP Authentication Header</title>
          <author initials="S." surname="Kent" fullname="S. Kent">
            <organization/>
          </author>
          <date year="2005" month="December"/>
        </front>
        <seriesInfo name="RFC" value="4302"/>
        <format type="TXT" octets="82328" target="http://www.rfc-editor.org/rfc/rfc4302.txt"/>
      </reference>
      <reference anchor="RFC4303">
        <front>
          <title>IP Encapsulating Security Payload (ESP)</title>
          <author initials="S." surname="Kent" fullname="S. Kent">
            <organization/>
          </author>
          <date year="2005" month="December"/>
        </front>
        <seriesInfo name="RFC" value="4303"/>
        <format type="TXT" octets="114315" target="http://www.rfc-editor.org/rfc/rfc4303.txt"/>
      </reference> 
      <reference anchor="RFC6054">
        <front>
          <title>Using Counter Modes with Encapsulating Security Payload (ESP) and Authentication Header (AH) to Protect Group Traffic</title>
          <author initials="D." surname="McGrew" fullname="D. McGrew">
            <organization/>
          </author>
          <author initials="B." surname="Weis" fullname="B. Weis">
            <organization/>
          </author>
          <date year="2010" month="November"/>
        </front>
        <seriesInfo name="RFC" value="6054"/>
        <format type="TXT" octets="22672" target="http://www.rfc-editor.org/rfc/rfc6054.txt"/>
      </reference>
      <reference anchor="chacha_poly">
        <front>
          <title>ChaCha20 and Poly1305 for IETF protocols</title>
          <author initials="A" surname="Langley" fullname="Adam Langley">
            <organization>Google Inc.</organization>
          </author>
          <author initials="Y" surname="Nir" fullname="Yoav Nir">
            <organization>Check Point</organization>
          </author>
          <date month="January" day="31" year="2014"/>
        </front>
        <seriesInfo name="Internet-Draft" value="draft-nir-cfrg-chacha20-poly1305-01"/>
        <format type="HTML" target="http://tools.ietf.org/id/draft-nir-cfrg-chacha20-poly1305-01.html"/>
      </reference>
    </references>
    <references title="Informative References"> 
      <reference anchor="FIPS-197" target="http://csrc.nist.gov/publications/fips/fips197/fips-197.pdf">
        <front>
          <title>Advanced Encryption Standard (AES)</title>
          <author>
            <organization>National Institute of Standards and Technology</organization>
          </author>
          <date month="November" year="2001" />
        </front>
        <seriesInfo name="FIPS" value="PUB 197" />
      </reference>
      <reference anchor="FIPS-46" target="http://www.itl.nist.gov/fipspubs/fip46-2.htm">
        <front>
          <title>Data Encryption Standard</title>
          <author>
            <organization>National Institute of Standards and Technology</organization>
          </author>
          <date month="December" year="1993" />
        </front>
        <seriesInfo name="FIPS" value="PUB 46-2" />
      </reference>
      <reference anchor="standby-cipher">
        <front>
          <title>Selection of Future Cryptographic Standards</title>
          <author initials='D' surname='McGrew' fullname='David McGrew'>
            <organization>Cisco Systems, Inc.</organization>
          </author>  
          <author initials='A' surname='Grieco' fullname='Anthony Grieco'>
            <organization>Cisco Systems, Inc.</organization>
          </author>  
          <author initials='Y' surname='Sheffer' fullname='Yaron Sheffer'>
            <organization>Porticor</organization>
          </author>  
        </front>
        <seriesInfo name="Internet-Draft" value="draft-mcgrew-standby-cipher" />
        <format type="HTML" target="http://tools.ietf.org/html/draft-mcgrew-standby-cipher-00" />
      </reference>
      <reference anchor="RFC4106">
        <front>
          <title>The Use of Galois/Counter Mode (GCM) in IPsec Encapsulating Security Payload (ESP)</title>
          <author initials="J." surname="Viega" fullname="J. Viega">
            <organization/>
          </author>
          <author initials="D." surname="McGrew" fullname="D. McGrew">
            <organization/>
          </author>
          <date year="2005" month="June"/>
        </front>
        <seriesInfo name="RFC" value="4106"/>
        <format type="TXT" octets="23399" target="http://www.rfc-editor.org/rfc/rfc4106.txt"/>
      </reference>
      <reference anchor="AE" target="http://cseweb.ucsd.edu/~mihir/papers/oem.html">
        <front>
          <title>Authenticated Encryption: Relations among notions and analysis of the generic composition paradigm</title>
          <author initials="M." surname="Bellare"/>
          <author initials="C." surname="Namprempre"/>
        </front>
      </reference>
    </references>
    <!-- ====================================================================== -->
  </back>
</rfc>
