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

<?rfc toc="yes"?>
<?rfc symrefs="yes"?>
<?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-ietf-ipsecme-safecurves-03" category="std">
  <front>
    <title abbrev="Curve25519 and Curve448 for IKEv2">
    Curve25519 and Curve448 for IKEv2 Key Agreement</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.ietf@gmail.com</email>
      </address>
    </author>
    
    <author initials="S." surname="Josefsson" fullname="Simon Josefsson">
      <organization abbrev="SJD">SJD AB</organization>
      <address>
        <email>simon@josefsson.org</email>
      </address>
    </author>
    <date year="2016"/>
    <area>Security Area</area>
    <keyword>Internet-Draft</keyword>
    <abstract>
      <t>This document describes the use of Curve25519 and Curve448
      for ephemeral key exchange in the Internet Key Exchange (IKEv2)
      protocol.</t>
    </abstract>
  </front>
  <middle>
    <!-- ====================================================================== -->
    <section anchor="introduction" title="Introduction">

      <t>The "Elliptic Curves for Security" document <xref target="RFC7748" /> 
      describes two elliptic curves: Curve25519 and Curve448, as well as the X25519 
      and X448 functions for performing key agreement (Diffie-Hellman) operations 
      with these curves.  The curves and functions are designed for both performance 
      and security.</t>
      
      <t>Almost ten years ago the "ECP Groups for IKE and IKEv2" document 
      <xref target="RFC4753" /> specified the first elliptic curve Diffie-Hellman 
      groups for the Internet Key Exchange protocol (IKEv2 - <xref 
      target="RFC7296" />). These were the so-called NIST curves. The state of the 
      art has advanced since then.  More modern curves allow faster implementations 
      while making it much easier to write constant-time implementations free from 
      time-based side-channel attacks. This document defines two such curves for 
      use in IKE.  See <xref target="Curve25519" /> for details about the speed and 
      security of the Curve25519 function.</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="crypto" title="Curve25519 &amp; Curve448">
      <t>All cryptographic computations are done using the X25519 and X448 
      functions defined in <xref target="RFC7748" />.  All related parameters 
      (for example, the base point) and the encoding (in particular, pruning 
      the least/most significant bits and use of little-endian encoding) are 
      inherited from <xref target="RFC7748" />.</t>
      
      <t>An ephemeral Diffie-Hellman key exchange using Curve25519 or Curve448 
      goes as follows: Each party picks a secret key d uniformly at random and 
      computes the corresponding public key. "X" is used below to denote either 
      X25519 or X448, and "G" is used to denote the corresponding base point:</t>
      <t><figure>
         <artwork><![CDATA[
   pub_mine = X(d, G)
   ]]></artwork></figure></t>
      <t>Parties exchange their public keys (see <xref target="ke_format" />) 
      and compute a shared secret:</t>
      <t><figure>
        <artwork><![CDATA[
      SHARED_SECRET = X(d, pub_peer).
      ]]></artwork></figure></t>
    <t> This shared secret is used directly as the value denoted g^ir in 
    section 2.14 of RFC 7296. It is 32 octets when Curve25519 is used, and 56 
    octets when Curve448 is used.</t>
    </section>
    
    <section anchor="in_ikev2" title="Use and Negotiation in IKEv2">
      <t> The use of Curve25519 and Curve448 in IKEv2 is negotiated using a 
        Transform Type 4 (Diffie-Hellman group) in the SA payload of either an 
        IKE_SA_INIT or a CREATE_CHILD_SA exchange.  The value TBA1 is used for
        the group defined by Curve25519 and the value TBA2 is used for the group 
        defined by Curve448.</t>
      <section anchor="ke_format" title="Key Exchange Payload">
        <t> The diagram for the Key Exchange Payload from section 3.4 of RFC 
          7296 is copied below for convenience:</t>
        <t><figure>
             <artwork><![CDATA[
                        1                   2                   3
    0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   | Next Payload  |C|  RESERVED   |         Payload Length        |
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   |   Diffie-Hellman Group Num    |           RESERVED            |
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   |                                                               |
   ~                       Key Exchange Data                       ~
   |                                                               |
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
]]></artwork></figure></t>
        <t><list style="symbols">
          <t> Payload Length - For Curve25519 the public key is 32 octets, so 
          the Payload Length field will be 40, and for Curve448 the public key 
          is 56 octets, so the Payload Length field will be 64.</t>
          <t> The Diffie-Hellman Group Num is TBA1 for Curve25519, or TBA2 for 
          Curve448.</t> <t> The Key Exchange Data is the 32 
          or 56 octets as described in section 6 of <xref target="RFC7748"/>
          </t></list></t>
      </section> 
      <section anchor="rec_test" title="Recipient Tests">
        <t>This document matches the discussion in <xref target="RFC7748"/> 
        related to receiving and accepting incompatible point formats.  In 
        particular, receiving entities MUST mask the most-significant bit in 
        the final byte for X25519 (but not X448), and implementations MUST 
        accept non-canonical values.  See section 5 of <xref target="RFC7748"/> 
        for further discussion.</t>
      </section>
    </section> 
    <section anchor="security" title="Security Considerations">
      <t>Curve25519 and Curve448 are designed to facilitate the production of 
      high-performance constant-time implementations.  Implementors are 
      encouraged to use a constant-time implementation of the functions.  This 
      point is of crucial importance if the implementation chooses to reuse its 
      supposedly ephemeral key pair for many key exchanges, which some 
      implementations do in order to improve performance.</t>

      <t>Curve25519 is intended for the ~128-bit security level, comparable to 
      the 256-bit random ECP group (group 19) defined in RFC 4753, also known 
      as NIST P-256 or secp256r1.  Curve448 is intended for the ~224-bit 
      security level.</t>

      <t>While the NIST curves are advertised as being chosen verifiably at 
      random, there is no explanation for the seeds used to generate them. In 
      contrast, the process used to pick these curves is fully documented and 
      rigid enough so that independent verification has been done. This is 
      widely seen as a security advantage, since it prevents the generating 
      party from maliciously manipulating the parameters.</t>
      
      <t>Another family of curves available in IKE, generated in a fully 
      verifiable way, is the Brainpool curves <xref target="RFC6954" />.  For 
      example, brainpoolP256 (group 28) is expected to provide a level of 
      security comparable to Curve25519 and NIST P-256.  However, due to the 
      use of pseudo-random prime, it is significantly slower than NIST P-256, 
      which is itself slower than Curve25519.</t>

    </section>
    <section anchor="iana" title="IANA Considerations">
      <t> IANA is requested to assign two values from the IKEv2 "Transform Type 
      4 - Diffie-Hellman Group Transform IDs" registry, with names "Curve25519" 
      and "Curve448" and this document as reference. The Recipient Tests field 
      should also point to this document:</t>
      <texttable anchor="tbl1" title="New Transform Type 4 Values">
        <ttcol align="center">Number</ttcol>
        <ttcol align="center">Name</ttcol>
        <ttcol align="center">Recipient Tests</ttcol>
        <ttcol align="center">Reference</ttcol>
        <c>TBA1</c><c>Curve25519</c><c>RFCxxxx <xref target="rec_test"/></c><c>RFCxxxx</c>
        <c>TBA2</c><c>Curve448</c><c>RFCxxxx <xref target="rec_test"/></c><c>RFCxxxx</c>
      </texttable>
    </section>  

    <section anchor="ack" title="Acknowledgements">

      <t>Curve25519 was designed by D. J. Bernstein and the parameters for
      Curve448 ("Goldilocks") is by Mike Hamburg.  The specification of
      algorithms, wire format and other considerations are in RFC 7748 by Adam
      Langley, Mike Hamburg, and Sean Turner.</t>
      
      <t>The example in <xref target="example25519"/> was calculated using the master
        version of OpenSSL, retrieved on August 4th, 2016.</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="RFC7296">
        <front>
          <title>Internet Key Exchange Protocol Version 2 (IKEv2)</title>
          <author initials="T." surname="Kivinen" fullname="Tero Kivinen">
            <organization/>
          </author>
          <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="2014" month="October"/>
        </front>
        <seriesInfo name="RFC" value="7296"/>
        <format type="HTML" target="https://tools.ietf.org/html/rfc5996"/>
      </reference>
      <reference anchor="RFC7748">
        <front>
          <title>Elliptic Curves for Security</title>
            <author initials="A" surname="Langley" fullname="Adam Langley"></author>
            <author initials="M" surname="Hamburg" fullname="Mike Hamburg"></author>
            <author initials="S" surname="Turner" fullname="Sean Turner"></author>
            <date month="January" year="2016"/>
          </front>
        <seriesInfo name='RFC' value='7748' />
        <format type='HTML' target='https://tools.ietf.org/html/rfc7748' />
      </reference>
    </references>
    <references title="Informative References"> 
      <reference anchor="RFC4753">
        <front>
          <title>ECP Groups For IKE and IKEv2</title>
          <author initials="D." surname="Fu" fullname="D. Fu">
          </author>
          <author initials="J." surname="Solinas" fullname="J. Solinas">
          </author>
          <date year="2007" month="January"/>
        </front>
        <seriesInfo name="RFC" value="4753"/>
        <format type="TXT" octets="28760" target="http://www.rfc-editor.org/rfc/rfc4753.txt"/>
      </reference>
      <reference anchor="Curve25519" target="http://dx.doi.org/10.1007/11745853_14">
        <front>
          <title>Curve25519: New Diffie-Hellman Speed Records</title>
          <author initials="J." surname="Bernstein"/>
          <date year="2006" month="February" />
        </front>
        <seriesInfo name="LNCS" value="3958"/>
      </reference>
      <reference anchor="RFC6954">
        <front>
          <title>
          Using the Elliptic Curve Cryptography (ECC) Brainpool Curves for the Internet Key Exchange Protocol Version 2 (IKEv2)
          </title>
          <author initials="J." surname="Merkle" fullname="J. Merkle" />
          <author initials="M." surname="Lochter" fullname="M. Lochter" />
          <date year="2013" month="July"/>
        </front>
        <seriesInfo name="RFC" value="6954"/>
        <format type="TXT" octets="20366" target="http://www.rfc-editor.org/rfc/rfc6954.txt"/>
      </reference>
    </references>
    
    <section anchor="example25519" title="Numerical Example for Curve25519">
      <t> Suppose we have both the initiator and the responder generating private keys
        by generating 32 random octets. As usual in IKEv2 and its extension, we will 
        denote Initiator values with the suffix _i and responder values with the 
        suffix _r:</t>
      <t><figure>
             <artwork><![CDATA[
  random_i = 75 1f b4 30 86 55 b4 76 b6 78 9b 73 25 f9 ea 8c 
             dd d1 6a 58 53 3f f6 d9 e6 00 09 46 4a 5f 9d 94 
        
  random_r = 0a 54 64 52 53 29 0d 60 dd ad d0 e0 30 ba cd 9e 
             55 01 ef dc 22 07 55 a1 e9 78 f1 b8 39 a0 56 88
]]></artwork></figure></t>
      <t> These numbers need to be fixed by unsetting some bits as described in 
        section 5 of RFC 7748. This affects only the first and last octets of each
        value:</t>
      <t><figure>
             <artwork><![CDATA[
  fixed_i =  70 1f b4 30 86 55 b4 76 b6 78 9b 73 25 f9 ea 8c 
             dd d1 6a 58 53 3f f6 d9 e6 00 09 46 4a 5f 9d 54 
        
  fixed_r =  08 54 64 52 53 29 0d 60 dd ad d0 e0 30 ba cd 9e 
             55 01 ef dc 22 07 55 a1 e9 78 f1 b8 39 a0 56 48
]]></artwork></figure></t>
      <t> The actual private keys are considered to be encoded in little-endian
        format:</t>
      <t><figure>
             <artwork><![CDATA[
d_i = 549D5F4A460900E6D9F63F53586AD1DD8CEAF925739B78B676B4558630B41F70
        
d_r = 4856A039B8F178E9A1550722DCEF01559ECDBA30E0D0ADDD600D295352645408
]]></artwork></figure></t>
      <t> The public keys are generated from this using the formula in <xref
        target="crypto"/>:</t>
      <t><figure>
             <artwork><![CDATA[
pub_i = X25519(d_i, G) = 
             48 d5 dd d4 06 12 57 ba 16 6f a3 f9 bb db 74 f1 
             a4 e8 1c 08 93 84 fa 77 f7 90 70 9f 0d fb c7 66
        
pub_r = X25519(d_r, G) = 
             0b e7 c1 f5 aa d8 7d 7e 44 86 62 67 32 98 a4 43 
             47 8b 85 97 45 17 9e af 56 4c 79 c0 ef 6e ee 25
]]></artwork></figure></t>
      <t> And this is the value of the Key Exchange Data field in the key exchange
        payload described in <xref target="ke_format"/>. The shared value is 
        calculated as in <xref target="crypto"/>:</t>
      <t><figure>
             <artwork><![CDATA[
SHARED_SECRET = X25519(d_i, pub_r) = X25519(d_r, pub_i) =
             c7 49 50 60 7a 12 32 7f-32 04 d9 4b 68 25 bf b0
             68 b7 f8 31 9a 9e 37 08-ed 3d 43 ce 81 30 c9 50 
]]></artwork></figure></t>
    </section>
  </back>
</rfc>
