September 23rd, 2024

Primer on Elliptic Curve Cryptography

Just dumbing down the ideas behind elliptic curve cryptography so that a highschooler can understand.

I'm going to be giving a talk that gives a quick primer on elliptic curve cryptography. But I thought I'd do a writeup on it before the presentation so that people who want to read up on it before-hand can do so. That, and also writing things down actually fleshes out what I'm about to talk about.

When building information systems, you're either storing information, or sending it somewhere else. But for every interaction you have with information, malicious actors will always be attempting to either steal or sabbotage information, impersonate someone, or fraudulently deny that they have ever committed a transaction.

Our goal is to thwart these malicious actors, and the predominant strategy for this has been to have intended actors be very easily able to disseminate and store information, while making it difficult for malicious actors to cause harm.

The Discrete Log Problem (or rather the Elliptic Curve Discrete Log Problem)

There are many strategies for difficulty, but with elliptic curves (in finite fields of prime order, which is a space we will discuss a bit later), the difficulty has been brought on by the difficulty in solving the discrete log problem.

That is, we have some function that takes two parameters of a particular group (for example, two points on an elliptic curve), which returns another element of that group. We repeatedly apply that function to a single element of that group, for a very large number of times. The result of that function invocation could be public information which is potentially used to identify an actor, along with the element that the function was applied on. Meanwhile, the very large number of times where the function was applied is private information that an actor will have derived before generating that public information. Everyone knows the public information—the result of the function invocations, and the element in which the invocation was applied to—but only the actor knows how many times they've called that function to derive that public information.

To put it in math terms, let's define some function operate\text{operate}, which takes two parameters PP and QQ of a group. What we're doing is given some publicly-known information. Where element GG, we're invoking it with some dd number of times:

operate(G,operate(G,operate(G,)))d=R\underbrace{\text{operate}(G, \text{operate}(G, \text{operate}(G, \ldots)))}_{d} = R

The element GG along with the result RR is public information, but dd is private information that should never be shared.

The basis of the elliptic curve discrete log problem is that even if we are publicly given the element GG, the result RR, and the underlying algorithm behind the hypothetical operate\text{operate} function, it should still be absolutely impossible to recover dd.

The operate\text{operate} function

Previously, we were introduced to the operate\text{operate} function, which takes two elements from a group, and returns another element from that same group.

But what does it mean to operate on two elements from a group to return an element of a group, and how does it relate to elliptic curves?

In the context of elliptic curves, we have a curve that looks like the one below:

An elliptic curve

We pick two points PP and QQ on that curve, and we draw a straight line that crosses the two points, that line will actually end up crossing a third point RR' on the curve.

The process of finding a third point on an elliptic curve

We call it RR' and not just RR is because RR' is not our result of our operateoperate function. Fortunately, finding RR from RR' is very easy: it's merely the result of vertically reflecting RR' to find RR.

And if PP and QQ are equal to eachother (e.g. P=QP = Q), then finding the result involves imagining that you are drawing a line that crosses two points that are negligibly different from each other, thus forming what is known by mathematicians a "tangent" line. And that tangent line will also cross another point, which is our RR', which we then flip veritcally to find RR.

In projective geometry, the idea of counting a tangent of a line as two distinct points is called "counting multiplicities".

Just a quick spoiler: regardless of whether you decide to draw line that crosses first with QQ or with PP, we will always get the same RR'. This effectively renders the operate\text{operate} function to have a "commutative property", that is operate(P,Q)=operate(Q,P)\text{operate}(P, Q) = \text{operate}(Q, P).

Later, we'll show that the the above elliptic curve rendered from the Weierstrass form y2=x3+ax+by^2 = x^3 + ax + b (where a,bFa, b \in \mathbb{F}), also shares associative properties.

Some math notations, and an introduction to Abelian groups

Earlier, I introduced the operate\text{operate} function. But writing it out gets a little wordy.

Mathematicians have instead opted for—rather confusingly—the infix ++ operator to express a 2-parameter operation on group elements.

That is, given two elements PP and QQ of a group, the expressed operate(P,Q)\text{operate}(P, Q) operation is instead expressed as:

P+Q=RP + Q = R

Yes, the ++ symbol is used for something that may not be intuitively an addition.

It could be argued that there is a good reason for this.

For one, even with the abbreviation, repeating the expression of several "additions", dd-number of times gets repetitive:

G+G+G++Gd=R\underbrace{G + G + G + \ldots + G}_{d} = R

So, we can just express the above as a scalar multiplication of G by the quantity dd:

G+G+G++Gd=dG=dG=R\underbrace{G + G + G + \ldots + G}_{d} = d\cdot G = dG = R

The dGdG expression is certainly a lot more compact than G+G+G++Gd\underbrace{G + G + G + \ldots + G}_{d}.

So in short, we settled with:

dG=RdG = R

Other arguments behind why is that a lot of cryptographic primitives form an Abelian group.

That is, they have the following properties:

  • Commutativity: the expression A+BA + B can equally be expressed as B+AB + A
  • Associativity: regardless of if you compute (A+B)+C(A + B) + C or A+(B+C)A + (B + C), the results will be the same
  • Existence of an identity element: given some element II, we can compute A+I=AA + I = A
  • Existence of an inverse: that is, not only do we have some AA, but also some AA', such that A+A=IA + A' = I. And in the case of Abelian groups that attempt to allude to the concept of an "addition", rather than expressing A+AA + A', we'd express AA=IA - A = I, analogous to a subtraction.

In the context of elliptic curve group operations (called "addition" going forward), the identity element isn't left to some variable name of II, of course. That will be discussed later.

Abelian group scalar multiplications

Earlier I mentioned that we are computing some dGdG such that we are repeatedly applying G+G+GGG + G + G \ldots G, all the way until GG has been added dd number of times.

The problem is that dd can be a ridiculously large number. Sometimes a number so large, by some estimates, it exceeds the total number of atoms in the known universe!

If computers are really bad at iterating over the number of atoms in a glass of water, there is no way we're going to be able to compute a number as large as the total number of atoms in the unverse, or anything near it!

Good thing is, Abelian groups have an associative property.

Thanks to this, we can group operations together.

For example, in the expression G+G+G+GG + G + G + G, rather than computing ((G+G)+G)+G((G + G) + G) + G, instead, let's compute (G+G)+(G+G)=2G+2G=4G(G + G) + (G + G) = 2G + 2G = 4G.

When we first compute the left set of additions 2G2G, we already know the value of the second 2G2G, thus saving us a computation.

And we can boadly apply this to eight additions.

G+G+G+G+G+G+G+G=2G+2G+2G+2G=4G+4G=8GG + G + G + G + G + G + G + G = 2G + 2G + 2G + 2G = 4G + 4G = 8G

This should yield just 3 computations rather than 8.

The double and add algorithm

We see that there is potential to cutting down computations from O(d)O(d) to just O(log2d)O(log_2d).

But the algorithm above implies that we're using something similar to dynamic programming. That is, to memoize individual results.

This requires O(log2d)O(log_2d) of auxiliary space.

We can do better. We can reduce that down to just O(1)O(1) auxiliary space.

This is where the double and add algorithm comes in.

The basic gist of the algorithm is this:

  • start with some identity element as the result RR
  • convert the number dd into binary digits, and iterate through each digits from most-significant bit, down to the last significant bit
    • if the digit 11 is encountered, set RR to 2R+G2R + G
    • otherwise set RR to 2R2R

Now you've saved time from O(d)O(d) down to O(log2d)O(log_2d), with no auxiliary space required.

Possible Side-Channel attack

So with the double and add algorithm, we see that one branch of the if-statement runs two operations, where as the other only computes one.

Problem is, someone can be snooping in on CPU cycles and use it to recover the secret number!

A mitigation to the side-channel attack is to resort to the Montgomery ladder.

Why is it easy to go one way but hard the other

It's easy to go one way because we're able to look at the binary structure of an integer, but going the other way is effectively a really difficult search problem, and there are just no (known) shortcuts.

Math of drawing lines across elliptic curves

I introduced the curve, that we call the "elliptic curve". But of course, it's difficult to draw such a curve perfectly. Not to mention, computers can't work with drawings very well.

Instead, they can work with math.

They have support for additions, subtractions, exponentiation, etc.

So let's use good old math for this.

Elliptic curves can be expressed as the equation:

y2=x3+ax+by^2 = x^3 + ax + b

That equation describes what is known as a "Weierstrass form", which knowing this name may be useful when discussing ECC.

Of course xx and yy are variables that relate to eachother, but aa and bb are constants that we pick right before we interact with others.

Regardless, now our problem is, if we happened to have picked two points PP and QQ on a curve, how would we find the xx-coordinate of the third point, and the corresponding yy-coordinate?

Here is where we will do some derivations for the math to recover those values.

Projective Geometry

In high school, when drawing two parallel lines, both will remain parallel forever.

This is called affine geometry.

However, with elliptic curves as used in cryptography, we're going to be taking advantage of another branch of geometry called projective geometry.

Projective geomoetry shares all the same properties of affine geometry, but one important facet of projective geometry that we're going to take advantage of is that parallel lines are not parallel in projective geometry.

Instead, they intersect at a point, and that point is the point at infinity.

We'll see later that this is a powerful concept that we can take full advantage of.

Finding the x-coordinate of the third point

Let's define P=(x1,y1)P = (x_1, y_1) as a point on the curve and Q=(x2,y2)Q = (x_2, y_2) on that same curve.

We'll first need to define the equation of the line that is secant to PP and QQ, and it will be this:

y=mx+βy = mx+\beta

Where we can think of mm as the slope of the line, and dd is where the line intercepts at the y-coordinate, when x=0x = 0, or simply known as the "yy-intercept".

Our mm isn't just any value; it's dependent on the positions of PP and QQ, for PQP \neq Q, and QPQ \neq -P. To compute the slope, it's merely the "rise over the run", or rather the rate of change of yy, with respect to xx. In other words, it's a ratio, and the ratio is computed by calculating the differences in the y coordinates with respect to the x-coordinates.

So:

m=y2y1x2x1m = \frac{y_2 - y_1}{x_2 - x1}

To find the yy-intercept β\beta, we'd simply sample a point on the equation of the line, and solve for dd. We'll just take the coordinates from PP.

β=y1mx1\beta = y_1 - mx_1

OK, this is nice to know and all, but what can we do with this?

Well, we need to find the third point on the curve.

Can we use algebra for this?

We can see that both the equation of the line, and the equation of the curve have a yy-coordinate.

How about we do a substitution? After all, the points on the line intersect with the points of the curve. Does this mean that both the line and the curve will intersect at all three points? Let's try:

y2=x3+ax+b(mx+β)2=x3+ax+by^2 = x^3 + ax + b \Rightarrow (mx+\beta)^2 = x^3 + ax + b

We can see that the left-hand side is quadratic with respect to x, and the right-hand side is cubic. Subtracting a quadratic from a cubic will still yield a cubic equation.

Let's do that.

(mx+β)2=x3+ax+b0=x3+ax+b(mx+β)2=x3+ax+bm2x22mxββ2=x3m2x2+(a2mβ)x+(bβ2)\begin{align} (mx+\beta)^2 = x^3 + ax + b \Rightarrow 0 & = x^3 + ax + b - (mx+\beta)^2 \\ & = x^3 + ax + b - m^2x^2 - 2mx\beta - \beta^2 \\ & = x^3 - m^2x^2 + (a - 2m\beta)x + (b - \beta^2) \end{align}

Now, here is a property that you have to remember: for cubic polynomials—such as the one that we derived on the right-hand side of the equation above—there are three possible values of xx that we can plug in for the equation to hold (e.g. the cubic polynomial to equal zero).

Let's call them x1x_1, x2x_2, and x3x_3.

We're getting close. We already know x1x_1 and x2x_2. Now all we need to do is find x3x_3.

Let's reinterpret the polynomial from above into some other polynomial where we re-express the constant coefficients of the polynomial as some other set of constants:

x3m2x2+(a2mβ)x+(bβ2)=a3x3+a2x2+a1x+a0x^3 - m^2x^2 + (a - 2m\beta)x + (b - \beta^2) = a_3x^3 + a_2x^2 + a_1x + a_0

Where a3=1a_3 = 1, a2=m2a_2 = m^2, a1=(a2mβ)a_1 = (a - 2m\beta), a0=(bβ2)a_0 = (b - \beta^2).

We can infer this from factorizing the cubic expression like so:

a3x3+a2x2+a1x+a0=a3(x3+a2a3x2+a1a3x+a0a3)=a3(xx1)(xx2)(xx3)\begin{equation} \begin{split} a_3x^3 + a_2x^2 + a_1x + a_0 & = a_3(x^3 + \frac{a_2}{a_3}x^2 + \frac{a_1}{a_3}x + \frac{a_0}{a_3}) \\ & = a_3(x-x_1)(x-x_2)(x-x_3) \end{split} \end{equation}

Expanding the right-hand side of the above equation should yield:

a3x3a3(x1+x2+x3)x2+a3(x1x2+x1x3+x2x3)xa3x1x2x3a_3x^3 - a_3(x_1 + x_2 + x_3)x^2 + a_3(x_1x_2 + x_1x_3 + x_2x_3)x - a_3x_1x_2x_3

Now, from the earlier derivation of our polynomial, we saw that the coefficient associatd with a3a_3 is just 11, so we can simply get rid of the a3a_3

That is:

x3(x1+x2+x3)x2+(x1x2+x1x3+x2x3)xx1x2x3x^3 - (x_1 + x_2 + x_3)x^2 + (x_1x_2 + x_1x_3 + x_2x_3)x - x_1x_2x_3

And also, remember, that above polynomial should equal to the one we derived earlier.

x3(x1+x2+x3)x2+(x1x2+x1x3+x2x3)xx1x2x3=x3m2x2+(a2mβ)x+(bβ2)x^3 - (x_1 + x_2 + x_3)x^2 + (x_1x_2 + x_1x_3 + x_2x_3)x - x_1x_2x_3 = x^3 - m^2x^2 + (a - 2m\beta)x + (b - \beta^2)

Now let's focus on the second term of both of the polynomials. We see that the second term are equal to each other.

(x1+x2+x3)x2=m2x2-(x_1 + x_2 + x_3)x^2 = -m^2x^2

Just get rid of the x2x^2 and the negative, and we get:

x1+x2+x3=m2x_1 + x_2 + x_3 = m^2

And we can finally solve for x3x_3:

x3=m2x1x2x_3 = m^2 - x_1 - x_2

Finding the y-coordinate of the third point

Finally, to solve for y3y_3, we just plug everything into the equation of the line:

y3=mx3+βy_3 = mx_3 + \beta

What if the two points on the curve are equal to each other?

So, what if two points on the curve are equal to each other.

This would mean that if we naively plug in m=y2y1x2x1=00m = \frac{y_2 - y_1}{x_2 - x_1} = \frac{0}{0}, which is indeterminate.

This means that we will need to think outside the box.

A primer on differential calculus

The trick to do is to pretend that we have a point that slightly differs on the curve, where the difference is so small, it may as well be 0, but we still get the slope of it.

I'm not going to go over the entire math behind it. But the gist of it goes like this.

Given some function ff, we want to find the instantaneous rate of change with respect to its input.

That is, as some value aa approaches the input xx of f(x)f(x), we will get the differentation at point xx, written as ddxf(x)\frac{d}{dx}f(x), defined as the limit of f(x)f(a)xa\frac{f(x) - f(a)}{x - a}, as aa approaches xx.

As a short-hand, the above can be written like so:

ddxf(x)=limaxf(x)f(a)xa\frac{d}{dx}f(x) = \lim_{a\rightarrow x}\frac{f(x) - f(a)}{x - a}

Alternative as some value hh approaches 00, we will get the differentation at point xx, written as ddxf(x)\frac{d}{dx}f(x), defined as the limit of f(x+h)f(x)x+hx\frac{f(x + h) - f(x)}{x + h - x}, as hh approaches 00.

It can be abbreviated to:

ddxf(x)=limh0f(x+h)f(x)x+hx=limh0f(x+h)f(x)h\frac{d}{dx}f(x) = \lim_{h\rightarrow 0}\frac{f(x + h) - f(x)}{x + h - x} = \lim_{h\rightarrow 0}\frac{f(x + h) - f(x)}{h}

Effectively, ddxf(x)\frac{d}{dx}f(x) is giving you the slope of some line at point (x,f(x))(x, f(x)).

We're just going to go over one example, and afterwards, I'm just going to include some common patterns that have been discovered.

The beauty of the "limit" operator as denoted by limxaf(x)\lim_{x\rightarrow a}f(x) is saying that we want to know what does the expression f(x)f(x) tend to as xx approaches aa. We might not know much about the value at aa, but we can give something that is pretty much the answer that we have been looking for.

This is great for functions where a function is not defined at aa.

Let's take the function x2x\frac{x^2}{x}. The function x2x\frac{x^2}{x} is indeterminate at x=0x = 0, even though x2x=x\frac{x^2}{x} = x. So, the limit expression limx0x2x\lim_{x\rightarrow 0}\frac{x^2}{x} is saying that we are going to find some expression that x2x\frac{x^2}{x} approaches as aa approaches 00. And the limit operator will help us reveal that the limit of x2x\frac{x^2}{x} as xx approaches 00 is simply 0.

limx0x2x=limx0x=0\lim_{x\rightarrow 0}\frac{x^2}{x} = \lim_{x \rightarrow 0}x = 0

Now onto computing an ifinitesimally small change in x to find the slope at xx.

Let's take the example of f(x)=x2f(x) = x^2. The slope at xx is derived as follows:

ddxx2=limh0(x+h)2x2h=limh0x2+2xh+h2x2h=limh02xh+h2h=limh0(2x+h)=limh02x+limh0h=2x+0=2x\begin{equation} \begin{split} \frac{d}{dx}x^2 &= \lim_{h\rightarrow 0}\frac{(x + h)^2 - x^2}{h} \\ &= \lim_{h\rightarrow 0}\frac{x^2 + 2xh + h^2 - x^2}{h} \\ &= \lim_{h\rightarrow 0}\frac{2xh + h^2}{h} \\ &= \lim_{h\rightarrow 0}(2x + h) \\ &= \lim_{h\rightarrow 0}2x + \lim_{h\rightarrow 0}h \\ &= 2x + 0 \\ &= 2x \end{split} \end{equation}

Therefore ddxx2=2x\frac{d}{dx}x^2 = 2x.

There are many more rules like this.

Here's a handful of rules:

  • Constant rule: ddxc=0\frac{d}{dx}c = 0
  • Identity rule: ddxx=1\frac{d}{dx}x = 1
  • Sum rule: ddxfFf(x)=fFddxf(x)\frac{d}{dx}\sum_f^{F}f(x)=\sum_f^F\frac{d}{dx}f(x)
  • Product rule: ddx(f(x)g(x))=f(x)ddxg(x)+(ddxf(x))g(x)\frac{d}{dx}(f(x)g(x)) = f(x)\frac{d}{dx}g(x)+(\frac{d}{dx}f(x))g(x)
  • Chain rule: ddxf(g(x))=ddg(x)f(g(x))ddxg(x)\frac{d}{dx}f(g(x)) = \frac{d}{dg(x)}f(g(x))\frac{d}{dx}g(x)

Then we can compose those above rules to create more rules.

For example, the coefficient rule is a combination of the constant rule and product rule:

ddxcf(x)=cddxf(x)+(ddxc)f(x)=cddxf(x)+0f(x)=cddxf(x)\frac{d}{dx}cf(x) = c\frac{d}{dx}f(x) + (\frac{d}{dx}c) f(x) = c\frac{d}{dx}f(x) + 0f(x) = c\frac{d}{dx}f(x)

And then, there is the positive integer power rule, which is just the product rule recursively applied, all the way until we reach the identity and constant rule.

I'll leave it as a exercise to prove that the positive integer power rule is pretty much ddxxn=nxn1\frac{d}{dx}x^n = nx^{n-1}, e.g. xdxx3=3x2\frac{x}{dx}x^3 = 3x^2.

Deriving the slope of the line at a point on the elliptic curve

OK, now that we have summarized some differentiation rules above, let's go ahead and derive the equation of the curve that will help us find the slope of the line tangent to a point curve.

Recall that the equation of the curve is defined as:

y2=x3+ax+by^2 = x^3 + ax + b

Also recall that ddxf(x)\frac{d}{dx}f(x) is the slope of the point at (x,f(x))(x, f(x)), pretending that we're trying to find a slope of the points (x,f(x))(x, f(x)) and (x+h,f(x+h))(x + h, f(x + h)), as hh approaches 0.

In math terms, we're looking for some mm such that:

m=limh0f(x)f(x+h)x+hxm = \lim_{h \rightarrow 0} \frac{f(x) - f(x + h)}{x + h - x}

In the equation of the curve, we're actually trying to find the change in yy with respect to xx.

This means we're trying to find m=dydxm = \frac{dy}{dx}.

We're going to apply the ddx\frac{d}{dx} operator on both sides of the equation.

dy2dx=ddx(x3+ax+b).\frac{dy^2}{dx} = \frac{d}{dx}(x^3 + ax + b).

Trying to find dy2dx\frac{dy^2}{dx}, and then ultimately derive dydx\frac{dy}{dx} will require some clever hacks. We'll get back to it later.

Let's start with the right-hand side.

dy2dx=ddx(x3+ax+b)=ddxx3+ddxax+dbdx=3x2+addxx+0=3x2+a\begin{equation} \begin{split} \frac{dy^2}{dx} &= \frac{d}{dx}(x^3 + ax + b) \\ &= \frac{d}{dx}x^3 + \frac{d}{dx}ax + \frac{db}{dx} \\ &= 3x^2 + a\frac{d}{dx}x + 0 \\ &= 3x^2 + a \\ \end{split} \end{equation}

Therefore dy2dx=3x2+a\frac{dy^2}{dx} = 3x^2 + a.

Now, onto the left-hand side of the equation.

What we're interested in is what happens to yy for some xx. You can think of yy being a function of xx.

So, we can go with chain rule.

The chain rule will give the derivative as the product of the differentation dy2dy\frac{dy^2}{dy} and dydx\frac{dy}{dx}

dy2dx=3x2+ady2dydydx=2ydydx=\begin{equation} \begin{split} \frac{dy^2}{dx} &= 3x^2 + a \\ \frac{dy^2}{dy}\frac{dy}{dx} &= \\ 2y\frac{dy}{dx} &= \end{split} \end{equation}

So, we get 2ydydx=3x2+a2y\frac{dy}{dx} = 3x^2 + a.

And remember, we're trying to find m=dydxm = \frac{dy}{dx}.

So, isolating dydx\frac{dy}{dx} from the resulting equation and we get:

dydx=m=3x2+a2y\frac{dy}{dx} = m = \frac{3x^2 + a}{2y}

What if the two points are vertical reflections of each other?

At this point, we stop.

We just assume the result is a point at infinity.

And recall that "adding" a point PP to a point QQ that is a mirror reflection of PP is as if Q=PQ = -P, and P+Q=P+(P)=PP=P + Q = P + (-P) = P - P = \infty.

Summary of elliptic curve "addition"

When two points are different, for P=(x1,y1)P = (x_1, y_1) and Q=(x2,y2)Q = (x_2, y_2) the slope is simply defined as:

m=y2y1x2x1m = \frac{y_2 - y_1}{x_2 - x1}

And for P=QP = Q, then we use the derivative:

m=3x2+ay2m = \frac{3x^2 + a}{y2}

The yy-intercept of the line is defined as:

d=y1mx1d = y_1 - mx_1

Finally, to find the third point:

y3=mx3+βy_3 = mx_3 + \beta

And if Q=PQ = -P, then we do nothing, and just have the "addition" yield the point at infinity.

Relating back to Abelian groups

Commutativity

As we can see, drawing a straight line that crosses between two points PP and QQ also crosses a third point on the curve. This is true regardless of from which direction you decided to draw that line. Did you decide to have that line cross PP first, or QQ first? The result is the same! The order doesn't matter.

Associativity

What's cool about this is that we can also apply this operation with three points PP, QQ, and SS.

Regardless of if you start by attempting to find some R1R_1 by first drawing a line through PP and QQ, or through QQ and SS, after you've drawn a line through R1R_1 and the remaining point where you didn't "add" yet, you'll still get the same R2R_2.

Not convinced?

Stay tuned for the proof.

Identity element

This is where Mathematicians used their imagination.

It may sometimes be emphasized that PP and QQ shouldn't be vertical reflections of each other?

What happens if they are?

The resulting line will never intersect anywhere on the curve in affine geometry, but instead will intersect at a point at infinity in projective geometry, which we will denote as \infty.

It may sound blasphemous, but there is an important opportunity for us here.

For one, we can treat this as the "identity element".

Imagine if PP and QQ were indeed vertical reflections of each other.

Then computing P+QP + Q will give us \infty.

How can we use the fact that there exists some \infty that we can play around with?

Well, imagine if we have PP, and draw a perfectly vertical line that crosses PP.

It will of course go on for \infty. We can think of this as P+P + \infty. Now, the thing about crossing PP and \infty, it will also cross some point that is a reflection of PP.

And remember the operation: the idea is, once we've crossed a third point, we reflect vertically!

This means that crossing PP and \infty will cross the vertical reflection of PP, which we will call PP', and doing so will require flipping vertically, thus giving us PP again.

This means that P+P + \infty yield PP, or P+=PP + \infty = P.

Existence of an inverse

I've already mentioned earlier that if PP and QQ were vertical reflections of each other, then we get some point at infinity denoted as \infty. In other words P+Q=P + Q = \infty, only if PP and QQ are vertical reflections of each other.

But if P+=PP + \infty = P, is there a PP=P - P = \infty?

Yes!

If PP is a vertical reflection of QQ, then this merely means that QQ could simply be denoted as P-P.

In other words, "negation" is merely the act of vertically reflecting PP.

Bonus: Proof of Associativity

Commutativity is obvious: regardless of which direction you start to draw the line between PP and QQ, you will always land on the same point (P+Q)-(P + Q).

But associativity is a bit more tricky.

For many, it's not enough to look at a drawing and be satisfied by the associative properties. Is there a case for some PP, QQ, and RR, such that (P+Q)+RP+(Q+R)(P + Q) + R \neq P + (Q + R)?

Fortunately, we have proof that this will not be the case.

Using Bezout's Theorem

Given two polynomials of degrees mm and nn, then they will intersect at exactly mnmn points (counting multiplicity), and no more unless they have a component in common.

If we are to draw lines that are the result of summing (A+B)+C(A + B) + C, we see that it yields 3 lines, and all 3 lines will intersect at exactly 9 points.

Likewise for A+(B+C)A + (B + C).

If we are to treat both sets of lines as curves on a projective plane, then both sets of lines can be thought of as cubic polynomials, and all of them will intersect at exactly 9 points, including the points crossing (A+B)+C(A + B) + C and A+(B+C)A + (B + C).

Using Cayley-Bacharach theorem

Given three points PP, QQ, and RR on an elliptic curve, we aim to show that (P+Q)+R=P+(Q+R)(P+Q)+R=P+(Q+R).

To prove associativity, we will utilize the Cayley–Bacharach theorem, which asserts that for any cubic curve over an algebraically closed field, if the curve passes through any eight points, it also passes through a ninth point (counting multiplicities), including the point at infinity.

Consider the set of points: RR, P+QP + Q, PP, QQ, (P+Q)−(P + Q), Q+RQ + R, (Q+R)−(Q + R), and the point at infinity. Suppose we construct two lines: one passing through PP and QQ intersecting the curve again at P+QP+Q, and another passing through QQ and RR intersecting the curve again at Q+RQ + R. By reflecting these sums P+QP + Q and (Q+R)(Q + R) about the curve, we obtain points (P+Q)−(P+Q) and (Q+R)−(Q+R).

These intersections provide us with two groups of lines whose intersections with the cubic yield eight distinct points (considering each pair of points contributes an intersection). By the Cayley–Bacharach theorem, any cubic passing through these eight points must also pass through a ninth point, which is exactly where (P+Q)+R(P+Q)+R intersects the curve, and also where P+(Q+R)P+(Q+R) intersects.

If these points were different, the sets would intersect at a tenth distinct point, violating Bézout's theorem, which states that a line and a cubic can intersect at no more than three points. Thus, we conclude that (P+Q)+R=P+(Q+R)(P+Q)+R=P+(Q+R), proving associativity.

How the Cayley-Bacharach theorem work

By Bezout's Theorem, we're effectively saying that two cubics C1C_1 and C2C_2 in projective space with no common components will intersect at 99 points (counting with multiplicity). If a C3C_3 passes through all 9 points (counting multiplicity) of the intersections of C1C_1 and C2C_2, then C3C_3 can only be expressed as the linear combination a1C1+a2C2=C3a_1C_1 + a_2C_2 = C_3, where a1,a2Fa_1,a_2 \in \mathbb{F}, by the properties of projective geometry. That is, the degrees of freedom has been restricted to only pass through the 99 points.

Building on this, the Cayley-Bacharch theorem further refines our understanding of these intersections. The Cayley-Bacharch theorem implies that if C3C_3 shares eight of the nine intersections of that of C1C_1 and C2C_2, then it must also pass through the ninth intersection point.

Applying this back to the intersections of 3 lines with the curve, what we're trying to do is that if we have a curve, intersect 3 lines on that curve, then constructing a third curve will necessarily require that the third curve is a linear combination of the curve and the 3 lines.

The general idea is, once the first 8 points have already been selected, the degrees of freedom that we now have is highly constrained, to the point that all three curves are linearly dependent on all 9 points.

N.B. multiple lines on a plane forms a polynomial

So earlier I seemed to have treated distinct lines as a single polynomial curve.

Is that even legal?

Yes.

We're all familiar with the equation of the line of the form y=mx+βy = mx + \beta.

But there is nothing stopping us from interpreting it as the impiclit equation 0=mx+βy0 = mx + \beta - y.

As we can see, that equation of the line is effectively a polynomial. What happens if we compute the product of several lines to give us a polynomial, that is for example (m1x+b1)(m2x+b2)(m3x+b3)=0(m_1x+b_1)(m_2x+b_2)(m_3x+b_3) = 0?

Well, if we are to plot out the result of the implicit polynomial, this would yield a curve that looks no different than as if all lines were entirely distinct!

Try it out yourself.

Elliptic curve in finite fields

In the above derivations, if you are familiar with high school math, you'd think that we were working with real numbers.

Yes, perhaps the math would work with real numbers.

But the math would work with whatever math there is with a concept known as "field".

Real numbers are fields.

But cryptography doesn't always work with real numbers.

What they instead work with is finite fields of prime order.

Problem: computers are really bad with real numbers

Computers are really bad with real numbers.

Yes, two CPUs implementing the exact same architecture will come up with the same exact numbers, given the same exact set of instructions, but not everyone is on the same CPU architecture. At the time of writing this, people on their laptops are often on Intel-based systems. Apple has made the push for something based on ARM. And a lot of smartphones are also on ARM-based CPUs. And not to mention, RISC-V is a new contender in the CPU architecture space.

Every one of them will give you different results.

Not to mention, different implementation details will ultimately end up yielding different results. And even small discrepancies can really throw everything off.

Solution? Work exclusively with integers?

We could perhaps ditch real numbers and aim for integers.

But here's the problem with integers: they don't have a very good definition for a multiplicative inverse.

The division problem

Before we start computing divisions of integers, we got to ask ourselves: what is a divison?

Well, as far as humans and counting is concerned, divisions is just trying to discover how many times can one number fit into another.

For example, how many times can 33 fit into 1212? The answer is 44.

But if we are to think strictly in terms of group theory, a divison ab\frac{a}{b} is to take some aa and multiplying it by the multiplicative inverse of bb. That is, the multiplicative inverse of bb is some quantity cc such that bc=1bc = 1, which is impossible with integers.

Group theory and the multiplicative inverse

Recall that in an Abelian group, we have four properties:

  • Commutativity
  • Associativity
  • Identity element
  • Inverse

With integer addition and multiplication we get commutativity and associativity. We may have an identity element with additions, but multiplications? What do we get?

Well, we still get 1, but if we are to multiply two integers aa and bb, can we ever get the number 11?

Of course, with integers this is literally impossible.

Forget real numbers; forget integers. Finite fields of prime order is here to save the day

So we just found out we may have some "identity" element with integers. But we lose the multiplicative inverse with integers. That is, there can never exist two integers aa and bb where their product will yield 11.

This is where we ditch real numbers and the integer space, but instead work with another much smaller integer space called finite fields of prime order.

Working within a finite field means to work with integers 00 to p1p - 1, where pp is a prime number.

The math with finite fields is very similar to integers and real numbers, but like elliptic curve groups, the "+" operator and—now—multiplication works slightly differently.

All operations not only give the "addition" (as intuitively understood by the act of addition, since we were taught in elementary and high school), but additions greater than equal to the prime pp wraps around.

For example, given some finite field with prime p=13p = 13, the sum 10+410 + 4 would yield 11. The expression is similar to the integer arithmetic (10+4) mod 13=1(10 + 4) \text{ mod } 13 = 1, but mathematicians prefer to "abbreviate" things using the congruence 10+41 (mod p)10 + 4 \equiv 1 \text{ }(\text{mod } p), with—in our—p=13p = 13.

With finite fields, we most certainly have Abelian group properties, for both the additive and multiplicative groups, but the multiplicative aspects also has one additional property: distributivity.

That is, a(b+c)=ab+aca(b + c) = ab + ac.

Finite fields actually saving the day for multiplicative inverses

Other than distributivity, we also retain the one important property: multiplicative inverse.

That is, given some aa, we can find some bb such that:

ab1 (mod p)ab \equiv 1 \text{ }(\text{mod } p)

Again, this is possible, because the modulo operator forces everything to just "wrap around", and we want to find some bb (the multiplicative inverse of aa) such that their products "wrap around" to the value 11.

Notation for multiplicative inverse

In real numbers, the expression 1a\frac{1}{a} can also be expressed as a1a^{-1}.

Likewise for finite fields.

And better yet, we can express the property of the multiplicative inverse as:

aa1a1a1 (mod p)aa^{-1} \equiv a^{-1} a \equiv 1 \text{ }(\text{mod } p).

Modular arithmetics

OK, so I used the mod\text{mod} operator previously.

For those not familiar with that operator, it's pretty much a facet of math that we were taught roughly around the 4th grade.

It's the idea of "division with remainder". This "4th grader math" has the fancy name "Euclidean division", which is named after the mathematician who is known for having formalized and documented it in his work.

It goes like this: take for example the division 1010 divided by 44.

44 does not divide 1010.

But 44 does fit into 1010 up to 22 times, which would yield the number 88. What remains is 22.

The mod\text{mod} operator only cares about the remainder in a Euclidean divison, which in the case of the division 1010 divided by 44, the modulo 10 mod 4=210 \text{ mod } 4 = 2.

Multiplicative inverses in finite fields

OK, with finite fields, we can most certainly have an aa and a bb such that their product yields 1 (mod p)1 \text{ }(\text{mod } p) (where pp is a prime). Such an operation is literally impossible with integers, but possible with finite fields.

But now, how do we find the multiplicative inverse?

Perhaps using the greatest common divisor (gcd\text{gcd})?

For the record, the gcd\text{gcd} function takes two integers, and attempts to find their greatest common divisor.

So, if we are to pick some integer 0<a<p0 < a < p, where pp is prime, then the gcd(a,p)=1\text{gcd}(a, p) = 1.

We may be onto something.

There's also Bezout's identity.

It stipulates that the gcd(a,b)\text{gcd}(a, b) is the linear combination:

ax+by=gcd(a,b)ax + by = \text{gcd}(a, b)

That is, we can find some x, and some y, such that the above linear combination holds true.

But in the case of aa and pp, where—recall that—pp is prime, we get:

ax+py=gcd(a,p)=1ax + py = \text{gcd}(a, p) = 1

If we compute the modulo of both sides, we get

(ax+py) mod p=((ax mod p)+(py mod p)) mod p(ax + py) \text{ mod } p = ((ax \text{ mod } p) + (py \text{ mod } p)) \text{ mod } p

In the above equation, because pypy is a multiple of pp, then py mod ppy \text{ mod } p effectively "wraps" around to 00.

So then

((ax mod p)+(py mod p)) mod p=((ax mod p)+0) mod p=(ax mod p)((ax \text{ mod } p) + (py \text{ mod } p)) \text{ mod } p = ((ax \text{ mod } p) + 0) \text{ mod } p = (ax \text{ mod } p)

And thus

ax+pyaxgcd(a,p)1 (mod p)ax + py \equiv ax \equiv \text{gcd}(a, p) \equiv 1 \text{ }(\text{mod } p)

The multiplicative inverse

To find the multiplicative inverse, we can take full advantage Bezout's Identity.

Again, in modular arithmetic:

ax+pygcd(a,p)1 (mod p)ax + py \equiv \text{gcd}(a, p) \equiv 1 \text{ }(\text{mod } p)

And remember py0 (mod p)py \equiv 0 \text{ }(\text{mod } p) cancels out, so we're left with:

axgcd(a,p)1 (mod p)ax \equiv \text{gcd}(a, p) \equiv 1 \text{ }(\text{mod } p)

We can then use the extended Euclidean algorithm to derive Bezout's identity.

And remember, the whole idea of the multiplicative inverse is that there exists some aa and bb, such that their product yields 11. This means, using Bezout's identity, we can effectively find the multiplicative inverse quite easily.

Euclidean algorithm

Before we talk about the extended Euclidean algorithm, let's first talk about the Euclidean algorithm.

The Euclidean algorithm is just a fancy word for an algorithm that repeatedly applies the Euclidiean division between a dividend and divisor, all the way until we reach 0.

The Euclidean algorithm can be succinctly defined as the recurrence:

gcd(a,b)={aif b=0gcd(b,a mod b)otherwise\text{gcd}(a, b) = \begin{cases} a &\text{if } b = 0 \\ \text{gcd}(b, a\text{ mod } b) &\text{otherwise} \end{cases}

Extended Euclidean

We've seen a very simple algorithm to compute the greatest common denominator of two (positive) integers.

Now onto the extended Euclidean algorithm, which should help us find the coefficients xx an yy in Bezout's identity, ax+ay=gcd(a,b)ax + ay = gcd(a, b).

If aa and bb isn't a representation of the base case (that is b=0b = 0), then the above equation can also be expressed as:

ax+by=gcd(a,b)=gcd(b,a mod b)ax + by = gcd(a, b) = gcd(b, a \text{ mod } b)

But, careful, just because gcd(a,b)=gcd(b,a mod b)gcd(a, b) = gcd(b, a \text{ mod } b), doesn't mean that ax+byax + by is bx+(a mod a)ybx + (a \text{ mod } a)y.

Instead, the xx and the yy are something different, so we'll use xx' and yy', that is:

ax+by=bx+(a mod b)y=gcd(a,b)ax + by = bx' + (a \text{ mod } b)y' = gcd(a, b)

So, we will need to do more algebraic manipulation to make finding xx and yy easy.

The trick would be to look at one definition of the modulo operator.

One plausible definition of the operator a mod ba \text{ mod } b is

aabb=(a mod b)a - \lfloor\frac{a}{b}\rfloor b = (a \text{ mod } b)

So we can rewrite the above equation representing one level below the start of the recursion as:

bx+(aabb)y=bx+ayabby=ay+b(xaby)=gcd(a,b)\begin{equation} \begin{split} bx' + (a - \lfloor\frac{a}{b}\rfloor b)y' &= bx' + ay' - \lfloor\frac{a}{b}\rfloor by' \\ &= ay' + b(x' - \lfloor\frac{a}{b}\rfloor y') \\ &= gcd(a, b) \end{split} \end{equation}

Now we see that

ax+bx=ay+b(xaby)ax + bx = ay' + b(x' - \lfloor\frac{a}{b}\rfloor y')

And we can see that x=yx = y' and y=xabyy = x' - \lfloor\frac{a}{b}\rfloor y'.

Of course, the expression ay+b(xaby)ay' + b(x' - \lfloor\frac{a}{b}\rfloor y') doesn't really tell us much about xx and yy itself. But, we will get a good insight once we reach the base case.

Recall that going one level below the recursion to gives us ay+b(xaby)ay' + b(x' - \lfloor\frac{a}{b}\rfloor y') which is also equal to bx+(a mod b)ybx' + (a \text{ mod } b)y'.

We can clearly draw the parallel between gcd=gcd(b,a mod b)gcd = gcd(b, a \text{ mod } b). So not only does gcd\text{gcd} have a base case, but so will the recurrence equation.

Once we reach the base case, we'll just set x=1x' = 1, and yy' shouldn't matter, since bb is equal to zero.

We're going to write some psuedopython to represent the recurrence.

We're not actually going to return some equation. Instead, we're just going to return the xx, and yy coefficients.

def extended_gcd(a, b):
    if b is 0:
        return (1, 1)
    x1, y1 = extended_gcd(b, a % b)
    return (y1, x1 - (a//b)*y1)

Divisions in finite field

In real numbers, divisions are just that: divisions.

With integers, I did mention divisions become problematic when attempting to naively divide two numbers as if we were trying to divide real numbers.

For example, 104\frac{10}{4} yields 2.52.5 in real numberes, but things get awkward in integers.

Recall also that in real numbers, that there indeed exists some aa and bb such that ab=1ab = 1. This is because a multiplicative inverse for aa exists in real numbers. Nothing like that exists in integers.

And this is why we use finite fields.

Finite field math is often coupled with modular arithmetics, and modular arithmetics pretty much has things "wrap around". With the help of the extended Euclidean algorithm, when attempting to find the modular inverse of aa, we're looking for something that when multiplied by it, the product will "wrap around" to 11.

I've also mentioned that a notation for 1a\frac{1}{a} in real numbers is a1a^{-1}, and we can do the same in finite fields.

Better yet, many mathematicians express the congruence aa1a1a1(mod p)aa^{-1} \equiv a^{-1}a \equiv 1 (\text{mod } p) (where pp is prime) as just

aa1 (mod p)\frac{a}{a} \equiv 1 \text{ }(\text{mod } p)

This brings us to divisions in finite field.

Divisions in finite field simply involves finding the multplicative inverse of the denominator (a.k.a. the divisor). Once found the multiplicative inverse, we take that value and multiply the "dividend" with the computed multiplicative inverse.

The cyclic group

Elliptic curves in finite field forms not only an Abelian group, that is, it satisfies the commutative, associative, identity, and inverse properties, but it also forms a cyclic group.

What it means for something to be a cyclic is that there exists some element in the group—called the Generator—such that its scalar multiplication or exponentiation yields every element in the group.

In the case of elliptic curves, given the coefficients aa and bb for the Weierstrass equation, and the prime field, there exists a finite number of points on the curve, denoted as nn. In a lot of these curves, ther could exist one point GG on the curve such that for every coefficient dd in 0,1,2,,n{0, 1, 2, \ldots, n}, the multiple dGdG will yield every point on the curve. In this case, GG is known as the generator.

Putting it all together

We've defined the math of finding a third point on an elliptic curve. The act of flipping that "third point" on the curve vertically is the algorithm of an elliptic curve group "addition".

Now that we know about the math, let's put this all together with finite field math.

Recall that real numbers form a field.

Not only is the computation of a third point on the curve can be done in the real number field, but we can also do the same computation with finite field of prime order. Since finite fields are fields, the curve equation works perfectly with finite fields.

The only difference being that everything happens modulo a prime for the finite field, and that division isn't simply the act of finding how many times the divisor fits inside the dividend, but instead, we compute the multiplicative inverse, such that the product of the divisor aa by the multiplicative inverse of aa yield aa11(mod p)aa^{-1} \equiv 1 (\text{mod } p) (where a1a^{-1} is the multiplicative inverse, and that pp is prime).

Application to cryptography

Elliptic curve group arithmetic in finite field of prime order is the math that is used to take full advantage of the hardness of the solution to the discrete log problem. And because it is known to be difficult to solve (on a classical computer), it is an excellent cryptographic primitive for various cryptographic schemes in cybersecurity applications.

First thing's first: public and private keys

The discrete log problem stipulates that given some 2-parameter group operation (such the elliptic curve "addition"), given some positive integer dd, and a group element GG, we can compute the scalar multiplication nG=RnG = R, where having access to GG and/or RR is not at all adequate to find the integer dd. In order to recover dd, we will actually need to physically steal it.

Thus, the integer dd can be regarded as private information, and GG, and RR can be shared publicly.

In real-world applications, GG is typically some standardized parameter, such as the G variable that is defined in the secp256r1 specification. Thus GG is never explicitly shared by either communicating parties, but instead has been agreed upon, and already known by everyone, and ahead of time.

The only thing that "belongs" to someone is the scalar multiplication nGnG. For example, Alice can generate her secret number dAd_A, and she can use it to derive dAGd_A G. She would share the result of the scalar multiplication dAGd_A G, but she will never share dAd_A on it's own; it's a secret. Again, by the nature of the hardness of the discrete log problem dAd_A can never be extracted from dAGd_A G.

In the real world, dAd_A is the private key, and dAGd_A G is the public key.

The curve parameters

When Alice and Bob wants to engage in a transaction that involves elliptic curves, it is a good idea for them to work with provably secure parameters that many applications are aware of.

Earlier I mentioned "secp256r1".

secp256r1 is an example of standard curve parameters.

It stipulates

  • the order of the finite field pp (the prime number that represents the order of the field, which is the total number of elements in the field)
  • the value of the aa and bb coefficients of the equation in Weierstrass form
  • the generator point GG

The parameters also includes numbers that would have otherwise needed to be computed, such as the order of the curve nn–which is the total number of points on the curve, including the point at infinity.

In fact, the nn will be the most helpful, since it's ideal if coefficients avoid ever equaling nn, since doing so will yield the point at infinity.

How these points are chosen

Typically, cryptographers would pick some arbitrary prime pp, and points aa and bb. Then count the total number of points on the curve to derive nn. If nn is a prime, there would only ever be one cyclic subgroup, and thus one generator GG, such that multiplying it with every value dd in 1,2,3,n{1, 2, 3, \cdots n} will yield every point on the curve, including the point at infinity.

Next is to find some point GG such that nGnG yields the point at infinity.

Thus we have our aa, bb, and pp parameters of our curve, and the derivations of the order nn, and our generator GG, such that nG=nG = \infty.

Key exchange, for encryption

ECC isn't typically used for encryption.

That said, we can use ECC for deriving a shared secret, which is then used against a symmetric cipher, such as AES.

So we've established that extracting the scalar coefficient in an elliptic curve scalar multiplication is prohibitively difficult to do.

We've also established that ellitpic curve arithmetic forms an Abelian group, with associative properties.

This means that not only can Alice derive her public key dAGd_A G, but she can then send it to Bob, so that Bob, using his private key dBd_B can derive dBdAGd_B d_A G. And Bob can likewise send his public key dBGd_B G to Alice, and she can then compute dAdBGd_A d_B G.

And due to the commutative nature, dAdBG=dBdAGd_A d_B G = d_B d_A G.

Both Alice and Bob should land on the same value on the Elliptic curve, and neither of them will have ever shared dAd_A nor dBd_B, and no one can extract those values.

How shared secrets are used

Typically, once the shared curve point on an elliptic curve has been established, the xx-coordinate of the curve point is used as the input to a key-derivation function (KDF).

Typically, the KDF used is HKDF. It has the most provable security, and it is strongly resistant against key material weakness.

For HKDF, we need some cryptographically-secure salt, and our derived xx-coordinate from our key exchange. Once derived, we should then have a secure key, from which it is impossible to derive the shared xx-coordinate.

The derived key and a plaintext is then input into a cipher, such as AES-256-GCM (of course, along with cryptographically-random initialization vector).

The decryptor will then take the derived key to decrypt the message.

Digital signatures

Digital signatures involves having Alice prove that she sent a message, by "signing" it using her private key, and Bob can then "verify" the signature against the message using Alice's public key.

The most widely used digital signature algorithm is ECDSA.

This is how it works.

Let's say Alice wants to send a message mm to Bob, and she signs it using her private key dAd_A.

Alice would send to Bob two values, represented in the following tuple:

(r,s)=((kG)x,HASH(m)+(kG)xdAk)(r, s) = ((kG)_x, \frac{\text{HASH}(m) + (kG)_xd_A}{k})

Where kk is a totally random number between 11 and n1n - 1, and HASH\text{HASH} is some hash function such as SHA256SHA-256.

And note: that tuple does not represent any point on the curve! rr and ss are two distinct values.

Alice sends (r,s)(r, s) to Bob, and when Bob wants to verify the signature using Alice's public key QAQ_A, he'd compute

HASH(m)sG+rs(QA)=R\frac{\text{HASH}(m)}{s}G+\frac{r}{s}(Q_A) = R

Bob will absolutely know that the signature is valid if Rx=rR_x = r

How digital signature verification works

Even though Bob has no clue about the values kk and dAd_A that was used by Alice to compute how rr and ss, but as long as Bob is aware of the overall algorithm, he can know how to derive kGkG, even if he doesn't know kk.

Expanding the above HASH(m)sG+rsQA\frac{\text{HASH}(m)}{s}G+\frac{r}{s}Q_A, we get

HASH(m)sG+rsQA=HASH(m)HASH(m)+(kG)xdAkG+(kG)xHASH(m)+(kG)xdAkdAG\frac{\text{HASH}(m)}{s}G+\frac{r}{s}Q_A = \frac{\text{HASH}(m)}{\text{HASH}(m)+(kG)_xd_A}kG + \frac{(kG)_x}{\text{HASH}(m)+(kG)_xd_A}kd_AG

From the above equation, we can factor out kGHASH(m)+(kG)xdA\frac{kG}{\text{HASH}(m)+(kG)_xd_A}

HASH(m)HASH(m)+(kG)xdAkG+(kG)xHASH(m)+(kG)xdAkdAG=(HASH(m)+(kG)xdA)kGHASH(m)+(kG)xdA\frac{\text{HASH}(m)}{\text{HASH}(m)+(kG)_xd_A}kG + \frac{(kG)_x}{\text{HASH}(m)+(kG)_xd_A}kd_AG = (\text{HASH}(m)+(kG)_xd_A)\frac{kG}{\text{HASH}(m)+(kG)_xd_A}

Then the denominator cancels out parts of the nominator, and finally all we are left with is kGkG, from which, the xx-coordinate should equal to Alice's supplied rr.

Conclusion

Elliptic curve cryptography leverages group operations on an elliptic curve in finite fields of prime order, in projective plane geometry.

Multiplying the generator GG of the curve by some dd will yield some point dGdG in O(log2n)O(log_2n) time by taking advantage of elliptic curve Abelian commutative properties, without ever revealing to anyone what dd is. Most importantly, there are no known efficient algorithm to recover dd without an exhaustive search. In other words, easy to compute one way, but hard to go the other, which is the basis of most cryptosystems.

We're then able to exploit this property and use it in various cryptographic use cases. The simplest example is deriving a shared secret between Alice and Bob, by having them share each other's publicly available point on the curve, then having each of them then multiply it with their own secret number to derive the shared secret.