<?xml version="1.0" encoding="ISO-8859-1"?>

<!DOCTYPE rfc SYSTEM "rfc2629.dtd" [
<!ENTITY rfc2119 SYSTEM "http://xml.resource.org/public/rfc/bibxml/reference.RFC.2119.xml">
<!ENTITY rfc4250 SYSTEM "http://xml.resource.org/public/rfc/bibxml/reference.RFC.4250.xml">
<!ENTITY rfc4251 SYSTEM "http://xml.resource.org/public/rfc/bibxml/reference.RFC.4251.xml">
<!ENTITY rfc4253 SYSTEM "http://xml.resource.org/public/rfc/bibxml/reference.RFC.4253.xml">
<!ENTITY rfc5656 SYSTEM "http://xml.resource.org/public/rfc/bibxml/reference.RFC.5656.xml">
<!ENTITY rfc6234 SYSTEM "http://xml.resource.org/public/rfc/bibxml/reference.RFC.6234.xml">
<!ENTITY rfc7748 SYSTEM "http://xml.resource.org/public/rfc/bibxml/reference.RFC.7748.xml">
]>

<?rfc compact="yes"?>
<?rfc toc="yes"?>
<?rfc symrefs="yes"?>

<?xml-stylesheet type='text/xsl' href='rfc2629.xslt' ?>
<?rfc strict="yes" ?>
<?rfc tocdepth="4"?>
<?rfc sortrefs="yes" ?>
<?rfc subcompact="no" ?>

<rfc category="std" ipr="trust200902"
     docName="draft-ietf-curdle-ssh-curves-03">

  <front>

    <title abbrev="Curve25519/448 for SSH">
      Secure Shell (SSH) Key Exchange Method using Curve25519 and
      Curve448
    </title>

    <author initials="A." surname="Adamantiadis" fullname="Aris Adamantiadis">
      <organization>libssh</organization>
      <address>
	<email>aris@badcode.be</email>
      </address>
    </author>

    <author initials="S." surname="Josefsson" fullname="Simon Josefsson">
      <organization>SJD AB</organization>
      <address>
	<email>simon@josefsson.org</email>
      </address>
    </author>

    <author initials="M. D." surname="Baushke"
            fullname="Mark D. Baushke">
      <organization>Juniper Networks, Inc.</organization>
      <address>
        <email>mdb@juniper.net</email>
      </address>
    </author>

    <date year="2017"/>

    <workgroup>Internet Engineering Task Force</workgroup>

    <abstract>

      <t>
	This document describes the conventions for using Curve25519
	and Curve448 key exchange methods in the Secure Shell (SSH)
	protocol.
      </t>

    </abstract>

  </front>

  <middle>

    <section title="Introduction">

      <t>
	Secure Shell (SSH) <xref target="RFC4251"/> is a secure remote
	login protocol.  The key exchange protocol described in <xref
	target="RFC4253"/> supports an extensible set of methods.
	<xref target="RFC5656"/> describes how elliptic curves are
	integrated in SSH, and this document reuses those protocol
	messages.
      </t>

      <t>
	This document describes how to implement key exchange based on
	<xref target="Curve25519" /> and <xref
	target="Ed448-Goldilocks" /> in SSH.  For Curve25519 with
	SHA-256 <xref target="RFC6234"/>, the algorithm we describe is
	equivalent to the privately defined algorithm
	"curve25519-sha256@libssh.org", which is currently implemented
	and widely deployed in libssh and OpenSSH.  The Curve448 key
	exchange method is novel but similar in spirit, and we chose
	to couple it with SHA-512 <xref target="RFC6234"/> to further
	separate it from the Curve25519 alternative.
      </t>

      <t>
	This document provide Curve25519 as the prefered choice, but
	suggests that the fall back option Curve448 is implemented to
	provide an hedge against unforseen analytical advances against
	Curve25519 and SHA-256.  Due to different implementation
	status of these two curves (high-quality free implementations
	of Curve25519 has been in deployed use for several years,
	while Curve448 implementations are slowly appearing), it is
	accepted that adoption of Curve448 will be slower.
      </t>

      <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">RFC 2119</xref>.
      </t>

    </section>

    <section title="Key Exchange Methods">

      <t>
	The key exchange procedure is similar to the ECDH method
	described in chapter 4 of <xref target="RFC5656" />, though
	with a different wire encoding used for public values and the
	final shared secret.  Public ephemeral keys are encoded for
	transmission as standard SSH strings.
      </t>

      <t>
	The protocol flow, the SSH_MSG_KEX_ECDH_INIT and
	SSH_MSG_KEX_ECDH_REPLY messages, and the structure of the
	exchange hash are identical to chapter 4 of <xref
	target="RFC5656" />.
      </t>

      <t>
	The method names registered by this document are
	"curve25519-sha256" and "curve448-sha512".
      </t>

      <t>
	The methods are based on Curve25519 and Curve448 scalar
	multiplication, as described in <xref target="RFC7748"/>.
	Private and public keys are generated as described therein.
	Public keys are defined as strings of 32 bytes for Curve25519
	and 56 bytes for Curve448.  Clients and servers MUST fail the
	key exchange if the length of the received public keys are not
	the expected lengths, or if the derived shared secret only
	consists of zero bits.  No further validation is required
	beyond what is discussed in <xref target="RFC7748"/>.  The
	derived shared secret is 32 bytes when Curve25519 is used and
	56 bytes when Curve448 is used.  The encodings of all values
	are defined in <xref target="RFC7748"/>.  The hash used is
	SHA-256 for Curve25519 and SHA-512 for Curve448.
      </t>

      <section title="Shared Secret Encoding">

	<t>
          The following step differs from <xref target="RFC5656"/>,
          which uses a different conversion.  This is not intended to
          modify that text generally, but only to be applicable to the
          scope of the mechanism described in this document.
	</t>

	<t>
	  The shared secret, K, is defined in <xref target="RFC4253"/>
	  as a multiple precision integer (mpint).  Curve25519/448
	  outputs a binary string X, which is the 32 or 56 byte point
	  obtained by scalar multiplication of the other side's public
	  key and the local private key scalar.  The 32 or 56 bytes of
	  X are converted into K by interpreting the bytes as an
	  unsigned fixed-length integer encoded in network byte order.
	  This conversion follows the normal "mpint" process as
	  described in section 5 of <xref target="RFC4251"/>.
	</t>

	<t>
	  To clarify a corner-case in this conversion, when X is
	  encoded as an mpint K, in order to calculate the exchange
	  hash, it may vary as follows:

	  <list style="symbols">

	    <t>
	      If the high bit of X is set, the mpint format requires a
	      zero byte to be prepended.  In this case, the length of
	      the encoded K will be larger.
	    </t>

	    <t>
	      If X has leading zero bytes, the mpint format requires
	      such bytes to be skipped.  In this case, the length of
	      the encoded K will be smaller.
	    </t>

	  </list>
	</t>

      </section>

    </section>

    <section title="Acknowledgements">

      <t>
	The "curve25519-sha256" key exchange method is identical to
	the "curve25519-sha256@libssh.org" key exchange method created
	by Aris Adamantiadis and implemented in libssh and OpenSSH.
      </t>

      <t>
	Thanks to the following people for review and comments: Denis
	Bider, Damien Miller, Niels Möller, Matt Johnston.
      </t>

    </section>

    <section title="Security Considerations">

      <t>
	The security considerations of <xref target="RFC4251"/>, <xref
	target="RFC5656"/>, and <xref target="RFC7748"/> are
	inherited.
      </t>

      <t>
	Curve25519 provide strong security and is efficient on a wide
	range of architectures, and has properties that allows better
	implementation properties compared to traditional elliptic
	curves.  Curve448 with SHA-512 is similar, but have not
	received the same cryptographic review as Curve25519, and is
	slower, but it is provided as an hedge to combat unforseen
	analytical advances against Curve25519 and SHA-256.
      </t>

      <t>
	The way the derived binary secret string is encoded into a
	mpint before it is hashed (i.e., adding or removing zero-bytes
	for encoding) raises the potential for a side-channel attack
	which could determine the length of what is hashed.  This
	would leak the most significant bit of the derived secret,
	and/or allow detection of when the most significant bytes are
	zero.  For backwards compatibility reasons it was decided not
	to adress this potential problem.
      </t>

    </section>

    <section anchor="iana-considerations" title="IANA Considerations">

      <t>
	IANA is requested to add "curve25519-sha256" and
	"curve448-sha512" to the "Key Exchange Method Names" registry
	for SSH <xref target="IANA-KEX"/> that was created in <xref
	target="RFC4250">RFC 4250 section 4.10</xref>.
      </t>

    </section>

  </middle>

  <back>

    <references title="Normative References">

      &rfc2119;
      &rfc4250;
      &rfc4251;
      &rfc4253;
      &rfc5656;
      &rfc6234;
      &rfc7748;

    </references>

    <references title="Informative References">

     <reference anchor="Curve25519"
		target="http://dx.doi.org/10.1007/11745853_14">
       <front>
         <title>
           Curve25519: New Diffie-Hellman Speed Records
         </title>
         <author surname="Bernstein" initials="D. J."
                 fullname="Daniel J. Bernstein">
           <organization></organization>
         </author>
         <date month="February" year="2006"/>
       </front>
       <seriesInfo 
	   name="Lecture Notes in Computer Science (LNCS)"
	   value="vol 3958, pp. 207-228" />
     </reference>

     <reference anchor="Ed448-Goldilocks"
		target="https://eprint.iacr.org/2015/625">
       <front>
         <title>
           Ed448-Goldilocks, a new elliptic curve
         </title>
         <author surname="Hamburg" initials="M." fullname="Mike Hamburg">
           <organization></organization>
         </author>
         <date month="June" year="2015"/>
       </front>
     </reference>

     <reference
         anchor="IANA-KEX"
	 target="http://www.iana.org/assignments/ssh-parameters/ssh-parameters.xhtml#ssh-parameters-16">
       <front>
	 <title>Secure Shell (SSH) Protocol Parameters:
	 Key Exchange Method Names</title>
	 <author>
	   <organization>Internet Assigned Numbers Authority (IANA)
	   </organization>
	 </author>
	 <date month="March" year="2017"/>
       </front>
     </reference>

    </references>

    <section title="Copying conditions">

      <t>
	Regarding this entire document or any portion of it, the
	authors make no guarantees and are not responsible for any
	damage resulting from its use.  The authors grant irrevocable
	permission to anyone to use, modify, and distribute it in any
	way that does not diminish the rights of anyone else to use,
	modify, and distribute it, provided that redistributed
	derivative works do not contain misleading author or version
	information.  Derivative works need not be licensed under
	similar terms.
      </t>

    </section>

   <!-- Change Log

v01 2017-03-17 MDB   Updated draft-josefsson-ssh-curves-04 as
                     draft-ietf-curdle-ssh-curves-01. Fixed
                     initials="" for Curve25519. Expanded LNCS.
		     Trimmed trailing whitespace.

v01 2017-04-11 MDB   Moved to Standards Track, updated Abstract, and
                     updated Introduction per Daniel Migault.
                     Add initils for Mike Hamburg citation.
                     Add an IANA-KEX reference.		     

v01 2017-04-12 MDB   Fix NIT RFC4634 -> RFC6234

   -->
 </back>
</rfc>
