Writing

Papaver ellipticalisleg. cstef, 29.xi.2024

Elliptic Curves for Sane People

A gentle introduction to elliptic curve cryptography, without the need for a PhD in mathematics.

6 min readcrypto

[!NOTE] I am not a cryptographer, nor a mathematician. This article is the result of my own research and understanding of the subject. If you find any mistakes, please let me know!

The vast majority of what is written here is taken from various sources, which are listed at the end of this article. I highly recommend you to read them if you want to dive deeper into the subject.

Elliptic curve cryptography (ECC) is a fascinating field of study that has been around for a while. It’s a cornerstone of modern cryptography, and it’s used in many applications, from secure messaging to cryptocurrencies. RSA, the most widely used public-key cryptosystem, is slowly being replaced by ECC due to its efficiency and security.

The trapdoor function (easy to do one way, hard the other) for an elliptic curve is the multiplication of a point 𝑃 by a scalar 𝑛 which is just adding the point 𝑃 to itself 𝑛 times. This operation is denoted as 𝑛⋅𝑃. If 𝑛 is large enough, it is computationally impossible to find 𝑛 for 𝑄=𝑛⋅𝑃, being given both 𝑄 and 𝑃, in a reasonable time.

What is a "reasonable time"?

Let’s suppose we have supercomputer that is able to compute 1012 point multiplications per second (generous assumption).

In a year, we have about 365βˆ—24βˆ—60βˆ—60≃31β€²556β€²952 seconds, that means we could compute:

31β€²556β€²952β‹…1012≃1019[keys/year]

Let’s take a SECP256k1 private key for our example. The elliptic curve is over a 256-bit field, which means we have 2256≃1077 possible keys.

10771019=1077βˆ’19=1058[years]

For reference, the age of the universe is about 1010 years :D

Even with a quantum computer capable of running non-stop, using Shor’s algorithm, you’d need to perform 2256=2128≃1038 multiplications:

10381019=1019[years]

Let’s start out by graphically representing the addition of two points 𝐺 and 𝐴 in an elliptic curve.

One easy way to think of the addition is to draw a line that goes through 𝐺 and 𝐴, and find the third point of intersection with the curve. The symmetrical point is the result of the addition of 𝐺 and 𝐴. This is because elliptic curve have the property that any line between two points intersects the curve at most one more time.

In the case where there is no third point of intersection (i.e. the line is vertical), we define the result of the addition as the point at infinity, denoted as π’ͺοΈ€.

The resulting point 𝐡=𝐺+𝐴 is then reflected to 𝐢 over the x-axis. This symmetry property is easily explained by the fact that the curve’s 𝑦 coordinates are squared, so for a given π‘₯ coordinate, there are two possible 𝑦 coordinates, 𝑦 and βˆ’π‘¦.

The operation can then be done over and over again to find subsequent points.

[!NOTE] We will be working with Short Weierstrass form curves, which are the most common form of elliptic curves used in cryptography. The equation of the curve is 𝑦2=π‘₯3+π‘Žπ‘₯+𝑏.

Given two points 𝐴(π‘₯𝐴,𝑦𝐴) and 𝐡(π‘₯𝐡,𝑦𝐡), the resulting coordinates of the point 𝐢(π‘₯𝐢,𝑦𝐢)=𝐴+𝐡 can be found by:

  1. Finding the slope π‘š of the line between 𝐴 and 𝐡.

    π‘š=π‘¦π΅βˆ’π‘¦π΄π‘₯π΅βˆ’π‘₯𝐴
  2. Finding the π‘₯ coordinate of 𝐢 by substituting 𝑦=π‘š(π‘₯βˆ’π‘₯𝐴)+𝑦𝐴 into the curve equation.

    𝑦2=π‘₯3+7⟺(π‘š(π‘₯βˆ’π‘₯𝐴)+𝑦𝐴)2=π‘₯3+7⟺(π‘š2(π‘₯βˆ’π‘₯𝐴)2+2π‘š(π‘₯βˆ’π‘₯𝐴)𝑦𝐴+𝑦𝐴2)=π‘₯3+7βŸΊπ‘š2π‘₯2βˆ’π‘š22π‘₯𝐴π‘₯+π‘š2π‘₯𝐴2+2π‘šπ‘¦π΄π‘₯+2π‘šπ‘¦π΄π‘₯𝐴+𝑦𝐴2=π‘₯3+7

    Grouping each power of π‘₯ together nicely:

    π‘₯3βˆ’π‘š2π‘₯2+(2π‘š2π‘₯π΄βˆ’2π‘šπ‘¦π΄)π‘₯+(7βˆ’π‘š2π‘₯𝐴2βˆ’π‘¦π΄2βˆ’2π‘šπ‘¦π΄π‘₯𝐴)=0

    We have an single-variable third degree equation, and our good old friend ViΓ¨te tells us that for a polynomial 𝑃(π‘₯)=π‘Ž0+π‘Ž1π‘₯+…+π‘Žπ‘›π‘₯𝑛 of degree 𝑛, we have 𝑛 roots:

    𝑃(π‘₯)=0⟺{ π‘₯=π‘₯1 π‘₯=π‘₯2 … π‘₯=π‘₯𝑛

    Among other properties, these roots π‘₯𝑖 always satisfy:

    βˆ‘π‘–=0𝑛π‘₯𝑖=π‘₯1+π‘₯2+…+π‘₯𝑛=βˆ’π‘Žπ‘›βˆ’1π‘Žπ‘›

    Which means that in our case, we can write:

    π‘₯𝐴+π‘₯𝐡+π‘₯𝐢=βˆ’βˆ’π‘š21=π‘š2

    Because we already know that the line will intersect with 𝐴 and 𝐡 (the grouped equation will be satisfied at both π‘₯𝐴 and π‘₯𝐡), we are left with only π‘₯𝐢:

    π‘₯𝐢=π‘š2βˆ’π‘₯π΄βˆ’π‘₯𝐡
  3. Finding 𝑦𝐢 is as easy as plugging our freshly found π‘₯𝐢 into the equation of the line and reflecting it over the π‘₯-axis:

    𝑦𝐢′=π‘š(π‘₯πΆβˆ’π‘₯𝐴)+𝑦𝐴

    𝑦𝐢′ is our intermediate point before it being reflected.

    𝑦𝐢=βˆ’π‘¦πΆβ€²=βˆ’π‘š(π‘₯πΆβˆ’π‘₯𝐴)βˆ’π‘¦π΄=π‘š(π‘₯π΄βˆ’π‘₯𝐢)βˆ’π‘¦π΄

In the case where 𝐺=𝐴, we can’t really draw a line between the two points, so we take the tangent to the curve at 𝐺 and find the third point of intersection. This is the result of the addition of 𝐺 with itself, denoted as 2⋅𝐺.

To find the tangent at 𝐺(π‘₯𝐺,𝑦𝐺), we need to find the slope π‘š=𝑑𝑦𝑑π‘₯=𝑦′(π‘₯).

Differentiating both sides with respect to π‘₯, 𝑦2, which actually depends on π‘₯ can be written as 𝑦(π‘₯)2 for clarity:

(𝑦(π‘₯)2)β€²=2𝑦(π‘₯)⋅𝑦′(π‘₯)

See this as if we were differentiating 𝑒2, where 𝑒=𝑦(π‘₯).

The right side is just a function of π‘₯, so we can differentiate it as we would with any other function:

(π‘₯3+7)β€²=3π‘₯2

Our differentiated equation is:

2𝑦(π‘₯)⋅𝑦′(π‘₯)=3π‘₯2

Solving for π‘š=𝑦′(π‘₯):

𝑦′(π‘₯)=3π‘₯22𝑦(π‘₯)=π‘š

Notice that the tangent’s slope depends on both π‘₯ and 𝑦, which makes sense because we’d have two different slopes otherwise:

3π‘₯22𝑦(π‘₯)=Β±3π‘₯22π‘₯3+7

And we have our tangent equation for π‘₯𝐺 and 𝑦𝐺:

𝑑:𝑦=π‘š(π‘₯βˆ’π‘₯𝐺)+𝑦𝐺=3π‘₯𝐺22𝑦𝐺(π‘₯βˆ’π‘₯𝐺)+𝑦𝐺

Working with finite fields

Elliptic curves are defined over a finite field, which means that all operations are done modulo a prime number 𝑝. This is done to ensure that the curve has a finite number of points, which is necessary for cryptographic applications.

References and Suggested readings

  • A (Relatively Easy To Understand) Primer on Elliptic Curve Cryptography
    Nick Sullivan
    cloudflare.com

  • Elliptic Curve Cryptography (ECC)
    Svetlin Nakov
    cryptobook.nakov.com