Information and Network Security: Ms. Hansa Vaghela
Information and Network Security: Ms. Hansa Vaghela
2
Contents
1. Prime numbers
2. Euler Totient function
3. Euler’s theorem
4. Fermat’s Theorem
5. Testing for primality
6. Principles of public key Cryptosystems
7. RSA algorithm
8. Diffie – Hellman Key exchange algorithm
3
Prime Numbers
• An integer p > 1 is a prime number if and only if its only divisors are 1 and itself
• Ex. 2,3,5,7 are prime, 4,6,8,9,10 are not
•List of prime number less than 200 is:
• 2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97 101
103 107 109 113 127 131 137 139 149 151 157 163 167 173 179 181 191
193 197 199
• Prime Factorisation
•The prime factorisation of a number n is when its written as a product of primes
•eg. 91=7x13 ; 3600=24x32x52
4
Relative Prime Number
• Two numbers a, b are relatively prime if have no common divisors apart from 1
5
EULER’S TOTIENT FUNCTION
6
Euler Totient Function ø(n)
• The Euler’s totient function ø(n), defined as the number of positive
integers less than n & relatively prime to n.
• Term “residue” refers to numbers less than some modulus, and the
“reduced set of residues” to those numbers (residues) which are
relatively prime to the modulus (n).
Ex for n=10,
complete set of residues is {0,1,2,3,4,5,6,7,8,9}
Reduced set of residues is {1,3,7,9}
7
Euler Totient Function ø(n)
• To compute ø(n) need to count number of residues to be excluded
• eg.
• ø(37) = 36
• ø(21) = (3–1)x(7–1) = 2x6 = 12
8
Euler’s Theorem
• For every a and n that are relatively prime
aø(n) ≡ 1 (mod n) for any a,n where gcd(a,n)=1
• Ex.
• a=3; n=10; ø(10)=4;
• hence 34 = 81 = 1 mod 10
9
FERMAT’S THEOREM
10
Fermats theorem
if 'p' is a prime number and 'a' is a positive integer not divisible by 'p' then a(p-1)
= 1 (mod p)
Example: Does Fermat's theorem hold true tor P= 5 and a=2?
Solution: Given P=5&a=2
a(P-1) = 1 (modp)
2(5-1)= 1 Imod 5)
2(4) = 1 (mod5)
16 = 1 (mods)
Therefore, fermats theorem hold true for above.
11
Fermat’s Theorem
• ap-1=1(mod p)
12
Fermat’s Theorem
• Solve following:
• 2345 mod 11
• 350 by 7
• 5101mod31
13
TESTING FOR PRIMALITY
• For many cryptographic algorithms, it is necessary to select one or more
very large prime numbers at random.
• Thus, we are faced with the task of determining whether a given large
number is prime.
• There is no simple yet efficient means of accomplishing this task.
• Miller-Rabin Algorithm
• Probabilistic primality test
• checks whether a specific property, which is known to hold for prime
values, holds for the number under testing
14
Miller-Rabin Algorithm
• The algorithm due to Miller and Rabin [MILL75, RABI80] is typically used
to test a large number for primality
TEST (n)
1. Find integers k, q, with k > 0, q odd, so that (n-1 = 2 kq);
2. Select a random integer a, 1 < q < n-1;
3. if aq mod n = 1 then return (“inconclusive”);
4. for j = 0 to k – 1 do
5. if a2jq mod n = n – 1 then return (“inconclusive”);
6. return (“composite”);
15
Example
• Suppose n =29
• Find ( n- 1) = 28 = 22(7)= 2kq
• Let us try a = 10
• 107 mod 29 = 17 (its neither 1 nor 28, so continue test)
• (107)2 mod 29 = 28 hence test return “in clonclusive”
16
Example
• Now let us apply the test to the composite number
• N = 13*17 = 221
• Then
• (n-1) = 220 = 22(55)= 2kq
• Let us try a=5
• 555mod 221 = 112 (neither 1 nor 220)
• (555)2 mod 221 = 168 test return “Composite”
17
PRINCIPLES OF PUBLIC KEY CRYPTO SYSTEMS
18
Principles Of Public-Key Cryptosystems
• Public-Key Cryptosystems
• Applications for Public-Key Cryptosystems
• Requirements for Public-Key Cryptography
• Public-Key Cryptanalysis
19
Introduction
• Asymmetric encryption is a form of cryptosystem in which encryption
and decryption are performed using the different keys- one is a public
key and one a private key. It is also known as public-key encryption.
• Asymmetric encryption transform plaintext into ciphertext using one of
two keys and an encryption algorithm. Using the paired key and
decryption algorithm, plaintext is recovered from the ciphertext.
• Asymmetric encryption can be used for confidentiality, authentication,
or both.
• The most widely used public-key cryptosystem is RSA. The difficulty of
attacking RSA is based on the difficulty of finding the prime factors of a
composite number.
20
Principles of Public-key Cryptosystems
• Public-key algorithms are based on mathematical functions rather than
on substitution and permutation.
• Public-key encryption is more secure from cryptanalysis than is
symmetric encryption.
• The concept of public-key cryptography evolved from an attempt to
attack two of the most difficult problems associated with symmetric
encryption.
• (1) two communications already share a key, which somehow has been
distributed to them.
• (2) the use of key distribution center.
• The idea of public-key cryptography was invented by Diffie and Hellman.
21
Public-key Cryptosystems
• Asymmetric algorithm rely on one key for encryption and a different but
related key for decryption.
22
Public-key Cryptosystems (Conti…)
• Plaintext
• Encryption algorithm
• Ciphertext
• Decryption algorithm
24
Public-key Cryptosystems (Conti…)
• The essential steps for the communication in PKC are as follows:
• Each user generate a pair of keys to be used for the encryption and
decryption of messages.
• Each user places one of the two keys in a public register or other
accessible file. This is public key. The companion key is kept private.
• If bob wishes to send a confidential message to alice, bob encrypts the
message using alice’s public key.
• When alice receives the message, she decrypt it using her private key.
No other recipient can decrypt the message because only alice knows
her private key.
25
Public-key Cryptosystems (Conti…)
• With this approach, all participants have access to public keys, and
private keys are generated locally by each participant and therefore
need never be distributed .
• At any time, a system can change its private key and publish the
companion public key to replace its old key.
26
Public-key Cryptosystems (Conti…)
• Y = E(PUb, X)
• X = D(PRb, Y)
28
Public-key Cryptosystems (Conti…)
• Encryption/decryption
• Digital signature
• Key exchange
33
Requirements for Public-key Cryptography
• The PKC algorithm must fulfill the following conditions
34
THE RSA ALGORITHM
35
The RSA Algorithm
• RSA - Ron Rivest, Adi Shamir and Len Adleman at MIT, in 1977.
• RSA is a block cipher
• The most widely implemented
• Provides confidentiality (encryption/decryption) and digital
signatures for authentication and integrity checking.
• Encryption: Data is encrypted using the recipient's public key. This
scrambled data, called ciphertext, can only be decrypted with the
corresponding private key.
• Decryption: The recipient uses their private key to decrypt the
ciphertext, transforming it back to the original data (plaintext).
• The security of RSA relies on the difficulty of factoring large numbers.
Because the public key is based on the product of two large prime
numbers, cracking it would involve factoring this large number, which
is computationally infeasible with current technology.
36
RSA Algorithm
Here's why RSA is important for network security:
Confidentiality: It ensures only authorized parties with the private key can access
encrypted information.
Digital Signatures: RSA can be used for digital signatures, allowing verification of
the sender's identity and message integrity.
However, it's important to note that RSA isn't perfect. The key size is crucial, and
with increasing computing power, larger key sizes are needed to maintain
security.
37
The RSA Algorithm (Conti…)
Key Generation Alice
• Select p,q p and q both are prime, p≠q
• Calculate n= p*q
• Calculate ø (n)= (p-1)*(q-1)
• Select integer e gcd(ø(n),e)=1; 1<e< ø(n)
• Calculate d d=e-1 (mod(ø(n)))
• Public Key PU= {e,n}
• Private Key PR={d,n}
38
The RSA Algorithm (Conti…)
• To encrypt a message
c = me mod n
• To decrypt a message
m = cd mod n
= (me mod n)d mod n
= med mod n
= m1+kø(n)mod n
= m . mkø(n)mod n
=m
39
RSA Example- Key setup
• Select two prime numbers
• P=17 and q=11
• Compute n
n= p*q = 17*11= 187
• Compute ø Value
Ø (n) = (p-1)*(q-1)= (17-1)*(11-1)= 16*10 = 160
• Select Encryption Parameter
e : gcd(e,160)=1; choose e =7
40
RSA Example- Key setup
• Determine Decryption Parameter
d: de=1 mod 160 and d < 160
Value of d = 23 since 23*7 = 161
41
RSA Example- En/Decryption
• Encrypt message M =88
C = 887 mod 187
= 88 (3+3+1) mod 187
= ((883 mod 187) (883mod 187)(88 mod 187)) mod 187
= (44 * 44 * 88 ) mod 187
= 11
• Decryption is:
M = 1123 mod 187 = 88
42
RSA Example- Key setup
• Select two prime numbers
P=11 and q=3
• Compute n
n= p*q = 11*3= 33
• Compute ø Value
Ø (n) = (p-1)*(q-1)= (11-1)*(3-1)= 10*2 = 20
• Select Encryption Parameter
e : gcd(e,20)=1; choose e =3
• Determine decryption parameter
d: de=1 mod 20 and d<20 ; d=7 since
43
RSA Example- En/Decryption
• The sample RSA private/public operations are:
• Given message M = 7
• Encryption is:
• C= 73 mod 33
• = 343 mod 33
• = 13
• Decryption is:
M = 137 mod 33
= 13(3+3+1) mod 33
=((133 mod 3)*(133 mod 33)*(13 mod 33)) mod 33
=19*19*13 mod 33= 4693 mod 33 = 7
44
RSA Example- Key setup
• Consider the text grouping in the groups of three i.e
• ATTACKXATXSEVEN = ATT ACK XAT XSE VEN
• Represent the blocks in base 26 using A=0, B=1, C=2 …
• ATT = 0*262 + 19*261 + 19 = 513
• ACK =0*262+ 2*261 + 10 = 62
• XAT= 23*262 + 0*261 + 19 = 15567
• XSE= 23 *262 + 18 * 261 + 4 = 16020
• VEN= 21*262 + 4*261 + 13 = 14313
• What should be the value of n?
• The value of n should be greater than 17575. How & Why?
• Let p = 137 and q = 131; so that n= pq = 17947
45
RSA Example- Key setup
• Compute phi value:
• Ø(n) = (p-1)(q-1) = 136*130 = 17680
• Select encryption parameter
• e: gcd(e,17680)=1; choose e=3
• Determine decryption parameter
• d: de=1 mod 17680 and d< 17680
• Value is d=11787 since 11787*3 = 35361= 11787*2+1
• Publish public key PU= {3, 17947}
• Keep secret private key PR={7, 17947}
46
RSA Example- En/Decryption
• The sample RSA private/public operations are:
• Given message M = ATT = 513
• Encryption is
• C = 5133 mod 17947 = 8363
• Decryption is
• M= 836311787 mod 17947 = 513
• Plaintext is represented as the set of integer’s m
• {513, 62, 15567, 16020, 14313}
• Cipher text is represented as the set of integers m
• { 8363, 5017, 11884, 9546, 13366}
47
The RSA Algorithm (Conti…)
Encryption by Bob with Alice’s Public Key
Plaintext: M<n
Cipher Text C= M e mod n
48
The Security of RSA
• Four possible approaches to attacking the RSA algorithm are as follows:
• Brute force: this involves trying all possible private keys.
• The defense against the brute-force approach is same for RSA as for
other cryptosystem, namely, use a large key space.
• So the large number of bit in d is better.
• However, because the calculations involve, both in key generation and
in encryption/decryption, are complex, the large the size of key, the
slower the system will run.
• Timing attacks: these depend on the running time of the decryption
algorithm.
• Chosen ciphertext attacks: this type of attack exploits properties of the
RSA algorithm.
49
The Security of RSA (Conti…)
• The Factoring Problem: we can identify three approaches to attacking
RSA mathematically.
• Factor n into its two prime factors. This enables calculation of ø(n)=(p-1)
(q-1), which, in turn, enables determination of d = e -1 mod ø(n)
50
The Security of RSA (Conti…)
• Timing Attacks:
• Timing attacks are applicable not just for RSA, but to other public-key
cryptography systems.
51
The Security of RSA (Conti…)
• There are simple countermeasures that can be used for timing attack:
• Constant exponentiation time.
• Ensure that all exponentiations take the same amount of time before
returning a result. This is a simple but does degrade performance.
• Random delay
• Better performance could be achieved by adding a random delay to the
exponentiation algorithm to confuse the timing attack.
• Blinding: multiply the ciphertext by a random number before
performing exponentiation .
• This process prevents the attacker from knowing what ciphertext bits
are being processed inside the computer and so prevents the bit-by-bit
analysis essential to the timing attack
52
Issue:
53
DIFFIE-HELLMAN KEY EXCHANGE ALGORITHM
54
Diffie Hellman Algorithm
• The Diffie-Hellman (DH) key exchange algorithm is a clever
method for two parties (like Alice and Bob) to securely establish
a shared secret key over an insecure public channel, without ever
actually exchanging the key itself. Here's a simplified
explanation:
• Imagine Alice and Bob want to chat secretly over a walkie-talkie:
• Public Agreement: They agree on two publicly known numbers: a
large prime number (p) and a base number (g). Think of these like
ingredients for a secret recipe.
55
Diffie Hellman Algorithm
• Secret Ingredients: Each keeps a secret number to themselves (a for Alice
and b for Bob). These are their private keys.
• Key Exchange:
• Alice uses her secret (a) and the public ingredients (g and p) to create a
message (A) and sends it over the walkie-talkie (insecure channel).
• Bob does the same with his secret (b), creating a message (B) and
sending it back.
• Secret Handshake:
• Alice now uses Bob's message (B) along with her own secret (a) and
the public numbers (p and g) to create a shared secret key (K).
• Bob uses Alice's message (A) along with his own secret (b) and the
public numbers to arrive at the same shared secret key (K).
56
Diffie Hellman Algorithm
• Crucially, no one listening on the walkie-talkie can figure out the secret key
(K) from the messages exchanged (A and B). The math behind DH makes it
very difficult to derive the secret key without the private information (a and
b).
57
Alice wants to send a message to Bob
Eve
Alice
Bob
58
Can use cryptography
Eve
Bob
Alice
60
Introduction
61
Introduction Cont..
• Security of transmission is critical for many network and Internet
applications
62
Key exchange
= =
63
Key Exchange Cont…
= =
64
Basic Concept
eas
+ y
har
+ d
Based on the difficulty of computing discrete
logarithms of large numbers.
65
Key exchange
YA YB q
q
α α
XA = YA YB
= XB
66
Key Exchange Cont…
YA YB
=
XA XB
=
K
K
YB YA
67
Algorithm
• Global Public Elements
• q prime number
• α α < q and α a primitive root of q
• User A Key Generation
• Select private XA XA < q
• Calculate public YA YA= αXA mod q
• User B Key Generation
• Select private XB XB < q
• Calculate public YB YB = αXB mod q
68
Algorithm Cont…
69
Example
• Alice and Bob get public numbers
• q = 23, α = 9
70
Example cont..
71
Applications
• Diffie-Hellman is currently used in many protocols, namely:
72
Conclusion
73
Man in the middle attack
Suppose Alice and Bob wish to exchange keys, and Darth is the adversary.
1. Darth prepares for the attack by generating two random private keys XD1 and
XD2 and then computes corresponding public keys YD1 and YD2.
2. Alice transmits YA to Bob.
3. Darth intercepts YA and transmits YD1 to Bob. Darth also calculates K2=(YA)XD2
mod q.
4. Bob receives YD1 and calculates K1 = (YD1)XB mod q.
76
www.paruluniversity.ac.in
77