Those of you who know what public-key cryptography is may have already heard of ECC, ECDH or ECDSA. The first is an acronym for Elliptic Curve Cryptography, the others are names for algorithms based on it.
Today, we can find elliptic curves cryptosystems in TLS, PGP and SSH, which are just three of the main technologies on which the modern web and IT world are based. Not to mention Bitcoin and other cryptocurrencies.
Before ECC become popular, almost all public-key algorithms were based on RSA, DSA, and DH, alternative cryptosystems based on modular arithmetic. RSA and friends are still very important today, and often are used alongside ECC. However, while the magic behind RSA and friends can be easily explained, is widely understood, and rough implementations can be written quite easily, the foundations of ECC are still a mystery to most.
With a series of blog posts I’m going to give you a gentle introduction to the world of elliptic curve cryptography. My aim is not to provide a complete and detailed guide to ECC (the web is full of information on the subject), but to provide a simple overview of what ECC is and why it is considered secure, without losing time on long mathematical proofs or boring implementation details. I will also give helpful examples together with visual interactive tools and scripts to play with.
Specifically, here are the topics I’ll touch:
- Elliptic curves over real numbers and the group law (covered in this blog post)
- Elliptic curves over finite fields and the discrete logarithm problem
- Key pair generation and two ECC algorithms: ECDH and ECDSA
- Algorithms for breaking ECC security, and a comparison with RSA
In order to understand what’s written here, you’ll need to know some basic stuff of set theory, geometry and modular arithmetic, and have familiarity with symmetric and asymmetric cryptography. Lastly, you need to have a clear idea of what an “easy” problem is, what a “hard” problem is, and their roles in cryptography.
Ready? Let’s start!
Elliptic Curves
First of all: what is an elliptic curve? Wolfram MathWorld gives an excellent and complete definition. But for our aims, an elliptic curve will simply be the set of points described by the equation:
where


Depending on the value of
For our aims, we will also need a point at infinity (also known as ideal point) to be part of our curve. From now on, we will denote our point at infinity with the symbol 0 (zero).
If we want to explicitly take into account the point at infinity, we can refine our definition of elliptic curve as follows:
Groups
A group in mathematics is a set for which we have defined a binary operation that we call “addition” and indicate with the symbol +. In order for the set
- closure: if
and are members of , then is a member of ; - associativity:
; - there exists an identity element 0 such that
; - every element has an inverse, that is: for every
there exists such that .
If we add a fifth requirement:
- commutativity:
,
then the group is called abelian group.
With the usual notion of addition, the set of integer numbers
Groups are nice because, if we can demonstrate that those four properties hold, we get some other properties for free. For example: the identity element is unique; also the inverses are unique, that is: for every
The group law for elliptic curves
We can define a group over elliptic curves. Specifically:
- the elements of the group are the points of an elliptic curve;
- the identity element is the point at infinity 0;
- the inverse of a point
is the one symmetric about the -axis; - addition is given by the following rule: given three aligned, non-zero points
, and , their sum is .

Note that with the last rule, we only require three aligned points, and three points are aligned without respect to order. This means that, if
So far, so great. But how do we actually compute the sum of two arbitrary points?
Geometric addition
Thanks to the fact that we are in an abelian group, we can write

This geometric method works but needs some refinement. Particularly, we need to answer a few questions:
- What if
or ? Certainly, we can’t draw any line (0 is not on the -plane). But given that we have defined 0 as the identity element, and , for any and for any . - What if
? In this case, the line going through the two points is vertical, and does not intersect any third point. But if is the inverse of , then we have from the definition of inverse. - What if
? In this case, there are infinitely many lines passing through the point. Here things start getting a bit more complicated. But consider a point . What happens if we make approach , getting closer and closer to it?
As the two points become closer together, the line passing through them becomes tangent to the curve.
As

Let’s assume that
The geometric method is now complete and covers all cases. With a pencil and a ruler we are able to perform addition involving every point of any elliptic curve. If you want to try, take a look at the HTML5/JavaScript visual tool I’ve built for computing sums on elliptic curves!
Algebraic addition
If we want a computer to perform point addition, we need to turn the geometric method into an algebraic method. Transforming the rules described above into a set of equations may seem straightforward, but actually it can be really tedious because it requires solving cubic equations. For this reason, here I will report only the results.
First, let’s get get rid of the most annoying corner cases. We already know that
If
The intersection of this line with the elliptic curve is a third point
or, equivalently:
Hence
If we wanted to check whether this result is right, we would have had to check whether
Instead, let’s play with an example: according to our visual tool, given
Yes, this is correct!
Note that these equations work even if one of
We get the result
The case
Note that, as we would expect, this expression for
To prove the validity of this result it is enough to check that
Which gives us
Although the procedure to derive them can be really tedious, our equations are pretty compact. This is thanks to Weierstrass normal form: without it, these equations could have been really long and complicated!
Scalar multiplication
Other than addition, we can define another operation: scalar multiplication, that is:
where
Written in that form, it may seem that computing
One of them is the double and add algorithm. Its principle of operation can be better explained with an example. Take
(We have taken each binary digit of
In view of this, we can write:
What the double and add algorithm tells us to do is:
- Take
. - Double it, so that we get
. - Add
to (in order to get the result of ). - Double
, so that we get . - Add it to our result (so that we get
). - Double
to get . - Don’t perform any addition involving
. - Double
to get . - Add it to our result (so that we get
). - …
In the end, we can compute
If this is not clear enough, here’s a Python script that implements the algorithm:
def bits(n):
"""
Generates the binary digits of n, starting
from the least significant bit.
bits(151) -> 1, 1, 1, 0, 1, 0, 0, 1
"""
while n:
yield n & 1
n >>= 1
def double_and_add(n, x):
"""
Returns the result of n * x, computed using
the double and add algorithm.
"""
result = 0
addend = x
for bit in bits(n):
if bit == 1:
result += addend
addend *= 2
return result
If doubling and adding are both
Logarithm
Given
I don’t know of any “easy” algorithm for the logarithm problem, however playing with multiplication it’s easy to see some patterns. For example, take the curve
But there’s a variant of the logarithm problem: the discrete logarithm problem. As we will see in the next post, if we reduce the domain of our elliptic curves, scalar multiplication remains “easy”, while the discrete logarithm becomes a “hard” problem. This duality is the key brick of elliptic curve cryptography.
See you next week
That’s all for today, I hope you enjoyed this post! Next week we will discover finite fields and the discrete logarithm problem, along with examples and tools to play with. If this stuff sounds interesting to you, then stay tuned!
Comments