Diffie-Hellman is a simple public-key algorithm that enables two users to establish a secret key using a public-key scheme based on discrete logarithms.

  1. Principals share a prime number and an integer that is a primitive root of . Both and may be public, or could send them in the first message.
  2. and generate random numbers and both less than . (these are private keys)
  3. computes , computes . (these are public keys, also known as “Diffie-Hellman half keys”)
  4. and exchange and .
  5. computes , computes . (the keys are equal, i.e. )