Asymmetric Ciphers
Asymmetric Ciphers
Asymmetric Ciphers
• Encryption:- C = Pe (mod n)
• Decryption:- P = Cd (mod n)
• P,C ∈ Zn
• To make the RSA algorithm faster, a specific number for ‘e’ is chosen.
• The most common choice for ‘e’ is 65537 (i.e. 216+1).
• Other popular choices for e are 3 and 17.
• These choices have only two 1 bits, which reduces the number of
multiplications needed.
• RSA can be weak with a small public key (e = 3).
Efficient RSA Public Key generation
(e=3)
Assume that there are 3 different recipients who use e=3, but unique values of n
(i.e. n1, n2, n3)
In that case, the sender would send 3 different CTs to the 3 different recipients:-
• C1 = M3 mod n1
• C2 = M3 mod n2
• C3 = M3 mod n3
If n1, n2, n3, are pairwise relatively prime, then the attacker can calculate M 3 using
Efficient RSA Private Key Operation
• Small value of ‘d’ will make RSA vulnerable to BFA and other
cryptanalysis methods.
• We can speed up the calculation M=C d mod n using CRT.
• Vp = Cd mod p; Vq = Cd mod q
• Let Xp = q*MI(q) mod p; Xq = p*MI(p) mod q
• According to CRT, M = (Vp*Xp + Vq*Xq) mod n
Efficient RSA Private Key Operation
(Contd..)
• if d>p, Vp = Cd mod p = Cd mod (p-1) mod p
• if d>q, Vq = Cd mod q = Cd mod (q-1) mod q
• if d=p, Vp = Cd mod p = C
• if d=q, Vq = Cd mod q = C
• If d>p, and d>q, then the CRT method is 4 times the speed of
d
calculating (M = C mod n) directly.
Computational Aspects for Key
Generation
Finding large prime numbers efficiently is important.
There’s no perfect way to find very large primes, so a different method is used:
• Randomly pick an odd number and check if it’s prime.
• If it’s not prime, keep picking new numbers until a prime is found.
Primality can be tested using various tests (Common one is Miller Rabin
algorithm)
Computational Aspects for Key
Generation
Steps to find a prime number:-
• Randomly choose an odd number ‘n’.
• Randomly choose another number ‘a’ (a<n).
• As long as ‘n’ fails the test, start over from Step 1.
• If ‘n’ passes enough number of tests, accept ‘n’ as a prime, else go to step 2.
Solution:-
• p = 61, q = 59, M = 123
• n = p*q = 3599
• Φ(n) = (p-1)*(q-1) = 3480
• e = 17
• d = MI(e) mod Φ(n) = MI(17) mod 3480
Numerical 1 (Contd..)
q a b r v1 v2 v
204 3480 17 12 0 1 -204
1 17 12 5 1 -204 205
2 12 5 2 -204 205 -614
2 5 2 1 205 -614 1433
2 2 1 0 -614 1433 -3480
1 0 1433
CT = C = 2868
Numerical 2
• In reference to the previous numerical, calculate the PT when CT=2868.
Solution:-
• M = Cd mod n = 28681433 mod 3599
• 1433 = 1024 + 256 + 128 + 16 + 8 + 1
PT = M = 123
Numerical 3
• A PT (consists of 5 characters) is encrypted by using its corresponding ASCII
equivalents, and each character is encrypted separately. The key generation
primes are 11 and 19, and the public exponent is 47. The CT has a sequence
(41, 141, 76, 76, 29). Calculate the private key and PT.
Solution:-
• p = 11, q = 19, e = 47
• n = p*q = 209
• Φ(n) = (p-1)*(q-1) = 180
• d = MI(e) mod Φ(n) = MI(47) mod 180
Numerical 3 (Contd..)
q a b r v1 v2 v
3 180 47 39 0 1 -3
1 47 39 8 1 -3 4
4 39 8 7 -3 4 -19
1 8 7 1 4 -19 23
7 7 1 0 -19 23 -180
1 0 23 -180
• Private Key = d = 23 = 16 + 4 + 2 + 1
Numerical 3 (Contd..)
M1 = C1d mod n = 4123 mod 209:-
• 412 mod 209 = 9
4
• 41 mod 209 = 81
16
• 41 mod 209 = 36
• 4123 mod 209 = (4116 mod 209 * 414 mod 209 * 412 mod 209 * 41)
mod 209
23
• 41 mod 209 = (36 * 81 * 9 *41) mod 209 = 72
• M1 = ‘H’
Numerical 3 (Contd..)
M2 = C2d mod n = 14123 mod 209:-
• 1412 mod 209 = 26
4
• 141 mod 209 = 49
16
• 141 mod 209 = 163
• 14123 mod 209 = (14116 mod 209 * 1414 mod 209 * 1412 mod 209 *
141) mod 209
23
• 141 mod 209 = (163 * 49 * 26 * 141) mod 209 = 69
• M2 = ‘E’
Numerical 3 (Contd..)
M3 = C3d mod n = 7623 mod 209:-
• 762 mod 209 = 133
• 764 mod 209 = 133
• 7616 mod 209 = 133
• 7623 mod 209 = (7616 mod 209 * 764 mod 209 * 762 mod 209 * 76) mod
209
• 7623 mod 209 = (133 * 133 * 133 * 76) mod 209 = 76
• M3 = ‘L’
PT = ‘HELLO’
Diffie-Hellmann Key Exchange
(DHKE)
History and Evolution of DHKE
Solution:-
• q = 59, α = 6, XA = 4, XB = 8
XA
• YA = α mod q = 64 mod 59 = 57
XB
• YB = α 8
mod q = 6 mod 59 = 4
Numerical 1 (Contd..)
K = (Y )XA mod q = 44 mod 59 = 20
A B
• 574 mod 59 = 16
• 578 mod 59 = 20
• KB = 20
Numerical 2
• Alice and Bob agree upon the DHKE global parameters (1009 and 22), where
22 is the primitive root of 1009. The private key of Alice is 25 and that of
Bob is 75. Calculate the public keys generated by the 2 communicating
entities, and the secret key established by both the entities.
Solution:-
q = 1009, α = 22, XA = 25, XB = 75
• 75 = 64 + 8 + 2 + 1
Numerical 2 (Contd..)
• 222 mod 1009 = 484
• 224 mod 1009 = 168
• 228 mod 1009 = 981
• 2216 mod 1009 = 784
• 2232 mod 1009 = 175
• 2264 mod 1009 = 355
• 2275 mod 1009 = (355 * 981 * 484 * 22) mod 1009 =
• 2275 mod 1009 = [(355 * 981) mod 1009 * (484 * 22) mod 1009] mod 1009
• 2275 mod 1009 = (150 * 558) mod 1009 = 962 = YB
Numerical 2 (Contd..)
X
KA = (YB) A mod q = 96225 mod 1009
• 25 = 16 + 8 + 1
• 9622 mod 1009 = 191
• 9624 mod 1009 = 157
• 9628 mod 1009 = 433
• 96216 mod 1009 = 824
• 96225 mod 1009 = (824 * 433 * 962) mod 1009 = 356
• KA = 356
• Assume that a group of users (for example on LAN) agree
upon the global public parameters (‘α’ and ‘q’)
• Assume that a group of users (for example on LAN) each
creates a long-lasting private key (Xi).
• Each user calculates a public number (Y i) from their private.
• All public keys are stored in a trusted central location.
Use case of • Any user (j) can access another user’s (i) public value and
compute a secret key.
DHKE for • This key can be used to send encrypted messages between
users.
a group of • Only users ‘i’ and ‘j’ can figure out the key, so no one else
can read the messages.
users • User ‘i’ knows that only user ‘j’ could have sent the message,
confirming their identity. (Authentication, and Eventually
Resistance to Replay attack).
MITM on
DHKE
• Alice and Bob think they have a secret key together.
• But Bob has a secret key (K1) with Darth, and Alice has a
secret key (K2) with Darth.
• This setup allows Darth to intercept and manipulate
messages between Alice and Bob.
MITM on
DHKE • Alice sends a PT to Bob, encrypted with K2: E(K2, PT).
(Contd..) • Darth intercepts this message and decrypts it to get PT.
• Darth can send the original message PT to Bob, encrypted
with K1: E(K1, PT)
• Or Darth can even send a modified message to Bob, also
encrypted with K1: E(K1, PTm)
• Hence, there is severe threat to Authentication +
Confidentiality.