0% found this document useful (0 votes)
11 views

RKU PPT-4

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

RKU PPT-4

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

UNIT-4

Public Key Cryptography


Outline

 Introduction to Asymmetric Key Cryptography


 Overview of Asymmetric Key Cryptography
 RSA Algorithm
 Comparison of Symmetric Key Cryptography and Asymmetric Key Cryptography
Symmetric Key Encryption

Secret key shared


Secret key shared
by sender and
by sender and
recipient
recipient
K
K
Transmitted
cipher text
Y = E(K, X)
X X
Plainte Encryption Decryption Plainte
xt Algorithm Algorithm xt
input (e.g. AES) (reverse of output
encryption
algorithm)
Symmetric Key Encryption example

 Safe with a strong lock, only Alice and Bob have a copy of the key
• Alice encrypts: locks message in the safe with her key
• Bob decrypts: uses his copy of the key to open the safe
Asymmetric cryptography (public key cryptography)

 Asymmetric cryptography, also known as public key cryptography, uses public and private
keys to encrypt and decrypt data.
 The keys are simply large numbers that have been paired together but are not identical
(asymmetric).
 One key in the pair can be shared with everyone; it is called the public key.
 The other key in the pair is kept secret; it is called the private key. Either of the keys can be
used to encrypt a message; the opposite key from the one used to encrypt the message is
used for decryption.
 Many protocols like SSH, OpenPGP, S/MIME, and SSL/TLS rely on asymmetric cryptography
for encryption and digital signature functions.
 It is also used in software programs, such as browsers, which need to establish a secure
connection over an insecure network like the Internet or need to validate a digital
signature
How asymmetric encryption works

 Asymmetric encryption algorithms use a mathematically-related key pair for encryption


and decryption; one is the public key and the other is the private key.
 If the public key is used for encryption, the related private key is used for decryption and
if the private key is used for encryption, the related public key is used for decryption.
 The two participants in the asymmetric encryption workflow are the sender and the
receiver. First, the sender obtains the receiver's public key.
 Then the plaintext is encrypted with the asymmetric encryption algorithm using the
recipient's public key, creating the ciphertext.
 The ciphertext is then sent to the receiver, who decrypts the ciphertext with his private
key so he can access the sender's plaintext.
Asymmetric Key Encryption with Public Key
Bob’s
Public  The entire encrypted message serves as a
key confidentiality.
Joy ring
Ted
Mike Alice
PUa Alice’s PRa Alice’s
public key private key

Transmitted
X cipher text X

Y = E(PUa, X)
Plaintext Plaintext
input Encryption Decryption output
Algorithm Algorithm
(e.g. RSA)

Bob Alice
Asymmetric Key Encryption with Private Key
Alice’s
Public
 The entire encrypted message
key
serves as a digital signature. Joy ring
Ted
Mike Bob

PRb Bob’s private PUb


key Bob’s public key

Transmitted
X cipher text X
Y = E(PRb,
Plaintext X) Plaintext
input Encryption Decryption
output
Algorithm Algorithm
(e.g. RSA)
Bob Alice
Asymmetric Key Encryption example

New Idea:
Use the good old mailbox principle:

Everyone can drop a letter

But Only the owner has the


correct key to open the box

Public Key

Private Key
Authentication and Confidentiality
Source A Source B

Y
X Y Encryption Z X
Message Encryption Decryption Decryption Message
source Algorithm Algorithm Algorithm Algorithm Dest.

PUb PRb
PRa

Key pair
PUa source

Key pair
source

Z = E(PUb, E(PRa, X)) X = D(PUa, D(PRB, Z))


Applications for Public-Key Cryptosystems
 Encryption/decryption: The sender encrypts a message with the recipient’s public key.
 Digital signature: The sender “signs” a message with its private key. Signing is achieved by
a cryptographic algorithm applied to the message or to a small block of data that is a
function of the message.
 Key exchange: Two sides cooperate to exchange a session key. Several different
approaches are possible, involving the private key(s) of one or both parties.
RSA Algorithm

 RSA (Rivest–Shamir–Adleman) is an algorithm used by modern computers to encrypt and


decrypt messages.
 It is an asymmetric cryptographic algorithm. Asymmetric means that there are two different
keys.
 This is also called public key cryptography, because one of the keys can be given to anyone.
The other key must be kept private. The algorithm is based on the fact that finding the factors
of a large composite number is difficult: when the integers are prime numbers
 RSA involves a public key and private key. The public key can be known to everyone; it is used
to encrypt messages. Messages encrypted using the public key can only be decrypted with
the private key.
RSA Algorithm

 RSA is a block cipher in which the Plaintext and Ciphertext are represented as integers
between 0 and n-1 for some value of n.
 Large messages can be broken up into a number of blocks.
 Each block would then be represented by an integer.

Step-1: Generate Public key and Private key.

Step-2: Encrypt message using Public key.

Step-3: Decrypt message using Private key.


Step-1: Generate Public key and Private key
 Select two large prime numbers: p and q
 Calculate modulus : n = p * q
 Calculate Euler’s totient function : φ(n) = (p-1) * (q-1)
 Select e such that e is relatively prime to φ(n) and 1 < e < φ(n)
Two numbers are relatively prime if
they have no common factors other
 Determine d such that d * e ≡ 1 (mod φ(n)) than 1 or (gcd(φ(n) , e)=1).
 To convert ≡ into = we have to apply mod on both sides
 d ≡ e -1 mod φ(n) = - equal to
≡ - congruent modulo
 Apply mode on both sides
 d *e mod φ(n) = 1 (mod φ(n)) (1 * any= 1)
 Therefore, d *e mod φ(n) = 1
 Publickey : PU = { e, n }
 Privatekey : PR = { d, n }
Step-2 and 3: Encryption and Decryption

Step-2: Encryption using Public Key:

Plaintext: M

Ciphertext: C = Me mod n
Step-3: Decryption using Private Key:
Ciphertext: C
Plaintext: M = Cd mod n
Step-1: Generate Public key and Private key
 Select two large prime numbers: p = 3 and q = 11
 Calculate modulus : n = p * q = 3 * 11 = 33
 Calculate Euler’s totient function : φ(n) = (p-1) * (q-1)
φ(n) = ( 3 – 1 ) * ( 11 – 1 ) = 20
 Select e such that e is relatively prime to φ(n) and 1 < e < φ(n)
 We have several choices for e :3, 7, 11, 13, 17, 19 Let’s take e = 7
 Determine d such that d * e ≡ 1 (mod φ(n))
 ? * 7 ≡ 1 (mod 20), 3 * 7 ≡ 1 (mod 20)
 ? * 7 (mod 20) ≡ 1, 3 * 7 (mod 20) ≡ 1
 Public key : PU = { e, n } , PU = { 7, 33 }
 Private key : PR = { d, n }, PR = { 3, 33 }
Step-2 : Encrypt Message

 Encryption using Public Key: C = Me mod n

Ciphertext Input Public


Message key
PU = { e, n } , PU = { 7, 33 }

For message M = 14

C = 147 mod 33
C = [(141 mod 33) X (142 mod 33) X (144 mod 33)] mod 33
C = (14 X 31 X 4) mod 33 = 1736 mod 33
C = 20
Step-3 : Decrypt Message

 Decryption using Private Key:


M = Cd mod n

Plaintext Cipher Private key


Message Message
PR = { d, n } , PR = { 3, 33 }

For Ciphertext C = 20

M = 203 mod 33
M = [(201 mod 33) X (202 mod 33)] mod 33
M = (20 X 4) mod 33 = 80 mod 33
M = 14
Example RSA Algorithm
RSA Example - 1

 Find n, φ(n), e, d for p=7 and q= 19 then demonstrate encryption and decryption for M = 6
Finding e relatively prime to 108
n = p * q = 7 * 19 = 133 e = 2 => GCD( 2, 108 ) = 2 (no)
e = 3 => GCD( 3, 108 ) = 3 (no)
φ(n) = ( p – 1 ) * ( q – 1) = 108 e = 5 => GCD( 5, 108 ) = 1 (Yes)

Finding d such that (d * e ) mod φ(n) = 1 Public key :


PU = { e, n } = {5, 133}
Private key :
PR = { d, n } = {65, 133}
RSA Example – cont…

 Encryption:
C = Me mod n PU = { e, n } , PU = { 5, 133 }
For message M = 6
C = 65 mod 133
C = 7776 mod 33
C = 62
 Decryption:
M = Cd mod n PR = { d, n } , PU = { 65, 133 }
For C = 62
M = 6265 mod 133
M = 2666 mod 33
M=6
RSA Example - 2

 P and Q are two prime numbers. P=7, and Q=17. Take public key E=5. If plain
text value is 10, then what will be cipher text value according to RSA algorithm?
 n = 119
 φ(n) = 96
 e=5
 d = 77
 PU = { 5, 119 }
 PR = {77, 119}
 C = 105 mod 119 => C = 40
RSA Example - 3

 P and Q are two prime numbers. P=17, and Q=11. If plain text value is 88, then
what will be cipher text value according to RSA algorithm?
 n = 187
 φ(n) = 160
 e=7
 d = 23
 PU = { 7, 187 }
 PR = {23, 187}
 C = 887 mod 187 => C = 11
DIFFERENCE:
Benefits and disadvantages of asymmetric cryptography

The benefits of asymmetric cryptography include:

 the key distribution problem is eliminated because there's no need for exchanging keys.
 security is increased as the private keys don't ever have to be transmitted or revealed to
anyone.
 the use of digital signatures is enabled so that a recipient can verify that a message comes
from a particular sender.
 it allows for non-repudiation so the sender can't deny sending a message.
Disadvantages include:

 it's a slow process compared to symmetric crytography, so it's not appropriate for decrypting

bulk messages.

 if an individual loses his private key, he can't decrypt the messages he receives.

 since the public keys aren't authenticated, no one really knows if a public key belongs to the

person specified. Consequently, users have to verify that their public keys belong to them.

 if a hacker identifies a person's private key, the attacker can read all of that individual's

messages.
Diffie-Hellman key Exchange

 The purpose of the Diffie-Hellman algorithm is to enable two users to securely exchange a
key that can be used for subsequent encryption of message.
 The effectiveness of an algorithm is depends on the difficulty of computing discrete
logarithms.
Primitive root

 Let be a prime number.


 Then is a primitive root for , if the powers of modulo generates all integers from
1 to – 1 in some permutation.
2 𝑝−1
𝑎𝑚𝑜𝑑 𝑝 , 𝑎 𝑚𝑜𝑑 𝑝 , … , 𝑎 𝑚𝑜𝑑 𝑝
 Example: p = 7 then primitive root is 3 because powers of 3 mod 7 generates all
the integers from 1 to 6.
Discrete Logarithm

 For any integer and a primitive root of prime number , we can find a unique exponent
such that
𝑖
𝑏=𝑎 ( 𝑚𝑜𝑑 𝑝 ) 𝑤h𝑒𝑟𝑒 0 ≤ 𝑖 ≤( 𝑝 − 1)
 The exponent is referred as the discrete logarithm of for the base , mod . It expressed as
below.

𝑏 d log 𝑎 ,𝑝 (𝑏)
Diffie-Hellman Key Exchange – Cont…

 User A and User B agree on two large prime numbers q and α. User A and User B can use
insecure channel to agree on them.
 User A selects a random integer and calculates .
 User B selects a random integer and calculates .
Diffie-Hellman Key Exchange – Cont…

Global Public Elements


prime number
< and is primitive root of

User A Key Generation


Select private
Calculate public

User B Key Generation


Select private
Calculate public
Diffie-Hellman Key Exchange – Cont…

User A Key Generation


Select private
Calculate public
User B Key Generation
Select private
Calculate public
Calculation of Secret Key by User A

Calculation of Secret Key by User b


Diffie-Hellman Key Exchange – Cont…

User A Key Generation


Private , Public
User B Key Generation
Private , Public
Secret Key by User A :
Secret Key by User B :
Diffie-Hellman Key Exchange Illustration
Alice Bob
Alice and Bob share a prime number Alice and Bob share a prime number q
q and an integer such that a < q and an integer such that a < q and a
and a is a primitive root of q is a primitive root of q

Alice generates a private key XA Bob generates a private key XB such


such that XA < q that XB < q
Alice calculates a public key Y Bob calculates a public key
YA = a mod q A YB YB = a mod q
Alice receives Bob’s public key YB in Bob receives Alice’s public key YA in
plaintext plaintext
Alice calculates shared secret key Bob calculates shared secret key
K = (YB) mod q K = (YA) mod q
Diffie-Hellman Key Exchange Example

 Alice and bob agrees on a prime number


 as primitive root of .
 Alice selects a private integer
 Alice computes =>
 Bob selects a private integer
 Bob computes =>
 Alice sends to Bob and Bob sends to Alice.
 Alice computes key =>

 Bob computes key =>


Diffie-Hellman Key Exchange Example

 Alice and bob agrees on a prime number


 as primitive root of .
 Alice selects a private integer
 Alice computes =>
 Bob selects a private integer
 Bob computes =>
 Alice sends to Bob and Bob sends to Alice.
 Alice computes key =>

 Bob computes key =>


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) mod q.

4. Bob receives YD1 and calculates K1 = (YD1) mod q.

5. Bob transmits YB to Alice.

6. Darth intercepts YB and transmits YD2 to Alice. Darth calculates K1=(YB) mod q.

7. Alice receives YD2 and calculates K2 = (YD2) mod q.


 A man-in-the-middle attack is a type of cyberattack where a malicious actor inserts
him/herself into a conversation between two parties, impersonates both parties and gains
access to information that the two parties were trying to send to each other. A man-in-
the-middle attack allows a malicious actor to intercept, send and receive data meant for
someone else, or not meant to be sent at all, without either outside party knowing until it
is too late. Man-in-the-middle attacks can be abbreviated in many ways, including MITM,
MitM, MiM or MIM.
Alice q = 19 and a = 3 Darth q = 19 and a = 3 Bob

XA = 10
XB = 11
YA = 3 mod 19 =
YB = 3 mod 19 = 10
16 YA = YB = 10
16
XD1 = 2
XD2 = 7
YD1 = 3 mod 19 = 9
YD2 = 3 mod 19 = 2
YD2 = YD1 =
2 9
K2 = (2) mod 19 K2 = (16) mod K1 = (9) mod 19
k2 = 17 19 k2 = 17 k1 = 5

K1 = (10) mod
19 k1 = 5

Alice and Darth Darth and Bob


share Key K2 = 17 share Key K1 = 5
Digital Envelope
 A digital envelope is a secure electronic data container that is used to protect a message through
encryption and data authentication. A digital envelope allows users to encrypt data with the
speed of secret key encryption and the convenience and security of public key encryption.
 A digital envelope is also known as a digital wrapper.
 A digital envelope uses two layers for encryption: Secret (symmetric) key and public key
encryption. Secret key encryption is used for message encoding and decoding. Public key
encryption is used to send a secret key to a receiving party over a network.
 This technique does not require plain text communication.
 Either of the following methods may be used to create a digital envelope:

 Secret key encryption algorithms, such as Rijndael or Twofish, for message encryption.

 Public key encryption algorithm from RSA for secret key encryption with a receiver’s
public key.

A digital envelope may be decrypted by using a receiver's private key to decrypt a secret key,
or by using a secret key to decrypt encrypted data.

You might also like