Diffie-Hellman Key Exchange – A Non-Mathematician’s Explanation

Published on: October 17, 2000
Last Updated: October 17, 2000

Diffie-Hellman Key Exchange – A Non-Mathematician’s Explanation

Published on: October 17, 2000
Last Updated: October 17, 2000

A colleague recently asked if I could help him understand the Diffie-Hellman key exchange protocol… without digging through the math.

My answer was “Yes I can, but not easily.” Doing so requires a few diagrams because, in this particular case, a picture is worth at least a thousand words!

First things first – why do we care about Diffie-Hellman? Simply stated, if you are involved in any sort of Virtual Private Network (VPN), you are probably using Diffie-Hellman, even if you didn’t realize it.

If that VPN is operating on the IPSec standard, then Diffie-Hellman is certainly in use. To follow the standards trail for key management in IPSec, we begin with the overall framework called Internet Security Association and Key Management Protocol (ISAKMP; see RFC 2408).

Within that framework is the Internet Key Exchange (IKE) protocol (see RFC 2401). IKE relies on yet another protocol known as OAKLEY and it uses Diffie-Hellman as described in RFC 2412.

It is an admittedly long trail to follow, but the result is that Diffie-Hellman is, indeed, a part of the IPSec standard.

While it is true that a given VPN system could be in use for years without it’s administrators understanding Diffie-Hellman, I have found that an understanding of underlying protocols helps a great deal when trouble-shooting a system.

That is not to say that we have to completely understand the math behind the protocol. In fact, I have worked with encryption systems for years even though any mathematical operation more difficult than balancing a checkbook baffles me completely.

There are bona fide experts in the field of encryption mathematics. When they say a system is mathematically secure, I take them at their word.

This frees me to concentrate on other issues such as keeping the system operational and discerning the finer points of cooking a steak on the Bar-B-Q – things that really matter!

The Diffie-Hellman algorithm, introduced by Whitfield Diffie and Martin Hellman in 1976, was the first system to utilize “public-key” or “asymmetric” cryptographic keys.

(Note: Evidence shows that Comm-Electronics Security Group (an arm of the U.K. government) may have invented the concept of asymmetric key 6 years before D-H.

The CESG papers were classified for 20 years, but Diffie-Hellman figured it out on their own without the information in those papers.)

These systems overcome the difficulties of “private-key” or “symmetric” key systems because key management is much easier.

In a symmetric key system, both sides of the communication must have identical keys. Securely exchanging those keys has always been an enormous issue.

As one example, the National Security Agency has an entire fleet of it’s own planes manned by armed couriers to shuttle around the approximately fifteen tons of paper based symmetric key used by the United States Government every year.

Businesses simply do not want to mess with that. Asymmetric key systems alleviate that issue because they use two keys – one called the “private key” that the user keeps secret and one called the “public key” that can be shared with the world.

Unfortunately, the advantages of asymmetric key systems are overshadowed by speed – they are extremely slow for any sort of bulk encryption.

Today, it is typical practice to use a symmetric system to encrypt the data and an asymmetric system to encrypt the symmetric keys.

That is precisely what Diffie-Hellman is capable of doing – and does do when used for key exchange as described here.

Diffie-Hellman is not an encryption mechanism as we normally think of them in that we do not typically use it to encrypt data.

Instead, it is a method to securely exchange the keys that encrypt data. Diffie-Hellman accomplishes this secure exchange by creating a “shared secret” (sometimes called a “key encryption key”) between two devices. The shared secret then encrypts the symmetric key (or “data encryption key” i.e. DES, Triple DES, CAST, IDEA, Blowfish, etc.) for secure transmittal.

The process begins when each side of the communication generates a private key (depicted by the number 1 in Figure 1). Each side then generates a public key (number 2), which is a derivative of the private key. The two systems then exchange their public keys. Each side of the communication now has their own private key and the other systems public key (number 3).

Noting that the public key is a derivative of the private key is important – the two keys are mathematically linked.

However, in order to trust this system, you must accept that you cannot discern the private key from the public key.

Because the public key is indeed public and ends up on other systems, the ability to figure out the private key from it would render the system useless.

This is one area requiring trust in the mathematical experts. The fact that the very best in the world have tried for years to defeat this and failed bolsters my confidence a great deal.

I should also explain the box labeled “Optional: CA Certifies Public Key”. It is not common, but the ability does exist with the Diffie- Hellman protocol to have a Certificate Authority certify that the public key is indeed coming from the source you think it is.

The purpose of this certification is to prevent Man In the Middle (MIM) attacks. The attack consists of someone intercepting both public keys and forwarding bogus public keys of their own.

The “man in the middle” potentially intercepts encrypted traffic, decrypts it, copies or modifies it, re-encrypts it with the bogus key, and forwards it on to its destination.

If successful, the parties on each end would have no idea that there is an unauthorized intermediary. It is an extremely difficult attack to pull off outside the laboratory, but it is indeed possible.

Properly implemented Certificate Authority systems have the potential to disable the attack.

Once the key exchange is complete, the process continues. An important feature of the Diffie-Hellman protocol is its ability to generate “shared secrets” – an identical cryptographic key shared by each side of the communication.

Figure 2 depicts this operation with the “DH Math” box (trust me, the actual mathematical equation is a good deal longer and more complex).

By running the mathematical operation against your own private key and the other side’s public key, you generate a value.

When the distant end runs the same operation against your public key and their own private key, they also generate a value. The important point is that the two values generated are identical.

At this point, the Diffie-Hellman operation could be considered complete. The shared secret is, after all, a cryptographic key that could encrypt traffic.

That is very rare however. The reason being that the shared secret is, by its mathematical nature, an asymmetric key.

As with all asymmetric key systems, it is inherently slow. If the two sides are passing very little traffic, the shared secret may encrypt actual data.

Any attempt at bulk traffic encryption requires a symmetric key system such as DES, Triple DES, IDEA, CAST, Blowfish, etc.

In most real applications of the Diffie-Hellman protocol (IPSec in particular), the shared secret encrypts a symmetric key for one of the symmetric algorithms, transmits it securely, and the distant end decrypts it with the shared secret.

Figure 3 depicts this operation. Because the symmetric key is a relatively short value as compared to bulk data, the shared secret can encrypt and decrypt it very quickly. Speed is not so much of an issue with short values.

Which side of the communication actually transmits the symmetric key varies. However, it is most common for the initiator of the communication to be the one that transmits the key.

I should also point out that some sort of negotiation typically occurs to decide on the symmetric algorithm, mode of the algorithms (i.e. Cipher Block Chaining, etc.), hash functions (MD5, SHA1, etc) key lengths, refresh rates, and so on.

That negotiation is not a part of Diffie- Hellman, but it is an obviously important task since both sides must support the same schemes for encryption to function.

This also points out why key management planning is so important – and why poor key management so often leads to failure of systems.

Once secure exchange of the symmetric key is complete (and note that passing that key is the whole point of the Diffie-Hellman operation), data encryption and secure communication can occur.

Figure 4 depicts data encrypted and decrypted on each end of the communication by the symmetric key. Note that changing the symmetric key for increased security is simple at this point.

The longer a symmetric key is in use, the easier it is to perform a successful cryptanalytic attack against it.

Therefore, changing keys frequently is important. Both sides of the communication still have the shared secret and it can be used to encrypt future keys at any time and any frequency desired.

The use of Diffie-Hellman greatly reduces the headache of using symmetric key systems.

These systems have astounding speed benefits, but managing their keys has always been difficult to say the very least.

Because the steps we have just gone through happen in a matter of a second or two and are completely transparent to the user, ease of use could not be better… provided it works.

The good news is that it almost always does work. Understanding the underlying protocol only becomes necessary in the rare case that it doesn’t.

Stay on top of the latest technology trends — delivered directly to your inbox, free!

Subscription Form Posts

Don't worry, we don't spam

Written by Bobby

Bobby Lawson is a seasoned technology writer with over a decade of experience in the industry. He has written extensively on topics such as cybersecurity, cloud computing, and data analytics. His articles have been featured in several prominent publications, and he is known for his ability to distill complex technical concepts into easily digestible content.