Authenticated ECDH In Python using X25519

--

Curve 25519 is one of the most widely used ECC (Elliptic Curve Cryptography) methods and you are likely to be using it for the connection that you have on this connection. It uses a curve of y²=x³+486662x²+x, and which is a Montgomery curve. The prime number used is 2²⁵⁵−19.

So let’s create a Python to implement X25519. This method uses Curve 25519), but only focuses on the x-axis point for the sharing of values. A weakness of the Diffie-Hellman and core ECDH (Elliptic Curve Diffie Hellman) methods is that Eve can perform an Eve-in-the-middle attack, so let’s see if we can overcome this with the usage of Bob and Alice’s long term public key.

In this case, Bob and Alice share their public keys initially, and then each session has its own key exchange, with keys created from their long-term public keys and their session keys.

When Bob and Alice are communicating over a network, they might want to create a unique encryption key for each session. This is often achieved by using X25519, and uses ECDH (Elliptic Curve Diffie Hellman). With this we select a base x co-ordinate point of G, and then Bob and Alice generate random values, and determine their public keys. Alice generates a long-term private key of a, and Bob generates a long term private key of b.

--

--

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.