When Alice sends x, Harry intercepts it and sends 1 to Bob
When Bob sends y, Harry intercepts it and sends 1 to Alice
Alice and Bob now compute k = 1, and of course Harry knows k
Solution: Bob must make sure x ≠ 1, Alice must make sure y ≠ 1
Problem 2: Small subgroup attack
Harry is in the middle between Alice and Bob
When Alice sends x, Harry intercepts it and sends h to Bob, where h is a generator for a small subgroup of Zp*
Bob now computes k = hb, which is a member of a small set
Harry can now do an exhaustive search to find Bob's k
Harry does the same to Alice
Solution: Make sure g is a generator for a large subgroup of Zp*; Bob and Alice must make sure x and y are members of this subgroup
To make sure g is a generator for a large subgroup:
Use a safe prime p = 2q + 1, where q is a large prime
Then the only subgroup orders are the factors of p−1 = 2q, namely p−1, q, 2, and 1
We want to use the order-q subgroup
To find a safe prime:
Pick a large random number q
Test whether q is prime
Test whether p = 2q + 1 is prime
Repeat until both p and q are prime
To find a generator for the order-q subgroup:
Pick a random number α in the range 2 .. p−2
Set g = α2 (mod p)
If g = 1, then g is a generator for the order-1 subgroup {1}, so try again with another random α
If g = p−1, then g is a generator for the order-2 subgroup {1, p−1}, so try again with another random α
Otherwise, g is a generator for the order-q subgroup {α0, α2, α4, . . .} (the odd powers of α are missing), so go with it
To make sure x (and y) are members of the subgroup generated by g:
Make sure that x ≠ 1 and xq (mod p) = 1
Problem 3: The above choice of subgroup leads to computations that take too long
E.g., if p is a 2048-bit number, then q is a 2047-bit number, the exponents in Alice's and Bob's calculations can be as many as 2047 bits long, and the modular exponentiations can take as many as 2047 squarings and multiplications
Solution: Use a smaller (but still large enough) subgroup
E.g., let q be a 256-bit prime, then the subgroup order is about 2256, too large for Harry to do an exhaustive search
Diffie-Hellman parameter generation
Repeat:
Pick a random 256-bit odd number q
Pick a random 1792-bit even number N
Until q is prime and p = Nq + 1 is prime (p is a 2048-bit number)
Repeat:
Pick a random α in the range 1 .. p−1
Set g = αN (mod p)
Until g ≠ 1 and gq (mod p) = 1
Publish (p, q, g) as the Diffie-Hellman parameters -- modulus, subgroup order, generator for order-q subgroup
Diffie-Hellman Key Exchange, Version 2
Alice picks a secret random number a in the range 1 < a < q−1
Alice computes x = ga (mod p) and sends x to Bob
Bob picks a secret random number b in the range 1 < b < q−1
Bob computes y = gb (mod p) and sends y to Alice
Alice makes sure 1 < y < p and yq (mod p) = 1
Alice computes k = ya (mod p) = gba (mod p)
Bob makes sure 1 < x < p and xq (mod p) = 1
Bob computes k = xb (mod p) = gab (mod p)
Alice and Bob derive the secure channel session key from k
RFC 2407: The Internet IP Security Domain of Interpretation for ISAKMP, November 1998
RFC 2408: Internet Security Association and Key Management Protocol (ISAKMP), November 1998
RFC 2409: The Internet Key Exchange (IKE), November 1998
RFC 5996: Internet Key Exchange Protocol Version 2 (IKEv2), September 2010
El Gamal Encryption
T. ElGamal.
A public key cryptosystem and a signature scheme based on discrete logarithms.
IEEE Transactions on Information Theory,
31(4):469-472, July 1985.
Based on the difficulty of the Discrete Logarithm Problem in Zp*
Public parameters (same as Diffie-Hellman)
p = Zp* modulus -- 2048-bit prime
Subgroup order q -- 256-bit prime
g = Generator for an order-q subgroup of Zp*
Bob's key generation
Bob picks a random number b in the range 1 < b < q−1
Bob's private key = b
Bob's public key = gb (mod p)
(This is Bob's half of a Diffie-Hellman key exchange)
Alice encrypting a message m for Bob
m is an encoded message, using a padding function similar to OAEP
Alice picks a random number a in the range 1 < a < q−1
Alice computes ga (mod p)
(This is Alice's half of a Diffie-Hellman key exchange)
Alice computes k = (gb)a (mod p) from Bob's public key
Alice computes masked message c = km (mod p)
Alice sends ciphertext = (ga, c) to Bob
Note that ciphertext size = 2 * plaintext size
Bob decrypting a ciphertext (ga, c)
Bob computes k = (ga)b (mod p) -- modular exponentiation