Image for post
Image for post

Barebones P256: There Is Beauty in Elliptic Curves

The basic form of an elliptic curve is y² = x² + ax +b, and a plot of y² = x³-3x+10 is [here]:

Image for post
Image for post

For the NIST P256 curve, we have a finite field defined by the prime number of p=2²⁵⁶−2²²⁴+2¹⁹²+2⁹⁶−1. The other parameters are x=-3, b=41058363725152142129326129780047268409114441015993725554835256314039467401291 and the base point is at:

The simplest operations we have is to take a base point G on this curve, and then perform point addition. We always end up with another point on the curve. So 2G is equal to G+G and where we get a new point on the elliptic curve. For 3G we can have G+2G, and so on. We can also perform a scalar multiplication, such as taking a scalar of 3 and finding 3G. In the following code we have three scalar values of 1, 2 and 3, and then use point addition and scalar multiplication to find 2G and 3G, and where we should get the same values as G+G and G+2G, respectively:

one := suite.Scalar().SetInt64(1)
two := suite.Scalar().SetInt64(2)
three := suite.Scalar().SetInt64(3)
G:=suite.Point().Base()

n := suite.Scalar().Pick(suite.RandomStream())
G_1 := suite.Point().Mul(one,G)
G_2 := suite.Point().Mul(two,G)
G_3 := suite.Point().Mul(three,G)
G_T1 := suite.Point().Add(G_1,G_1)
G_T2 := suite.Point().Add(G_1,G_2)

Note in Curve NIDT, we have an (x,y) point. A sample run shows that 2G is equal to G+G, and 3G is equal to G+2G:

An outline of the code is:

and here is an online demo that you can add your own scalar to:

A sample run gives for a user entered value of 4 is:

Conclusions

Beauty exists in many forms, and for cybersecurity, elliptic curves are the nearest thing to providing beauty.

Written by

Professor of Cryptography. Serial innovator. Believer in fairness, justice & freedom. EU Citizen. Auld Reekie native. Old World Breaker. New World Creator.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store