ECC Eng
ECC Eng
MA II - FIB
y 2 = x3 + ax + b,
where a, b are integers modulo p and 4a3 + 27b2 6≡ 0 (mod p), together with a point at infinity O.
The set of points of the curve is
In terms of implementation, the point O can be represented with three coordinates, the last of which
being a 0.
In this set, addition is defined using the following condition: the sum of three points is O if and only if
the points lie on a line. More concretely, the sum of points is given in the following way: if P = (x1 , y1 )
is a point of the curve, set −P = (x1 , −y1 mod p). Then,
• P +O=P
• P + (−P ) = O
• if Q = (x2 , y2 ) 6= −P , then P + Q = (x0 , λ(x1 − x0 ) − y1 mod p), where x0 = λ2 − x1 − x2 mod p
and
(y2 − y1 )(x2 − x1 )−1 mod p si Q 6= P,
λ=
(3x1 + a)(2y1 )−1 mod p
2
si Q = P.
With this operation, the set of points of the elliptic curve has the structure of an abelian group: the sum
is associative and commutative, has an identity element (namely O) and every element P has an inverse
−P (the inverse of O is itself).
In this group, the exponentiation kP can be done with the algorithm of “successive squares”: first
the binary expression of k is computed, that is, k = br 2r + · · · + b1 2 + b0 , where bi ∈ {0, 1} and br = 1;
then
R ← O, i ← r
while i ≥ 0 do
R←R+R
if bi = 1 do R ← R + P
i←i−1
output R
In the elliptic curves that are used in Cryptography, the group of points E(Fp ) has size 2m n, where n is
a prime number and the cofactor h = 2m has exponent 0 ≤ m ≤ 16. Under these conditions, there is
always a point G of order n, that is, nG = O but all the previous multiples G, 2G, 3G, . . . , (n − 1)G are
6= O.
Given the parameters p, a, b, n, G of a cryptographic system, the private key of a user is a random
integer r, 1 < r < n − 1, and his/her public key is the point P = rG.
1
Diffie-Hellman key exchange. If the private and public keys of a pair of users are (r1 , P1 = r1 G)
and (r2 , P2 = r2 G), then the first user can compute r1 P2 and the second one can compute r2 P1 , so that
both of them are actually computing the same point: r1 r2 G = (x, y)
This can be used to obtain a 256-bit secret key, which they can, for instance, feed to AES:
K = SHA256(s||x)
where s is a random number that they can interchange publicly and || indicates the concatenation of
binary words.
ECDSA (Elliptic Curve Digital Signature Algorithm). With the same parameters p, a, b, n, G
as before, the signature of a message M by the user whose private key is r and whose public key is P
works as follows:
If f1 = 0 or f2 = 0, one must go back to the first step and generate a new value of k. Notice that if the
prime number p has length `, then the signature has length ≤ 2`.
The receiver verifies the signature in the following way:
In this algorithm, H(M ) denotes a hash of the message M . In the implementation we will consider that
that the prime number p has 256 bits and that the hash function is SHA256. In particular, the signature
will be expressed with 64 bytes.
Implementation: signatures. Define the class ecc including the following methods:
input: P point of the curve given by 3 coordinates (x, y, z), (if z = 0, it’s the point at infinity),
ParametresCorba={a, b, p}, are the parameters of the curve y 2 = x3 + ax + b mod p ;
output: a list {Rx ,Ry ,Rz } representing the inverse of P , R = −P (if Rz = 0, it’s the point at
infinity).
input: P and Q points of the curve given by 3 coordinates (x, y, z), (if z = 0, it’s the point at
infinity),
ParametresCorba={a, b, p} are the parameters of the curve y 2 = x3 + ax + b mod p ;
output: a list {Rx ,Ry ,Rz } representing the point R = P +Q (if Rz = 0, it’s the point at infinity).
2
public static BigInteger [] multiple(BigInteger k, BigInteger [] P, BigInteger[] ParametresCorba)
input: k integer,
P point of the curve given by 3 coordinates (x, y, z), (if z = 0, it’s the point at infinity),
ParametresCorba={a, b, p} are the parameters of the curve y 2 = x3 + ax + b mod p ;
output: a list {Rx ,Ry ,Rz } representing the point R = P + · · · + P = k · P (if Rz = 0, it’s the
point at infinity.