CNS Unit -3
CNS Unit -3
UNIT III
Asymmetric Encryption
Mathematics of Asymmetric Key Cryptography, Asymmetric Key Cryptography
A Table of values of x)
Example 1
Find the number of primes less than 1,000,000.
The approximation gives the range 72,383 to 78,543.
77
Cryptography and Network Security B.Tech(CSE) III Year II Sem
The actual number of primes is 78,498.
Checking for Primeness
Given a number n, how can we determine if n is a prime? The answer is that we need to see if the number is
divisible by all primes less than
Example 1:
Is 97 a prime?
The floor of 97) = 9. The primes less than 9 are 2, 3, 5, and 7. We need to see if 97 is divisible by any of
these numbers. It is not, so 97 is a prime.
Example 2:
Is 301 a prime?
The floor of 301) = 17. We need to check 2, 3, 5, 7, 11, 13, and 17. The numbers 2, 3, and 5 do not divide
301, but 7 does. Therefore 301 is not a prime.
Little Theorem
First Version: if p is prime and a is positive integer, then
ap 1 p
Second Version:
ap p
This means that if we divide ap by p then the remainder should be
Example 1:
Find the result of 610 mod 11.
We have 610 mod 11 = 1. This is the first version of little theorem where p = 11.
Example 2
Find the result of 312 mod 11.
Here the exponent (12) and the modulus (11) are not the same. With substitution this can be solved using
little theorem.
Multiplicative Inverses
a mod p = a p 2
mod p
Example
The answers to multiplicative inverses modulo a prime can be found without using the extended Euclidean
algorithm:
78
Cryptography and Network Security B.Tech(CSE) III Year II Sem
Example:
How to calculate multiplicative inverse of 5 modulo 23 that is 5-1 mod 23?
Solution:
1. 5-1 mod 23 = 523-2 mod 23 (Ref: a-1 mod p= ap-2 mod p)
23-2 21
2. 5 mod 23 = 5 mod 23
3. Calculate following to solve 521 mod 23:
51 mod 23 = 5
52 mod 23=25 mod 23=2
54 mod 23= (52)2 mod 23= (2)2 mod 23=4
58 mod 23= (54)2 mod 23 (4)2 mod 23=16
516 mod 23= (58)2 mod 23 (16)2 mod23=256 mod 23=3
Now binary equivalence of 21 is 10101, so multiply 51 , 54 and 516 values, leave 52 and 58 because these are
in binary form.
521 mod 23 = (516 x 54 x 51 ) mod 23=(3x4x5) mod 23=60 mod 23= 14 mod 23.
Finally 5-1 mod 23 = 521 mod 23 = 14 mod 23
79
Cryptography and Network Security B.Tech(CSE) III Year II Sem
4) Find (32)?
(32)= (32)- (32-1) = 9-3=6
5) What is the value of (13)?
Because 13 is a prime, (13) = (13 = 12.
6) What is the value of (10)?
We can use the third rule: (10) = (2) × (5) = 1 × 4 = 4, because 2 and 5 are primes.
7) What is the value of (240)?
We can write 240 = 24 × 31 × 51. Then
(240) = (24 3) × (31 30) × (51 50) = 64
8) Can we say that (49) = (7) × (7) = 6 × 6 = 36?
No. The third rule applies when m and n are relatively prime. Here 49 = 72. We need to use the fourth rule:
(49) = 72 1
= 42.
9) What is the number of elements in Z14*?
The answer is (14) = (7) × (2) = 6 × 1 = 6. The members are 1, 3, 5, 9, 11, and 13.
Example 2:
Find the result of 624 mod 35.
Solution
We have 624 mod 35 = 6 (35) mod 35 = 1.
Example :
Find 34 mod 10 ?
Solution
Example 3:
Find the result of 2062 mod 77.
Solution
If we let k = 1 on the second version,
we have f(77)= f(7)x f(11)=6x10=60
2062 mod 77 = (20 mod 77) (2060+1 mod 77) mod 77=
(20 mod 77) (20f(77) + 1 mod 77) mod 77
= (20)(20) mod 77 = 15.
Multiplicative Inverses
theorem can be used to find multiplicative inverses modulo a composite.
80
Cryptography and Network Security B.Tech(CSE) III Year II Sem
Example:
The answers to multiplicative inverses modulo a composite can be found without using the extended
Euclidean algorithm if we know the factorization of the composite:
Primitive Root :
81
Cryptography and Network Security B.Tech(CSE) III Year II Sem
If the Group G=<Zn*,x> has any primitive root, the number of primitive roots is
(n))
Example: Find the Number of primitive roots of 25
(25)=20
Find the primitive root of 761
( (761))= (760)
= (23x5x19) = (23)x (5)x (19)
=(23 - 22)x 4x18=4x4x18
=288
82
Cryptography and Network Security B.Tech(CSE) III Year II Sem
Example:
Find the solution to the simultaneous equations:
Solution:
We follow the four steps.
1. M = 3 × 5 × 7 = 105
2. M1 = 105 / 3 = 35, M2 = 105 / 5 = 21, M3 = 105 / 7 = 15
3. The inverses are M 1 = 2, M 2 = 1, M 3= 1
4. x = (2 × 35 × 2 + 3 × 21 × 1 + 2 × 15 × 1) mod 105 = 23 mod 105
Example 2:
Find an integer that has a remainder of 3 when divided by 7 and 13, but is divisible by 12.
Solution
This is a CRT problem. We can form three equations and solve them to find the value of x.
Example 3
Assume we need to calculate z = x + y where x = 123 and y = 334, but our system accepts only numbers less
than 100.
Now three equations can be solved using the Chinese remainder theorem to find z. One of the acceptable
answers is z = 457.
QUADRATIC CONGRUENCE
Quadratic Congruence is a congruence of the equation of the form a2x2 + a1x + a0 0 (mod n).
We limit our discussion to quadratic equations in which
a2 = 1 and a1 = 0, that is equation of the form.
x2 a (mod n)
83
Cryptography and Network Security B.Tech(CSE) III Year II Sem
There are two ways:
1. Quadratic Congruence Modulo a Prime
2. Quadratic Congruence Modulo a Composite
Quadratic Congruence Modulo a Prime
In this, we consider the modulus is a prime number. That is the form. x2 a (mod p)
Where p is a prime and is an integer.
Example 1: Solve the x2 3 (mod 11)
Solution: 3 congruent to modulo 11 are 3,14,25 (25 is 5x5 or (-5)x(-5))
The given equation has two solutions:
x2 25 (mod 11)
x 5 (mod 11) and x -5 (mod 11),
But -
So, the solutions are 5 and 6
Check the result: substitute x=5
52 25 =3 (mod 11)
substitute x=6
62 36 =3 (mod 11)
Example 2: Solve the y2 10 (mod 13)
Solution: The number 10 congruent to 13 are 10,23,36 (36 is 6x6 or (-6)x(-6))
The given equation has two solutions:
x (mod 13) and x -6 (mod 13),
But - (mod 13)
So, the solutions are 6 and 7
Check the result: substitute x=6
62 36 10 (mod 13)
substitute x=7
7 49 10 (mod 13)
Quadratic Congruence Modulo a Composite
Quadratic Congruence Modulo a Composite can be solved by set of Quadratic Congruence Modulo a Prime.
Decomposition of congruence modulo a composite:
84
Cryptography and Network Security B.Tech(CSE) III Year II Sem
The Trust Problem: Ensuring the integrity of received data and verifying the identity of the source of
85
Cryptography and Network Security B.Tech(CSE) III Year II Sem
4 Private key encryption, the other is used for decryption. The exact transformations
performed by the
algorithm depend on the public or private key that is provided as input
This is the scrambled message produced as output. It depends on the
5 Ciphertext plaintext and the key. For a given message, two different keys will produce
two different
ciphertexts.
6 Decryption This algorithm accepts the ciphertext and the matching key and produces the
algorithm original plaintext.
86
Cryptography and Network Security B.Tech(CSE) III Year II Sem
There is some source A that produces a message in plaintext X = [X1, X2, . . . ,XM].
The M elements of X are letters in some finite alphabet. The message is intended for destination B. B
generates a related pair of keys: a public key, PUb, and a private key, PRb.
PRb is known only to B, whereas PUb is publicly available and therefore accessible by A.
With the message X and the encryption key PUb as input, A forms the ciphertext Y = [Y1, Y2, . . . , YN]:
The intended receiver, in possession of the matching private key, is able to invert the
transformation:
Public key cryptography for proving Authentication:
87
Cryptography and Network Security B.Tech(CSE) IV Year I Sem
The above diagrams show the use of public-key encryption to provide authentication:
It is impossible to alter the message without access to private key, so the message is
authenticated both in terms of source and in terms of data integrity.
It is, however, possible to provide both the authentication function and confidentiality by a double use of
decrypted only by the intended receiver, who alone has the matching private key. Thus, confidentiality is
provided.
Public-Key Cryptanalysis
As with symmetric encryption, a public-key encryption scheme is vulnerable to a brute-force attack. The
countermeasure is the same: Use large keys. However, there is a tradeoff to be considered. Public- key
systems depend on the use of some sort of invertible mathematical function. The complexity of
calculating these functions may not scale linearly with the number of bits in the key but grow more
rapidly than that. Thus, the key size must be large enough to make brute-force attack impractical but
small enough for practical encryption and decryption. In practice, the key sizes that have been proposed
do make brute-force attack impractical but result in encryption/decryption speeds that are too slow for
general-purpose use. Instead, as was mentioned earlier, public-key encryption is currently confined to key
management and signature applications.
RSA Algorithm
It is the most common public key algorithm.
This RSA name is get from its inventors first letter (Rivest (R), Shamir (S) and Adleman (A))
in the year 1977.
The RSA scheme is a block cipher in which the plaintext & ciphertext are integers between
0 and n-1 for some n.
A typical size for n is 1024 bits or 309 decimal digits. That is, n is less than 21024
n. that is, the block size must be less than or equal to log2(n)
RSA uses two exponents e and d where e public and d private.
Encryption and decryption are of following form, for some PlainText
M and CipherText block C
For any integer b and a, here a is a primitive root of prime number P, then
aimod P 0 i (P-1)
The exponent i is refer as discrete logarithm or index of b for the base a, mod P.
The value denoted as ind a,p(b)
Algorithm for Diffie-Hellman Key Exchange:
Step 1 Select global public numbers q,
q Prime number
primitive root of q and q.
Step 2 if A & B users wish to exchange a key
a) User A select a random integer XA<q and computes
b) User B independently select a random integer XB <q and computes
c) Each side keeps the X value private and Makes the Y value available publicly to
the outer side.
Step 3 User A Computes the key as
User B Computes the key as
Step 4 two calculation produce identical results
The result is that the two sides have exchanged a secret key.
Example:
The key exchange protocol is vulnerable to such an attack because it does not
authenticate the participants. This vulnerability can be overcome with the use of digital
signatures and public-key certificates.
Elliptic Curve Cryptography
Elliptical curve cryptography (ECC) is a public key encryption technique based on elliptic
curve theory that can be used to create faster, smaller, and more efficient cryptographic
keys. ECC generates keys through the properties of the elliptic curve equation instead of the
traditional method of generation as the product of very large prime numbers
An elliptic curve is defined by an equation in two variables with coefficients. For
cryptography, the variables and coefficients are restricted to elements in a finite field, which
results in the definition of a finite abelian group.
ECC-Key Exchange:
Take two Global public Elements
Eq(a,b) : Elliptic curve with parameters a,b, & q
G : Point on elliptic curve whose order is large value n
Alice Key Generation:
Select private key nA : nA < n
Calculate public key PA: PA = nAxG
Bob Key Generation:
Select private key nB : nB < n
Calculate public key PB : PB = nBxG
Secrete Key calculation by Alice
K=nAxPB
Secrete Key calculation by Bob
K=nBxPA
ECC- Encryption
Let the message be M
First encode the message M into a point on the elliptic curve
Let this point be Pm
Now this point is encrypted
For encryption choose a random positive integer k
Then Cm={ kG,Pm+kPB } where G is the base point
ECC-Decryption
Multiply first point in the pair with receivers secrete key
i.e, kG x nB
Then subtract it from second point in the pair
i.e, Pm + kPB- (kGx nB)
EIGamal Algorithm:-
Thus, functions as a one-time key, used to encrypt and decrypt the message.
For example, let us start with the prime field GF(19); that is, q = 19. It has
RABIN CRYPTOSYSTEM
Rabin Cryptosystem is an public-key cryptosystem invented by Michael Rabin, is a variation of the RSA.
RSA is based on the exponentiation congruence; Robin is based on quadratic congruence.
The public key in the Rabin is n, private key is the tuple(p,q). Everyone can encrypt a message using n, only
Bob can decrypt the message using p and q.
Decryption of the message is infeasible It uses asymmetric key encryption for communicating between two
parties and encrypting the message.
The security of Rabin cryptosystem is related to the difficulty of factorization. It has the advantage over the
others that the problem on which it banks has proved to be hard as integer factorization.
It has the disadvantage also, that each output of the Rabin function can be generated by any of four possible
inputs. if each output is a cipher text, extra complexity is required on decryption to identify which of the
four possible inputs was the true plaintext.
Decryption
1. Accept C from sender.
2. Compute:
a1 = C(p+1)/4 mod p
a2= - C(p+1)/4 mod p
b1= C(q+1)/4 mod q
b2= - C(q+1)/4 mod q
3. Calculate four Plain text by using Chinese Remainder Algorithm:
M1=Chainese_Remainder(a1,b1,p,q)
M2=Chainese_Remainder(a1,b2,p,q)
M3=Chainese_Remainder(a2,b1,p,q)
M4=Chainese_Remainder(a2,b2,p,q)
4. Choose one of the above (M1,M2,M3 and M4) is the appropriate plaintext.
The Rabin cryptosystem is not deterministic: Decryption creates four equally probable plain texts
Example:
1. Bob selects p=23 and q=7, note both are congruent to 3 mod 4
2. Bob calculates n=pxq=161
3. Bob announces n publickly; he keeps p and q private
4. Allice want to send plain text P=24. Note that 161and 24 are relatively prime; 24 is in Z161*
She calculates C=242 mod 161 =93 mod 161, and sends the ciphertext 93 to Bob
5. Bob receives 93 and calculates four values:
a. a1=+(93(23+1)/4 mod 23=1 mod 23
b. a2=-(93(23+1)/4 mod 23=22 mod 23
c. b1=+(93(7+1)/4 mod 7=4 mod 7
d. b2=-(93(7+1)/4 mod 7=3 mod 7
6. Bob takes four possible answers, (a1,b1), (a1,b2), (a2,b1),(a2,b2) and uses Chinese Remainder Theorem to
find 4 possible plain texts: 116,24,137 and 45.
Case 1:
By using (a1=1,b1=4) combinations with modulo (p=23,q=7), Let X is plain text:
X = 1 mod 23
X= 4 mod 7
By using Chinese Remainder Theorem:
M=23x7=161, M1=M/23=161/23=7, M2=M/7=161/7=23
M1-1=7-1 mod 23 = 723-2 mod 23 = 721 mod 23=10
M2-1=23-1 mod 7 = 237-2 mod 7 = 235 mod 7=4
X= (a1 x M1xM -11 +a2xM2xM -12) mod M
=( 1 x 7 x 10 + 4 x 23 x 4) mod 161 = 438 mod 161=116
Case 2:
By using (a1=1,b2=3) combinations with modulo (p=23,q=7), Let X is plain text:
X = 1 mod 23
X= 3 mod 7
By using Chinese Remainder Theorem:
M=23x7=161, M1=M/23=161/23=7, M2=M/7=161/7=23
M1-1=7-1 mod 23 = 723-2 mod 23 = 721 mod 23=10
M2-1=23-1 mod 7 = 237-2 mod 7 = 235 mod 7=4
X= (a1 x M1xM -11 +a2xM2xM -12) mod M
=( 1 x 7 x 10 + 3 x 23 x 4) mod 161 = 346 mod 161=24
Case 3:
By using (a2=22,b1=4) combinations with modulo (p=23,q=7), Let X is plain text:
X = 22 mod 23
X= 4 mod 7
By using Chinese Remainder Theorem:
M=23x7=161, M1=M/23=161/23=7, M2=M/7=161/7=23
M1-1=7-1 mod 23 = 723-2 mod 23 = 721 mod 23=10
M2-1=23-1 mod 7 = 237-2 mod 7 = 235 mod 7=4
X= (a1 x M1xM -11 +a2xM2xM -12) mod M
=( 22 x 7 x 10 + 4 x 23 x 4) mod 161 = (1540+368) mod 161=137
Case 4:
By using (a2=22,b2=3) combinations with modulo (p=23,q=7), Let X is plain text:
X = 22 mod 23
X= 4 mod 7
By using Chinese Remainder Theorem:
M=23x7=161, M1=M/23=161/23=7, M2=M/7=161/7=23
-1 -1 23-2 21
M1 =7 mod 23 = 7 mod 23 = 7 mod 23=10
M2-1=23-1 mod 7 = 237-2 mod 7 = 235 mod 7=4
X= (a1 x M1xM -11 +a2xM2xM -12) mod M
=( 22 x 7 x 10 + 3 x 23 x 4) mod 161 = (1540+276) mod 161=45
So, Finally from four cases: we got four plain text messages
Case 1: 116
Case 2: 24
Case 3: 137
Case 4: 45.
Only second answer(24) is Alice plain text, Bob needs to make a decision based on the situation