From 49ecbae99026ebfbdfbc878d980ef14dbbba0052 Mon Sep 17 00:00:00 2001 From: Michael Zhang Date: Sun, 6 Mar 2022 20:00:00 -0600 Subject: [PATCH] a --- ...-by-implementing-elliptic-curve-crypto.md} | 26 +++++++++++++------ 1 file changed, 18 insertions(+), 8 deletions(-) rename content/posts/{2022-03-03-learn-by-implementing-elliptic-curve-crypto.md => 2022-03-04-learn-by-implementing-elliptic-curve-crypto.md} (82%) diff --git a/content/posts/2022-03-03-learn-by-implementing-elliptic-curve-crypto.md b/content/posts/2022-03-04-learn-by-implementing-elliptic-curve-crypto.md similarity index 82% rename from content/posts/2022-03-03-learn-by-implementing-elliptic-curve-crypto.md rename to content/posts/2022-03-04-learn-by-implementing-elliptic-curve-crypto.md index 28bd759..25de63d 100644 --- a/content/posts/2022-03-03-learn-by-implementing-elliptic-curve-crypto.md +++ b/content/posts/2022-03-04-learn-by-implementing-elliptic-curve-crypto.md @@ -35,10 +35,9 @@ production, but it's not great for understanding the algorithm. ## Basic Ideas 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 -_custom_ addition operation over two points, you can form a cyclic structure -where adding a point to itself some number of times gets you back where you -started. += x^3 + ax + b$ that operates over a finite field $\mathbb{F}_p$, and defining +an addition operation over two points, you can form a cyclic structure where +adding a point to itself some number of times gets you back where you started. 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 @@ -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 -> go run /tmp/ecc.go +> TODO: > ``` +[literate]: https://en.wikipedia.org/wiki/Literate_programming + ### Math primitives ```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 -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{} } ```