Photo by Takacs Alexandra on Unsplash

ECDH using Python and Hazmat

--

The most interesting topic area I have found in cybersecurity is the implementation of key exchange with the Diffie-Hellman method. With this, in 1978, Whitfield Diffie and Martin Hellman thought up an amazing approach to create a shared secret between Bob and Alice, and where they can communicate openly: Diffie-Hellman (DH) key exchange. Overall it used discrete logs, and which has since required increasing key sizes to keep up with security standards. A more efficient method these days is to use elliptic curves, and which do not have as great a performance hit when we increase security levels. In this article, we will implement ECDH using the Hazmat privities within the Python cryptography library.

In the Diffie-Hellman (DH) key exchange method, we have a base of g and a shared prime number of p, and where Bob generates a random value of b and Alice generates a random value of a. Bob sends:

B=g^b (mod p)

to Alice, and Alice sends:

A=g^a (mod p)

to Bob. Alice then generates the shared key of:

B^a (mod p)

and Bob generates the same shared key of:

A^b (mod p)

The shared key is actually:

g^{ab} (mod p)

--

--

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.