Sage and Elliptic Curves: P256 and secp256k1

--

Our world of trust on the Internet is built on a foundation of elliptic curves. Two of the most important of these are NIST P-256 and secp256k1 (as used in Bitcoin, Ethereum and Tor). For this, we can use Sage to model our curves:

In this case, we have the NIST P-256 curve, and which has the form of:

and which is the mod of a prime number (p):

p=2²⁵⁶-2²²⁴+2¹⁹²+2⁹⁶-1

We also have a base point of (G) of:

48439561293906451759052585252797914202762949526041747995844080717082404635286,36134250956749795798585127919587881956611106672985015071877198253568414405109

In Sage, we can define the base point (gx, gy) and the order of the curve (n) with:

gx = 48439561293906451759052585252797914202762949526041747995844080717082404635286L
gy = 36134250956749795798585127919587881956611106672985015071877198253568414405109L
n = 115792089210356248762697446949407573529996955224135760342422259061068512044369L

Next we can define the curve (EC) and the base point (G) with:

p256 = 115792089210356248762697446949407573530086143415290314195533631308867097853951La256 = p256 - 3b256 =…

--

--

Prof Bill Buchanan OBE FRSE
ASecuritySite: When Bob Met Alice

Professor of Cryptography. Serial innovator. Believer in fairness, justice & freedom. Based in Edinburgh. Old World Breaker. New World Creator. Building trust.