Return to topic cards

Understanding Diffie-Hellman

CryptographyAsymmetric EncryptionKey ExchangeDiffie-HellmanCybersecurity

Diffie-Hellman is an asymmetric encryption algorithm that allows the secure exchange of a secret key over a public channel. This method ensures that two parties can establish a shared secret even if the communication channel is insecure.

Key Points

  • Asymmetric Encryption: Diffie-Hellman uses a pair of keys (public and private) for encryption and decryption.
  • Public Channel: The algorithm allows the exchange of a secret over an insecure public channel.
  • Prime Number Requirement: The algorithm requires a prime number q and a generator g that satisfies certain conditions.

How It Works

Step-by-Step Process

  1. Agree on Parameters: Alice and Bob agree on a prime number q and a generator g. For example, q = 29 and g = 3.
  2. Alice's Calculation:
    • Alice chooses a random number a smaller than q.
    • She calculates A = (g^a) mod q.
    • Alice sends A to Bob while keeping a secret.
    • Example: Alice picks a = 13, calculates A = 3^13 % 29 = 19, and sends 19 to Bob.
  3. Bob's Calculation:
    • Bob chooses a random number b smaller than q.
    • He calculates B = (g^b) mod q.
    • Bob sends B to Alice while keeping b secret.
    • Example: Bob picks b = 15, calculates B = 3^15 % 29 = 26, and sends 26 to Alice.
  4. Shared Secret Calculation:
    • Alice receives B and calculates the shared secret key = B^a mod q.
    • Bob receives A and calculates the shared secret key = A^b mod q.
    • Example: Both Alice and Bob calculate the shared secret key = 10.

Example Calculation

StepAliceBob
Choose aa = 13
Calculate AA = 3^13 % 29 = 19
Send A19
Choose bb = 15
Calculate BB = 3^15 % 29 = 26
Send B26
Receive BB = 26
Calculate Keykey = 26^13 % 29 = 10
Receive AA = 19
Calculate Keykey = 19^15 % 29 = 10

Security Considerations

Man-in-the-Middle (MitM) Attack: The Diffie-Hellman key exchange is vulnerable to MitM attacks, where an attacker intercepts and relays messages between Alice and Bob, pretending to be the other party.

Learn More

For a more detailed explanation, watch this YouTube video.