Diffie-Hellman Key Exchange
Diffie-Hellman Key Exchange
http://www.math.ucla.edu/~baker/40/handouts/r...
next
previous
Next: About this document Up: No Title Previous: No Title
1 of 4
11/18/2016 02:17 PM
http://www.math.ucla.edu/~baker/40/handouts/r...
One solution. 28 = 256; 11 goes into 256 with quotient 23 and remainder 3.
Another solution. Find 22, 24, 28 by squaring repeatedly, but take remainders
mod 11 each chance you get: 22 = 4, 24 = 42 = 16 5, 28 52 = 25 3.
Example 3. Find all the powers of 2 up to 210 , each modulo 11.
Solution. Keep doubling, taking remainders modulo 11 whenever possible:
2, 4, 8, 16 5, 10, 20 9, 18
2, 4, 8, 5, 10, 9, 7, 3, 6, 1.
7, 14
3, 6, 12
Notice that the powers of 2 run through all possible remainders modulo 11,
except 0. We say 2 is a "generator" modulo 11. There is a theorem that if you
take a prime modulus, then there is always some generator, and in fact 2 often
works. If 2 doesn't, maybe 3 will.
C. The Diie-Hellman method
The idea of Diie and Hellman is that it's easy to compute powers modulo a
prime but hard to reverse the process: If someone asks which power of 2
modulo 11 is 7, you'd have to experiment a bit to answer, even though 11 is a
small prime. If you use a huge prime istead, then this becomes a very diicult
problem even on a computer. Steps:
1. Alice and Bob, using insecure communication, agree on a huge prime p and
a generator g. They don't care if someone listens in.
2. Alice chooses some large random integer xA < p and keeps it secret.
Likewise Bob chooses xB < p and keeps it secret. These are their "private
keys".
3. Alice computes her "public key" yA gxA (mod p) and sends it to Bob using
insecure communication. Bob computes his public key yB
it to Alice. Here 0 < yA < p, 0 < yB < p.
yB x A
(gx A )xB = g(xA xB ) (mod p). So this value is their shared secret key. They
can use it to encrypt and decrypt the rest of their communication by some
faster method.
2 of 4
11/18/2016 02:17 PM
http://www.math.ucla.edu/~baker/40/handouts/r...
In this calculation, notice that the step yBxA (gxB )xA involved replacing g
xB by its remainder y , (in the reverse direction) so we were really using
B
the "as often as you want" principle.
D. Notes (not on nal exam)
It's easy to see why the "as often as you want" principle works for modular
arithmetic with positive integers in base 10. In Example 1, imagine doing
the multiplication with paper-and-pencil arithmetic, but ignoring
everything except the last digit. You get
...7
x ...8
------...6
....
....
....
------......6
In other words, you can multiply and then take the last digit, or you can
take remainders early, by saving just the 7 and 8, taking their product, and
saving its last digit.
Congruences work ne for negative numbers if you always use a remainder
that is positive or 0; for example, -13 7 (mod 10) because -20 is a
multiple of 10 and -13 is 7 larger. The % operation in Perl works this way
but the same operation in C and C++ does not.
The notation is meant to suggest =, because several properties of are
similar to those of =. For example, a b and b c give a c (all mod m).
Another interesting fact is that modulo 11, we have 210 1, 310 1, 410
1,...,1010 1, and of course 110 =1 to start with. More generally, there is a
theorem saying that for any prime p and for any a from 1 to p-1 we get ap-1
1 (mod p).
The Diie-Hellman method works best if p = 2q+1 where q is also a prime.
(For example, 5 and 11 are prime and 11 = 2 x 5 + 1.) Then half the
integers 1,2,...,p-1 are generators, and it is possible to check whether g is a
generator just by seeing whether gq -1 (mod p).
Diie-Hellman does have a weakness: If an intruder Charlie can intercept
and resend email between Alice and Bob, then the intruder can pretend to
be Bob for Alice and pretend to be Alice for Bob, substituting his own y C
and tricking each of Alice and Bob into having a shared secret key with
him. There are ways to x this problem.
The Diie-Hellman method illustrates the concept of "public-key
cryptography", where people can give out public information that enables
other people to send them encrypted information.
E. An example
3 of 4
11/18/2016 02:17 PM
http://www.math.ucla.edu/~baker/40/handouts/r...
5 (mod 11), so yB = 5.
next
previous
Next: About this document Up: No Title Previous: No Title
Kirby A. Baker
Sun Mar 21 19:36:51 PST 1999
4 of 4
11/18/2016 02:17 PM