a
This commit is contained in:
parent
1884515c6b
commit
49ecbae990
1 changed files with 18 additions and 8 deletions
|
@ -35,10 +35,9 @@ production, but it's not great for understanding the algorithm.
|
||||||
## Basic Ideas
|
## Basic Ideas
|
||||||
|
|
||||||
ECC starts with the idea that starting with an elliptic curve formula like $y^2
|
ECC starts with the idea that starting with an elliptic curve formula like $y^2
|
||||||
= x^3 + ax + b$ that operates over a finite field $\mathbb{F}_p$, and defining a
|
= x^3 + ax + b$ that operates over a finite field $\mathbb{F}_p$, and defining
|
||||||
_custom_ addition operation over two points, you can form a cyclic structure
|
an addition operation over two points, you can form a cyclic structure where
|
||||||
where adding a point to itself some number of times gets you back where you
|
adding a point to itself some number of times gets you back where you started.
|
||||||
started.
|
|
||||||
|
|
||||||
The interesting thing about this cyclic structure is that given the starting
|
The interesting thing about this cyclic structure is that given the starting
|
||||||
point $G$, also called the **generator** and some number $n$, you can find the
|
point $G$, also called the **generator** and some number $n$, you can find the
|
||||||
|
@ -80,12 +79,13 @@ import (
|
||||||
)
|
)
|
||||||
```
|
```
|
||||||
|
|
||||||
> You can run this blog post using [Markout]:
|
> This is a [literate document][literate]. You can run this blog post using [Markout]:
|
||||||
> ```
|
> ```
|
||||||
> markout -l go content/posts/2022-03-03-learn-by-implementing-elliptic-curve-crypto.md > /tmp/ecc.go
|
> TODO:
|
||||||
> go run /tmp/ecc.go
|
|
||||||
> ```
|
> ```
|
||||||
|
|
||||||
|
[literate]: https://en.wikipedia.org/wiki/Literate_programming
|
||||||
|
|
||||||
### Math primitives
|
### Math primitives
|
||||||
|
|
||||||
```go
|
```go
|
||||||
|
@ -96,8 +96,18 @@ type Point struct {
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Addition on $P$ and $Q$ is defined by first finding the line $PQ$, determining
|
||||||
|
the point $-R$ where it intersects the curve again, and then returning $R$. We
|
||||||
|
can find the line $PQ$ by using high school geometry:
|
||||||
|
|
||||||
|
$$\begin{aligned}
|
||||||
|
(y - y_0) = m(x - x_0)
|
||||||
|
\end{aligned}$$
|
||||||
|
|
||||||
```go
|
```go
|
||||||
func (a Point) Add(b Point) Point {
|
func (A Point) Add(B Point) Point {
|
||||||
|
// Find the slope between points A and B.
|
||||||
|
slope := big.NewRat(A.y - B.y, A.x - B.x)
|
||||||
return Point{}
|
return Point{}
|
||||||
}
|
}
|
||||||
```
|
```
|
Loading…
Reference in a new issue