Skip to content
This repository was archived by the owner on Mar 24, 2022. It is now read-only.

Commit dd28d42

Browse files
committed
Minor changes and added double and add algorithm for scalar multiplication in Elliptic Curves
1 parent dcd4db2 commit dd28d42

File tree

6 files changed

+76
-12
lines changed

6 files changed

+76
-12
lines changed

Elliptic-Curves/Pictures/2.jpg

15.9 KB
Loading

Elliptic-Curves/Pictures/20.gif

1.77 KB
Loading

Elliptic-Curves/Pictures/21.gif

718 Bytes
Loading

Elliptic-Curves/Pictures/8.gif

-35 Bytes
Loading

Elliptic-Curves/README.md

Lines changed: 76 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,28 @@ Prerequisites:
55
2. [Cyclic Groups](https://masterpessimistaa.wordpress.com/2018/01/14/dlp-and-baby-step-giant-step-algorithm/)
66
3. [Discrete Logarithm Problem](../Discrete-Logarithm-Problem)
77

8-
To start with Elliptic Curve Cryptography we will first have to see various aspects involved in it. This tutorial is an attempt to help people understand Elliptic Curves better and dive deeper into the concepts of ECC as we move forward step by step. This tutorial includes implementation and explanation of the following:
8+
To start with Elliptic Curve Cryptography we will first have to see various aspects involved in it. This tutorial is an attempt to help people understand Elliptic Curves better and dive deeper into the concepts as we move forward step by step. This tutorial includes implementation and explanation of the following:
99
1. Defining Elliptic Curves
1010
2. Mathematics behind Elliptic Curves (painful?)
1111
+ Point Arithmetic
12-
+ Dot operation or Point Addition
12+
+ Point Addition
1313
+ Point Doubling
1414
+ Scalar Multiplication
15-
+ Optimisation algorithms- how have they improved over the years
15+
+ Double and Add algorithm
16+
+ Montgomery Ladder [To be added]
1617

1718

1819

1920
## Elliptic Curves- definition
2021
Consider the polynomial ![picture2](Pictures/2.gif). All the solutions of this polynomial, when plotted in a graph will look something like this:
21-
![picture3](https://i.imgur.com/dt89o8U.png)
22-
This polynomial has some very interesting properties and a modified version of this polynomial is used for cryptographic purposes. Elliptic Curves provide security with relatively smaller key sizes when compared to other public key systems such as RSA, Discrete Logarithm Problem, Diffie Hellman Key Exchange etc. The original polynomial mentioned above is not used directly, as it is favorable to have the curve over a finite set (particularly Finite Fields) than to have it defined over real numbers, for cryptographic purposes. We will see one such popular form of the polynomial which is used as an Elliptic Curve, and can be defined over ![picture1](Pictures/1.gif) as the following:
22+
![picture3](Pictures/1.png)
23+
*Source: https://blog.cloudflare.com/a-relatively-easy-to-understand-primer-on-elliptic-curve-cryptography/*
2324

24-
> An Elliptic Curve over ![picture1](Pictures/1.gif) with p>3, is the set of all pairs (x, y) in ![picture1](Pictures/1.gif) that satisfy ![picture4](Pictures/4.gif), along with an arbitrary value, where ![picture5](Pictures/5.gif)
25+
This polynomial has some very interesting properties and a modified version of this polynomial is used for cryptographic purposes. Elliptic Curves provide security with relatively smaller key sizes when compared to other public key systems such as RSA.
26+
27+
The original polynomial mentioned above is not used directly, as it is favorable to have the curve over a finite set (particularly Finite Fields) than to have it defined over real numbers, for cryptographic purposes. We will see one such popular form of the polynomial which is used as an Elliptic Curve, and can be defined over ![picture1](Pictures/1.gif) as the following:
28+
29+
> An Elliptic Curve over ![picture1](Pictures/1.gif) with p>3, is the set of all pairs (x, y) in ![picture1](Pictures/1.gif) that satisfy ![picture4](Pictures/4.gif), along with an arbitrary point 0, where ![picture5](Pictures/5.gif)
2530
2631

2732
In this tutorial, we will first define operations on Elliptic Curve over _real numbers_ and then formulate the same for Elliptic Curves over _Finite Fields_.
@@ -50,9 +55,10 @@ We can calculate `C` geometrically with the help of following steps:
5055
> 2. Reflect the point obtained along the x-axis and on the curve. This mirrored point is point C.
5156
5257

53-
To understand it better have a look at this GIF below taken from Nick Sullivan's blog post on Elliptic Curves- [https://blog.cloudflare.com/a-relatively-easy-to-understand-primer-on-elliptic-curve-cryptography/](https://blog.cloudflare.com/a-relatively-easy-to-understand-primer-on-elliptic-curve-cryptography/):
58+
To understand it better have a look at this GIF:
5459

5560
![picture](Pictures/9.gif)
61+
*Source: https://blog.cloudflare.com/a-relatively-easy-to-understand-primer-on-elliptic-curve-cryptography/*
5662

5763
Now that we have defined point addition geometrically, let us formulate the same arithmetically with the help of observations noted from geometric definition of point addition:
5864
1. We know that A, B, C' (C' is the reflection of point C along x-axis) lie on the curve as well the line joining A=(x<sub>1</sub>, y<sub>1</sub>), B=(x<sub>2</sub>,y<sub>2</sub>). Our approach will be to first calculate the coordinates of C' and then we can simply negate the y-coordinate of C' keeping the x-coordinate as it is to get coordinates of C. We can write:
@@ -77,28 +83,86 @@ You can find an implementation of the above discussed method in python here: [el
7783
Point Doubling is similar to Point Addition, just that the formula for calculating slope is different, rest of the formulae for getting the coordinates of x<sub>3</sub> and y<sub>3</sub> are the same. We will first define point doubling geometrically and then define it arithmetically. Please note here `doubling` is just a notation, the operation that takes place on point lying on the curve is very different from normal doubling.
7884

7985
Consider a point P=(x<sub>3</sub>, y<sub>3</sub>) that we want to `double`. We can calculate 2P with the help of following steps:
80-
> 1. Draw a tangent on the curve through P and obtain a second point of interesection between the curve and the line.
86+
> 1. Draw a tangent on the curve through P and obtain a second point of intersection between the curve and the line.
8187
> 2. Reflect the point obtained along the x-axis and on the curve. This mirrored point is 2P.
8288
8389

84-
![picture](https://i.imgur.com/jd3LBjO.jpg)
90+
![picture](Pictures/2.jpg)
8591

8692

8793
We can also understand it using Point Addition: Consider addition two points P and Q on an Elliptic Curve, as Q approaches P, the line joining the two points to `add` these points approaches closer and as Q becomes very very close to P, the line becomes a tangent at point P.
8894

95+
Formula for slope will be different, as we have only one point on the curve and we want to compute the slope of its tangent, let us see how we can do it:
96+
1. We know that ![picture](Pictures/2.gif). Differentiating both sides of this equation with respect to x, we get:
97+
2. ![picture](Pictures/20.gif)
98+
3. Thus, with the given point (x<sub>1</sub>, y<sub>1</sub>), we can write `m` as:
99+
+ ![picture](Pictures/21.gif), where `m` is slope of the tangent passing through the point P
100+
89101
Arithmetically, we can express coordinates of 2P as:
90102
> ![picture](Pictures/19.gif)
91103
> Here m is the slope of the tangent passing through P
92104
93105

94106
You can find an implementation of the above method in python here: [ellipticcurve.py](ellipticcurve.py) and in sage here(lesser lines of code): [ellipticcurve.sage](ellipticcurve.sage)
95107

108+
## Scalar Multiplication
109+
There are two algorithms for implementing scalar multiplication in Elliptic Curves:
110+
1. Double and Add algorithm
111+
2. Montgomery Ladder
112+
113+
We will see how to implement each algorithm and also discuss why Montgomery ladder is preferred over Double and Add algorithm.
114+
115+
### Double and Add Algorithm
116+
This is a very simple algorithm for multiplication of a point with a scalar. Let us try to first understand multiplication of two scalars `a` and `b` using double and add, and then apply the same logic for points on an Elliptic Curve.
117+
Suppose you want to multiply 5 = (101)<sub>2</sub> by 11 = (1011)<sub>2</sub>
118+
1. We can write: 5\*11 = 5 \* (1\*2<sup>0</sup> + 1\*2<sup>1</sup> + 0\*2<sup>2</sup> + 1\*2<sup>3</sup>)
119+
+ 5\*11 = 5\*1\*2<sup>0</sup> + 5\*1\*2<sup>1</sup> + 5\*0\*2<sup>2</sup> + 5\*1\*2<sup>3</sup>
120+
2. For each term starting from the left, corresponding bit of `b` (ie equal to 11 in our example) is multiplied with a*2<sup>i</sup>, where i = 0,...,n (`n` is number of bits of `b` minus 1)
121+
+ All the terms are then added together to give the result
122+
123+
Let us implement this algorithm for multiplying two scalars `a` and `b`:
124+
```python
125+
def doubleandadd(a, b):
126+
res = 0
127+
addend = a
128+
for i in bin(b)[2:][::-1]:
129+
if i == "1":
130+
res = res + addend
131+
addend *= 2
132+
return res
133+
```
134+
135+
We can apply the same for Elliptic Curves, the only difference is that instead of `a` we have a point `P` lying on an Elliptic Curve `E`:
136+
137+
```python
138+
from sage.all import *
139+
# Declaring parameters of Elliptic Curve
140+
# Select appropriate values of p, a, b
141+
142+
# Declaring a Weierstrass Curve
143+
E = EllipticCurve(GF(p), [a, b])
144+
145+
def doubleandadd(E, P, b):
146+
# P is a point on the Elliptic Curve E
147+
148+
# (0:1:0) are projective coordinates of arbitrary point at infinity
149+
res = E((0, 1, 0))
150+
addend = P
151+
for i in bin(b)[2:][::-1]:
152+
if i == "1":
153+
res = res + addend
154+
addend = addend * 2
155+
return res
156+
```
157+
[Projective coordinates of points on Elliptic Curves](https://math.stackexchange.com/questions/1973640/elliptic-curve-point-op-zero-point-p)
96158

97159
## Resources
98160
There are some pretty cool resources on ECC which you can refer:
99-
1. [Nick Sullivan's blog post on Elliptic Curves](https://blog.cloudflare.com/a-relatively-easy-to-understand-primer-on-elliptic-curve-cryptography/)
100-
2. [Introduction to Cryptography by Christof Paar- Introduction to Elliptic Curves](https://www.youtube.com/watch?v=vnpZXJL6QCQ)
101-
3. [Introduction to Cryptography by Christof Paar- Elliptic Curve Cryptography](https://www.youtube.com/watch?v=zTt4gvuQ6sY)
161+
1. [Andrea Corbellini- Gentle Introduction to Elliptic Curves](https://andrea.corbellini.name/2015/05/17/elliptic-curve-cryptography-a-gentle-introduction)
162+
2. [Andrea Corbellini- Finite Fields and Discrete Logarithms](https://andrea.corbellini.name/2015/05/23/elliptic-curve-cryptography-finite-fields-and-discrete-logarithms/)
163+
3. [Nick Sullivan- Primer on Elliptic Curves](https://blog.cloudflare.com/a-relatively-easy-to-understand-primer-on-elliptic-curve-cryptography/)
164+
4. [Introduction to Cryptography by Christof Paar- Introduction to Elliptic Curves](https://www.youtube.com/watch?v=vnpZXJL6QCQ)
165+
5. [Introduction to Cryptography by Christof Paar- Elliptic Curve Cryptography](https://www.youtube.com/watch?v=zTt4gvuQ6sY)
102166

103167

104168

0 commit comments

Comments
 (0)