Diffie-Hellman (DH), invented in 1976 by Whitfield Diffie and Martin Hellman, lets 2 parties agree on a shared secret key using only publicly exchanged information. Security rests on the difficulty of computing discrete logarithms.
The protocol has 4 parts: define public parameters, generate key pairs, exchange public keys, compute the shared secret.
Public Parameters
- A large prime modulus , defining the multiplicative group .
- A generator , a primitive root modulo .
is a primitive root modulo iff every coprime to satisfies for some integer , called the discrete logarithm of to base .
For prime , the values generate , in some order, via .
Key Pair Generation
Each party chooses a secret integer and publishes its exponentiation modulo .
- Alice chooses secret , computes public .
- Bob chooses secret , computes public .
Exchange of Public Keys
Public keys need no confidentiality, only authenticity and integrity, since a forged public key lets an attacker substitute their own key undetected.
Methods: a trusted public key server, in-person or verified exchange, or a CA-issued digital certificate.
Shared Secret Key
Alice computes . Bob computes . Both arrive at the same value since .
Worked Example
, , , .
- .
- .
- Alice: .
- Bob: .
Man-in-the-Middle Attack
The basic DH protocol has no authentication of public keys, so it is vulnerable to a man-in-the-middle attack.
Mallory now holds a separate shared key with each party, and can decrypt, inspect, modify, or inject messages in the supposedly secure channel between Alice and Bob.