0.3 Elliptic Curve Cryptography

To create a decentralized ledger, we need a way for users to authenticate their transactions without relying on a central authority. This is where Elliptic Curve Cryptography (ECC) comes in.

Elliptic Curve Cryptography is a form of asymmetric cryptography that provides the same security as traditional methods like RSA but with much smaller key sizes. This efficiency makes it well-suited for use in blockchain and cryptocurrencies.

ECC is based on mathematical structures called elliptic curves, which follow an equation of the form:

y2=x3+ax+b  (mod p)y^2 = x^3+a\cdot x+b\ \ (\text{mod}\ p)

When we consider this equation in the domain of finite fields of the form Z/pZ where p is a prime number, the set of solutions forms a group, where addition is defined as the operation of adding points on the curve according to specific rules.

In ECC, addition of two points P and Q on the elliptic curve is defined geometrically:

  • If P≠Q, draw a line through P and Q. This line will intersect the curve at a third point R. The reflection of R over the x-axis gives the sum P+Q.

  • If P=Q, draw the tangent line at P. This line intersects the curve at a new point, which is reflected to get 2P.

  • If the line is vertical, the result is the identity element (point at infinity).

A key operation in ECC is scalar multiplication, where a point P is added to itself repeatedly:

kP=P+P+...+P   (k times)k\cdot P = P + P+...+P \ \ \text{ (}k\text{ times)}

These curves sometimes have unique properties that make cryptographic operations secure. One of the fundamental concepts behind ECC is the Elliptic Curve Discrete Logarithm Problem (ECDLP).

The idea is the following. Let's say we chose the elliptic curve parameters so the group of points on the curve has a cyclic sub-group of order q, a high prime, with generator G.

If someone takes a random scalar in [0, q-1] uniformly, and computes:

A=aGA=a\cdot G

Then the ECDLP is said to be "hard" if it is difficult to find aa given any AA in a short amount of time. Basically the only solution would have to be to check every possible aa. Although it remains "easy" to compute AA from . In fact, parameters of ECC curves are also chosen to make computing a multiplication operation as fast as possible.

This is exactly how an asymmetric key pair is generated:

  • Generate a random scalar a[1,q1]a\in [1, q-1]

  • Compute A=aGA=a\cdot G

aa is the private key, and AA the public key. On the chain, you are identified as A. You can broadcast your public key so other users can encrypt messages using AA that only you can decrypt. Let's see how this work in practice:

Encryption

BB wants to send a message to AA. The message is encoded as a single field element: m[0,p1]m \in [0, p-1].

  1. BB generate a random r[1,q1]r\in [1, q-1]. It should be new and never be used again.

  2. BB computes from rr a "nonce" group element: N=rGN= r\cdot G.

  3. BB then generates a view key group element: E=rAE= r\cdot A.

  4. BB hashes the view key to get a field element: h=hash(E)[0,p1]h= \text{hash}(E) \in [0, p-1].

  5. BB calculates the cipher text: c=m+hc= m+h.

(c,N)(c, N) is the encrypted message that can be shared with AA through an insecure channel.

Decryption

AA receives (c,N)(c, N), and recovers the original message mm following those steps;

  1. AA computes aNa\cdot N , which is the view key group element EE because: aN=a(rG)=(ar)G=(ra)G=r(aG)=rA=Ea\cdot N = a\cdot(r\cdot G) = (ar)\cdot G = (ra)\cdot G = r\cdot(a\cdot G) = r\cdot A=E.

  2. AA hashes the view key to get back the field element: h=hash(E)h= \text{hash}(E).

  3. AA computes the plain text message: m=chm= c-h.

Let's see in next chapter how your private key k allows you to authenticate the transaction you want to broadcast to the network to spend your coins.

Last updated