<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE rfc SYSTEM "rfc2629.dtd" [
     <!ENTITY rfc2119 PUBLIC ''
       'http://xml.resource.org/public/rfc/bibxml/reference.RFC.2119.xml'>
     <!ENTITY rfc2406 PUBLIC ''
       'http://xml.resource.org/public/rfc/bibxml/reference.RFC.2406.xml'>
     <!ENTITY rfc2407 PUBLIC ''
       'http://xml.resource.org/public/rfc/bibxml/reference.RFC.2407.xml'>
     <!ENTITY rfc2409 PUBLIC ''
       'http://xml.resource.org/public/rfc/bibxml/reference.RFC.2409.xml'>
     <!ENTITY rfc2410 PUBLIC ''
       'http://xml.resource.org/public/rfc/bibxml/reference.RFC.2410.xml'>
     <!ENTITY rfc2412 PUBLIC ''
       'http://xml.resource.org/public/rfc/bibxml/reference.RFC.2412.xml'>
     <!ENTITY rfc3979 PUBLIC ''
       'http://xml.resource.org/public/rfc/bibxml/reference.RFC.3979.xml'>
     <!ENTITY rfc4879 PUBLIC ''
       'http://xml.resource.org/public/rfc/bibxml/reference.RFC.4879.xml'>
     <!ENTITY rfc4301 PUBLIC ''
       'http://xml.resource.org/public/rfc/bibxml/reference.RFC.4301.xml'>
     <!ENTITY rfc4306 PUBLIC ''
       'http://xml.resource.org/public/rfc/bibxml/reference.RFC.4306.xml'>
     <!ENTITY rfc3264 PUBLIC ''
       'http://xml.resource.org/public/rfc/bibxml/reference.RFC.3264.xml'>
     <!ENTITY rfc3394 PUBLIC ''
       'http://xml.resource.org/public/rfc/bibxml/reference.RFC.3394.xml'>
     <!ENTITY rfc3548 PUBLIC ''
       'http://xml.resource.org/public/rfc/bibxml/reference.RFC.3548.xml'>
     <!ENTITY rfc3550 PUBLIC ''
       'http://xml.resource.org/public/rfc/bibxml/reference.RFC.3550.xml'>
     <!ENTITY rfc3610 PUBLIC ''
       'http://xml.resource.org/public/rfc/bibxml/reference.RFC.3610.xml'>
     <!ENTITY rfc3602 PUBLIC ''
       'http://xml.resource.org/public/rfc/bibxml/reference.RFC.3602.xml'>
     <!ENTITY rfc3686 PUBLIC ''
       'http://xml.resource.org/public/rfc/bibxml/reference.RFC.3686.xml'>
     <!ENTITY rfc3830 PUBLIC ''
       'http://xml.resource.org/public/rfc/bibxml/reference.RFC.3830.xml'>
     <!ENTITY rfc3711 PUBLIC ''
       'http://xml.resource.org/public/rfc/bibxml/reference.RFC.3711.xml'>
     <!ENTITY rfc4086 PUBLIC ''
       'http://xml.resource.org/public/rfc/bibxml/reference.RFC.4086.xml'>
     <!ENTITY rfc4563 PUBLIC ''
       'http://xml.resource.org/public/rfc/bibxml/reference.RFC.4563.xml'>
     <!ENTITY rfc4753 PUBLIC ''
       'http://xml.resource.org/public/rfc/bibxml/reference.RFC.4753.xml'>
     <!ENTITY rfc4754 PUBLIC ''
       'http://xml.resource.org/public/rfc/bibxml/reference.RFC.4754.xml'>
     <!ENTITY rfc4771 PUBLIC ''
       'http://xml.resource.org/public/rfc/bibxml/reference.RFC.4771.xml'>
     <!ENTITY rfc4568 PUBLIC ''
       'http://xml.resource.org/public/rfc/bibxml/reference.RFC.4568.xml'>
     <!ENTITY rfc5114 PUBLIC ''
       'http://xml.resource.org/public/rfc/bibxml/reference.RFC.5114.xml'>
     <!ENTITY I-D.wing-avt-dtls-srtp-key-transport SYSTEM "http://xml.resource.org/public/rfc/bibxml3/reference.I-D.wing-avt-dtls-srtp-key-transport">
]>

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

<?rfc toc="yes" ?>
<?rfc symrefs="yes" ?>
<?rfc sortrefs="yes"?>
<?rfc iprnotified="no" ?>
<?rfc strict="yes" ?>
<?rfc compact="yes" ?> 
<?rfc subcompact="no" ?>


<rfc category="std" 
     docName="draft-mcgrew-fundamental-ecc-03.txt" 
     ipr="trust200902" 
     category="info">

<front>
<title abbrev="Fundamental ECC">
Fundamental Elliptic Curve Cryptography Algorithms
</title>

<author initials="D.A.M." surname="McGrew" fullname="David A. McGrew">
<organization>Cisco Systems</organization>
<address>
<postal>
<street>510 McCarthy Blvd.</street>
<city>Milpitas</city>
<region>CA</region>
<code>95035</code>
<country>USA</country>
</postal>
<phone>(408) 525 8651</phone>
<email>mcgrew@cisco.com</email>
<uri>http://www.mindspring.com/~dmcgrew/dam.htm</uri>
</address>
</author>

<author initials="K.M.I" surname="Igoe" fullname="Kevin M. Igoe">
<organization>National Security Agency</organization>
<address>
<postal>
<street>Commercial Solutions Center </street>
<country>United States of America</country>
</postal>
<email>kmigoe@nsa.gov</email>
</address>
</author>

<author initials="M.S." surname="Salter" fullname="Margaret Salter">
<organization>National Security Agency</organization>
<address>
<postal>
<street>9800 Savage Rd.</street>
<city>Fort Meade</city>
<region>MD</region>
<code>20755-6709</code>
<country>USA</country>
</postal>
<email> msalter@restarea.ncsc.mil </email>
</address>
</author>



<date month="May" year="2010" />

<area>Network</area>
<keyword>Elliptic Curve Cryptography</keyword>

<abstract>
<t>
This note describes the fundamental algorithms of Elliptic Curve
Cryptography (ECC) as they are defined in some early references.
These descriptions may be useful for implementing the
fundamental algorithms without using any of the specialized methods
that were developed in following years.  Only elliptic curves defined over
fields of characteristic greater than three are in scope; these curves
are those used in Suite B.
</t>

</abstract>
</front>
				
<middle>
<section anchor="intro" title="Introduction">
<t>
ECC is a public-key technology that offers performance advantages at
higher security levels.  It includes an Elliptic Curve version of
the Diffie-Hellman key exchange protocol <xref target="DH1976"/> and 
Elliptic Curve versions of the ElGamal Signature Algorithm
<xref target="E1985"/>.  
The adoption of ECC has been slower than had been anticipated,
 perhaps due to the lack of freely available normative documents and
 uncertainty over intellectual property rights.
</t>
<t>
This note contains a description of the fundamental algorithms of ECC
over fields with characteristic greater than three, based directly on
original references.  Its intent is to provide the Internet community
with a summary of the basic algorithms that predate any specialized or
optimized algorithms, which can be used as a normative specification.
The original descriptions and notations were followed as closely
as possible.
</t>
<t>
There are several standards that specify or incorporate ECC
algorithms, including the Internet Key Exchange (IKE), ANSI X9.62, and
IEEE P1363.  The algorithms in this note can interoperate with some of
the algorithms in these standards, with a suitable choice of
parameters and options.  
The specifics are itemized in
<xref target="Interop"/>.
</t>
<t>
The rest of the note is organized as follows.  <xref target="Mod"/>,
<xref target="GROUP"/>, and <xref target="FIELD"/> furnish the
necessary terminology and notation from modular arithmetic, group
theory and the theory of finite fields, respectively.
<xref target="ECG"/> defines the groups based on elliptic curves over
finite fields of characteristic greater than three.
<xref target="ECDH"/> presents the fundamental ECDH algorithm.
<xref target="ECES"/> presents elliptic curve versions of the ElGamal
signature method.  The representation of integers as octet strings is
specified in <xref target="conversion"/>.  Sections 2 through 6,
inclusive, contain all of the normative text (the text that defines
the norm for implementations conforming to this specification), and
all of the following sections are purely informative.
Interoperability is discussed in <xref target="Interop"/>.  Validation
testing is described in <xref target="test"/>.  <xref target="IPR"/>
reviews intellectual property issues.  <xref target="SEC"/> summarizes
security considerations.  <xref target="rng"/> describes random number
generation, and other appendices provide clarifying details.
</t>
 <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="keywords"/>.
</t>
   </section>

</section>

<section title="Mathematical Background">
<t>
This section reviews mathematical preliminaries and establishes
terminology and notation that is used below.
</t>
<section anchor="Mod" title="Modular Arithmetic">
<t>
This section reviews modular arithmetic.  Two integers x and y are
said to be congruent modulo n if x - y is an integer multiple of n.
</t>
<t>
Two integers x and y are coprime when their greatest common divisor is
1; in this case, there is no third number z > 1 such that z divides x and
z divides y.
</t>
<t>
The set Zq = { 0, 1, 2, ..., q-1 } is closed under the operations of
modular addition, modular subtraction, modular multiplication, and
modular inverse.  These operations are as follows.  
<list>
<t>
For each pair of integers a and b in Zq, a + b mod q is equal to
<vspace blankLines="0"/> a + b if a + b < q, and is equal to a + b - q
otherwise.
</t>
<t>
For each pair of integers a and b in Zq, a - b mod q is equal to
<vspace blankLines="0"/> a - b if a - b >= 0, and is equal to a - b + q
otherwise.
</t>
<t>
For each pair of integers a and b in Zq, a * b mod q is equal to the remainder
of a * b divided by q.
</t>
<t>
For each integer x in Zq that is coprime with q, the inverse of x modulo q is
denoted as 1 / x mod q, and can be computed using the extended
euclidean algorithm (see Section 4.5.2 of <xref target="K1981v2"/>, for
example).
</t>
</list>
Algorithms for these operations are well known; for instance, see Chapter
4 of <xref target="K1981v2"/>.
</t>
</section>

<section anchor="GROUP" title="Group Operations">
<t>
This section establishes some terminology and notation for
mathematical groups, which is needed later on.  Background references
abound; see <xref target="D1966"/>, for example.
</t>
<t>
A group is a set of elements G together with an operation that
combines any two elements in G and returns a third element in G.  The
operation is denoted as * and its application is denoted as a * b, for
any two elements a and b in G.  The operation is associative, that is,
for all a, b and c in G, a * (b * c) is identical to (a * b) * c.
Repeated application of the group operation N-1 times to the element a
is denoted as a^N, for any element a in G and any positive integer N.
That is, a^2, = a * a, a^3 = a * a * a, and so on.  The associativity
of the group operation ensures that the computation of a^n is
unambiguous; any grouping of the terms gives the same result.
</t>
<t>
The above definition of a group operation uses multiplicative
notation.  Sometimes an alternative called additive notation is used,
in which a * b is denoted as a + b, and a^N is denoted as N * a.  In
multiplicative notation, g^N is called exponentiation, while the
equivalent operation in additive notation is called scalar
multiplication.  In this document, multiplicative notation is used
throughout for consistency.   <xref target="notation"/> 
elucidates the correspondence between the two notations.
</t>
<t>
Every group has a special element called the identity element, which
we denote as e.  For each element a in G, e * a = a * e = a.  By 
convention, a^0 is equal to the identity element for any a in G.  
</t>
<t>
Every group element a has a unique inverse element b such that <vspace blankLines="0"/>
a * b =
b * a = e.  The inverse of a is denoted as a^-1 in multiplicative
notation.  (In additive notation, the inverse of a is denoted as -a.)
</t>
<t>
For any positive integer X, a^(-X) is defined to be (a^-1)^(X). Using
this convention, exponentiation behaves as one would expect, namely
for any integers X and Y:
<list style="empty">
  <t> a^(X+Y) = (a^X)*(a^Y) </t>
  <t> (a^X)^Y = a^(XY) = (a^Y)^X. </t>
</list>
In cryptographic applications one typically deals with finite groups
(groups with a finite number of elements), and for such groups, the
number of elements of the group is also called the order of the group.
A group element a is said to have finite order if a^X = e for some
positive integer X, and the order of a is the smallest such X. If no
such X exists, a is said to have infinite order.  All elements of a
finite group have a finite order, and the order of an element is
always a divisor of the group order.
</t>
<t>
If a group element a has order R, then for any integers
X and Y,
<list>
  <t> a^X = a^(X mod R), </t>
  <t> a^X = a^Y if and only if X is congruent to Y mod R, </t>
<t>
  the set H = { a, a^2, a^3, ... , a^R=e } forms a subgroup of G, 
  called the cyclic subgroup generated by a, and a is said to be a 
  generator of H. 
</t>
</list>
</t>

<t>
 Typically there are several group elements that generate H. Any
 group element of the form a^M, with M relatively prime to R, also
 generates H.
<!-- A cyclic group of order R is a group that contains the R elements
<vspace blankLines="0"/> g, g^2, g^3, ..., g^R.  The element g is
called the generator of the group.  The element g^R is equal to the
identity element e.  
-->
Note that a^M is equal to g^(M modulo R) for any non-negative integer M.   
 <!-- 
 To compute g^(-r) for some integer r, one
could compute the value of (-r mod R), then raise g to that value.  
-->
</t>
<t>
Given the element a of order R, and an integer i between 1 and R-1,
inclusive, the element a^i can be computed by the "square and
multiply" method outlined in Section 2.1
of <xref target="M1983"></xref> (see also Knuth, Vol. 2, Section
4.6.3.), or other methods.
</t>
</section>


<section anchor="FIELD" title="Finite Fields">
<t>
This section establishes terminology and notation for finite fields
with prime characteristic.
</t>
<t>
When p is a prime number, then the set Zp, with the 
addition, subtraction, multiplication and division operations, is a
finite field with characteristic p.  
Each nonzero element x in Zp has an inverse 1/x.
There is a one-to-one correspondence
between the integers between zero and p-1, inclusive, and the elements of the
field.  The field Zp is sometimes denoted as Fp or GF(p).
</t>
<t>
Equations involving field elements do not explicitly denote the "mod p"
operation, but it is understood to be implicit.  For example,
the statement that x, y, and z are in Fp and 
<list>
<t>
  z = x + y 
</t>
</list>
is equivalent to the statement that x, y, and z are in the set <vspace blankLines="0"/> 
{ 0, 1, ..., p-1 } and
<list>
<t>
  z = x + y mod p.
</t>
</list>
</t>
</section>
</section>


<section anchor="ECG" title="Elliptic Curve Groups">
<t>
This note only covers elliptic curves over fields with characteristic
greater than three; these are the curves used in Suite B <xref target="SuiteB"/>.
  For other fields, the definition of the elliptic
curve group would be different.
</t>
<t>
An elliptic curve over a field Fp is defined by the curve equation 
<list style="empty">
<t>
y^2 = x^3 + a*x + b,  
</t>
</list>
where x, y, a, and b are elements of the field Fp
<xref target="M1985"/> and the discriminant is nonzero (as described
in <xref target="discrim"/>).  A point on an elliptic curve is a pair
(x,y) of values in Fp that satisfies the curve equation, or it is a
special point (@,@) that represents the identity element (which is
called the "point at infinity").  The order of an elliptic curve group
is the number of distinct points.
</t>
<t>
Two elliptic curve points (x1,y1) and (x2,y2) are equal whenever x1=x2
and y1=y2, or when both points are the point at infinity.
The inverse of the point (x1,y1) is the point (x1,-y1).
The point at infinity is its own inverse.
</t>
<t> 
The group operation associated with the elliptic curve group is as
follows <xref target="BC1989"/>.  To an arbitrary pair of points P and
Q specified by their coordinates (x1,y1) and (x2,y2) respectively, the
group operation assigns a third point P*Q with the coordinates
(x3,y3).  These coordinates are computed as follows:
<list style="empty">
<t>
  (x3,y3) = (@,@) when P is not equal to Q and x1 is equal to x2.
</t>
<t>
   x3 = ((y2-y1)/(x2-x1))^2 - x1 - x2  and <vspace blankLines="0"/>
   y3 = (x1-x3)*(y2-y1)/(x2-x1) - y1 when P is not equal to Q and <vspace/> 
x1 is not equal to x2.
</t>
<t>
(x3,y3) = (@,@) when P is equal to Q and y1 is equal to 0,
</t>
<t>
x3 = ((3*x1^2 + a)/(2*y1))^2 - 2*x1  and <vspace blankLines="0"/>
y3 = (x1-x3)*(3*x1^2 + a)/(2*y1) - y1 if P is equal to Q and y1 is not equal to 0.
</t>
</list>
In the above equations, a, x1, x2, x3, y1, y2, and y3 are elements of
the field Fp; thus, computation of x3 and y3 in practice 
must reduce the right-hand-side modulo p.  Pseudocode
for the group operation is provided in <xref target="pseudocodeA"/>.
</t>
<t>
The representation of elliptic curve points as a pair of integers in
Zp is known as the affine coordinate representation.  This
representation is suitable as an external data representation for
communicating or storing group elements, though the point at infinity
must be treated as a special case.
</t>
<t>
Some pairs of integers are not valid elliptic curve points.  A valid
pair will satisfy the curve equation, while an invalid pair will not.
</t>

<section title="Homogeneous Coordinates">
<t>
An alternative way to implement the group operation is to use
homogeneous coordinates <xref target="K1987"/> (see also <xref
target="KMOV1991"/>).  This method is typically more efficient because
it does not require a modular inversion operation.
</t>
<t>
An elliptic curve point (x,y) (other than the point
at infinity (@,@)) is equivalent to a point (X,Y,Z) in
homogeneous coordinates whenever x=X/Z mod p and y=Y/Z mod p.
</t>
<t>
Let P1=(X1,Y1,Z1) and P2=(X2,Y2,Z2) be points on an elliptic curve and
suppose that the points P1, P2 are not equal to (@,@), P1 is not equal
to P2, and P1 is not equal to P2^-1.  Then the product P3=(X3,Y3,Z3) =
P1 * P2 is given by
<list style="empty">
<t>
X3 = v * (Z2 * (Z1 * u^2 - 2 * X1 * v^2) - v^3) mod p
</t>
<t>
Y3 = Z2 * (3 * X1 * u * v^2 - Y1 * v^3 - Z1 * u^3) + u * v^3 mod p
</t>
<t>
Z3 = v^3 * Z1 * Z2 mod p
</t>
</list>
where u = Y2 * Z1 - Y1 * Z2  mod p and v = X2 * Z1 - X1 * Z2  mod p.
</t>
<t>
When the points P1 and P2 are equal, then (X1/Z1, Y1/Z1) is equal to
(X2/Z2, Y2/Z2), which is true if and only if u and v are both equal to
zero.
</t>
<t>
The product P3=(X3,Y3,Z3) = P1 * P1 is given by 
<list style="empty">
<t>
  X3 = 2 * Y1 * Z1 * (w^2 - 8 * X1 * Y1^2 * Z1)  mod p
</t>
<t>
  Y3 = 4 * Y1^2 * Z1 * (3 * w * X1 - 2 * Y1^2 * Z1) - w^3 mod p
</t>
<t>
  Z3 = 8 * (Y1 * Z1)^3  mod p
</t>
</list>
</t>
<t>
where w = 3 * X1^2 + a * Z1^2 mod p.
In the above equations, a, u, v, w, X1, X2, X3, Y1, Y2, Y3, Z1, Z2,
and Z3 are integers in the set Fp.
Pseudocode for the group operation in homogeneous coordinates is
provided in <xref target="pseudocodeH"/>.
</t>
<t>
When converting from affine coordinates to homogeneous coordinates, 
it is convenient to set Z to 1.   When converting from homogeneous
coordinates to affine coordinates, it is necessary to perform
a modular inverse to find 1/Z mod p.  
</t>
</section>

<section title="Other Coordinates">
<t>
Some other coordinate systems have been described; several are
documented in <xref target="CC1986"/>, including Jacobi coordinates.
</t>
</section>

<section anchor="params" title="ECC Parameters">
<t>
In cryptographic contexts, an elliptic curve parameter set consists of
a cyclic subgroup of an elliptic curve together with a preferred
generator of that subgroup.   When working over a prime order finite
field with characteristic greater than three, an elliptic curve group
is completely specified by the following parameters:
<list>
<t>
The prime number p that indicates the order of the field Fp.
</t>
<t>
The value a used in the curve equation.   
</t>
<t>
The value b used in the curve equation.
</t>
<t>
The generator g of the subgroup.  
</t>
<t>
The order n of the subgroup generated by g.
</t>
</list>
</t>
<t>
An example of an ECC parameter set is provided in <xref target="Example"/>.
</t>
<t>
Parameter generation is out of scope for this note.  
</t>
<t>
Each elliptic curve point is associated with a particular parameter
set.  The elliptic curve group operation is only defined between two
points in the same group.  It is an error to apply the group operation
to two elements that are from different groups, or to apply the group
operation to a pair of coordinates that is not a valid point.  (A
pair (x,y) of coordinates in Fp is a valid point only when they
satisfy the curve equation.)  See <xref target="twogroups"/> for
further information.
</t>
<section anchor="discrim" title="Discriminant">
<t>
For each elliptic curve group, the discriminant - 16*(4*a^3 + 27*b^2) 
must be nonzero modulo p <xref target="S1986"/>; this requires
that 
<list style="empty">
<t>
4*a^3 + 27*b^2 != 0 mod p.
</t>
</list>
</t>
</section>
<section title="Security">
<t>
Security is highly dependent on the choice of these parameters.
This section gives normative guidance on acceptable choices.
See also <xref target="SEC"/> for informative guidance.
</t>
<t>
The order of the group generated by g MUST be divisible by a large
prime, in order to preclude easy solutions of the discrete logarithm
problem <xref target="K1987"/>.
</t>
<t>
With some parameter choices, the discrete log problem is significantly
easier to solve.  This includes parameter sets in which b = 0 and p = 3
(mod 4), and parameter sets in which a = 0 and 
<vspace blankLines="0"/>
p = 2 (mod 3)
<xref target="MOV1993"/>.  These parameter choices are inferior for
cryptographic purposes and SHOULD NOT be used.
</t>

</section>
</section>


</section>


<section anchor="ECDH" title="Elliptic Curve Diffie-Hellman (ECDH)">
<t>
The Diffie-Hellman (DH) key exchange protocol <xref target="DH1976"/>
allows two parties communicating over an insecure channel to agree on
a secret key.  It was originally defined in terms of operations in the
multiplicative group of a field with a large prime characteristic.
Massey <xref target="M1983"/> observed that it can be easily
generalized so that it is defined in terms of an arbitrary
mathematical group.  Miller <xref target="M1985"/> and Koblitz <xref
target="K1987"/> analyzed the DH protocol over an elliptic curve
group.  We describe DH following the former reference.
</t>
<t>
Let G be a group, and g be a generator for that group, and let t
denote the order of G.  The DH protocol runs as follows.  Party A
chooses an exponent j between 1 and t-1, inclusive, uniformly at
random, computes g^j and sends that element to B.  Party B chooses an
exponent k between 1 and t-1, inclusive, uniformly at random, computes
g^k and sends that element to A.  Each party can compute g^(j*k);
party A computes (g^k)^j, and party B computes (g^j)^k.
</t>
<t>
See <xref target="rng"/> regarding generation of random integers.
</t>

<section title="Data Types">
<t>
Each run of the ECDH protocol is associated with a particular
parameter set (as defined in <xref target="params"/>), and the public
keys g^j and g^k and the shared secret g^(j*k) are elements of the
cyclic subgroup associated with the parameter set.
</t>
<t>
An ECDH private key z is an integer in Zt, where t is the order of the
subgroup.  
</t>
<!--
<t>
The corresponding ECDH public key Y is the group element, where Y =
g^z.  Each public key is associated with a particular parameter set as
per <xref target="params"/>.
</t>
<t> 
The shared secret computed by both parties is a group element.
</t>
-->
</section>


<section anchor="REP" title="Compact Representation">
<t>
As described in the final paragraph of <xref target="M1985"/>, the
x-coordinate of the shared secret value g^(j*k) is a suitable
representative for the entire point whenever exponentiation is used as
a one-way function.  In the ECDH key exchange protocol, after the element
g^(j*k) has been computed, the x-coordinate of that value can be used
as the shared secret.  We call this compact output.
</t>
<t>
Following <xref target="M1985"/> again, when compact output is used in
ECDH, only the x-coordinate of an elliptic curve point needs to be
transmitted, instead of both coordinates as in the typical affine
coordinate representation.  We call this the compact representation.
Its mathematical background is explained in <xref target="Xonly"/>. 
</t>
<t>
ECDH can be used with or without compact output.  Both parties in a
particular run of the ECDH protocol MUST use the same method.  ECDH
can be used with or without compact representation.  If compact
representation is used in a particular run of the ECDH protocol, then
compact output MUST be used as well.
</t>

</section>

</section>


<section anchor="ECES" title="Elliptic Curve ElGamal Signatures">
<section title="Background">
<t>
The ElGamal signature algorithm was introduced in 1984
<xref target="E1984a"/> <xref target="E1984b"/>
<xref target="E1985"/>.  It is based on the discrete logarithm
problem, and was originally defined for the multiplicative group of
the integers modulo a large prime number.  It is straightforward to
extend it to use other finite groups, such as the multiplicative group
of the field GF(2^w) <xref target="AMV1990"/> or an elliptic curve
group <xref target="A1992"/>.
<!--
"this idea can be extended to arbitrary groups" - AMV1993 
-->
</t>
<t>
An ElGamal signature consists of a pair of components.  There are many
possible generalizations of ElGamal signature methods that have been
obtained by different rearrangements of the equation for the second
component; see <xref target="HMP1994"/>, <xref target="HP1994"/>,
<xref target="NR1994"/>, <xref target="A1992"/>, and
<xref target="AMV1990"/>.  These generalizations are independent of
the mathematical group used, and have been described for the
multiplicative group modulo a prime number, the multiplicative group
of GF(2^w), and elliptic curve groups
<xref target="HMP1994"/><xref target="NR1994"/><xref target="AMV1990"/><xref target="A1992"/>.
</t>
<t> The Digital Signature Algorithm (DSA) <xref target="FIPS186"/> is
an important ElGamal signature variant.  
</t>

</section>

<section anchor="hash" title="Hash Functions">
<t>
ElGamal signatures must use a collision-resistant hash function, so
that it can sign messages of arbitrary length and can avoid
existential forgery attacks; see <xref target="existential"/>.  (This
is true for all ElGamal variants <xref target="HMP1994"/>.)  We denote
the hash function as h().  Its input is a bit string of arbitrary
length, and its output is a non-negative integer.
</t>
<t>
Let H() denote a hash function whose output is a fixed-length bit
string.  To use H in an ElGamal signature method, we define the
mapping between that output and the non-negative integers;
this realizes the function h() described above.  Given a bit string m,
the function h(m) is computed as follows:
<list style="numbers">
<t>
H(m) is evaluated; the result is a fixed-length bit string.
</t>
<t>
Convert the resulting bit string to an integer i by treating its
leftmost (initial) bit as the most significant bit of i, and treating
its rightmost (final) bit as the least significant bit of i.
</t>
<!--
<t>
After conversion, reduce i modulo n, where n is the group order.
</t>
-->
</list>
</t>
</section>


<section anchor="KTsigs" title="KT-IV Signatures">
<t>
Koyama and Tsuruoka described a signature method based on Elliptic
Curve ElGamal, in which the first signature component is the
x-coordinate of an elliptic curve point reduced modulo q
<xref target="KT1994"/>.  In this section we recall that method, which
we refer to as KT-IV.
</t>
<t>
The algorithm uses an elliptic curve group, as described in
<xref target="params"/>, with prime field order p and curve equation
parameters a and b.  We denote the generator as alpha, and the order
of the generator as q.  We follow <xref target="FIPS186"/> in checking
for exceptional cases.
</t>
<section anchor="kpair" title="Keypair Generation">
<t>
The private key z is an integer between 1 and q - 1, inclusive,
generated uniformly at random.  (See <xref target="rng"/> regarding
random integers.)  The public key is the group element <vspace /> Y =
alpha^z.
    <!-- NOTE: FIPS186 chooses z this way    -->
Each public key is associated with a particular particular
parameter set as per <xref target="params"/>.
</t>
</section>
<section title="Signature Creation">
<t>
To compute a KT-IV signature for a message m using the private key
z:
</t>
<t>

<list style="numbers">
  <t>
    Choose an integer k uniformly at random from the set of all
    integers between 1 and q-1, inclusive.  (See <xref target="rng"/> regarding
    random integers.)
    <!-- NOTE: FIPS186 chooses k this way    -->
  </t>
  <t>
    Calculate R = (r_x, r_y) = alpha^k.  
  </t>
  <t>
    Calculate s1 = r_x mod q.
  </t>
  <t>
    Check if h(m) + z * s1 = 0 mod q; if so, a new value of k MUST be
    generated and the signature MUST be recalculated.  As an option,
    one MAY check if s1 = 0; if so, a new value of k SHOULD be
    generated and the signature SHOULD be recalculated.  (It is
    extremely unlikely that s1 = 0 or h(m) + z * s1 = 0 mod q if
    signatures are generated properly.)
  </t>
  <t>
    Calculate s2 = k / (h(m) + z * s1)  mod q.
  </t>
</list>
The signature is the ordered pair (s1, s2).    Both signature components
are non-negative integers.
</t>
</section>
<section title="Signature Verification">
<t>
Given the message m, the public key Y, and the signature (s1, s2)
verification is as follows:
<list style="numbers">
  <t>
   Check to see that 0 < s1 < q and 0 < s2 < q; if either condition
   is violated, the signature SHALL be rejected.
  </t>
  <t>
    Compute the non-negative integers u1 and u2, where 
    <list style="empty">
      <t>
	u1 = h(m) * s2 mod q, and 
      </t>
      <t>
	u2 = s1 * s2 mod q.
      </t>
    </list> 
  </t>
  <t>
    Compute the elliptic curve point R' = alpha^u1 * Y^u2.
  </t>
  <t>
    If the x-coordinate of R' mod q is equal to s1, then the signature and
    message pass the verification; otherwise, they fail.
  </t>
</list>
</t>
</section>
</section>
<section title="KT-I Signatures">
<t>
Horster, Michels, and Petersen categorized many different ElGamal
signature methods, demonstrated their equivalence, and
showed how to convert signatures of one type to another type
<xref target="HMP1994"/>.  In their terminology, the signature method
of <xref target="KTsigs"/> and <xref target="KT1994"/> is a Type IV
method, which is why it is denoted as KT-IV.
</t>
<t> A Type I KT signature method has a second component that is
computed in the same manner as that of the Digital Signature
Algorithm.  In this section, we describe this method, which we refer
to as KT-I.
 </t>
<section title="Keypair Generation">
<t>
Keypairs and keypair generation are exactly as in <xref target="kpair"/>.
</t>
</section>
<section title="Signature Creation">
<t>
 To compute a KT-I signature for a message m using the private key
z:
</t>
<t>
<list style="numbers">
  <t>
    Choose an integer k uniformly at random from the set of all
    integers between 1 and q-1, inclusive.  (See <xref target="rng"/> regarding
    random integers.)
    <!-- NOTE: FIPS186 chooses k this way    -->
  </t>
  <t>
    Calculate R = (r_x, r_y) = alpha^k.  
  </t>
  <t>
    Calculate s1 = r_x mod q.
  </t>
  <t>
    Calculate s2 = (h(m) + z * s1) / k  mod q.
  </t>
  <t>
    As an option, one MAY check if s1 = 0 or s2 = 0. If either
    <vspace /> s1 = 0 or s2 = 0, a new value of k SHOULD be generated
    and the signature SHOULD be recalculated.  (It is extremely
    unlikely that s1 = 0 or s2 = 0 if signatures are generated
    properly.)
  </t>
</list>
The signature is the ordered pair (s1, s2).    Both signature components
are non-negative integers.
</t>
</section>
<section title="Signature Verification">
<t>
Given the message m, the public key Y, and the signature (s1, s2)
verification is as follows:
<list style="numbers">
  <t>
   Check to see that 0 < s1 < q and 0 < s2 < q; if either condition
   is violated the signature SHALL be rejected.  
  </t>
  <t>
    Compute s2_inv = 1 / s2 mod q. 
  </t>
  <t>
    Compute the non-negative integers u1 and u2, where 
    <list style="empty">
      <t>
	u1 = h(m) * s2_inv mod q, and 
      </t>
      <t>
	u2 = s1 * s2_inv mod q.
      </t>
    </list> 
  </t>
  <t>
    Compute the elliptic curve point R' = alpha^u1 * Y^u2.
  </t>
  <t>
    If the x-coordinate of R' mod q is equal to s1, then the signature
    and message pass the verification; otherwise, they fail.
  </t>
</list>

</t>
</section>
</section>
<section title="Converting KT-IV signatures to KT-I signatures">
<t>
A KT-IV signature for a message m and a public key Y can easily be
converted into a KT-I signature for the same message and public key.
If (s1, s2) is a KT-IV signature for a message m, then
<vspace /> (s1, 1/s2 mod q) is a KT-I signature for the
same message <xref target="HMP1994"/>.
</t>
<t>
The conversion operation uses only public information, and it
can be performed by the creator of the pre-conversion KT-IV signature, 
the verifier of the post-conversion KT-I signature, or by 
any other entity.  
</t>
<t>
An implementation MAY use this method to compute KT-I signatures.  
</t>
</section>
<section anchor="AECESrat" title="Rationale">
<t>
This subsection is not normative for this specification and is
provided only as background information.
</t>
<t>
<xref target="HMP1994"/> presents many generalizations of ElGamal signatures.
Equation (5) of that reference shows the general signature equation
<list>
  <t>
  A = x_A * B + k * C (mod q)
  </t>
</list>
where x_A is the private key, k is the secret value, and A, B, and C
are determined by the Type of the equation, as shown in Table 1 of
<xref target="HMP1994"/>.  DSA <xref target="FIPS186"/> is an EG-I.1
signature method (as is KT-I), with A = m, B = -r, and C = s.  (Here
we use the notation of <xref target="HMP1994"/> in which the first
signature component is r and the second signature component is s; in
KT-I and KT-IV these components are denoted as s1 and s2 respectively.
The private key x_A corresponds to the private key z.) Its signature
equation is
<list>
   <t>
    m = - r * z + s * k   (mod q).
    </t>
</list>
The signature method of <xref target="KT1994"/> and
<xref target="KTsigs"/> is an EG-IV.1 method, with A = m * s, B = - r
* s, C = 1.  Its signature equation is
<list>
  <t>
  m * s = - r * s * z + k (mod q)
  </t>
</list>
The functions f and g mentioned in Table 1 are merely multiplication,
as described under the heading "Fifth generalization".
</t>
<t>
No hash function is shown in the above equations, but as described in
<xref target="existential"/>, a hash function should be applied to the message prior to
signing in order to prevent existential forgery attacks.
</t>
<t>
Nyberg and Rueppel <xref target="NR1994"/> studied many different  
ElGamal signature methods, and defined "strong equivalence" as
follows:
<list style="empty">
  <t> 
    Two signature methods are called strongly equivalent if the
    signature of the first scheme can be transformed efficiently into
    signatures of the second scheme and vice versa, without knowledge
    of the private key.
  </t>
</list>
KT-I and KT-IV signatures are obviously strongly equivalent.  
</t>
<t>
A valid signature with s2=0 leaks the secret key, since in that case
<vspace blankLines="0"/> z = - h(m) / s1 mod q.  
We follow
<xref target="FIPS186"/> in checking for this exceptional case and the case that s1=0.  
The s2=0 check was suggested by Rivest <xref target="R1992"/>
and is discussed in <xref target="BS1992"/>.
</t>
<t>
<xref target="KT1994"/> uses "a positive integer q' that does not
exceed q" when computing the signature component s1 from the
x-coordinate r_x of the elliptic curve point R = (r_x, r_y).  The
value q' is also used during signature validation when comparing the
x-coordinate of a computed elliptic curve point to the value to s1.
In this note, we use the simplifying convention that q' = q.
</t>
</section>

</section>

<section anchor="conversion" title="Converting between integers and octet
strings">
<t>
A method for the conversion between integers and octet strings is
specified in this section, following the established conventions of
public key cryptography <xref target="R1993"/>.  This method allows
integers to be represented as octet strings that are suitable for
transmission or storage.  This method SHOULD be used when representing
an elliptic curve point or an elliptic curve coordinate as they are
defined in this note.
</t>
<section title="Octet-string-to-integer conversion">
<t>
The octet string S shall be converted to an integer x as follows. Let
S1, ..., Sk be the octets of S from first to last. Then the integer x
shall satisfy
<figure>
<artwork>
                       k
                 x =  SUM  2^(8(k-i)) Si .              
                     i = 1
</artwork>
</figure>
In other words, the first octet of S has the most significance in the
integer and the last octet of S has the least significance.
</t>
<t>
Note: the integer x satisfies 0 &lt;= x &lt; 2^(8*k).   
</t>

</section>
<section title="Integer-to-octet-string conversion">
<t>
The integer x shall be converted to an octet string S of length k
as follows. The string S shall satisfy
<figure>
<artwork>
                       k
                 y =  SUM  2^(8(k-i)) Si .              
                     i = 1
</artwork>
</figure>
where S1, ..., Sk are the octets of S from first to last.
</t>
<t>
In other words, the first octet of S has the most significance in the
integer and the last octet of S has the least significance.
</t>
</section>

</section>

<section anchor="Interop" title="Interoperability">
<t>
The algorithms in this note can be used to interoperate with some
other ECC specifications.  This section provides details for each
algorithm.
</t>
<section title="ECDH">
<t>
<xref target="ECDH"/> can be used with the Internet Key Exchange (IKE)
versions one <xref target="RFC2409"/> or two <xref
target="RFC4306"/>.  These algorithms are compatible
with the ECP groups defined by
<xref target="RFC4753"/>, 
<xref target="RFC5114"/>,
<xref target="RFC2409"/>, and <xref
target="RFC2412"/>.   The group definition in this protocol
uses an affine coordinate representation of the public key
and uses neither the compact output nor the compact representation
of <xref target="REP"/>.
<xref target="RFC4753"/> describes data formats that are compatible 
with those of <xref target="conversion"/>.
<!--
Note that some groups use a negative curve
parameter "a" and express this fact in the curve equation rather than
in the parameter. 
--> 
Note that some groups indicate that the curve parameter "a" is
negative; these values are to be interpreted modulo the order of the
field.  For example, a parameter of a = -3 is equal to p - 3, where p
is the order of the field.
 The test cases in Section 8 of <xref
target="RFC4753"/> can be used to test an implementation; these cases
use the multiplicative notation, as does this note.  The KEi and KEr
payloads are equal to g^j and g^k, respectively, with 64 bits of
encoding data prepended to them.
</t>
<t>
The algorithms in <xref target="ECDH"/> can be used to interoperate
with the IEEE <xref target="P1363"/> and ANSI <xref target="X9.62"/>
standards for ECDH based on fields of characteristic greater than
three.  IEEE P1363 ECDH can be used in a manner that will interoperate with
this note, with the following options and parameter choices from that
specification: 
<list style="empty">
  <t>
    prime curves with a cofactor of 1,
  </t> 
  <t>
    the ECSVDP-DH primitive, and
  </t>
  <t>
    the Key Derivation Function must be the "identity" function
    (equivalently, the KDF step should be omitted and the shared secret
    value should be output directly).
    </t>
</list>
</t>

</section>
<section anchor="SigInterop" title="KT-I and ECDSA">
<t>
The Digital Signature Algorithm (DSA) is based on the discrete
logarithm problem over the multiplicative subgroup of the finite field
with large prime order <xref target="DSA1991"/><xref target="FIPS186"/>.
The Elliptic Curve Digital Signature Algorithm (ECDSA) <xref
target="P1363"/> <xref target="X9.62"/> is an elliptic curve version
of DSA.
</t>
<t>
KT-I is mathematically and functionally equivalent to ECDSA,
and can interoperate with the IEEE <xref target="P1363"/> and ANSI
<xref target="X9.62"/> standards for Elliptic Curve DSA (ECDSA) based
on fields of characteristic greater than three.  KT-I
signatures can be verified using the ECDSA verification
algorithm, and ECDSA signatures can be verified using the 
KT-I verification algorithm.
</t>

</section>
</section>

<section anchor="test" title="Validating an Implementation">
<t>
It is essential to validate the implementation
of a cryptographic algorithm.   This section outlines tests
that should be performed on the algorithms defined in this note.
</t>
<t>
A known answer test, or KAT, uses a fixed set of inputs to test an
algorithm; the output of the algorithm is compared with the expected
output, which is also a fixed value.  KATs for ECDH and KT-I are set
out in the following subsections.  
</t>
<t>
A consistency test generates inputs for one algorithm being tested
using a second algorithm that is also being tested, then checks the
output of the first algorithm.  A signature creation algorithm can be
tested for consistency against a signature verification algorithm.
Implementations of KT-I should be tested in this way.  Their signature
generation processes are non-deterministic, and thus cannot be tested
using a KAT.  Signature verification algorithms, on the other hand,
are deterministic and should be tested via a KAT.  This combination of
tests provides coverage for all of the operations, including keypair
generation.  Consistency testing should also be applied to ECDH.
</t>
<section anchor="ECDHtest" title="ECDH">
<t>
An ECDH implementation can be validated using the known answer test
cases from <xref target="RFC4753"/> or <xref target="RFC5114"/>.  The
correspondence between the notation in RFC 4753 and the notation in
this note are summarized in the following table.  (Refer to
<xref target="params"/> and <xref target="ECDH"/>; the generator g is
expressed in affine coordinate representation as (gx, gy)).
</t>
   <texttable>
     <ttcol align="left"> ECDH </ttcol>
     <ttcol align="left"> RFC 4753 </ttcol>
     
     <c> order p of field Fp </c>
     <c> p  </c>

     <c> curve coefficient a  </c>
     <c> -3  </c>

     <c> curve coefficient b  </c>
     <c> b  </c>

     <c> generator g  </c>
     <c> g=(gx, gy)  </c>
     
     <c> private keys j and k </c>
     <c> i and r </c>

     <c> public keys g^j, g^k  </c>
     <c> g^i = (gix, giy) and g^r = (grx, gry) </c>

   </texttable>

<t>
 The correspondence between the notation in RFC 5114 and the notation
in this note are summarized in the following table.
</t>
   <texttable>
     <ttcol align="left"> ECDH </ttcol>
     <ttcol align="left"> RFC 5114 </ttcol>
     
     <c> order p of field Fp </c>
     <c> p  </c>

     <c> curve coefficient a  </c>
     <c> a  </c>

     <c> curve coefficient b  </c>
     <c> b  </c>

     <c> generator g  </c>
     <c> g=(gx, gy)  </c>
     
     <c> group order n   </c>
     <c> n   </c>

     <c> private keys j and k </c>
     <c> dA and dB </c>

     <c> public keys g^j, g^k  </c>
     <c> g^(dA) = (x_qA, y_qA) and  </c>
     <c>  </c>
     <c>  g^(dB) = (x_qB, y_qB) </c>

     <c> shared secret g^(j*k)   </c>
     <c> g^(dA*dB) = (x_Z, y_Z)   </c>

   </texttable>

</section>
<section anchor="AECEStest" title="KT-I">
<t>
A KT-I implementation can be validated using the known answer test
cases from <xref target="RFC4754"/>.  The correspondence between the
notation in that RFC and the notation in this note are summarized in
the following table.
</t>
   <texttable>
     <ttcol align="left"> KT-I </ttcol>
     <ttcol align="left"> RFC 4754 </ttcol>
     
     <c> order p of field Fp  </c>
     <c> p  </c>

     <c> curve coefficient a  </c>
     <c> -3  </c>

     <c> curve coefficient b  </c>
     <c> b  </c>

     <c> generator alpha  </c>
     <c> g  </c>

     <c> group order q  </c>
     <c> q  </c>

     <c> private key z </c>
     <c> w </c>

     <c> public key Y </c>
     <c> g^w = (gwx,gwy) </c>

     <c> random k </c>
     <c> ephem priv k </c>

     <c> s1 </c> 
     <c> r </c>
     
     <c> s2 </c>
     <c> s </c>

     <c> s2_inv </c>
     <c> sinv </c>

     <c> u1 </c>
     <c> u = h*sinv mod q </c>

     <c> u2 </c>
     <c> v = r*sinv mod q </c>

   </texttable>
</section>
</section>

<section anchor="IPR" title="Intellectual Property">
<t>
Concerns about intellectual property have slowed the adoption of ECC,
because a number of optimizations and specialized algorithms have
been patented in recent years.  
</t>
<t>
All of the normative references for ECDH (as defined in
<xref target="ECDH"/>) were published during or before 1989, and those
for KT-I were published during or before May, 1994.  All of the
normative text for these algorithms is based solely on their
respective references.
</t>

<section title="Disclaimer">
<t>
   This document is not intended as legal advice.  Readers are advised
   to consult their own legal advisers if they would like a legal
   interpretation of their rights.
</t>
<t>
   The IETF policies and processes regarding intellectual property and
   patents are outlined in <xref target="RFC3979"/> and
   <xref target="RFC4879"/> and at
   https://datatracker.ietf.org/ipr/about/.
</t>
</section>

</section>


<section anchor="SEC" title="Security Considerations">
<t>
The security level of an elliptic curve cryptosystem is determined by
the cryptanalytic algorithm that is the least expensive for an
attacker to implement.   There are several algorithms to consider.
</t>
<t>
The Pohlig-Hellman method is a divide-and-conquer technique
<xref target="PH1978"/>.  If the group order n can be 
factored as
<list style="empty">
  <t>
    n = q1 * q2 *  ... * qz,
    </t>
</list>
then the discrete log problem over the group can be solved by
independently solving a discrete log problem in groups of order q1,
q2, ..., qz, then combining the results using the Chinese remainder
theorem.   The overall computational cost is dominated by 
that of the discrete log problem in the subgroup with the
largest order. 
</t>
<t>
Shanks' algorithm <xref target="K1981v3"/> computes a discrete
logarithm in a group of order n using O(sqrt(n)) operations and
O(sqrt(n)) storage.  The Pollard rho algorithm <xref target="P1978"/>
computes a discrete logarithm in a group of order n using O(sqrt(n))
operations, with a negligible amount of storage, and can be
efficiently parallelized <xref target="VW1994"/>.
</t>
<t>
The Pollard lambda algorithm  <xref target="P1978"/> can 
solve the discrete logarithm problem using O(sqrt(w))
operations and O(log(w)) storage, when the exponent
is known to lie in an interval of width w.
</t>

<t>
The algorithms described above work in any group.  There
are specialized algorithms that specifically target
elliptic curve groups.  There are no known subexponential algorithms
against general elliptic curve groups, though
there are methods that target certain special 
elliptic curve groups; see <xref target="MOV1993"/>
and <xref target="FR1994"/>.
</t>
<section title="Subgroups">
<t>
A group consisting of a nonempty set of elements S with associated group
operation * is a subgroup of the group with the set of elements G, if
the latter group uses the same group operation and S is a subset of G.
For each elliptic curve equation, there is an elliptic curve group
whose group order is equal to the order of the elliptic curve; that
is, there is a group that contains every point on the curve.  
</t>
<t>
The order m of the elliptic curve is divisible by the order n of the
group associated with the generator; that is, for each elliptic curve
group, m = n * c for some number c.  The number c is called the
"cofactor" <xref target="P1363"/>.  Each ECC parameter set as in <xref
target="params"/> is associated with a particular cofactor.
</t>
<t>
It is possible and desirable to use a cofactor equal to 1.  
</t>
<!--
<t>
It is common to use a "safe prime group" in the conventional
Diffie-Hellman protocol over the multiplicative group of the prime
field Fp (see Appendix E of <xref target="RFC2412"/> for example).  A
safe prime group is the subgroup of prime order q of the
multiplicative group of Zp, where p-1 = 2*q.  The use of safe prime
groups simplifies protocol design, implementation and use, because they
minimize the effectiveness of some cryptanalytic attacks.  Elliptic
curve groups with a cofactor of 1 have similar benefits.
</t>
-->

</section>



<section title="Diffie-Hellman">
<t>
Note that the key exchange protocol as defined in
<xref target="ECDH"/> does not protect against active attacks; Party A
must use some method to ensure that (g^k) originated with the intended
communicant B, rather than an attacker, and Party B must do the same
with (g^j).
</t>
<t>
It is not sufficient to authenticate the shared secret g^(j*k), since
this leaves the protocol open to attacks that manipulate the public
keys.  Instead, the values of the public keys g^x and g^y that are
exchanged should be directly authenticated.  This is the strategy used
by protocols that build on Diffie-Hellman and which use end-entity
authentication to protect against active attacks, such as OAKLEY <xref
target="RFC2412"/> and the Internet Key Exchange <xref
target="RFC2409"/><xref target="RFC4306"/>.
</t>
<t>
When the cofactor of a group is not equal to 1, there are a number of
attacks that are possible against ECDH.   See <xref target="VW1996"/>,
<xref target="AV1996"/>, and <xref target="LL1997"/>.
</t>

</section>

<section anchor="twogroups" title="Group Representation and Security">
<t>
The elliptic curve group operation does not explicitly incorporate the
parameter b from the curve equation.  This opens the possibility that
a malicious attacker could learn information about an ECDH private key
by submitting a bogus public key <xref target="BMM2000"/>.  An
attacker can craft an elliptic curve group G' that has identical
parameters to a group G that is being used in an ECDH protocol, except
that b is different.  An attacker can submit a point on G' into a run
of the ECDH protocol that is using group G, and gain information from
the fact that the group operations using the private key of the device
under attack are effectively taking place in G' instead of G.
</t>
<t>
This attack can gain useful information about an ECDH private key that
is associated with a static public key, that is, a public key that is
used in more than one run of the protocol.  However, it does not
gain any useful information against ephemeral keys.
</t>
<t>
This sort of attack is thwarted if an ECDH implementation does not
assume that each pair of coordinates in Zp is actually a point on the
appropriate elliptic curve.
</t>
<t>
These considerations also apply when ECDH is used with compact representation
(see <xref target="Xonly"/>).
</t>
</section>



<section anchor="existential" title="Signatures">
<t>
Elliptic curve parameters should only be used if they come from a
trusted source; otherwise, some attacks are possible
<xref target="AV1996"/>, <xref target="V1996"/>.
</t>
<t>
If no hash function is used in an ElGamal signature system, then the
system is vulnerable to existential forgeries, in which an attacker
who does not know a private key can generate valid signatures for the
associated public key, but cannot generate a signature for a message
of its own choosing.  (See <xref target="E1985"/> for instance.)  The
use of a collision-resistant hash function eliminates this
vulnerability.
</t>
<t>
In principle, any collision-resistant hash function is suitable for
use in KT signatures.  To facilitate interoperability, we recognize
the following hashes as suitable for use as the function H defined in
<xref target="hash"/>:
<list style="empty">
  <t>
    SHA-256, which has a 256-bit output.  
  </t>
  <t>
    SHA-384, which has a 384-bit output.
  </t>
  <t>
    SHA-512, which has a 512-bit output.
  </t>
</list>
All of these hash functions are defined in <xref target="FIPS180-2"/>.
</t>
<t>
The number of bits in the output of the hash used in KT signatures
should be equal or close to the number of bits needed to represent the
group order.
</t>
</section>

</section>



<section title="IANA Considerations">
<t>
This note has no actions for IANA.  This section should be removed by
the RFC editor before publication as an RFC.
</t>
</section>

<section title="Acknowledgements">
<t>
The author expresses his thanks to the originators of elliptic curve
cryptography, whose work made this note possible, and all of the
reviewers, who provided valuable constructive feedback.   Thanks
are especially due to Howard Pinder, Andrey Jivsov, Alfred Hoenes (who
contributed the algorithms in <xref target="pseudocode"/>), and Dan Harkins.
</t>
</section>

</middle>

<back>
  
  <references title="Normative References">
	
	
	<reference anchor="R1993">
         <front>
           <title> PKCS#1: RSA Encryption Standard </title>
	   <author  surname="RSA Laboratories" >
	     <organization/>
           </author>
	  <date  year="1993"/>
         </front>
         <seriesInfo name="Technical Note" 
		     value="version 1.5" />
        </reference>



	<reference anchor="S1986">
         <front>
           <title> The Arithmetic of Elliptic Curves</title>
	   <author initials="J.H." surname="Silverman">
	     <organization/>
           </author>
	  <date year="1986"/>
         </front>
         <seriesInfo name="Springer-Verlag" value="New York" />
        </reference>


	<reference anchor="D1966">
         <front>
           <title> Abstract Algebra</title>
	   <author initials="W.E." surname="Deskins">
	     <organization/>
           </author>
	  <date year="1966"/>
         </front>
         <seriesInfo name="MacMillan Company" value="New York" />
        </reference>


	<reference anchor="K1981v2">
         <front>
           <title> The Art of Computer Programming, Vol. 2: Seminumerical Algorithms</title>
	   <author initials="D.E." surname="Knuth">
	     <organization/>
           </author>
	  <date year="1981"/>
         </front>
         <seriesInfo name="Addison Wesley" value="" />
        </reference>

	<reference anchor="DH1976">
         <front>
           <title> New Directions in Cryptography </title>
	   <author initials="W." surname="Diffie" >
	     <organization/>
           </author>
	   <author initials="M." surname="Hellman" >
	     <organization/>
           </author>
	  <date  year="1976"/>
         </front>
         <seriesInfo name="IEEE Transactions in Information Theory" 
		     value="IT-22, pp 644-654" />
        </reference>

	<reference anchor="M1983">
         <front>
           <title> Logarithms in finite cyclic groups - cryptographic issues </title>
	   <author initials="J.L." surname="Massey" >
	     <organization/>
           </author>
	  <date  year="1983"/>
         </front>
         <seriesInfo name="Proceedings of the 4th Symposium on Information Theory" 
		     value="" />
<!--
http://www.isiweb.ee.ethz.ch/archive/massey_pub/pdf/BI518.pdf
-->
        </reference>

	
	<reference anchor="M1985">
         <front>
           <title> Use of elliptic curves in cryptography</title>
	   <author initials="V." surname="Miller" >
	     <organization/>
           </author>
	  <date  year="1985"/>
         </front>
         <seriesInfo name="Advances in Cryptology - CRYPTO '85 Proceedings" 
		     value="Springer Lecture Notes in Computer Science (LNCS) volume 218" />
        </reference>




	<reference anchor="HMP1994">
         <front>
           <title> Meta-ElGamal signature schemes </title>
	   <author initials="P." surname="Horster" >
	     <organization/>
           </author>
	   <author initials="M." surname="Michels" >
	     <organization/>
           </author>
	   <author initials="H." surname="Petersen" >
	     <organization/>
           </author>
	  <date  month="May" year="1994"/>
         </front>
         <seriesInfo name="University of Technology Chemnitz-Zwickau Department of Computer Science Technical Report" 
		     value="TR-94-5" />
        </reference>


	<reference anchor="CC1986">
         <front>
           <title>
	     Sequences of numbers generated by addition in formal
             groups and new primality and factorization tests
	   </title>
	  <author initials="D.V." surname="Chudnovsky">
	      <organization/>
           </author>
	  <author initials="G.V." surname="Chudnovsky">
	      <organization/>
           </author>
	  <date month="December" year="1986"/>
         </front>	 
         <seriesInfo name="Advances in Applied Mathematics" 
		     value="Volume 7, Issue 4" />

        </reference>




	<reference anchor="K1987">
         <front>
           <title> Elliptic Curve Cryptosystems</title>
	   <author initials="N." surname="Koblitz" >
	     <organization/>
           </author>
	  <date  year="1987"/>
         </front>
         <seriesInfo name="Mathematics of Computation" 
		     value="Vol. 48, 1987, 203-209" />
        </reference>


	<reference anchor="BC1989">
	  <front>
	    <title> On the Implementation of Elliptic Curve Cryptosystems </title>
	    <author initials="A." surname="Bender">
	      <organization/>
	      </author>
	    <author initials="G." surname="Castagnoli">
	      <organization/>
	      </author>
	    <date year="1989"/>
	    </front>
         <seriesInfo name="Advances in Cryptology - CRYPTO '89 Proceedings" 
		     value="Spinger Lecture Notes in Computer Science (LNCS) volume 435" />	  
	  </reference>


	<reference anchor="AMV1990">
	  <front>
	    <title>
	      Improved Digital Signature Scheme based on Discrete Exponentiation
	    </title>
	    <author initials="G.B." surname="Agnew">
	      <organization/>
	      </author>
	    <author initials="R.C." surname="Mullin">
	      <organization/>
	      </author>
	    <author initials="S.A." surname="Vanstone">
	      <organization/>
	      </author>
	    <date year="July, 1990"/>
	    </front>
         <seriesInfo name="Electronics Letters" 
		     value="Vol. 26, No. 14" />	  
	  </reference>

<!--
	<reference anchor="AMV1993">
	  <front>
	    <title>
	      An Implementation of Elliptic Curve Cryptosystems Over F_{2^155}
	    </title>
	    <author initials="G.B." surname="Agnew">
	      <organization/>
	      </author>
	    <author initials="R.C." surname="Mullin">
	      <organization/>
	      </author>
	    <author initials="S.A." surname="Vanstone">
	      <organization/>
	      </author>
	    <date year="June, 1993"/>
	    </front>
         <seriesInfo name="IEEE JOURNAL ON SELECTED AREAS IN COMMUNICATIONS" 
		     value="Vol. 11, No. 5" />	  
	  </reference>


	<reference anchor="MV1993">
	  <front>
	    <title> Elliptic Curve Cryptosystems and Their Implementation </title>
	    <author initials="A.J." surname="Menezes">
	      <organization/>
	      </author>
	    <author initials="S.A." surname="Vanstone">
	      <organization/>
	      </author>
	    <date year="1993"/>
	    </front>
         <seriesInfo name="Journal of Cryptology" 
		     value="Volume 6, No. 4, pp209-224" />	  
	  </reference>


-->


	<reference anchor="MOV1993">
         <front>
           <title> 
	     Reducing Elliptic Curve Logarithms to
	     Logarithms in a Finite Field
	   </title>
	    <author initials="A.J." surname="Menezes">
	      <organization/>
	      </author>
	    <author initials="S.A." surname="Vanstone">
	      <organization/>
	      </author>
	    <author initials="T." surname="Okamoto">
	      <organization/>
	      </author>
	  <date  year="September, 1993"/>
         </front>
         <seriesInfo name="IEEE Transactions on Information Theory" 
		     value="Vol 39, No. 5, pp. 1639-1646" />
        </reference>

	<reference anchor="FR1994">
         <front>
           <title> 
	     A remark concerning m-divisibility and the discrete
	     logarithm in the divisor class group of curves.
	   </title>
	    <author initials="G." surname="Frey">
	      <organization/>
	      </author>
	    <author initials="H." surname="Ruck">
	      <organization/>
	      </author>
	  <date  year="1994"/>
         </front>
         <seriesInfo name="Mathematics of Computation" 
		     value="Vol. 62, No. 206, pp. 865-874" />
        </reference>

	<reference anchor="KT1994">
         <front>
           <title> Digital signature system based on elliptic curve
	     and signer device and verifier device for said system
	   </title>
	   <author initials="K." surname="Koyama" >
	     <organization/>
           </author>
	   <author initials="Y." surname="Tsuruoka" >
	     <organization/>
           </author>
	  <date  year="February 18, 1994"/>
         </front>
         <seriesInfo name="Japanese Unexamined Patent Application
		     Publication" value="H6-43809" />
        </reference>

<!--
	<reference anchor="MQV1994">
	  <front>
	    <title>
	      Submission to the IEEE P1363 Working Group (Part 6:
	    Elliptic Curve Systems, Draft 2) 
	    </title>
	    <author initials="A.J." surname="Menezes">
	      <organization/>
	      </author>
	    <author initials="M." surname="Qu">
	      <organization/>
	      </author>
	    <author initials="S.A." surname="Vanstone">
	      <organization/>
	      </author>
	    <date year="October, 1994"/>
	    </front>
         <seriesInfo name="Working Document" 
		     value="" />	  
	  </reference>
-->


	</references>



   <references title="Informative References">

         &rfc2119;
         &rfc4086;

	<reference anchor="HP1994">
         <front>
           <title>  Verallgemeinerte ElGamal-Signaturen</title>
	   <author initials="P." surname="Horster" >
	     <organization/>
           </author>
	   <author initials="H." surname="Petersen" >
	     <organization/>
           </author>
	  <date  year="1994"/>
         </front>
         <seriesInfo name="Proceedings der Fachtagung SIS '94, Verlag der Fachvereine" 
		     value="Zurich" />
        </reference>


	<reference anchor="BS1992">
         <front>
           <title> Response to Comments on the NIST Proposed Digital Signature Standard</title>
	  <author initials="D." surname="Branstad">
	      <organization/>
           </author>
	  <author initials="M." surname="Smid">
	      <organization/>
           </author>
	  <date month="August" year="1992"/>
         </front>	 
         <seriesInfo name="Advances in Cryptology - CRYPTO '92 Proceedings" 
		     value="Springer Lecture Notes in Computer Science (LNCS) volume 740" />

        </reference>


	<reference anchor="R1992">
         <front>
           <title> Response to the proposed DSS</title>
	   <author initials="R." surname="Rivest" fullname="Ronald Rivest">
	     <organization/>
           </author>
	  <date month="July" year="1992"/>
         </front>
         <seriesInfo name="Communications of the ACM" value="v.35 n.7 p.41-47." />
        </reference>

	<reference anchor="A1992">
         <front>
           <title> Response to the proposed DSS</title>
	   <author initials="J." surname="Anderson" fullname="John C. Anderson">
	     <organization/>
           </author>
	  <date month="July" year="1992"/>
         </front>
         <seriesInfo name="Communications of the ACM" value="v.35 n.7 p.50-52" />
        </reference>

	<reference anchor="E1984a">
         <front>
           <title> Cryptography and logarithms over finite fields</title>
	   <author initials="T." surname="ElGamal" >
	     <organization/>
           </author>
	  <date  year="1984"/>
         </front>
         <seriesInfo name="Stanford University" 
		     value="UMI Order No. DA 8420519" />
        </reference>
	
	<reference anchor="E1984b">
         <front>
           <title> Cryptography and logarithms over finite fields</title>
	   <author initials="T." surname="ElGamal" >
	     <organization/>
           </author>
	  <date  year="1984"/>
         </front>
         <seriesInfo name="Advances in Cryptology - CRYPTO '84 Proceedings" 
		     value="Springer Lecture Notes in Computer Science (LNCS) volume 196" />
        </reference>

	<reference anchor="E1985">
         <front>
           <title> A public key cryptosystem and a signature scheme
           based on discrete logarithms
	   </title>
	   <author initials="T." surname="ElGamal" >
	     <organization/>
           </author>
	  <date  year="1985"/>
         </front>
         <seriesInfo name="IEEE Transactions on Information Theory" 
		     value="Vol 30, No. 4, pp. 469-472" />
        </reference>



	<reference anchor="NR1994">
         <front>
           <title> Message Recovery for Signature Schemes Based on the Discrete Logarithm Problem </title>
	   <author initials="K." surname="Nyberg" >
	     <organization/>
           </author>
	   <author initials="R." surname="Rueppel" >
	     <organization/>
           </author>
	  <date  month="May" year="1994"/>
         </front>
         <seriesInfo name="Advances in Cryptology - EUROCRYPT '94 Proceedings" 
		     value="Springer Lecture Notes in Computer Science (LNCS) volume 950" />
        </reference>

        <reference anchor="SuiteB">
        <front>
          <title>NSA Suite B Cryptography</title>
          <author surname="U. S. National Security Agency (NSA)">
              <organization/>
          </author>
        </front>
        <seriesInfo name="Web Page" value="http://www.nsa.gov/ia/programs/suiteb_cryptography/index.shtml" />
        </reference>


	<reference anchor="PH1978">
         <front>
           <title>
	     An Improved Algorithm for Computing Logarithms over
	     GF(p) and its Cryptographic Significance
	   </title>
	   <author initials="S." surname="Pohlig" >
	     <organization/>
           </author>
	   <author initials="M." surname="Hellman" >
	     <organization/>
           </author>
	  <date  year="1978"/>
         </front>
         <seriesInfo name="IEEE Transactions on Information Theory" 
		     value="Vol 24, pp. 106-110" />
        </reference>


	<reference anchor="K1981v3">
         <front>
           <title> The Art of Computer Programming, Vol. 3:
           Sorting and Searching</title>
	   <author initials="D.E." surname="Knuth">
	     <organization/>
           </author>
	  <date year="1981"/>
         </front>
         <seriesInfo name="Addison Wesley" value="" />
        </reference>


	<reference anchor="P1978">
         <front>
           <title> 
	     Monte Carlo methods for index computation mod p
	   </title>
	   <author initials="J." surname="Pollard" >
	     <organization/>
           </author>
	  <date  year="1978"/>
         </front>
         <seriesInfo name="Mathematics of Computation" 
		     value="Vol. 32" />
        </reference>

	<reference anchor="KMOV1991">
         <front>
           <title> 
	     New Public-Key Schemes Based on Elliptic Curves over the Ring Zn
	   </title>
	    <author initials="K." surname="Koyama">
	      <organization/>
	      </author>
	    <author initials="U.M." surname="Maurer">
	      <organization/>
	      </author>
	    <author initials="S.A." surname="Vanstone">
	      <organization/>
	      </author>
	    <author initials="T." surname="Okamoto">
	      <organization/>
	      </author>
	  <date  year="1991"/>
         </front>
        <seriesInfo name="Advances in Cryptology - CRYPTO '91 Proceedings" 
		     value="Spinger Lecture Notes in Computer Science (LNCS) volume 576" />	  

        </reference>





	<reference anchor="AV1996">
         <front>
           <title>  
	     Minding Your P's and Q's 
	   </title>
	   <author initials="R." surname="Anderson" >
	     <organization/>
           </author>
	   <author initials="S." surname="Vaudenay" >
	     <organization/>
           </author>
	  <date  year="1996"/>
         </front>
         <seriesInfo name="Advances in Cryptology - ASIACRYPT '96
		     Proceedings" 
		     value="Spinger Lecture Notes in
		     Computer Science (LNCS) volume 1163" />
        </reference>


	<reference anchor="VW1994">
         <front>
           <title>  Parallel Collision Search with Application to Hash Functions and Discrete Logarithms
	   </title>
	   <author initials="P." surname="van Oorschot" >
	     <organization/>
           </author>
	   <author initials="M." surname="Wiener" >
	     <organization/>
           </author>
	  <date  year="1994"/>
         </front>
         <seriesInfo name="Proceedings of the 2nd ACM Conference on Computer and communications security " 
		     value="pp. 210-218" />
        </reference>


	<reference anchor="VW1996">
         <front>
           <title>  On Diffie-Hellman key agreement with short exponents 
	   </title>
	   <author initials="P." surname="van Oorschot" >
	     <organization/>
           </author>
	   <author initials="M." surname="Wiener" >
	     <organization/>
           </author>
	  <date  year="1996"/>
         </front>
         <seriesInfo name="Advances in Cryptology - EUROCRYPT '96 Proceedings" 
		     value="Spinger Lecture Notes in Computer Science (LNCS) volume 1070" />
        </reference>

	<reference anchor="V1996">
         <front>
           <title>  
	     Hidden Collisions on DSS
	   </title>
	   <author initials="S." surname="Vaudenay" >
	     <organization/>
           </author>
	  <date  year="1996"/>
         </front>
         <seriesInfo name="Advances in Cryptology - CRYPTO '96
		     Proceedings" value="Spinger Lecture Notes in
		     Computer Science (LNCS) volume 1109" />
        </reference>


	<reference anchor="LL1997">
         <front>
           <title>  
	     A Key Recovery Attack on Discrete Log-based Schemes
	     Using a Prime Order Subgroup
	   </title>
	   <author initials="C.H." surname="Lim" >
	     <organization/>
           </author>
	   <author initials="P.J." surname="Lee" >
	     <organization/>
           </author>
	  <date  year="1997"/>
         </front>
         <seriesInfo name="Advances in Cryptology - CRYPTO '97 Proceedings" 
		     value="Spinger Lecture Notes in Computer Science (LNCS) volume 1294" />
        </reference>


	<reference anchor="BMM2000">
         <front>
           <title>  
	     Differential fault analysis on elliptic curve cryptosystems
	   </title>
	   <author initials="I." surname="Biehl" >
	     <organization/>
           </author>
	   <author initials="B." surname="Meyer" >
	     <organization/>
           </author>
	   <author initials="V." surname="Muller" >
	     <organization/>
           </author>
	  <date  year="2000"/>
         </front>
         <seriesInfo name="Advances in Cryptology - CRYPTO 2000 Proceedings" 
		     value="Spinger Lecture Notes in Computer Science (LNCS) volume 1880" />
        </reference>


	<reference anchor="X9.62">
         <front>
           <title> Public Key Cryptography for the Financial Services
                   Industry: The Elliptic Curve Digital Signature
                   Algorithm (ECDSA) </title>
	  <author fullname="American National Standards Institute">
	      <organization/>
           </author>
         </front>
         <seriesInfo name="American National Standards Institute (ANSI)" value=" X9.62" />
        </reference>

	<reference anchor="P1363">
         <front>
           <title> Standard Specifications for Public Key Cryptography </title>
	  <author fullname="Institute of Electric and Electronic Engineers">
	      <organization/>
           </author>
	  <date year="2000"/>
         </front>	 
         <seriesInfo name="Institute of Electric and Electronic Engineers (IEEE)" value="P1363" />
        </reference>

	<reference anchor="FIPS186">
         <front>
           <title>  DIGITAL SIGNATURE STANDARD</title>
	  <author surname="U.S. National Institute of Standards and Technology">
	      <organization/>
           </author>
	  <date month="May" year="1994"/>
         </front>	 
         <seriesInfo name="Federal Information Processing Standard" value="FIPS-186" />
        </reference>

	<reference anchor="DSA1991">
         <front>
           <title>  DIGITAL SIGNATURE STANDARD</title>
	  <author surname="U.S. National Institute of Standards and Technology">
	      <organization/>
           </author>
	  <date month="August" year="1991"/>
         </front>	 
         <seriesInfo name="Federal Register" value="Vol. 56" />
        </reference>
	

	<reference anchor="FIPS180-2">
         <front>
           <title>  SECURE HASH STANDARD</title>
	  <author surname="U.S. National Institute of Standards and Technology">
	      <organization/>
           </author>
	  <date month="August" year="2002"/>
         </front>	 
         <seriesInfo name="Federal Information Processing Standard (FIPS)" value="180-2" />
        </reference>


	<reference anchor="L1969">
         <front>
           <title> Computer technology applied to the theory of numbers </title>
	  <author initials="D.H." surname="Lehmer" fullname="D. H. Lehmer">
	    <organization/>
           </author>
	  <date  year="1969" />
         </front>	 
         <seriesInfo name="M.A.A. Studies in Mathematics" value="180-2" />
        </reference>

	<reference anchor="R1988">
         <front>
           <title> 
	     A Course in Number Theory
	   </title>
	    <author initials="H." surname="Rose">
	      <organization/>
	      </author>
	  <date  year="1988"/>
         </front>
         <seriesInfo name="Oxford University Press" 
		     value="" />
        </reference>



         &rfc2409;
         &rfc2412;
         &rfc4306;
         &rfc4753;
         &rfc4754;

	&rfc3979;
	&rfc4879;
	&rfc5114;


   </references>

<section anchor="keywords" title="Key Words">
<t>
The definitions of these key words are quoted from <xref target="RFC2119"/> and are
commonly used in Internet standards.  They are reproduced in this note in order
to avoid a normative reference from after 1994.
</t>
<t>
<list style="numbers">
<t> MUST  - This word, or the terms "REQUIRED" or "SHALL", mean that the
   definition is an absolute requirement of the specification.
</t>
<t> MUST NOT  - This phrase, or the phrase "SHALL NOT", mean that the
   definition is an absolute prohibition of the specification.
</t>
<t>
   SHOULD  -  This word, or the adjective "RECOMMENDED", mean that there
   may exist valid reasons in particular circumstances to ignore a
   particular item, but the full implications must be understood and
   carefully weighed before choosing a different course.
</t>
<t>
   SHOULD NOT  - This phrase, or the phrase "NOT RECOMMENDED" mean that
   there may exist valid reasons in particular circumstances when the
   particular behavior is acceptable or even useful, but the full
   implications should be understood and the case carefully weighed
   before implementing any behavior described with this label.
</t>
<t>
   MAY  - This word, or the adjective "OPTIONAL", mean that an item is
   truly optional.  One vendor may choose to include the item because a
   particular marketplace requires it or because the vendor feels that
   it enhances the product while another vendor may omit the same item.
   An implementation which does not include a particular option MUST be
   prepared to interoperate with another implementation which does
   include the option, though perhaps with reduced functionality. In the
   same vein an implementation which does include a particular option
   MUST be prepared to interoperate with another implementation which
   does not include the option (except, of course, for the feature the
   option provides.)
</t>
</list>

</t>
</section>



<section anchor="rng" title="Random Integer Generation">
<t>
It is easy to generate an integer uniformly at random between zero and
2^t -1, inclusive, for some positive integer t.  Generate a random bit string that
contains exactly t bits, and then convert the bit string to a
non-negative integer by treating the bits as the coefficients in a
base-two expansion of an integer.
</t>
<t>
It is sometimes necessary to generate an integer r uniformly at random
so that r satisfies a certain property P, for example, lying within a
certain interval.  A simple way to do this is with the rejection
method:
<list style="numbers">
<t>
Generate a candidate number c uniformly at random from a set that
includes all numbers that satisfy property P (plus some other numbers,
preferably not too many)
</t>
<t>
If c satisfies property P, then return c.  Otherwise, return to Step
1.
</t>
</list> 
For example, to generate a number between 1 and n-1, inclusive,
repeatedly generate integers between zero and 2^t - 1, inclusive, stopping at the
first integer that falls within that interval.
</t>
<t>
Recommendations on how to generate random bit strings are provided
in <xref target="RFC4086"/>.
</t>
</section>


<section anchor="Xonly" title="Why Compact Representation Works">
<t>
In the affine representation, the x-coordinate of the point P^i does
not depend on the y-coordinate of the point P, for any non-negative
exponent i and any point P.  This fact can be seen as follows.  When
given only the x-coordinate of a point P, it is not possible to
determine exactly what the y-coordinate is, but the y value will be a
solution to the curve equation
<list>
  <t>
    y^2 = x^3 + a*x + b (mod p).
  </t>
</list>
There are at most two distinct solutions y = w and y = -w mod p,
and the point P must be either Q=(x,w) or Q^-1=(x,-w).  Thus P^n
is equal to either Q^n or (Q^-1)^n = (Q^n)^-1.  These values have the
same x-coordinate.  Thus, the x-coordinate of a point P^i can be
computed from the x-coordinate of a point P by computing one of the
possible values of the y coordinate of P, then computing the ith power
of P, and then ignoring the y-coordinate of that result.
</t>
<t>
In general, it is possible to compute a square root modulo p by using
Shanks' method <xref target="K1981v2"/>; simple methods exist for some
values of p.  When p = 3 (mod 4), the square roots of z mod p are w
and -w mod p, where
<list >
  <t>
    w = z ^ ((p+1)/4) (mod p);
  </t>
</list>
this observation is due to Lehmer <xref target="L1969"/>.  When p satisfies this
property, y can be computed from the curve equation, and either y = w or y = -w mod p, where
<list >
  <t>
     w = (x^3 + a*x + b)^((p+1)/4) (mod p).
  </t>
</list>
Square roots modulo p only exist for a quadratic residue modulo p, 
<xref target="R1988"/>; if z is not a quadratic residue, then 
there is no number w such that w^2 = z (mod p).  A simple 
way to verify that z is a quadratic residue after computing w 
is to verify that <vspace blankLines="0"/> w * w = z (mod p).  
If this relation does not hold for the above equation,
then the value x is not a valid x-coordinate for 
a valid elliptic curve point.
This is an important consideration when ECDH is used with compact
output; see <xref target="twogroups"/>.
</t>
<t>
The primes used in the P-256, P-384, and P-521 curves described in
<xref target="RFC4753"/> all have the property that p = 3 (mod 4).  
</t>
</section>

<section anchor="Example" title="Example ECC Parameter Set">
<t>
For concreteness, we recall an elliptic curve defined by Solinas and
Fu in <xref target="RFC4753"/> and referred to as P-256, which is
believed to provide a 128-bit security level.  We use the notation of 
<xref target="params"/>, and express the generator in the affine
coordinate representation g=(gx,gy), where the values gx and gy are 
in Fp.  
</t>
<t>
p: FFFFFFFF00000001000000000000000000000000FFFFFFFFFFFFFFFFFFFFFFFF
</t>
<t>
a: - 3
</t>
<t>
b: 5AC635D8AA3A93E7B3EBBD55769886BC651D06B0CC53B0F63BCE3C3E27D2604B
</t>
<t>
n: FFFFFFFF00000000FFFFFFFFFFFFFFFFBCE6FAADA7179E84F3B9CAC2FC632551

</t>


<t>
gx: 6B17D1F2E12C4247F8BCE6E563A440F277037D812DEB33A0F4A13945D898C296
</t>
<t>
gy: 4FE342E2FE1A7F9B8EE7EB4A7C0F9E162BCE33576B315ECECBB6406837BF51F5
</t>
<t>
Note that p can also be expressed as 
<list>
   <t>
     p = 2^(256)-2^(224)+2^(192)+2^(96)-1.
   </t>
</list>
</t>


</section>

<section anchor="notation" title="Additive and multiplicative notation">
<t>
The early publications on elliptic curve cryptography used
multiplicative notation, but most modern publications use additive
notation.  This section includes a table mapping between those two
conventions.  In this section, a and b are elements of an elliptic
curve group, and N is an integer.
</t>

   <texttable>
     <ttcol align="left">Multiplicative Notation </ttcol>
     <ttcol align="left">Additive Notation </ttcol>
     
     <c> multiplication  </c> 
     <c> addition </c>
     
     <c> a * b </c>
     <c> a + b </c>

     <c> squaring  </c>
     <c> doubling   </c>

     <c>  a * a = a^2 </c>
     <c>  a + a = 2a  </c>

     <c> exponentiation  </c>
     <c> scalar multiplication  </c>

     <c>  a^N = a * a * ... * a </c>
     <c>  Na = a + a + ... + a </c>

     <c> inverse </c>
     <c> inverse </c>

     <c> a^-1 </c>
     <c> -a </c>

   </texttable>



</section>


<section anchor="pseudocode" title="Algorithms">
<t>
This section contains a pseudocode description of the elliptic curve
group operation.   Text that follows the symbol "//" are to be
interpreted as comments rather than instructions.  
</t>
<section anchor="pseudocodeA" title="Affine Coordinates">
<t>
To an arbitrary pair of elliptic curve points P and Q specified by
  their affine coordinates P=(x1,y1) and Q=(x2,y2), the group
  operation assigns a third point R = P*Q with the coordinates
  (x3,y3).  These coordinates are computed as follows:
<figure>
<artwork>
  if P is (@,@), 
     R = Q
  else if Q is (@,@), 
     R = P
  else if P is not equal to Q and x1 is equal to x2, 
     R = (@,@)
  else if P is not equal to Q and x1 is not equal to x2,
     x3 = ((y2-y1)/(x2-x1))^2 - x1 - x2 mod p and
     y3 = (x1-x3)*(y2-y1)/(x2-x1) - y1 mod p
  else if P is equal to Q and y1 is equal to 0, 
     R = (@,@)
  else    // P is equal to Q and y1 is not equal to 0
     x3 = ((3*x1^2 + a)/(2*y1))^2 - 2*x1 mod p and
     y3 = (x1-x3)*(3*x1^2 + a)/(2*y1) - y mod p.
</artwork>
</figure>
  From the first and second case, it follows that the point at infinity
  is the neutral element of this operation, which is its own inverse.
</t>
<t>
  From the curve equation it follows that for a given curve point
  P = (x,y) distinct from the point at infinity, (x,-y) also is a curve
  point, and from the third and the fifth case it follows that this is
  the inverse of P, P^-1.
</t>
<t>
  Note: The fifth and sixth case are known as "point squaring".
</t>
</section>
<section anchor="pseudocodeH" title="Homogeneous Coordinates">
<t>
  An elliptic curve point (x,y) (other than the point at infinity
  (@,@)) is equivalent to a point (X,Y,Z) in homogeneous coordinates
  (with X, Y, and Z in Fp and not all three being zero at once)
  whenever x=X/Z and y=Y/Z.  "Homogenous coordinates" means that
  two triples  (X,Y,Z) and (X',Y',Z') are regarded as "equal" (i.e.
  representing the same point) if there is some non-zero s in Fp
  such that  X'=s*X, Y'=s*Y, and Z'=s*Z.  The point at infinity, (@,@)
  is regarded as equivalent to the homogenous coordinates (0,1,0), i.e.
  it can be represented by any triple (0,Y,0) with non-zero Y in Fp.
</t>
<t>
  Let P1=(X1,Y1,Z1) and P2=(X2,Y2,Z2) be points on the elliptic curve,
  and let u = Y2 * Z1 - Y1 * Z2 and v = X2 * Z1 - X1 * Z2.
</t>
<t>
  We observe that the points P1 and P2 are equal if and only if u and v
  are both equal to zero.  Otherwise, if either P1 or P2 are equal to
  the point at infinity, v is zero and u is non-zero (but the converse
  implication does not hold).
</t>
<t>
  Then the product P3=(X3,Y3,Z3) = P1 * P2 is given by:
<figure>
<artwork>
  if P1 is the point at infinity, 
     P3 = P2
  else if P2 is the point at infinity, 
     P3 = P1
  else if u is not equal to 0 but v is equal to 0, 
     P3 = (0,1,0)
  else if both u and v are not equal to 0, 
     X3 = v * (Z2 * (Z1 * u^2 - 2 * X1 * v^2) - v^3)
     Y3 = Z2 * (3 * X1 * u * v^2 - Y1 * v^3 - Z1 * u^3) + u * v^3
     Z3 = v^3 * Z1 * Z2
  else    // P2 equals P1, P3 = P1 * P1
      w = 3 * X1^2 + a * Z1^2 
     X3 = 2 * Y1 * Z1 * (w^2 - 8 * X1 * Y1^2 * Z1)
     Y3 = 4 * Y1^2 * Z1 * (3 * w * X1 - 2 * Y1^2 * Z1) - w^3
     Z3 = 8 * (Y1 * Z1)^3
</artwork>
</figure>
  It thus turns out that the point at infinity is the identity element
  and for P1=(X,Y,Z) not equal to this point at infinity, P2=(X,-Y,Z)
  represents P1^-1.
</t>
</section>

</section>



</back>
</rfc>
