1
Diffie-Hellman Key Exchange
•Diffie and Hellman published the first public key
algorithm
– Referred to as Diffie-Hellman Key Exchange
– Used in a number of commercial products.
– Oldest public key system still in use
– Less general than RSA
• It does neither encryption nor signatures
• Diffie-Hellman allows two individuals to agree on a
shared private key, by exchanging public messages.
2.
2
Diffie-Hellman Key Exchange
•Diffie-Hellman key exchange depends for its effectiveness on the
difficulty of computing discrete logarithms:
– We define a generator or primitive or primitive root of a prime number p as
one whose powers generate all the integers from 1 to p - 1. So, if a is a
primitive root of p, then the numbers:
a mod p, a2
mod p, a3
mod p, ... ap-1
mod p
are distinct and consist of the integers from 1 through p - 1 (in some
permutation)
– For any integer b and a generator a of p, we can find a unique exponent i such
that:
– The exponent i is referred to as the discrete logarithm (or index) of b for the
base a, mod p. It is the inverse of modular exponentiation, and finding the
discrete logarithm i, given b, is known to be a hard problem.
1)
-
(
0
where
mod p
i
p
a
b i
3.
3
Diffie-Hellman Key Exchange
•Here is what Diffie-Hellman key exchange involves:
– First, Alice and Bob agree on a large prime, p, and g, such
that g is a generator mod p. The numbers don't have to be
secret.
– Then the protocol goes as follows:
1) Alice chooses a random large integer x and sends Bob
X = gx
mod n
2) Bob chooses a random large integer y and sends Alice
Y = gy
mod n
3) Alice computes
k = Yx
mod n
4) Bob computes
k' = Xy
mod n
'
mod
mod
mod
k
n
X
n
g
n
Y
k
y
xy
x
4.
4
Diffie-Hellman Key Exchange
1)Alice chooses a random large
integer x and sends Bob
X = gx
mod n
2) Bob chooses a random large integer
y and sends Carol
Y = gy
mod n
3) Carol chooses a random large
integer z and sends Alice
Z = gz
mod n
4) Alice sends Bob
Z' = Zx
mod n
5) Bob sends Carol
X' = Xy
mod n
6) Carol sends Alice
Y' = Yz
mod n
7) Alice computes
k = Y'x
mod n
8) Bob computes
k = Z'y
mod n
9) Carol computes
k = X'z
mod n
• This protocol can also be extended to work with three or more people:
5.
5
Man-in-the-Middle Attack
• Oneproblem with Diffie-Hellman is that there is no
authentication, and so the protocol is subject to a man-
in-the-middle attack:
– Alice generates gx
and sends it to "Bob"
– Eve intercepts the message:
• Generates gv
, and sends it to Bob in place of Alice's message
– Bob receives gv
, generates gy
, and sends it to "Alice"
– Eve intercepts the message:
• Generates gw
, and sends it to Alice in place of Bob's message
– Alice computes k = (gw
)x
– Bob computes k' = (gv
)y
– Eve computes k = (gx
)w
and k' = (gy
)v
6.
6
Man-in-the-Middle Attack
• Thereare a number of techniques to defend
against such an attack:
– Each person can have a "somewhat permanent"
public and secret number, instead of creating one
for each message exchange. This can be considered
to be a kind of Digital Phonebook.
– If Alice and Bob share some kind of secret which
then can use to authenticate each other, then they
can use this secret to verify each other's messages
indeed came from the person they expected.
7.
Asymmetric Encryption
Key Diffie-HellmanMathematical Analysis
Bob & Alice
agree on non-secret
prime p and value a
Generate Secret
Random Number x
Compute Public Key
ax
mod p
Compute Session Key
(ay
)x
mod p
Generate Secret
Random Number y
Compute Public Key
ay
mod p
Compute Session Key
(ax
)y
mod p
Bob Alice
Identical Secret Key
Bob & Alice
exchange
public keys
Diffie – HellmanKey Exchange Algorithm
steps:
Step-1: Select p (prime number) and q (q is primitive root of p)
Step-2: User A Key Generation: select XA, XA < p
Calculate public key YA, YA = qX
A mod p
YA Shared with user B
Step-3: User B Key Generation: select XB, XB < p
Calculate public key YB, YB = qX
B mod p
YB shared with user A
Step-4: Calculation of secret key by user A: K = (YB)X
A mod p
Step-5: Calculation of secret key by user B: K = (YA)X
B mod p
10.
Same Secret keygenerate both sides
K = (YB) X
A mod q
= (qX
B mod p) X
A mod p
= (qX
B)X
A mod p
= (qX
A) X
B mod p
= (qX
A mod p) X
B mod p
= (YA) X
B mod p
= K
11.
Explanation of PrimitiveRoot(FOR
understanding Purpose only)
• Given a prime number n, the task is to find its
primitive root under modulo n. The primitive
root of a prime number n is an integer r
between[1, n-1] such that the values of
r^x(mod n) where x is in the range[1, n-2] are
different. Return -1 if n is a non-prime number.
12.
Examples:
Input : 7Output : Smallest primitive root = 3
Explanation:
n = 7
3^0(mod 7) = 1
3^1(mod 7) = 3
3^2(mod 7) = 2
3^3(mod 7) = 6
3^4(mod 7) = 4
3^5(mod 7) = 5
Input : 761 Output : Smallest primitive root = 6
A simple solution is to try all numbers from 2 to n-1. For every
number r, compute values of r^x(mod n) where x is in the range[0,
n-2]. If all these values are different, then return r, else continue for
the next value of r. If all values of r are tried, return -1.
13.
Diffie – HellmanKey Exchange Algorithm
explain with example:
Step – 1: Select p (prime number) and q (q is primitive root of p)
Example, here p = 7, q = 3.
Step – 2: User A Key Generation: Select XA < p,
calculate public key YA and shared with user B: YA = qX
A mod p
Example, Here XA = 6,
Calculate YA = qX
A mod p 3
⇒ 6
mod 7 1
⇒
Step – 3: User B Key Generation: Select XB < p,
calculate public key YB and shared with user A: YB = qX
B mod p
Example, Here XB = 4,
Calculate YB = qX
B mod p 3
⇒ 4
mod 7 4
⇒
14.
Step – 4:Calculation of secret key by user A:
K = (YB)X
A mod p
Example, Here YB = 4, XA = 6
Calculate K = (YB)X
A mod p 4
⇒ 6
mod 7 1
⇒
Step – 5: Calculation of secret key by user B:
K = (YA)X
B mod p
Example, Here YA = 1, XB = 4
Calculate K = (YA)X
B mod p 1
⇒ 4
mod 7 1
⇒
RSA Algorithm
Introduction
Ron Rivest,Adi Shamir and Len Adleman have developed this algorithm (Rivest-Shamir-
Adleman). It is a block cipher which converts plain text into cipher text and vice versa at
receiver side.
RSA Algorithm Steps
Step-1: Select two prime numbers p and q where p ≠ q.
Step-2: Calculate n = p * q.
Step-3: Calculate Ф(n) = (p-1) * (q-1).
Step-4: Select e such that, e is relatively prime to Ф(n), i.e. (e, Ф(n)) = 1 and 1 < e < Ф(n)
Step-5: Calculate d = e -1
mod Ф(n) or ed = 1 mod Ф(n).
Step-6: Public key = {e, n}, private key = {d, n}.
Step-7: Find out cipher text using the formula,
C = Pe
mod n where, P < n where C = Cipher text, P = Plain text, e = Encryption key and
n=block size.
Step-8: P = Cd
mod n. Plain text P can be obtain using the given formula. where, d =
decryption key
19.
Explanation
Step – 1:Select two prime numbers p and q where p ≠ q.
Example, Two prime numbers p = 13, q = 11.
Step – 2: Calculate n = p * q.
Example, n = p * q = 13 * 11 = 143.
Step – 3: Calculate Ф(n) = (p-1) * (q-1).
Example, Ф(n) = (13 – 1) * (11 – 1) = 12 * 10 = 120.
Step – 4: Select e such that, e is relatively prime to Ф(n), i.e. (e, Ф(n)) = 1 and 1 < e < Ф(n).
(Choose a number e less that n, such that n is relatively prime to (p - 1) x (q -1). It means
that e and (p - 1) x (q - 1) have no common factor except 1. Choose "e" such that 1<e < φ (n), e
is prime to φ (n), gcd (e, d (n)) =1. )
Example, Select e = 13, gcd (13, 120) = 1.
Step – 5: Calculate d = e -1
mod Ф(n) or e * d = 1 mod Ф(n)
20.
Example
Finding d: e* d mod Ф(n) = 1
13 * d mod 120 = 1
(How to find: d *e = 1 mod Ф(n)
d = ((Ф(n) * i) + 1) / e
d = (120 + 1) / 13 = 9.30 ( i = 1)
∵
d = (240 + 1) / 13 = 18.53 ( i = 2)
∵
d = (360 + 1) / 13 = 27.76 ( i = 3)
∵
d = (480 + 1) / 13 = 37 ( i = 4))
∵
21.
Step – 6:Public key = {e, n}, private key = {d, n}.
Example, Public key = {13, 143} and private key = {37, 143}.
Step – 7: Find out cipher text using the formula, C = Pe
mod n where,
P < n.
Example, Plain text P = 13. (Where, P < n)
C = Pe
mod n = 1313
mod 143 = 52.
Step – 8: P = Cd
mod n. Plain text P can be obtain using the given
formula.
Example, Cipher text C = 52
P = Cd
mod n = 5237
mod 143 = 13.
25.
Diffie-Hellman Key ExchangeAlgorithm
• Introduction
• The Diffie Hellman algorithm widely known as
Key exchange algorithm or key agreement
algorithm developed by Whitefield Diffie and
Martin Hellman in 1976. The purpose of the
algorithm is to enable two users to securely
exchange a key that can be used for subsequent
encryption of messages. The algorithm itself is
limited to the exchange of secret values.