<?xml version="1.0" encoding="US-ASCII"?>
<!-- This template is for creating an Internet Draft using xml2rfc,
     which is available here: http://xml.resource.org. -->
<!DOCTYPE rfc SYSTEM "rfc2629.dtd" [
<!-- One method to get references from the online citation libraries.
     There has to be one entity for each item to be referenced. 
     An alternate method (rfc include) is described in the references. -->

<!ENTITY RFC2119 SYSTEM "http://xml.resource.org/public/rfc/bibxml/reference.RFC.2119.xml">
<!ENTITY RFC5639 SYSTEM "http://xml.resource.org/public/rfc/bibxml/reference.RFC.5639.xml">
<!ENTITY RFC6090 SYSTEM "http://xml.resource.org/public/rfc/bibxml/reference.RFC.6090.xml">
]>
<?xml-stylesheet type='text/xsl' href='rfc2629.xslt' ?>
<!-- used by XSLT processors -->
<!-- For a complete list and description of processing instructions (PIs), 
     please see http://xml.resource.org/authoring/README.html. -->
<!-- Below are generally applicable Processing Instructions (PIs) that most I-Ds might want to use.
     (Here they are set differently than their defaults in xml2rfc v1.32) -->
<?rfc strict="yes" ?>
<!-- give errors regarding ID-nits and DTD validation -->

<!-- control the table of contents (ToC) -->
<?rfc toc="yes"?>
<!-- generate a ToC - - >
<?rfc tocdepth="4"?>
< ! - - the number of levels of subsections in ToC. default: 3 -->

<!-- control references -->
<?rfc symrefs="yes"?>
<!-- use symbolic references tags, i.e, [RFC2119] instead of [1] -->
<?rfc sortrefs="yes" ?>
<!-- sort the reference entries alphabetically -->
<!-- control vertical white space 
     (using these PIs as follows is recommended by the RFC Editor) -->
<?rfc compact="yes" ?>
<!-- do not start each main section on a new page -->
<?rfc subcompact="no" ?>
<!-- keep one blank line between list items -->
<!-- end of list of popular I-D processing instructions -->
<rfc category="info" docName="draft-jivsov-ecc-compact-05" ipr="trust200902">
  <!-- category values: std, bcp, info, exp, and historic
     ipr values: trust200902, noModificationTrust200902, noDerivativesTrust200902,
        or pre5378Trust200902
     you can add the attributes updates="NNNN" and obsoletes="NNNN" 
     they will automatically be output with "(if approved)" -->

  <!-- ***** FRONT MATTER ***** -->

  <front>
    <!-- The abbreviated title is used in the page header - it is only necessary if the 
         full title is longer than 39 characters -->

    <title abbrev="Compact representation of an EC point">Compact representation of an elliptic curve point</title>

    <!-- add 'role="editor"' below for the editors if appropriate -->

    <!-- Another author who claims to be an editor -->

    <author fullname="Andrey Jivsov" initials="A.J." surname="Jivsov">
      <organization>Symantec Corporation</organization>

      <address>
<!--
        <postal>
          <street></street>
          <city>Soham</city>
          <region></region>
          <code></code>
          <country>UK</country>
        </postal>
        <phone>+44 7889 488 335</phone>
-->
<!--        <email>Andrey_Jivsov@symantec.com</email> -->
        <email>crypto@brainhub.org</email>

        <!-- uri and facsimile elements may also be added -->
      </address>
    </author>

    <date year="2014" />

    <!-- If the month and year are both specified and are the current ones, xml2rfc will fill 
         in the current day for you. If only the current year is specified, xml2rfc will fill 
	 in the current day and month for you. If the year is not the current one, it is 
	 necessary to specify at least a month (xml2rfc assumes day="1" if not specified for the 
	 purpose of calculating the expiry date).  With drafts it is normally sufficient to 
	 specify just the year. -->

    <!-- Meta-data Declarations -->

    <area>General</area>

    <workgroup>Network Workign Group</workgroup>
    
	<keyword>ECC</keyword>
	<keyword>elliptic curve</keyword>
	<keyword>elliptic curve point</keyword>
	<keyword>compact representation</keyword>
	<keyword>point compression</keyword>
	<keyword>SEC1</keyword>
	<keyword>cryptography</keyword>
    <!-- Keywords will be incorporated into HTML output
         files in a meta tag but they have no effect on text or nroff
         output. If you submit your draft to the RFC Editor, the
         keywords will be used for the search engine. -->

    <abstract>
      <t>This document defines a format for efficient storage representation of an elliptic curve point over prime fields, suitable for use with any IETF format or protocol.</t>
    </abstract>
  </front>

  <middle>
	<section title="Introduction">
	<t>
		The National Security Agency (NSA) of the United States specifies elliptic curve cryptography (ECC) for use in its <xref target="SuiteB"/> set of algorithms.  
		The NIST elliptic curves over the prime fields <xref target="FIPS-186" />, which include <xref target="SuiteB"/> curves, or the Brainpool 
		curves <xref target="RFC5639" /> are the examples of curves over prime fields.
	</t>
	<t>
		This document provides an efficient format for compact representation of a point on an elliptic curve over a prime field.  
		It is intended as an open format that other IETF protocols can rely on to minimize space required to store an ECC point.  
		This document complements the <xref target="RFC6090"/> with the on-the-wire definition of an ECC point. The method described here
		can be applied to a various types of elliptic curves, see <xref target="otherCurves"/>.
	</t>
	<t>
		One of the benefits of the ECC is the small size of field elements. The compact representation reduces the encoded size of an ECC element in half, 
		which can be a substantial saving in cases such as encryption of a short message sent to multiple recipients.
	</t>


<!--
, thus it reduces the EC field from the set of points that can be represented as a tuple ( x, {0,1} ) to the set that is represented as x.
		This can be equated with the task of the format preserving encryption (FPE) <xref target="Ciphers"/>. In particular, the "Method 2: Cycle-Walking Cipher" can be adopted where the encryption is the multiplication by k of the generator G. The algorithm terminates when k^i, i is an integer greater than 0, is such that the k^i * G is a compliant point. In section "6. Discussion" the authors discuss the application of their FPE methods exactly to the problem that this document solves. -->



	</section>

	<section 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 title="Overview of the compact representation in IETF protocols" anchor="overview">
        <t>
		IETF protocols often use the <xref target="SEC1"/> representation of a point on an elliptic curve, which is a sequence of the following fields:
	</t>

	<texttable style="headers" title="SEC1 point representation">

          <ttcol width="10%" align="left">Field</ttcol>
          <ttcol width="90%" align="left">Description</ttcol>

          <c>B0</c>
          <c>{02, 03, 04}, 
		where 02 or 03 represent a compressed point (x only), while 04 represents a complete point (x,y)
	  </c>

          <c>X</c>
          <c>x coordinate of a point</c>

          <c>Y</c>
          <c>y coordinate of a point, optional (present only for B0=04)</c>
        </texttable>

	<t>
		The <xref target="SEC1"/> is an example of a general-purpose elliptic curve point compression. The idea behind these methods is the following: 
		<list style="symbols">
			<t>For the given point P=(x,y) the y coordinate can be derived from x by solving the corresponding elliptic curve equation. </t>
			<t>There are two possible y coordinates for any x of a given P</t>
			<t>The either of the two possibilities for y is encoded in some way in the compressed representation</t> 
		</list> 
	</t>
	
	<t>
		There are a few undesirable properties of the above representation:
		<list style="symbols">
			<t>The requirement to store one bit to identify the 'y' means that the whole byte is required.</t>
			<t>For most well-known elliptic curves the extra byte removes the power of two alignment for the encoded point.</t>
			<t>The requirement for the balanced security calls for 
			the ECC curve size to be equal the hash output size, yet the storage length of the ECC point is equal to the hash output size + 1.
			</t>
			<t>The encoded point is not a multi-precision integer, but a structured sequence of bytes. For example, special wording is 
			required to define the encoding of the <xref target="FIPS-186" /> P-521 to clarify how odd number of bits for x and y, or a bit representing y, 
			are packed into bytes.
			</t>
			<t>Some protocols, such as ECDH, don't depend on the exact value of the y. It is unnecessary
			to track the precise point P=(x,y) in such protocols. 
			</t> 
		</list> 
	</t>
	</section>

	<section title="The definition of the compact representation" anchor="def">
	<t>
		This document is an improvement to the idea by <xref target="Miller"/> to not transmit the y coordinate of an ECC point in the 
		elliptic curve Diffie-Hellman (ECDH) protocol. 
	</t>
        <t>
		We will use the following notations for the ECC point Q and the features of the corresponding elliptic curve:
		<list style="empty">
			<t>Q = k*G, where</t>
			<t>Q = (x,y) is the point on an elliptic curve (the canonical represenation) </t>
			<t>k - the private key (a scalar)</t>
			<t>G - the elliptic curve generator point</t>
			<t>y^2 = C(x) is the appropriate Weierstrass equation linking x and y; for example, C(x) = x^3 + a*x + b is used for the short Weierstrass form</t>
			<t>p - the order of the underlying finite field to which x and y belong</t>
			<t>Ord - the order of the elliptic curve field, i.e. the number of points on the curve ( Ord*G = O, where O is the identity element )</t>
		</list> 
		This document specify how Q is represented in the compact form. 
		The integer operations considered in this document are performed modulo prime p and "(mod p)" is assumed in every formula with x and y.  
	</t>
	<t>
		Every elliptic curve for prime p (more generally, for any underlying field that doesn't have characteristic 2) can be represented as y^2 = C(x) with appropriate substitution, 
		where C(x) is degree-3 polynomial in x. 
	</t>
	<t>
		The steps to create and interpret the compact representation of a point are described next. A special key generation algorithm
		is needed to make them possible, defined later in <xref target="x"/>.
	</t>

	<section title="Encoding and decoding of an elliptic curve point" anchor="encdec">

	<t>
		<list counter="reqs" hangIndent="5" style="hanging">
			<t hangText="Encoding:">
				Given the canonical representation of Q=(x,y), return the x as its compact representation.
			</t>

			<t hangText="Decoding:">
				Given the compact representation of Q, return canonical representation of Q=(x,y) as follows:
				<list style="numbers">
					<t>y' = sqrt( C(x) ), where y'>0</t>
					<t>y = min(y',p-y')</t>
					<t>Q=(x,y) is the canonical representation of the point</t>
				</list> 
			</t>
		</list> 
	</t>

		<t>
		Recall that the x is an element in the underlying finite field, represented by an integer. 
		Its precise encoding SHOULD be consistent with encoding of other multi-precision integers in the application, for example, it would 
		be the same encoding as used for the r or s integer that is a part of the DSA signature and it is typically a sequence of big-endian bytes. 
		</t>

	<t>
		The efficient algorithm to recover y for <xref target="SuiteB"/> or the Brainpool curves <xref target="RFC5639" />, 
		among others, is given in <xref target="sqrt"/>.
	</t>
	<t>	
		min(y,p-y) can be calculated with the help of the pre-calculated value p2=(p-1)/2. min(y,p-y) is y if y&lt;=p2 and p-y otherwise.
	</t>
	<t>
		The efficient encoding and decoding algorithms are possible with the special key generation algorithm, defined next. 
	</t>



	</section>

		<section title="The algorithms to generate a key pair" anchor="x">

		<t>
			This document specifies two algorithms, called the "black box" and the "deterministic" key generation algorithms, 
			to generate a key pair {k, Q=k*G=(x,y)}, where k is the private key and Q=(x,y) is the public key.
			A key pair generated according to the requirements in this section is called a compliant key pair, and the public key of such a key pair --
			a compliant public key. A compliant public key Q=(x,y) allows compact representation as x, as defined in <xref target="encdec"/>.
		</t>

		<t>
			Both key generation algorithms can be built with any general purpose key generation algorithm which would be needed in any ECC implementation that generates
			keys, regardless of the support for any method defined in this document.
			Such a general purpose key generation algorithm is referred in this section as "KG". 
		</t>
		<t>
			The black box algorithm works in scenarios when the KG doesn't allow any adjustments to the private key. 
			The disadvantage of this algorithm is that multiple KGs may be needed to generate a single key pair {k, Q}. 
			The deterministic algorithm is similar, except that it is allowed to perform a simple and fast modification to the 
			private key after the KG. The advantage of the second algorithm is performance, in particular, the guarantee that only a single KG is needed.
		</t>
		<section title="The black box key generation algorithm" anchor="x1">
		<t>
			The following algorithm calculates a key pair {k, Q=k*G=(x,y)}, where k is the private key and Q=(x,y) is the public key. 
		<list counter="reqs" hangIndent="5" style="hanging">
			<t hangText="Black box generation:">
			<!--Generate new key pair.-->
			<list style="numbers">
			<t>Generate a key pair {k, Q=k*G=(x,y)} with KG</t>
			<t>if( y != min(y,p-y) ) goto step 1</t>
			<t>output {k, Q=(x,y)} as a key pair</t>
			</list> 
			</t>

		</list> 
		</t>
		
		<t>
			Note that the step 1 is a general purpose key generation algorithm, such as an algorithm compliant with <xref target="NIST-SP800-133"/>. 
			Step 1 assumes neither changes to existing key generation methods nor access to the private key in clear. 
		</t>

		<t>The expected number of iterations in the loop in the above algorithm is 2. The step 2 is not needed for the ECDH keys.		
		</t>

		</section>
		<section title="The deterministic key generation algorithm" anchor="x2">
		<t>
			The following algorithm calculates a key pair {k, Q=k*G=(x,y)}, where k is the private key and Q=(x,y) is the public key. 
		<list counter="reqs" hangIndent="5" style="hanging">
			<t hangText="Deterministic generation:">
			<!--Generate new key pair.-->
			<list style="numbers">
			<t>Generate a key pair {k, Q=k*G=(x,y)} with KG</t>
			<t>if( y != min(y,p-y) ) k = Ord - k; y = p - y</t>
			<t>output {k, Q=(x,y)} as a key pair</t>
			</list> 
			</t>

		</list> 
		</t>
		<t>
		The step 2 is not needed for the ECDH keys.		
		</t>

		</section>
		<section title="The key generation algorithm for the sum of points" anchor="x3">
		<t>
			In some protocols a participant must produce a point Q, such that Q = S + P. Q is to be shared with other participants. In this equation S is some known point and P 
			is a point for the key pair {k, P=k*G=(x1,y1)} that the participant generates internally, but never makes available to other participants of the protocol.
			The Q must be compliant, while there is no such requirement for P. 

			The following algorithm is a generalization of the previous two algorithms to produce a compliant Q.

		</t>
		<t>
			It's easy to observe that the black box algorithm in section <xref target="x1"/> is easily adopted to this case. All that's needed is to continue to generate a new P so that the Q (not P) is compliant.
		</t>
		<t>
			A more efficient version of this algorithm that only requires one KG is described next. This algorithm expects that the participant generates a 
			delta key pair {d, D=d*G} and caches it for a certain period of time to ammortize the cost of generation of {d, D}. For example, {d, D} might be 
			generated once during the process start-up and is kept in memory until the process is terminated. 
			This allows the same {d, D} to be used with many protocol runs. In this case the formula is Q = S + (P + t*D), which means that the P is adjusted with t 
			additions of D until the point Q is a compliant point. The expected value of t is 1.
		</t>

		<t>
		<list counter="reqs" hangIndent="5" style="hanging">
			<t hangText="Before the first protocol run:">
			<list style="numbers">
			<t>Obtain the point S</t>
			<t>Generate a delta key pair {d, D=d*G} with KG; save it so it can be used in subsequent protocol runs</t>
			</list> 
			</t>

			<t hangText="Generation:">
			<!--Generate new key pair.-->
			<list style="numbers">
			<t>Generate an internal key pair {k, P=k*G=(x1,y1)} with KG</t>
			<t>Calculate Q=(x,y)=P+S</t>
			<t>Until ( y == min(y,p-y) ) do {Q += D; k += d;}</t>
			<t>Output {k, P}, Q=(x,y), where Q is a compliant point and {k, P} is a corresponding to Q internal key pair</t>
			</list> 
			</t>
		</list> 
		</t>

		</section>

		<section title="The key generation algorithm for the multiples" anchor="x4">
		<t>
			In some protocols a participant must produce a point Q, such that Q = k1*k2*...*kn*P. Q is to be shared with other participants. In this equation P 
			is a point for the key pair {k, P=k*G} that the participant generates internally, but never makes available to other participants of the protocol.
			The Q must be compliant, while there is no such requirement for P.
		</t>
		<t>
			It's easy to observe that the black box algorithm in section <xref target="x1"/> is easily adopted to this case. 
			All that's needed is to continue to generate a new P so that the Q (not P) is compliant.
		</t>
		<t>
			However, there is a deterministic algorithm with a single KG, based on the algorithm in section <xref target="x2"/>. 
			Q can be rewritten as Q = k1*k2*...*kn*k*G = k*(k1*k2*...*kn)G = k * S.
			The algorithm in section <xref target="x2"/> is used as is, except the G is replaced with S, so that Q=k*G is interpreted as Q=k*S. 
		</t>
		</section>


		</section>

		<section title="The efficient square root algorithm for p=4*k+3" anchor="sqrt">
		<t>
			When p mod 4 = 3, as is the case of <xref target="SuiteB"/> and the Brainpool curves <xref target="RFC5639" />, 
			there is an efficient square root algorithm to recover the y, as follows:
			<list style="empty">
				<t>Given the compact representation of Q as x,</t>
				<t>y2 = C(x)</t>
				<t>y' = y2^((p+1)/4)</t>
				<t>y = min(y',p-y')</t>
				<t>Q=(x,y) is the canonical representation of the point</t>
			</list> 
			See <xref target="Lehmer"/> for details.
		</t>
		</section>

		<section title="General applicability" anchor="otherCurves">
		<t>
			The method described in this document should work for any elliptic curve over the prime fields provided that the canonical repsentation of the point is in affine coordinates. For the given x there are two solutions to the equation y^2 = C(x); the method described here selects the smallest y; this corresponds to the private keys k or Ord-k. 
		</t>
		<t>
			The extension of the method described above is straightforward. Note that the fundamental technique described above relies on the relationship between {k,Ord-k} and {Q, -Q}. -Q refers to the explicit affine negation formula. The transition between Q, -Q and k, Ord-k is exceptionally fast. In general, the appropriate affine point negation formula changes the coordinate that we will omit in the compact representation (this is typically the y coordinate). The code that recovers the omitted coordinate assumes that it is the smallest possible coordinate y, such that y^2 = C(x). This assumption is assured by the selection of the corresponding {k, Ord-k}. This will be clear from the following examples.
		</t>
		<t>
			Many definitions of elliptic curve are known and the list may keep keep growing. <xref target="EFD"/> specifies the affine point negation formula for various curves. Here are a few possibilities for -Q, where Q = (x,y): 
		</t>

		<texttable style="headers" title="Affine negation methods">

		  <ttcol width="10%" align="left">Formula</ttcol>
		  <ttcol width="70%" align="left">Method</ttcol>
		  <ttcol width="20%" align="left">Synopsis</ttcol>

		  <c>(x,-y)</c>
		  <c>Use step-by-step instructions in this specification
		  </c>
		  <c>y=min(y,p-y)
		  </c>

		  <c>(-x,y)</c>
		  <c>Edwards curves. Given that the curve definition is symmetric for x and y, rename x and y in the description of the above methods 
		  </c>
		  <c>x=min(x,p-x); y is compact representation</c>

		  <c>(y,x)</c>
		  <c>This specification, except change the formula for negation to "exchange x with y"</c>
		  <c>y = min(x,y)</c>

		  <c>(x/y,1/y)</c>
		  <c>This specification, except change the formula for negation to use division by y</c>
		  <c>y = min(y,1/y), x=x/y</c>

		</texttable>

		<t>
					</t>

		</section>

	</section>

	<section title="Interoperability considerations" anchor="interop">
	<t>
		The compact representation described in this document allows two-phase introduction.
	</t>
	<t>
		First, key pairs must be generated as defined in <xref target="x"/> to allow compact representation. No accompanied changes are 
		needed elsewhere to use these keys. 
		This allows safe deployment of the new key generation, which, in turn, allows encoding and decoding of compact representation, 
		possibly at a later time. 
	</t>
	<t>
		Finally, the encoding of public keys in the new compact representation format can be enabled after there is confidence in the universal 
		support of new compact representation. 
		This event would not need to change any private key material, only public key representation. 
	</t>
	<t>	
		The above two phases can be implemented at once for new formats. 
	</t>
	<t>
		Most ECC cryptographic protocols, such as ECDSA <xref target="FIPS-186"/>, are intended to work with persistently stored public keys that are 
		generated as fresh key pairs, as opposed to some derivation function that transforms an ECC point. The algorithm described in 
		<xref target="x"/> is possible in all these cases. Furthermore, a typical instantiation of the ECDH protocol, such as ECDH specified in <xref target="NIST-SP800-56A"/>, 
		makes any ECC key used in a DH key key agreement automatically compliant for the purpose of this specification ( as noted in the <xref target="x"/> ). 
		The algorithm in <xref target="x"/> will even work for secure devices that never reveal the private key, such as smartcards or
		Hardware Security Modules. A public key that is generated according to the <xref target="x"/> can be used without limitations in existing protocols that 
		use ECC points encoded in other ways, such as <xref target="SEC1"/>, with compression or not, with the added advantage that the keys
		generated according to the method in <xref target="x"/> will allow the <xref target="encdec"/> encoding.
	</t>
	</section>

	<section anchor="Acknowledgements" title="Acknowledgements">
	<t>
		The methods described in this document eliminates one bit that is tranditionally needed to identify either of the two y coordinates. <xref target="FPE"/> is the earliest reference about such an approach to compact representation in the prime underlying finite field that the author is aware of, viewed in that work in the context of the format preserving encryption.
	</t>

	</section>

	<section anchor="IANA" title="IANA Considerations">
	<t>This document defines a low-level format that may be suitable for a wide range of applications. However, it is responsibility of the application that adopts this format
	to define the IDs that will enable the ECC compact point representation in that application.
	</t>
	<t>A new ID may not be always necessary. For example, an application that currently allows the <xref target="SEC1"/> encoding may allow the compact representation defined 
	in this document as an extension to the <xref target="SEC1"/> as follows. Consider the encoding of a compressed <xref target="FIPS-186"/> P-256 point, for example. The 
	<xref target="SEC1"/> compressed representation of a P-256 point will always occupy exactly 33 bytes. On the other hand, the compact representation defined in this document 
	will never exceed 32 bytes (it may occupy fewer that 32 bytes when the most significant byte has happened to be zero). This size will allow reliable discrimination 
	between two encoding formats. 
	</t>
	</section>

	<section anchor="Security" title="Security Considerations">
	<t>
		The key pair generation process in <xref target="x"/> excludes exactly half of the points on the elliptic curve. 
		What is left is the subset of points suitable for compact representation. 
		The filtering of points is based on a public criteria that are applied to the public output of the ECC one-way function. 
	</t>
	<t>	
		The set of Ord points on the elliptic curve can be subdivided as follows. First, remove the point O, which leaves Ord-1 points. 
		Of these points there are exactly (Ord-1)/2 points that have unique x coordinate. This document specifies
		a method to form the (Ord-1)/2 of points, each having a unique x coordinate. These points are called compliant public 
		keys in <xref target="x"/>.
	</t>
	<t>
		For any two public keys P=(x,y) and P=(x,y') there is up to one bit of entropy in y' v.s. y and this information is public. This bit of entropy doesn't 
		contribute to the difficulty of the underlying hard problem of the ECC: the elliptic curve discrete logarithm problem (ECDLP). 
	</t>
	<t>	
 		It will be shown next that breaking the ECDLP with a key generated according to <xref target="x"/> is not easier than 
		breaking the ECDLP with a key obtained through a standard key generation algorithm, referred to as the KG algorithm in the <xref target="x"/>.
	</t>
	<t>
		Let us assume that there is an algorithm A that solves the ECDLP for the KG. The algorithm A can be transformed into the algorithm A' as follows. 
		<list style="symbols">
			<t>If P=(x,y) is a compliant public key, the ECDLP is solved with A for the point (x,y): the result is k, such that k*G=(x,y)</t>
			<t>If P=(x,y) is not a compliant public key, the ECDLP is solved with A for the point (x,p-y); assuming the output produced by A is k, 
			the output produced by A' is set to (Ord-k). Note that (Ord-k)*G = (x,y), which means that the output of A' is the correct solution. </t>
		</list> 
		A' is equivalent to A. The complexity of one additional substraction in the prime field is negligible even to the 
		complexity of a single elliptic curve addition. Observe that A' works for all public keys by performing the actual work only on compliant public keys. 
	</t>
	<t>
		If we now consider only the compliant public keys, which cuts the number of points in half, we observe that the ECDLP solving algorithm A' doesn't get to break 
		fewer public keys. This concludes the proof.
	</t>

	<t>
		The same result can be observed based on the details of the current state of the art attacks on the ECDLP. These attacks use Pollard's rho algorithm, which uses
		the collision search in the sequence(s) of generated points with the goal to produce the points P1=(x1,y1) and P2=(x2,y2), such that x1=x2 and y1=y2. 
		The match in the x coordinate is the sufficient event for the successful attack. 
		After this event has occurred, the sequence(s) that led to x1=x2 collision can be adjusted in a constant number of steps to ensure that y1=y2, 
		if this is not already the case. Furthermore, collision search requires the storage of candidates for the collision. It's wasteful to store (x,y) v.s. storing x and only 
		calculating y when the collision in x is detected.  Thus, the ECDLP attack does not benefit from the unpredictability of the y.
	</t>
	<t>
		Finally, note that a common design feature of an ECDH-based system is not to depend on the y coordinate, such as the one defined in the <xref target="NIST-SP800-56A"/>. 
		Thus, the security of the system is unaffected if we fix either of the two possibilities for the point with the given x coordinate.		
	</t>
	</section>
  </middle>

  <!--  *****BACK MATTER ***** -->

  <back>
    <!-- References split into informative and normative -->

    <!-- There are 2 ways to insert reference entries from the citation libraries:
     1. define an ENTITY at the top, and use "ampersand character"RFC2629; here (as shown)
     2. simply use a PI "less than character"?rfc include="reference.RFC.2119.xml"?> here
        (for I-Ds: include="reference.I-D.narten-iana-considerations-rfc2434bis.xml")

     Both are cited textually in the same manner: by using xref elements.
     If you use the PI option, xml2rfc will, by default, try to find included files in the same
     directory as the including file. You can also define the XML_LIBRARY environment variable
     with a value containing a set of directories to search.  These can be either in the local
     filing system or remote ones accessed by http (http://domain/dir/... ).-->

    <references title="Normative References">
      <!--?rfc include="http://xml.resource.org/public/rfc/bibxml/reference.RFC.2119.xml"?-->
      &RFC2119;

    </references>

    <references title="Informative References">
      <!-- Here we use entities that we defined at the beginning. -->

	&RFC5639;
	&RFC6090;

      <reference anchor="Miller">
        <front>
          <title>Use of elliptic curves in cryptography</title>
          <author initials="V.S." surname="Miller" fullname="Victor S. Miller">
	  	<organization>Springer-Verlag New York, Inc.</organization>
          </author>
          <date month="June" year="1986"/>
        </front>
	<seriesInfo name="Proceedings" value="Lecture notes in computer sciences; 218 on Advances in cryptology -- CRYPTO 85"/>
      </reference>

      <reference anchor="Lehmer">
        <front>
          <title>Computer technology applied to the theory of numbers</title>
          <author initials="D.H." surname="Lehmer">
	  	<organization>The Mathematical Association of America (Incorporated)</organization>
          </author>
          <date year="1969"/>
        </front>
      </reference>


      <reference anchor="SuiteB" target="http://www.nsa.gov/ia/programs/suiteb_cryptography/">
        <front>
          <title>NSA Suite B Cryptography</title>
          <author>
	  	<organization>National Security Agency</organization>
          </author>
          <date year="2010" month="March" day="11"/>
        </front>
      </reference>

      <reference anchor="FIPS-186" target="http://csrc.nist.gov/publications/PubsSPs.html">
        <front>
          <title>Digital Signature Standard (DSS)</title>
          <author>
	  	<organization>National Institute of Standards and Technology</organization>
          </author>
          <date year="2009" month="June"/>
        </front>
	<seriesInfo name="FIPS" value="186-3"/>
      </reference>

      <!-- A reference written by by an organization not a person. -->
      <reference anchor="SEC1" target="www.secg.org/collateral/sec1_final.pdf">
        <front>
          <title>SEC 1: Elliptic Curve Cryptography</title>
          <author>
	  	<organization>STANDARDS FOR EFFICIENT CRYPTOGRAPHY</organization>
          </author>
          <date year="2000" month="September" day="20"/>
        </front>
      </reference>

      <reference anchor="NIST-SP800-56A" target="http://csrc.nist.gov/publications/PubsSPs.html">
        <front>
          <title>Recommendation for Pair-Wise Key Establishment Schemes Using Discrete Logarithm Cryptography</title>
          <author>
	  	<organization>National Institute of Standards and Technology</organization>
          </author>
          <date year="2007" month="March" />
        </front>
	<seriesInfo name="SP" value="800-56A Revision 1"/>
      </reference>

      <reference anchor="NIST-SP800-133" target="http://csrc.nist.gov/publications/PubsSPs.html">
        <front> 
          <title>Recommendation for Cryptographic Key Generation</title>
          <author>
	  	<organization>National Institute of Standards and Technology</organization>
          </author>
          <date year="2012" month="November" />
        </front>
	<seriesInfo name="SP" value="800-133"/>
      </reference>

      <reference anchor="OpenSSL" target="http://rt.openssl.org/Ticket/History.html?id=3069">
        <front> 
          <title>An enhancement to EC key generation to enable compact point representation</title>
	  <author initials="A." surname="Jivsov" fullname="Andrey Jivsov">
		<organization>OpenSSL bug reporting system</organization>
          </author>
          <date year="2013" month="June" />
        </front>
      </reference>

      <reference anchor="FPE" target="http://www.cs.ucdavis.edu/~rogaway/papers/subset.pdf">
        <front>
          <title>Ciphers with arbitrary finite domains.</title>
		<author initials="P." surname="Rogaway" fullname="Phillip Rogaway" />
		<author initials="J." surname="Black" fullname="John Black" />
          <date year="2002" />
        </front>
	<seriesInfo name="Proceedings" value="Topics in Cryptology CT-RSA. Springer Berlin Heidelberg"/>
      </reference>

      <reference anchor="EFD" target="http://www.hyperelliptic.org/EFD/index.html">
        <front>
          <title>Genus-1 curves over large-characteristic fields</title>
		<author initials="D.J." surname="Bernstein" fullname="Daniel J. Bernstein" /> 
		<author initials="T." surname="Lange" fullname="Tanja Lange" />
          <date year="2014" />
        </front>
      </reference>

    </references>

<!--
	<section anchor="FPE" title="Prior work">

	<t>
		This method eliminates one bit that is needed to represent either of the two y coordinates, thus it reduces the EC field from the set of points that can be represented as a tuple ( x, {0,1} ) to the set that is represented as x.
		This can be equated with the task of the format preserving encryption (FPE) <xref target="Ciphers"/>. In particular, the "Method 2: Cycle-Walking Cipher" can be adopted where the encryption is the multiplication by k of the generator G. The algorithm terminates when k^i, i is an integer greater than 0, is such that the k^i * G is a compliant point. In section "6. Discussion" the authors discuss the application of their FPE methods exactly to the problem that this document solves. 
	</t>
	</section>
-->

	<section anchor="patches" title="Sample code change to add compliant key generation to libgcrypt and openssl">

	<t> 
		The complete changes that were needed to make libgcrypt library generate a compliant key are shown inline in this section, followed by pending changes to OpenSSL. 
	</t>
	<section anchor="libgcrypt-patch" title="libgcrypt changes">
	<t> 
		In the following changes, the Q is the initial public key, G generator, and d is the corresponding private key. "-" prefix marks the two lines that were replaced with the lines starting with "+". Lines starting with "+" represent the code that adds compliant key generation to libgcrypt.
 
<figure><artwork><![CDATA[
@@ generate_key (ECC_secret_key *sk, 
     unsigned int nbits, 
     const char *name,
   point_set (&sk->E.G, &E.G);
   sk->E.n = mpi_copy (E.n);
   point_init (&sk->Q);
-  point_set (&sk->Q, &Q);
-  sk->d    = mpi_copy (d);
+
+  /* We want the Q=(x,y) be a "compliant key" in terms of the
+   * http://tools.ietf.org/html/draft-jivsov-ecc-compact,
+   * which simply means that we choose either Q=(x,y) or -Q=(x,p-y) 
+   * such that we end up with the min(y,p-y) as the y coordinate.
+   * Such a public key allows the most efficient compression: y can 
+   * simply be dropped because we know that it's a minimum of 
+   * the two possibilities without any loss of security.
+   */
+  {
+    gcry_mpi_t x, p_y, y;
+    const unsigned int nbits = mpi_get_nbits (E.p);
+
+    x = mpi_new (nbits);
+    p_y = mpi_new (nbits);
+    y = mpi_new (nbits);
+
+    if (_gcry_mpi_ec_get_affine (x, y, &Q, ctx))
+      log_fatal ("ecgen: Failed to get affine coordinates for Q\n");
+
+    mpi_sub( p_y, E.p, y );  /* p_y = p-y */
+
+    if( mpi_cmp( p_y /*p-y*/, y ) < 0 )  {  /* is p-y < p ? */
+      gcry_mpi_t z = mpi_copy( mpi_const (MPI_C_ONE) );
+      /* we need to end up with -Q; this assures that new Q's y 
+       * is the smallest one */
+      sk->d = mpi_new (nbits);
+      mpi_sub( sk->d, E.n, d );  /* d = order-d */
+      /* log_mpidump ("ecgen d after ", sk->d); */
+      gcry_mpi_point_set (&sk->Q, x, p_y/*p-y*/, z);  /* Q = -Q */
+      if (DBG_CIPHER)
+      {
+        log_debug   ("ecgen converted Q to a compliant point\n");
+      }
+      mpi_free (z);
+    }
+    else
+    {
+      /* no change is needed exactly 50% of the time: just copy */
+      sk->d = mpi_copy (d);
+      point_set (&sk->Q, &Q);
+      if (DBG_CIPHER)
+      {
+        log_debug   ("ecgen didn't need to convert Q to "
+                     "a compliant point\n");
+      }
+    }
+    mpi_free (x);
+    mpi_free (p_y);
+    mpi_free (y);
+  }
]]></artwork></figure>

	</t>
	</section>

	<section anchor="openssl-patch" title="OpenSSL changes">
	<t> 
		OpenSSL changes are even more compact than in <xref target="libgcrypt-patch"/>. They are tracked at <xref target="OpenSSL"/>. 
	</t>
	</section>
	</section>

  </back>
</rfc>
