Alice and Bob want to share a secret key in the Internet. They agree on a very big prime number .

Alice chooses a random value , and sends to Bob the value .

Bob chooses a random value and sends to Alice the value .

Alice can now compute . It’s computationally very hard to recover from .

Bob can compute .

The two computed keys are the same. Alice don’t know but it’s able to compute , and Bob don’t know but it’s able to compute .

Men in the middle are able to see and but it’s very hard to get from those values.

Authenticated Diffie Hellman

Bob has a public key . We can send , the message encrypted with Bob’s public key. Bob sends the message where is the hash togheter with some message and .

Then alice can compute , append a message such as “handshake”, hash it and compare it with the sent hash. Alice and Bob agreed on a secret key and Bob has proved its identity to Alice because of the public key (Only Bob is albe to decript the message sent from Alice, since it’s encrypted with its public key). If the hash is different from the one computed by Alice, it means that the message doesn’t come from Bob.