CNS UNIT-3
CNS UNIT-3
• A key needs to be delivered to the recipient of the coded message for it to be deciphered
The concept of public key cryptography is invented for two most difficult problems of Symmetric key
encryption.
Asymmetric Encryption
• Messages encoded using public key can only be decoded by the private key
– Every entity can generate a key pair and release its public key
Use public key for encryption and private key for decryption.
Use private key for encryption and public key for decryption. But anyone can decrypt it using public
key.
First encrypt with private key of A then again encrypt using public key of B at sender side.
Then decrypt with private key of B then again decrypt using public key of A at Receiver side. .
Man-in-the-middle attack
Hacker could generate a key pair, give the public key away and tell everybody, that it belongs
to somebody else. Now, everyone believing it will use this key for encryption, resulting in the
hacker being able to read the messages. If he encrypts the messages again with the public key of
the real recipient, he will not be recognized easily.
• Key agreement is a method to create secret key by exchanging only public keys.
• Example
– Bob uses Alice’s public key and his private key to generate a session key
– Alice uses Bob’s public key and her private key to generate a session key
– Fermat’s
– Euler’s
– Miller Rabin
– Fast exponentiation
• Prime factorization
• Primality test
• Discrete Logarithms
Introduction
Modulo arithmetic
Properties of primes
Multiword arithmetic
– RSA algorithm
• Diffie-Hellman algorithm
• Any number can be factored uniquely into a product of primes to some power
• note that factoring a number is relatively hard compared to multiplying the factors together to
generate the number
• Fermat’s
• Euler’s theorem
• Miller-Rabin test
• Fast exponentiation
SUTHOJU GIRIJA RANI, Assistant Professor, CSE
Cryptography and Network Security NGIT
– Convert x to binary – for example x8 is x squared three times
Fermat’s Theorem
• ap-1 = 1 (mod p)
• also ap = p (mod p)
Euler’s Theorem
• aø(n) = 1 (mod n)
hence 34 = 81 = 1 mod 10
a=2;n=11; ø(11)=10;
Now introduce the Euler’s totient function ø(n), defined as the number of positive integers less
than n & relatively prime to n. Note the 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). Note by convention that ø(1) = 1.
• reduced set of residues is those numbers (residues) which are relatively prime to n
– eg for n=10,
• number of elements in reduced set of residues is called the Euler Totient Function ø(n)
• eg. ø(37) = 36
Primality Testing
– ie. divide by all numbers (primes) in turn less than the square root of the number
– but some composite numbers, called pseudo-primes, also satisfy the property
algorithm is as follows:
4. for j = 0 to k – 1 do
6. return ("composite")
• hence if repeat test with different random a then chance n is prime after t tests is:
One of the most useful results of number theory is the Chinese remainder theorem (CRT), so
called because it is believed to have been discovered by the Chinese mathematician Sun-Tse in
around 100 AD. It is very useful in speeding up some operations in the RSA public-key
scheme, since it allows you to do perform calculations modulo factors of your modulus, and
then combine the answers to get the actual result. Since the computational cost is proportional
to size, this is faster than working in the full modulus sized modulus.
One of the useful features of the Chinese remainder theorem is that it provides a way to
manipulate (potentially very large) numbers mod M, in terms of tuples of smaller numbers.This
can be useful when M is 150 digits or more. However note that it is necessary to know
beforehand the factorization of M.
• since computational cost is proportional to size, this is faster than working in the full modulus
M
• to compute A(mod M)
Primitive Roots
• from Euler’s theorem have aø(n)mod n=1
Discrete Logarithms
Discrete logarithms are fundamental to a number of public-key algorithms, including Diffie-Hellman
key exchange and the digital signature algorithm (DSA).
Discrete logs (or indices) share the properties of normal logarithms, and are quite useful. The logarithm
of a number is defined to be the power to which some positive base (except 1) must be raised in order to
equal that number. If working with modulo arithmetic, and the base is a primitive root, then an integral
discrete logarithm exists for any residue.
However whilst exponentiation is relatively easy, finding discrete logs is not, in fact is as hard as
factoring a number. This is an example of a problem that is "easy" one way (raising a number to a
power), but "hard" the other (finding what power a number is raised to giving the desired answer).
Problems with this type of asymmetry are very rare, but are of critical usefulness in modern
cryptography.
• the inverse problem to exponentiation is to find the discrete logarithm of a number modulo p
• whilst exponentiation is relatively easy, finding discrete logarithms is generally a hard problem
– Provided ability for messages to be exchanged securely without having to have shared
some secret information previously
– Inception of public key cryptography which allowed keys to be exchanged in the open
BOB
ALICE
Both Bob and Alice generates an identical secret key – Same key
RSA Cryptosystem
• Developed by Ron Rivest, Adi Shamir, Len Adelman
Encryption and Decryption is also possible by RSA algorithm along with key generation.
• Choose number e, less than n, which has no common factor (other than 1) with z
o 15 759375 15 - O – m
is plain
text
v 22 5153632 22 - V
– c
e 5 3125 10 - J is
cipher
text
• Decryption: m = cd mod n
• e=5
17 481968572106750915091411825223072000 12 l
15 12783403948858939111232757568359400 15 o
22 852643319086537701956194499721110000000 22 v
10 100000000000000000000000000000 5 e
Generated back the Plain text successfully using RSA Cryptosystem in the above table
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 in feasible It uses asymmetric key encryption for communicating
between two parties and encrypting the message.
The security of Rabin crypto system 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.
Steps in Rabin cryptosystem Key generation
1. Generate two very large prime numbers, p and q, which satisfies the condition
p≠q→p≡q≡3(mod4)
For example:
p=139 and q=191
2. Calculate n=p.q
3. Public_key=n
4. Private_key=(p,q)
5. Return public_key,Private_keys
Encryption
1. Get the public key n.
2. Convert the message to ASCII value. Then convert it to binary and extend the binary
value with itself, and change the binary value back to decimal M.
3. Encrypt with the formula: C = M2 mod n
4. Send C to recipient.
Decryption
1. Accept C from sender.
2. Compute:
(p+1)/4
a1 = C 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 crypto system is not deterministic: Decryption creates four equally probable
plaintexts
Example:
1. Bob selects p=23 and q=7, note both are congruent to 3mod4
2. Bob calculates n=pxq=161
3. Bob announces n publicly; he keeps p and q private
4. Alice want to send plaintext P=24. Note that 161and 24are relatively prime; 24 is in Z 161*
She calculates C=242 mod161 =93mod161, and sends the cipher text 93toBob
5. Bob receives 93 and calculates four values:
a. a1=+(93(23+1)/4mod23=1mod23
b. a2=-(93(23+1)/4mod23=22mod23
c. b1=+(93(7+1)/4mod7=4mod7
d. b2=-(93(7+1)/4mod7=3mod7
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.
Case1:
By using (a1=1, b1=4) combinations with modulo (p=23, q=7),
Let X is plaintext: 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 mod23=10
M2-1=23-1mod7=237-2mod7=235mod 7=4
X=(a1xM1xM1 -1+a2xM2xM-12 ) mod M = (1x7x10+4x23x4) mod 161=438 mod 161=116
Case2:
By using (a1=1,b2=3)combinations with modulo(p=23,q=7),Let X is plaintext: X = 1 mod 23
X=3mod7
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 mod23=10
M2-1=23-1mod7=237-2mod7=235mod 7=4
X=(a1xM1xM1 -1+a2xM2xM-12 )modM =(1x7x10+3x23x4)mod161=346mod161=24
Similarly case3 & case 4 to be calculated.
So, Finally from four cases: we got four plaintext messages
Case1:116
Case2:24
Case3:137
Case4:45.
Only second answer(24) is Alice plaintext, Bob needs to make a decision based on the situation
ECC-Key Exchange:
Bob Key Generation: Select private key nB: nB< n Calculate public key PB:PB=nBxG
ECC-Encryption
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 primitive roots
{2, 3, 10, 13, 14, 15 }. We choose α = 10.
Alice generates a key pair as follows: