Elleptic Curve
Elleptic Curve
Elleptic Curve
- By
Introduction
When someone sends bitcoin to you, they send the bitcoin to your address. If
you want to spend any of the bitcoin that is sent to your address, you create a
transaction and specify where your bitcoin ought to go. Such a transaction
may look like:
Of course, anyone can create a transaction that looks like the one above, so if
it was added to the blockchain as is and without issue, then you would be out
$30,000+ whether you like it or not. Luckily, such a transaction does not
belong in the blockchain, because it is missing a valid digital signature. By
adding a digital signature, you can prove that you know the private key that
corresponds to the address 1A1zP1eP5QGe 2DMPTfTL5SLmv7DivfN. If you
don’t know the corresponding private key, then you probably shouldn’t have
https://hackernoon.com/what-is-the-math-behind-elliptic-curve-cryptography-f61b25253da3 1/17
9/29/2019 What is the math behind elliptic curve cryptography? - By
been telling people to send bitcoin to you via that address since you are
unable to spend any of the bitcoin sent there!
When you create a bitcoin address for yourself (or an address/account for any
other cryptocurrency), you generate the private key rst. From the private key,
you compute the corresponding public key and by hashing that public key you
get your address. Hopefully you can’t choose an address rst and then
determine the private key from that, otherwise you could determine the
private key for any address using the same method. What is Satoshi’s address
again?
Public-key cryptography
Public keys, private keys, and digital signatures form the basic components of
public-key cryptography. No matter what mathematical basis is used to
implement a public-key cryptographic system, it must satisfy the following, at
least for our purposes:
What is an elliptic curve? An elliptic curve consists of all the points that satisfy
an equation of the following form:
y² = x³+ax+b
https://hackernoon.com/what-is-the-math-behind-elliptic-curve-cryptography-f61b25253da3 2/17
9/29/2019 What is the math behind elliptic curve cryptography? - By
Notice that all the elliptic curves above are symmetrical about the x-axis. This
is true for every elliptic curve because the equation for an elliptic curve is:
y² = x³+ax+b
And if you take the square root of both sides you get:
y = ± √x³+ax+b
So if a=27 and b=2 and you plug in x=2, you’ll get y=±8, resulting in the points
(2, -8) and (2, 8).
The elliptic curve used by Bitcoin, Ethereum, and many other cryptocurrencies
is called secp256k1. The equation for the secp256k1 curve is y² = x³+7. This
curve looks like:
Point addition
https://hackernoon.com/what-is-the-math-behind-elliptic-curve-cryptography-f61b25253da3 3/17
9/29/2019 What is the math behind elliptic curve cryptography? - By
You know how you can add two numbers together to get a third number? You
can add two points on an elliptic curve together to get a third point on the
curve.
To add two points on an elliptic curve together, you rst nd the line that goes
through those two points. Then you determine where that line intersects the
curve at a third point. Then you reflect that third point across the x-axis (i.e.
multiply the y-coordinate by -1) and whatever point you get from that is the
result of adding the rst two points together.
Let’s take a look at an example of this. Let’s say you want to add the following
two points together:
First, you nd the line that goes through the two points:
https://hackernoon.com/what-is-the-math-behind-elliptic-curve-cryptography-f61b25253da3 4/17
9/29/2019 What is the math behind elliptic curve cryptography? - By
Then you nd the third point on the curve that the line intersects:
https://hackernoon.com/what-is-the-math-behind-elliptic-curve-cryptography-f61b25253da3 5/17
9/29/2019 What is the math behind elliptic curve cryptography? - By
Therefore, P+Q=R.
For example, let’s say we have the following curve with base point P:
https://hackernoon.com/what-is-the-math-behind-elliptic-curve-cryptography-f61b25253da3 6/17
9/29/2019 What is the math behind elliptic curve cryptography? - By
Now let’s add P to itself. First, we have to nd the equation of the line that
goes through P and P. There are in nite such lines! In this special case, we opt
for the tangent line.
Now we nd the “third” point that this line intersects and reflect it across the
x-axis.
https://hackernoon.com/what-is-the-math-behind-elliptic-curve-cryptography-f61b25253da3 7/17
9/29/2019 What is the math behind elliptic curve cryptography? - By
We can continue to add P to itself to compute 4•P and 5•P and so on.
The base point used by secp256k1 curve has the following x- and y-
coordinates:
x-coordinate:
550662630222773436695787188951685343262506034537775941755001873603891167
y-coordinate:
326705100207588169780830851305070431844712733806592432759389043357573374
In the examples above, a different base point is used so that all the point
addition operations t in a small window.
Speeding up point addition
How many steps would it take to compute 10•P? It would appear to take nine
steps, because 10•P is
P+P+P+P+P+P+P+P+P+P
https://hackernoon.com/what-is-the-math-behind-elliptic-curve-cryptography-f61b25253da3 8/17
9/29/2019 What is the math behind elliptic curve cryptography? - By
It turns out that you can compute 10•P in just four steps. This is because the
following property holds for point addition:
n•P+r•P = (n+r)•P
For example:
P+P = 2•P
2•P+2•P = 4•P
4•P+4•P = 8•P
2•P+8•P=10•P
How many steps would it take to compute x•P, where x is a random 256-bit
integer? In this case, x can range anywhere from 0 to 1.1579209e+77.
It turns out that computing x•P would never require more than 510 point
addition operations. Here’s why. First, compute the following series:
You can calculate the above series with 255 point addition operations,
because there are 256 points, and you can get from one point to the next by
adding the current point to itself. This is because 2^n•P+2^n•P = 2^(n+1)•P.
The rst point, 2⁰•P, is given. 2⁰•P=1•P=P.
The next step is to nd the binary expansion of x. For example, if x is 246, the
binary expansion will be 2⁷ + 2⁶ + 2⁵ + 2⁴ +2² + 2¹ = 246. Then we multiply the
binary expansion of x by P: 2⁷•P + 2⁶•P + 2⁵•P + 2⁴•P + 2²•P + 2¹•P. Then we
simply add all these points together to get 246•P. We don’t have to compute
the individual points 2¹•P, 2²•P, … , 2⁷•P since we calculated them earlier.
At most the binary expansion of x will contain 256 elements (2⁰ up to 2²⁵⁵), so
we won’t ever have to add more than 256 points together, and thus, the
second step will require at most 255 point addition operations. Thus,
computing x•P will take at most 255+255=510 point addition operations.
https://hackernoon.com/what-is-the-math-behind-elliptic-curve-cryptography-f61b25253da3 9/17
9/29/2019 What is the math behind elliptic curve cryptography? - By
Let’s say I compute x•P, where x is a random 256-bit integer. The result will be
some point on the curve. Let’s call that point X.
If I give you X, could you determine x? In other words, could you determine
how many times I added P to itself to get the point X on the curve? Let’s
assume that you know what P is and you know what curve I was using.
It turns out that is not feasible for you to gure out x, even if you had a super
computer. There is no known algorithm for determining x, so your only option
is to keep adding P to itself until you get X or keep subtracting P from X until
you get P. On average, x will be somewhere between 0 and 2²⁵⁶-1, about 2¹²⁸.
Thus, it will take you on average 2¹²⁸ point addition operations to determine x
no matter your approach. Even if your computer could do one trillion point
addition operations per second and you had been running your computer
since the beginning of the universe, you would’ve only done 2⁹⁸ point addition
operations by now. 2⁹⁸/2¹²⁸ =1/1073741824.
What if you start in the middle? You can calculate 2¹²⁸•P in 510 steps or less
after all. Well, on average, x is no closer to 2¹²⁸ than it is to 0 or 2²⁵⁶-1, because
x is random, so it doesn’t matter where you start — you will still have to do 2¹²⁸
point addition operations on average.
So, because someone can’t gure out x given X, where X=x•P, it might be
convenient to make x your private key and X your public key. Your private key
would then be a random 256-bit integer and your public key would be the x-
and y- coordinates of a point on an elliptic curve. This would satisfy the
following property of private and public keys:
Before we get into proving to someone that you know x, we should update our
elliptic curve model.
https://hackernoon.com/what-is-the-math-behind-elliptic-curve-cryptography-f61b25253da3 10/17
9/29/2019 What is the math behind elliptic curve cryptography? - By
One of the problems with our current model is that x•P might result in a point
whose x- and y-coordinates can’t be stored in a standard 512-bit public key.
Either the x- or y-coordinate could be too long.
The solution is to de ne our elliptic curve over a nite eld. Basically, we’ll
make sure that there are only integer points and that there is a limit to how
large the coordinates of a point can get.
To do this we transform
y² = x³+ax+b
to
https://hackernoon.com/what-is-the-math-behind-elliptic-curve-cryptography-f61b25253da3 11/17
9/29/2019 What is the math behind elliptic curve cryptography? - By
So what happens when you add two points together and the line that goes
between those two points goes outside of the bounds before intersecting a
third point? You wrap the line around the con nes!
In the picture above, you can see how adding P and Q together requires
wrapping the line “between” P and Q around the con nes several times.
Despite these changes to our model, everything we have discussed so far still
applies.
So if you compute X=x•P, where x is a random 256-bit integer, how can you
prove to someone that you know the x that corresponds to X without revealing
any useful information about x?
n•P+r•P = (n+r)•P
https://hackernoon.com/what-is-the-math-behind-elliptic-curve-cryptography-f61b25253da3 12/17
9/29/2019 What is the math behind elliptic curve cryptography? - By
If you expand the right-hand side of the equation above, you will get the left-
hand side, so the equation above holds for any m, r, and n.
So now we have:
Okay, here’s the claim: if you can provide an m, R, and s that satisfy the above
equation, then this proves that you know the x corresponding to the X in the
equation, where x•P=X.
For this to be the case, the following two conditions must be met:
1. If you know x, then you should be able to provide working values for m, R,
and s.
2. If you don’t know x, then you should not be able to provide working
values for m, R, and s.
If you know x, you can clearly come up with working values for m, R, and s.
Choose random values for m and r, then compute R=r•P and s=hash(m)*x+r. If
you plug these values into hash(m,R)•X+R=s•P, then you get:
which is the equation that we said would hold earlier for any m, r, and n (x is n
in this case).
What if you don’t know x? Could you come up with working values for m, R,
and s? The problem is that you would have to solve hash(m,R)•X+R=s•P.
Basically, you would have to nd an input for a hash that has a speci c hash
value, which is not possible, or at least it’s not computationally feasible,
because of the preimage resistance property of cryptographic hash functions.
https://hackernoon.com/what-is-the-math-behind-elliptic-curve-cryptography-f61b25253da3 13/17
9/29/2019 What is the math behind elliptic curve cryptography? - By
If you provide working values for m, R, and s, can anything useful about x be
gleaned from those values?
m and R have nothing to do with x, so those values can’t reveal any useful
about x.
Since they don’t know r, they can’t compute x from s. They can’t obtain r from
the fact that R=r•P (they are given R), because that’s the same as determining
how many times P would have to be added to itself to get R, which is the same
computationally infeasible problem that prevents someone from determining
x from X.
s also doesn’t reveal any information about x, such as “x must be less than
yadda yadda”. If r is generated randomly and we allow hash(m, R)*x+r to
overflow so r can be any 256-bit integer, then the value for s is completely
random, meaning s could be any 256-bit integer. A random 256-bit integer
tells you just as much as about x as the GDP of New Zealand does.
Digital signatures
m, R, and s can be used to prove that one knows the x that corresponds to X,
where X=x•P. Verifying the proof requires plugging m, R, and s into
hash(m,R)•X+R=s•P. Can we make it so that a speci c message is required for
the veri cation to be successful, so that the proof — m, R, and s — forms a
digital signature for that message? Yes!
Let m be that speci c message and R and s be the digital signature for that
message. The veri cation process would then only be successful if the
speci c message, m, is plugged into the veri cation equation. If a different
value for m is plugged in, then the left-hand side of hash(m,R)•X+R=s•P would
fail to equal the right-hand side, because s was calculated using a different
message.
https://hackernoon.com/what-is-the-math-behind-elliptic-curve-cryptography-f61b25253da3 14/17
9/29/2019 What is the math behind elliptic curve cryptography? - By
Thus, one can prove that they know the private key, x, that corresponds to a
public key, X, for a speci c message, m, by providing a digital signature R and
s for m.
Conclusion
When you want to send bitcoin or ether from your address to another address,
you create a transaction. You set m to the unsigned part of that transaction,
and compute R and s from that m. Then you attach R and s to the transaction.
After you broadcast your transaction, any node will be able to verify that m
(the unsigned part of the transaction), R, and s satisfy hash(m,R)•X+R=s•P.
This of course assumes that you also include X in your transaction, since your
public key cannot be determined from your address. For Ethereum, instead of
providing X you provide v, which allows one to determine X from R and s.
The end
Well, that’s the end of it! If you made it this far and understood almost
everything, then congratulations! If you want a higher level explanation of
elliptic curve cryptography (more mathematical), then check out this link. This
is my rst article, so let me know if there are any mistakes and please leave
feedback.
# Cryptocurrency
https://hackernoon.com/what-is-the-math-behind-elliptic-curve-cryptography-f61b25253da3 15/17
9/29/2019 What is the math behind elliptic curve cryptography? - By
Email Address *
TOPICS OF INTEREST
Raiden Network
Sep 19
# Ethereum
Sebastian Gerske
Dec 20
# Blockchain
https://hackernoon.com/what-is-the-math-behind-elliptic-curve-cryptography-f61b25253da3 16/17
9/29/2019 What is the math behind elliptic curve cryptography? - By
Alex Wang
Mar 28
# Cryptocurrency
BlockEx
# Ripple
Anthony Xie
# Startup
Help
About
Start Writing
Sponsor:
Brand-as-Author
Sitewide Billboard
Contact Us
Privacy
Terms
https://hackernoon.com/what-is-the-math-behind-elliptic-curve-cryptography-f61b25253da3 17/17