Diffie-Hellman & The Mathematics Behind It : Session 2
Vikrant Singh
VP of Engineering
Overview
Learning Points
Gallery
Moments from the Centre
From cryptography workshops to research discussions — explore the people, ideas and moments shaping our community.



Deep Dive
This session went deep into the mathematics required to understand why Diffie-Hellman (DH) works. The group first reviewed modular arithmetic the "clock arithmetic" where numbers wrap around after reaching a fixed modulus p. Modular exponentiation (g^x mod p) was introduced as the core operation, and participants worked through small numerical examples by hand to build intuition.
The discrete logarithm problem (DLP) was then introduced: given g, p, and the result of g^x mod p, it is computationally very difficult to determine x, even though computing g^x mod p itself (the forward direction) is fast.
This asymmetry easy in one direction, hard to reverse is what makes DH secure, similar in spirit to how hash functions are easy to compute but hard to invert.
The full Diffie-Hellman protocol was walked through step by step:
- Both parties (Alice and Bob) publicly agree on a large prime
pand a generatorg. - Alice privately chooses a secret integer
aand computes A = g^a mod p, sendingAto Bob.- Bob privately chooses a secret integer
band computes B = g^b mod p, sendingBto Alice.- Alice computes the shared secret as
B^a mod p; - Bob computes it as
A^b mod p. Both arrive at the same value:g^(ab) mod p.
Crucially, the session emphasized that an eavesdropper who intercepts p, g, A, and B still cannot feasibly compute the shared secret without solving the discrete logarithm problem to recover a or b.
The group also discussed the well-known limitation of basic DH: it provides no authentication. Without an additional mechanism to verify identities, the protocol is vulnerable to a man-in-the-middle (MITM) attack, where an attacker performs separate key exchanges with each party while impersonating the other.
This limitation directly motivated the implementation session later in the series, where authentication of exchanged keys was addressed in practice.
Parameter selection was also discussed why small or poorly chosen primes make DH vulnerable to attacks like Logjam, and why current best practice recommends using well-vetted standard groups (e.g., RFC 3526 groups) or moving to elliptic-curve-based Diffie-Hellman (ECDH), previewed as a topic connecting to the later ECC session.