IPSec Overview Part Three: Cryptographic Technologies
IPSec Cryptographic Components
This article looks at the cryptographic component technologies used in IPSec.
Data Encryption Standard (DES) Encryption
DES encryption includes the following components:
Encryption and decryption algorithms
Matching shared secret keys on each peer
Input cleartext data to be encrypted
At the core of DES is the encryption algorithm:
A shared secret key is input to the algorithm. Then cleartext data is fed into the algorithm in fixed-length blocks and is converted to cyphertext.
The cyphertext is transmitted to the IPSec peer using ESP.
The peer receives the ESP packet, extracts the cyphertext, runs it through the decryption algorithm, and outputs cleartext identical to that input on the encrypting peer.
Figure 1 shows the DES encryption algorithm in action. In this figure, a pre-shared key is in use.
Figure 1 DES encryption.
Diffie-Hellman Key Agreement
The Diffie-Hellman key agreement (D-H) is a public key encryption method that provides a way for two IPSec peers to establish a shared secret key that only they know, although they're communicating over an insecure channel.
With D-H, each peer generates a public and private key pair. The private key generated by each peer is kept secret and never shared. The public key is calculated from the private key by each peer and is exchanged over the insecure channel. Each peer combines the other's public key with its own private key, and computes the same shared secret number. The shared secret number is then converted into a shared secret key. The shared secret key is never exchanged over the insecure channel.
As Figure 2 shows, Diffie-Hellman key exchange is a complicated process. This adds to the effectiveness of the encryption algorithm.
Figure 2 Diffie-Hellman key agreement.
This is the Diffie-Hellman process:
The D-H process starts with each peer generating a large prime integer (in this example, p and q). Each peer sends the other its prime integer over the insecure channel. For example, Peer A sends p to Peer B. Each peer then uses the p and q values to generate g, a primitive root of p.
Each peer generates a private D-H key (peer A: XA, peer B: XB).
Each peer generates a public D-H key. The local private key is combined with the prime number p and the primitive root g in each peer to generate a public key, YA for peer A and YB for peer B. The formula for peer A is YA = g ^ XA mod p; the formula for peer B is YB = g ^ XB mod p. The exponentiation is computationally expensive. The caret (^) character denotes exponentiation (g to the XA power); mod denotes modulus.
The public keys YA and YB are exchanged in public.
Each peer generates a shared secret number (ZZ) by combining the public key received from the opposite peer with its own private key. The formula for peer A is ZZ = YB ^ XA mod p. The formula for peer B is ZZ = (YA ^ XB ) mod p. The ZZ values are identical in each peer. Knowing p or g or the D-H public keys is not enough to guess or easily calculate the shared secret valuelargely because of the difficulty in factoring large prime numbers.
Shared secret keys are derived from the shared secret number ZZ for use by DES or HMACs.
Each IPSec peer has three keys:
A private key that's kept secret and never shared. It's used to sign messages.
A public key that's shared. It's used by others to verify a signature.
A shared secret key that's used to encrypt data using an encryption algorithm (DES, MD5, and so on). The shared secret key is derived from Diffie-Hellman key generation.
Hashed Message Authentication Codes (HMAC)
The fundamental hash algorithms used by IPSec are the cryptographically secure Message Digest 5 (MD5) and Secure Hash Algorithm 1 (SHA-1) hash functions. Hashing algorithms have evolved into HMACs, which combine the proven security of hashing algorithms with additional cryptographic functions. The hash produced is encrypted with the sender's private key, resulting in a keyed checksum as output.
In Figure 3, the hash function takes as input the variable-length cleartext data that needs to be authenticated, and a private key. The private key length is the same as that of the output of the hash. The HMAC algorithm is run, with a resultant fixed-length checksum as output. This checksum value is sent with the message as a signature. The receiving peer runs an HMAC on the same message data that was input at the sender, using the same private key, and the resultant hash is compared with the received hash, which should match exactly.
Figure 3 Hashed Message Authentication Codes (HMAC).
The HMAC-MD5-96 (also known as HMAC-MD5) encryption technique is used by IPSec to make sure that a message has not been altered. HMAC-MD5 uses the MD5 hash developed by Ronald Rivest of the Massachusetts Institute of Technology and RSA Data Security Incorporated, and is described in RFC 1321.
HMAC-MD5 uses a 128-bit secret key and produces a 128-bit authenticator value. This 128-bit value is truncated to the first 96 bits. Upon sending, the truncated value is stored within the authenticator field of AH or ESP-HMAC. Upon receipt, the entire 128-bit value is computed and the first 96 bits are compared to the value stored in the authenticator field.
MD5 alone has recently been shown to be vulnerable to collision-search attacks. This form of attack and other currently known weaknesses of MD5 do not compromise the use of MD5 within HMAC, however, as no known attacks against HMAC-MD5 have been proven. HMAC-MD5 is recommended where the superior performance of MD5 over SHA-1 is important.
The HMAC-SHA-1-96 (also known as HMAC-SHA-1) encryption technique is also used by IPSec to make sure that a message has not been altered. HMAC-SHA-1 uses the SHA-1 specified in FIPS-190-1 combined with HMAC (as per RFC 2104), and is described in RFC 2404.
HMAC-SHA-1 uses a 160-bit secret key and produces a 160-bit authenticator value. This 160-bit value is truncated to the first 96 bits. Upon sending, the truncated value is stored within the authenticator field of AH or ESP-HMAC. Upon receipt, the entire 160-bit value is computed and the first 96 bits are compared to the value stored in the authenticator field.
SHA-1 is considered cryptographically stronger than MD5, yet it takes more CPU cycles to compute. HMAC-SHA-1 is recommended where the slightly superior security of SHA-1 over MD5 is important.
This brings us to the end of the third part of this five-part series of articles covering IPSec. Be sure to catch the next installment.