0% found this document useful (0 votes)
34 views11 pages

CNS Assignment 2 Ans PDF

Uploaded by

yashwini sai
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
34 views11 pages

CNS Assignment 2 Ans PDF

Uploaded by

yashwini sai
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

Unit - 2

PUBLIC KEY CRYPTOGRAPHY


2.0 INTRODUCTION
The concept of
symmetric encryption. public key
cryptography came to attack two problems
associated with
The problems are,
1, Key Distribution:
For the key
distribution many alternatives were discussed.
2. The Digital Signatures:
If the use of cryptography was to
have wide spread uses in
purposes, the messages need to have an
all the commercial and
private
This unit discusses about the
equivalent of signatures used in paper
public key documents.
2.1 FRAME WORK cryptography.
FOR PUBLIC KEY
The public key CRYPTOGRAPHY
use of one key for cryptography is otherwise called as Asymmetric
encryption, yet another different key for cryptography. They make
Characteristics of Public Key Cryptographie Algorithms:decryption.
1. It should be
computationally
cryptographic algorithm and the infeasible
to determine the decryption key given the
2
encryption key.
Either of the two keys can be used for
encryption, while the other is used for decryption.
2.2
INGREDIENTS OF PUBLIC KEY CRYPTOGRAPHY
1. Plain Text :
The data that is fed into the
algorithm as input.
2.
Encryption Algorithm :
The Encryption algorithm performs
transformations on the plain text.
2.

2.2
Cayptography &Network Securi
3 Public and Private Kevs :

This is a pair of key that have been selected so that one


other key is used for decryption. key is used for encryption and th
4 Cipher Text :

This is the scrambled message produced as output. The


and the key. For a given message, two output depends on the plain te:
different keys will produce two different ciphe
texts.

Decryption Algorithm:
This algorithm accepts the cipher tevt and the
keys to produce the original plain text.
Encryption:
The essential steps are

Each user generates a pair of keys to be used for encryption and decryption of message
2 Each user places one of the two keys in a public register which is accessible to all. This
the public key. The other key is the private key.

B's B's
User
Public key l Private key
User
A

Plain CT
Text
Encryption Decryption ’PT
Algorithm Algorithm

Figure: 2.1

The above figure shows that each user maintains the public key of others, which is th
model for security.
3. Awants to transmit a confidential message to B, Aencrypt's the message with B's public ke
4. When B receives the message, decrypts the message with it's own private key.

The above method works well, when all the participants have access to public keys, an
private keys which is generated by itself and kept securely. Hence there is no need of key exchang

Public Key Cryptography


Differences between Public Key Cryptography and Symmetric -

S.No. Symmetric Public key


ame aloorithm and same One algorithm is used for encryption and
The same algorithm and s a m e O n e alg nm 1S
key is used for encryption and decryption, one key is used for encryption and
decryption. another key for decryption.
The sender and receiver shoukd The sender and the receiver should have one
2.
share the algorihm and key key.
3 The key must be kept secret. One of the keys should be kept secret.

4. It must be computat io na lly It should be computationally secure.


secure.

5. It must be unco nditio nally It must be unconditiona lly secure


secure.

2.3 PUBLIC KEY CRYPTOGRAPHY FOR SECURITY


Source A
Crypt Destination B
analysing >PR,

Encryption Decryption X
Message
Message algorithm algorithm

PU, PR,
Key
pair

Figure 2.2 Public Key Cryptography for Security


A be the source and B be the destination.

The explanation to the above figure,


Bgenerates a pair of keys PU, the public key, PR, the private key kept securely. PU, is
made available in the database accessible by all the users.
Y = E (PU, X) Where X in the plain text.

Y in the cipher text.


V The receiver has its own private key, hence the decryption is X= D (PR,, Y).

2.4 Cryptography &Network Security

The crypt analyst can act in between to determine the estimate of the key PR (or) the
estimate of the message &.
Crypt
A analyst >PR,
Message
SOurce
EA Y
DA
X Message
TDestination
PR, PU,

Key Figure 2.3


sOurce pait Public Key Cryptography
for Authenticat ion

The above figure is needed to provide authentication:


Y= E(PR,, X)
X = D(PU, Y)
Because as the message was encrypted using A's private key, no one else would have
prepared the message. Hence the above stands as digital signature. No one can alter the message.
Hence the message is authenticated of source and data integrity.
In order to have confidentiality and authentication we have the following.
X
Message E A E A DA DA Message
source Designaion

PR, PU, PR, PU,


Key
SOurce
pair B

Key
Source
pair A Figure 2.4

Z =E(PU,, E(PR, X))


54- D(PU, DPR, 2)
Y in the cipher text.
The receiver has its own private key, hence the decryption is X =D (PR,, Y).

Cryptography & Network Security


24

The crypt analyst can act in between to determine the estimate of the key PR, (or) the

estimate of the message å. Crypt


A analyst >PR,
Message XEAY DA XMessage
source Destination
PR

Figure 2.3 Public Key Cryptography


sOurce pait
for Authentication
The above figure is needed to provide authentication:
Y= E(PR,, X)
X = D(PU,, Y)
Because as the message was encrypted using A's private key, no one else would have
prepared the message. Hence the above stands as digital signature. No one can alter the message.
Hence the message is authenticated of source and data integrity.
In order to have confidentiality and authentication we have the following.
X

|MessageEA EA DA DAMessage
source Designaion

PR, PU, PR, PU,

Key
SOurce
pair B

Key
sOurce
pair A
Figure 2.4

Z =E(PU, E(PR, X)
X = D(PU, DPR, Z)

Public Key Cryptography 2.5

In the above figure we can ensure security and authentication. The message is encrypted
using senders private key, providing digital signatures. Next the second encryption is done using
the receivers public key. Hence the final cipher text can be decrypted only by the intended
receiver who alone has the private key. Thus confidentiality is provided.
The Disadvantage of this method is that:

The Algorithm is complex.


2. Should be executed 4 times for one way communication.
2.4 APPLICATIONS OF PUBLIC KEY SYSTEMS
1 Encryption / Decryption:
Here the sender encrypts the message with receiver's public key.
Digital Signature:

The sender signs the message with its private key. Signing is achieved by an algorithm
applied to the message or to the block of data.

3 Key Exchange:

The public key cryptography is used to exchange session key. The famous algorithms are
RSA, ECC, Diffie Hellman, DSS.
2.5 REQUIREMENT FOR PUBLIC KEY CRYPTOGRAPHY
It should be computationally easy for party B to generate a pair of key.
2 It should be computationally easy for sender A to generate the cipher text M, knowing the
public key of B.
C=E (PU,, M)
It should be computationally easy for the receiver to decrypt the message using the private
key to recover the original message.
M = D(PR, C)
= D[PR,, E (PU,, M))
4 It should be computationally infeasible to determine the private key given the public key.
5. It should be computationally infeasible to determine the plain text given the CT, public key.
6. The two keys can be applied in any order. In M =D [PU,, E (PR,, M)] = D [PR,, E (PU,, M)].

2.6 CrYptography &Network Security

Crypt Analysis:
Attack Type 1:
Puon

C- E (PU, M)
3. It should be computationally easy for the receiver to decrypt the message using the private
key to recover the original message.
M = D(PR,, C)
- D[PR, E (PU,, M)]
4. It should be computationally infeasible to determine the private key given the public key.
5. It should be computationally infeasible to determine the plain text given the CT, public key.
6. The two keys can be applied in any order. In M=D[PU, E(PR,, M)] =D[PR,, E(PU,, M)].

2.6 Cyptography &Network Security


Crypt Analysis :
Atack Type 1:
Public key eryptography is vulnerable to brute force attacks, therefore use large key size.
The trade off is that itmakes use of mathematical function, which should be invertible. Therefore
choose key size such that the Brute force attack is not possible, at the same time should not be
too slow for general use.
Atack Type 2:

Attack is of other types (i.e.) given the algorithm and the public key deduce private key.
This method has not been successful till date.

Atack Type 3:
Probable message attack.
When a confidential message is to be transmitted using DES, the attacker will find all 2%
possible keys using the public key and discover the encrypted key by matching the generated
cipher text and the actual cipher.
This attack can be avoided by appending some random bits to the message.
2.6 RSA

RSA is a public key Cryptographic Algorithm.


RSA stands for the first alphabets of the 3 authors.
R’ Ron Rivest.
S’ Adi Shamir.
A ’ Aldeman.

This algorithm was developed at MIT, Published in 1978


2.6.1 GENERAL FEATURES

This is a block cipher, in which plain text and cipher text are integers between 0ton-1 for
some 'n'. Size of n can be 1024 bits. M< 21024,

2.6.2 DESCRIPTION OF THE ALGORITHM

Plain text is encrypted in blocks. The block has some binary value, less than some
numbern.

Public Key Cryptography 27


Encryption is denoted by E.
Decryption is denoted by D.
Plain text is M, equivalent cipher text C.
C= M mod .

M = c mod n

- (m) mod n.
- me mod n.

Both the sender and the receiver must know n.

The sender knowS e and the receiver knows d.


The public key is {e, n} and private key is {d, n}.
The requirements to be satisfied by the algorithm are:

It is possible to find values of e, d, n s.t Med = Mmod n for all M<H


2 It is easy to calculate M and c for all values of M<n.
3 It is infeasible to determine d given e and n.

Algorithm

p, q are the two prime numbers (private, chosen)


n= pg (public, calculated)
cipher text and the actual cipher.

This attack can be avoided by appending some random bits to the message.
2.6 RSA

RSA is a public key Cryptographic Algorithm.


RSA stands for the first alphabets of the 3 authors.
R’ Ron Rivest.
S ’ Adi Shamir.

A ’ Aldeman.

This algorithm was developed at MIT, Published in 1978


2.6.1 GENERAL FEATURES

This is a block cipher, in which plain text and cipher text are integers between 0 to n-1 for
some 'n'. Size of n can be 1024 bits, M< 21024

2.6.2 DESCRIPTION OF THE ALGORITHM


Plain text is encrypted in blocks. The block has some binary value, less than some
5tnber n.

Public Key Cryptography 2.7

Encryption is denoted by E.
Decryption is denoted by D.

Plain text is M, equivalent cipher text C.


C = Mmod n.

M Cd mod n.

(m°) mod n.
= me mod n.
Both the sender and the receiver must know n.

The sender knows e and the receiver knows d.

The public key is {e, n} and private key is {d, n}.

The requirements to be satisfied by the algorithm are:


1.
It is possible to find values of e, d, n s.t M = Mmod n for all M<n
M<n.
2 It is easy to calculate M and cfor all values of

3 It is infeasible to determine d given e and n.

Algorithm
(private, chosen)
p, q are the two prime numbers
(public, calculated)
n = p
(public, chosen)
e is chosen s.t. gcd( (n), e) = 1; 1<e<o (n)
(private calculated).
d=e'mod (n)
Step 1: Select two prime numbers.
Step 2: Calculate n = pg

Step 3: Calculate (n) as (p-1) (g-1)


and < n).
4. Select e s.t. e is relatively prime to (n)
using Extended
Determine e s.t.d l mod (n) and d<o (n). d is calculated
57 Euclid's algorithm.
Cyptography &Network Securit
V
Euclid's algorithm.

2.8 Cryptography &Network Security

SUMMARY:

Key Generation:
Select p, 4
calculate n =p X4

calculate (n)-(p-l) (g-1)


select e

calculate d

public key ={e, n}


private key = {d, n}
Encryption:
Plaintext m<n
cipher text C = m(mod n)
Decryption:
Cipher text = C
Plain Text m = C (mod n)

Example:
1. p=17,q= 11
2. n =p x q= 17 x 1| = 187

(n) =(p-l)Xq-1)=16x10=160
4. Select e =7

5. Find d using Euclid's algorithm.


The parameters for Euclids are e, (n).
2. 160
.. d= (Refer Next Page)
58 d=23

Public Key Cryptography 2.9


Encryption:
K,, = {7, 187} = {e, n}

K = {23, 187} = {d, n}


M = 88.

C = m'mod n

C= 88' mod 187

= ((88 mod 187) x (88 mod 187) x (88' mod 187)] mod 187
(88 x 77 x 132) mod 187

Decryption:
m =c mod n

m =1125 mod 187

1|2 mod 187 =[(1|' mod 187) x (112 mod 187) x (11 mod 187)

(11 mod 187) (11 mod 187)] mod 187


5. Find d using Euclid's algorithm.
The parameters for Euclids are e, (n).
Z160
. d= (Refer Next Page)
d= 23

Public Key Cryptography 2

Encryption:

K, = {7, 187} - (e, n}


K, {23, 187} = {d, n}
M= 88.

C = m modn

C = 88 mnod 187

- [(88* mod 187) x(88² mod 187) x (88' mod187)] mod 187
= (88 x 77 x 132) mod 187
= ||

Decryption:
m =c mod n
m=1123 mod 187

1|P mod l87 = [(11' mod 187) x (I1' mod 187) x (11' mod 187)
(11 mod 187) (119 mod 187)] mod 187

=(|| x 121 x 55 x 33 x 33) mod 187

= 88

Evclids Muitiplicative Inverse Algorithm (7, 160)


A,A,, 4, = 1,0, 160
B,, B,, B, =01,7
B, 0, B, l

T, =A, - QB, = 1-22 x 0 = 1


T, =A, - QB, =0- 22 x 1 =-22

2.10 Cyptography & Network Securi


I=A, - QB, = 160 - 22 x 7= +6

A,, A,, A,=B,, B,, B, 0, 1,7


B,, B,, B, = 1, - 22, +6
B,+ 0, B,+ l

T =A, - QB, =0- 1 x 1


T, -A,- QB, = 1 -[1x-22] = 1+22 - 23
Gemini
PrivacyHub
O See the latest updates to the Gemini Apps
Algorithm for the following. P=7; q=11;
V Perform encryption and decryption using RSA
e-17; M-8
Show drafts v

RSA Encryption and Decryption

Understanding the RSA Algorithm:

RSA is an asymmetric encryption algorithm that


uses a pair of keys: a public key for encryption
and aprivate key for decryption. The keys are
generated based on two large prime numbers (p
and q).
Given Values:

" p:

17 (public key exponent)


" M: 8 (plaintext message)

Steps:

1. Calculate n:
on=p*q=7*11= 77
2. calculate (n):
o n) = (p-1) * (q-1) =6 *10 =60

3. Find d (private key exponent):


d*e1(mod o(n)
Using the extended Euclidean algorithm, we find that d = 23.

4. Encryption:
oC= M^e mod n
oC=8^17 mod 77 = 45

5. Decryption:
M= C^d mod n

o M=45^23 mod 77 = 8

Conclusion:

The encrypted message (ciphertext) is 45.


The decrypted message (plaintext) is 8, which matches the
original message.
Note:

The choice of e and d is crucial for the


security of the RSA algorithm. They should
be carefully selected to avoid
vulnerabilities.
For practical applications, p and q should be much larger prime
numbers to make
it computationally infeasible to factor n.

Would you like to try another example or learn


more about the RSA algorithm?

Sources and related content a

github.com

github.com
,

Enter a prompt here


We define a primitive root of a prime number p' as one
whose pOwers generate all the integers from 1through p 1.
If 'a' is a primitive root of prime number 'p' then the
numbers,
a mod p, a' mod p, aP modp are distinct and consist
of integers from 1through p - lin some permutation.
For any integer 'b' and a primitive root 'a' of prime rumber 'p',
we can find a unique exponent i' such that,
bsa' modp, where 0<<i << (p-1)
The exponent 'i' is referred to as the discrete logarithm or
index of b for the base a mod p denoted as, indap (b).
With this background, Let us discuss Diffie-Hellman key
exchange algorithm.
2.3.2 Diffie - Hellman Key Exchange algorithm
For this scheme, there are two publicly known numbers,
a prime number 'q' and
Integer 'c', c<q and primitive root of q.
Suppose User A and B wish to exchange a secret key, the
following steps are needed.
Step I : User AKey pair generation
User A selects a random integer and private key X , in such a
way XA<q and calculate public Key YA as
Y=«^^ mod q.
Step 2 : User Bkey pair generation
Similarly User B selects private key and random integer
XB, Xp Kqand computes public key Y «^B mod q.
Note: Each side keeps the X' value private and makes the Y
value available publicly to the other side.
Step 3 : Generation of secret key by User A
Now User A computes the key as.
K= (Ys) ^A mod g.

PUBLIC KEY CRYPTOGRAPHY


2. 19
Step 4: Generation of seeret key by User B
User B computes the kev as,
K=(Y,) Mod
Sep 5 :Now both A and B havc
exchanged a secret key.
Proof: We able tO prove that the two key
produce the same results as follows, gencration calculation
K = (Yp)A mod q
= (c^B mod q)A
mod q
- («BXA mod q (by the rules of
modular arithmetic)
mod q
- («XA mod g)*B mod q
= (YXB mod q
The result is that two sides have exchanged a
secret key.
Advantage :
It is relatively easy to calculate exponentials modulo a
prime, but it is very difficult to calculate discrete logarithms for
K=(Y) mod q.

PUBLIC KEY CRYPTOGRAPHY 2. 19

Sep 4 : Generation of sceret key by User B


Iiser Bcomputes the key as,
K=(Y) Nu mod q
Step 5 :Now bothA and B have exchanged a secret key.
Proof: We able to prove that the two key gencration calculation
produce the same results as follows,
K =(Yg)A mod q
= (o«^B mod q)'A mod q
=(oc^B)XA mod q (by the rules of modular arithmetic)
= «-B^Amod q
= («XA mod q)*B mod q
- (Y)X8 mod q
The result is that two sides have exchanged a secret key.
Advantage :
It is relatively easy to calculate exponentials modulo a
prime, but it is very difficult to calculate discrete logarithms for
very large prime numbers.
Eg: X , Xp - private. The opponent knows q, «, Ya and
Yg and compute Xg as,
Xg = ind,Yg) and calculate secret key as in step 4. But
it is infeasible.
Drawback:
break
For small prime numbers brute force attack should
this concept.
Example for Diffie - Hellman key Exchange:
Generate
Generate
random X, <qi random X <q:
Calculate
Calculate
Y, = «u mod q;
Y, =«A mod q
Calculate
Calculate
K- (Y,)' mod q
K= (Y,)A mod q
Exchange
Fig. 2.11 : Difle - Hellman Key

2.20 CRYPTOGRAPHY AND NETWORK SE

Let us assume, prime number q = 353 ; primitive 1


353, ie., c=3, Now A and B select secret keys X = 97 ane
233 respectively. Each computes its public key as given b

Acomputes : YA=3 mnod 353 =40


< SALE 50

II 1s relatively easy to calculate exponentials modulo a


prime, but it is very difficult to calculate discrete logarithms for
very large prime numbers.
Eg: X , Xp private. The opponent knows q, «, Ya and
Yg and compute X as,
X¡ = ind,rYR) and calculate secret key as in step 4. But
it is infeasible.
Drawback:
For smallprime numbers brute force attack should break
this concept.
Example for Diffie -Hellman key Exchange:
Generate Generate
random X,<q; random X, <4:
Calculate Calculate
Y, =«A mod q Y, = «u mod :
Calculate Calculate
K=(Y,)A mod q K-(Y,'"mod q
Fig. 2.11: Diffie - Hellman Key Exchanpe

2.20 CRYPTOGRAPHY AND NETWORK SECURITY


Let us assume, prime number q= 353; primitive root of
353, ie., c=3, Now A and B select secret keys X = 97 and Xp =
233 respectively. Each computes its public key as given below,
A computes : YA =3 mod 353 = 40
B computes : Ya =333 mod 353 = 248
After they exchange publickeys, each can compute the common
secret key:
A computes K = (Y)"A mod 353 = 24897 mod 353 = 160
Bcomputes K = (YA)B mod 353 = 40233 mod 353 = 160

You might also like