ECDSA:  Elliptic Curve Signatures

This is the second post on this topic – following on from the first post here.  Read that first for more of the maths behind this!  In this post I’ll look at this from a computational angle – and make a simple Python code to create and verify Elliptic Curve Signatures.

Why Elliptical Curve Signatures?

Say I create 100 MATHSCOINS which I sell.  This MATHSCOIN only has value if it can be digitally verified to be an original issued by me.  To do this I share some data publicly – this then allows anyone who wants to check via its digital signature that this is a genuine MATHSCOIN.  Once you understand this idea you can (in theory!) create your own digital currency or NFT – complete with a digital signature that allows anyone to check that it has been issued by you.

Python code

This code will revolve around solutions mod M to the following elliptical curve:

We can run a quick Python code to find these solutions for a defined M:

This Python code then needs to use the algorithms for repeated addition of the base pair.  It then needs to store all the coordinate pairs in a list (one list for the x coordinates and one for the y coordinates).   These can then follow the algorithm for creating the digital signature.  Note that we need to define the mod of the curve (M), the starting base pair (a,b), the order of the base pair (n), our data to digitally sign (z1), our private key (k1) and a public key (k2).

The full code for digital signatures

Running this code

I have put this code online at Replit.com here – so you can see how it works.  It should look something like this:

Checking a digital signature is genuine

We might also want to work backwards to check if a digital signature is correct.  The following code will tell us this – as long as we specify all the required variables below.  Note we need the digital signature (s1, s2) as well as (r1,r2) – which is worked out by the previous code.

Running this code

You can run this code here – again on Replit.com.   You should see something like this:

Try it yourself!

To create your own digital signatures you need to find a mod M and a base pair with order n, such that both M and n are prime.  Remember you can use this site to find some starting base pairs mod M.  Here are some to start off with

(1)

M =  907.  Base pair = (670,30).  n = 967

(2)

M = 79.   Base pair = (60, 10).  n = 67

(3)

M = 97.  Base pair = (85, 92).  n = 79

(4)

M = 13.  Base pair = (8,8).  n = 7

Can you run the code to create a digital signature, and then run the verification code to check that it is indeed genuine?