In the previous parts of this blog series I introduced the general principle of asymmetric cryptography and explained how one can use the Diffie-Hellman Key Exchange to establish a shared secret among multiple parties over an unsecure channel. In this blog I will introduce you to Elliptic Curve Cryptography (ECC), which allows using shorter keys than, for example, the DH key exchange or the RSA cryptosystem.

## Elliptic Curves

An elliptic curve is a collection of points space that satisfy the equation *y ^{2} = x^{3} + ax^{2} + bx + c*

^{1,2}. For most practical uses a

*depressed*cubic curve is sufficient, which means that

*a = 0*and therefore

*y*(using reassigned coefficients). If we choose

^{2}= x^{3}+ ax + b*a*=

*-1*and

*b = 1*, the curve will look like this:

#### Preparation

To use the elliptic curves for asymmetric cryptography in a way similar to the DH key exchange, we will need to define an Abelian group that is based on the curve. To do this as a first step there needs to be a group operation *. For elliptic curves this operation is called *addition* and behaves as follows:

- To add two distinct points
*P*, connect the points in a straight line and draw that line further until it intersects the curve again in a point_{1 }= (x_{1},y_{2}) and P_{2 }= (x_{2},y_{2})*P*. Mirror this point on the x-axis and you get the result of_{3}*P*. Thus R = (x_{1}+P_{2}_{r},y_{r}) = (δ – x_{1}– x_{2}, δ(x_{1}– x_{r}) – y_{1}) while δ = (y_{2 }– y_{1})/(x_{2 }– x_{1}). - To add a point to itself one cannot connect the two addends. Instead you just use the tangent on the curve in that point and thus get to P
_{3}. The rest works the same as in 1, therefore R = (x_{r},y_{r}) = (δ – x_{1}– x_{2}, δ(x_{1}– x_{r}) – y_{1}) while δ = (3x_{1}^{2}+ b)/2y_{1}. - Connecting two points where x
_{1 }= x_{2}will only intersect the curve a third time at infinity. Therefore we introduce the point (∞,∞) and add it to the group as the identity element.

It is easy to see, that this leads to the satisfaction of four out of five requirements of an Abelian group^{3}.

For the same reason as in the “normal” Diffie-Hellman algorithm, we do not want to have an infinite amount of points so that we take all the points on the curve modulo a certain number. Geometrically this is quite counter-intuitive but algebraically it works well. Say we take the curve from figure 1 and use modulo 7, which will lead to the following points:

- x=0; y
^{2}=1 → y=1 or y=6 - x=1; y
^{2}=1 → y=1 or y=6 - x=2; y
^{2}=0 → y=0 - x=3; y
^{2}=4 → y=2 or y=5 - x=4; y
^{2}=5 → no integer square root - x=5; y
^{2}=2 → no integer square root - x=6; y
^{2}=1 → y=1 or y=6 - x=∞; → y=∞

This Abelian group over a discrete elliptic curve can be used for cryptography similarly to the previous blog post, which will be explained in the following section.

#### Elliptic Curve Diffie-Hellman (ECDH)

Like exponentiation on integers, multiplication^{4} on elliptic curves is a one-way function and therefore can be used for the Diffie-Hellman key exchange in a similar way. Alice and Bob agree on a discrete elliptic curve and a specific generator point, i.e. the following parameters:

- p: the prime number that is the order of the group.
- a & b: the coefficients for the elliptic curve.
- x
_{g}& y_{g}: the coordinates of the generator point G - q: the order of the sub-group generated by G
- h: the cofactor of the curve, which is the ratio between the number of points on the curve and the number of points generated by G

First of all they both secretly create their private keys *α* and *β*, which are both integers while *0 < α,β < p* holds. They then create their public keys *A = αG* and *B = βG* and share them with their counterparts. All parties can now calculate the shared secret *S = αB = αβG = βαG = βA* and use it for symmetric encryption.

#### Encryption/Decprytion

Gaining authenticity is quite similar to ECDH and works as follows. Say Alice wants to send an encrypted message to Bob using his public key *B*. What she must do first is to create a random number *r* (*0 < r < q*). She then generates a point *R* on the curve by multiplying *r* with the generator point *G* (*R = rG*). Additionally she creates the (symmetric) encryption key *S* which is Bob’s public key *B* multiplied with her random number *r* (*S = rB*) and uses this to encrypt the message. She then sends *R* along with the ciphertext to Bob.

Upon reception of the point-ciphertext pair, Bob multiplies R with his private key *β*, which leads to *βR = βrG = rβG = rB = S* to restore the shared secret which he uses to decrypt Alices’ message.

#### Digital Signatures

To sign her message Alice will first create a random number *k* (*0 < k < q*). Similarly to encryption she generates a point *R* using that number (*R = kG*) and uses its x-coordinate as *r (mod q)*. Note that *r* must not be zero. She now computes *s* as in *s = (h + αr)/k mod q*, h being the hashed message to be signed, and sends the pair *(r,s)* along with the message to Bob.

To verify Alice’s signature he calculates a point *P* as follows: *P = (h/s)G + (r/s)A mod q*. He then compares *x _{p}* (i.e. the x-coordinate of point P) and

*r*. If they are equal, the signature is valid

^{5}.

###### A note on the random number* k*

It is very important that Alice chooses a different *k* for each signature she creates. Refraining from doing so will lead to a situation where a third-party can easily recover Alice’s private key *α*. This can be seen as follows: Using *k* for two different signatures will lead to *r _{1 }= kG = r_{2}* and therefore

*s*and

_{1 }= (h_{1}+ αr)/k mod q*s*which is a system of two linear equations with two unknowns (

_{2 }= (h_{2}+ αr)/k mod q*k*and

*α*), which is trivial to solve.

#### Footnotes

1. Elliptic curves do not represent ellipses! The name stems from the calculation of arc lengths of ellipses.

2. Additionally the curve must be non-singular, meaning the discriminant must not be zero.

3. Except for associativity which can be proven as shown here.

4. As in simple arithmetics, multiplication of a point on an elliptic curve with a scalar *n* is the same as adding that point *n* times to itself.

5. The proof of this is left as an exercise for the reader.