Unveil

Code

The cryptography of computers: hashes, AES and HMAC, RSA’s weak keys, Diffie–Hellman, certificates, one-time passwords, Shor and Grover, ML-KEM, BB84, Shamir’s shares, time locks, passwords.

Diffie–Hellman

Walks through a Diffie–Hellman exchange step by step: a public prime p and base g with g's order, Alice's and Bob's secrets, the public values g^a and g^b mod p, the secret both compute, and what an eavesdropper finds when p is this small. Whitfield Diffie and Martin Hellman published the method in “New Directions in Cryptography” (1976); RFC 7919 defines groups of 2048 to 8192 bits.

Terms

History, how it works, how it was checked, limits

History

Whitfield Diffie and Martin Hellman published the exchange in “New Directions in Cryptography” (1976): two parties who share nothing agree on a secret over a channel anyone can read. Each raises a public g to a private power modulo a public prime p, sends the result, and raises what the other sent to the same power; both reach g^ab mod p. Finding a from g^a mod p, the discrete logarithm, gives the secret away, and is hard only when p is large.

How it works

A preset pairs a prime p from 23 to 7919 with a primitive root g; a custom p is a prime of up to twelve digits, g from 2 to p − 2, and the order of g is given. Alice’s a and Bob’s b are typed, or drawn without bias at random. The exchange is drawn as a protocol and stepped: a column each, each value sent an arrow, and under it what Eve, reading the channel, then holds; the secret in gold. A ring of the numbers 1 to p − 1 joins the powers of g in order, A, B and s marked. Once A and B have crossed, a card shows Eve’s search for an exponent of A, Shanks’s baby-step giant-step, drawn on the ring as the baby steps and the giant steps from A meeting.

How it was checked

The tests run the tool’s logic on the shared BigInt module: every preset’s g has order p − 1, and 2 has order 11 modulo 23; p = 23, g = 5, a = 6 and b = 15 give A = 8, B = 19 and the secret 2 on both sides; the eavesdropper recovers 6 and the secret, also for a twelve-digit prime; RFC 5114’s test data gives its public values and secret; bad parameters are refused. Every number drawn is the exchange’s own, Eve holds after each step exactly what has crossed, and the walks drawn are the search’s own for every A modulo 23.

The tests hold 28 checks of this tool; 1 rests on outside material:

  • A standard’s own vectors RFC 5114 Appendix A.1 test data: from xA and xB the exchange gives its yA, yB and shared Z, both ways

Every tool’s checks

Limits

The primes are small, which is why the eavesdropper succeeds: RFC 7919’s groups have 2,048 bits or more. The typed secrets are kept out of sessions and links. Plain Diffie–Hellman authenticates no one, and the tool shows neither the attack of someone in the middle nor the signatures that prevent it. The ring is drawn for p up to 10,000, the search for p up to 160,000.