chapter 3
chapter 3
Fundaments of
Cryptography
1
Cryptography
• Cryptography is the process of hiding or coding
information so that only the person a message
was intended for can read it.
2
Cryptography…
6
Cryptography
• Encryption Overview
– Plain text is converted to cipher text by use of
an algorithm and key.
• Algorithm is publicly known
• Key is held private
– Three Main Categories
• Secret Key
– single key is used to encrypt and decrypt information
• Public/Private Key
– two keys are used: one for encryption (public key) and
one for decryption (private key)
• One-way Function
– information is encrypted to produce a “digest” of the
original information that can be used later to prove its 7
authenticity
Encryption
• Encryption is the process
of taking some data and a
key and feeding it into a
function and getting
encrypted data out
Encryption
• Encrypted data is, in Function
principle, unreadable
unless decrypted
8
Decryption
• Decryption is the
process of taking
encrypted data and a
key and feeding it into
a function and getting
out the original data
– Encryption and
decryption functions are Decryption
linked Function
9
Encryption Techniques
Symmetric Encryption
• Encryption and decryption
algorithms that use the same
key are called symmetric
– In this case everyone wanting Encrypt
to read encrypted data must
share the same key
• Sender and receive have the
same secret key that will
encrypt and decrypt plain
text.
• Strength of encryption Decrypt
technique depends on key
length
10
Encryption Techniques…
11
Encryption Techniques…
Asymmetric Encryption
• Encryption and decryption
algorithms that use a key
pair are called asymmetric
– Keys are mathematically
linked
• Most common algorithm is
the RSA (Rivest Shamir
Adelman) algorithm with
key lengths from 512 to
1024 bits.
12
ENCRYPTION DECRYPTION
Same Key
Message 2 SYMMETRIC
The Internet knows no geographical boundaries. Encrypted Message 2
It has redefined time and space. Advances in a520eecb61a770f947ca856cd675463f1c95a9a2b
computer and telecommunication technologies 8d4e6a71f80830c87f5715f5f59334978dd7e97da
have led to the explosive growth of the Internet. 0707b48a1138d77ced56feba2b467c398683c7db
This in turn is affecting the methods of eb86b854f120606a7ae1ed934f5703672adab0d7
communication, work, study, education, be66dccde1a763c736cb9001d0731d541106f50b
interaction, leisure, health, governance, trade b7e54240c40ba780b7a553bea570b99c9ab3df13
and commerce. d75f8ccfdddeaaf3a749fd1411
Encrypted Message 2 Message 2
a520eecb61a770f947ca856cd675463f1c95a The Internet knows no geographical boundaries. It has
9a2b8d4e6a71f80830c87f5715f5f59334978 redefined time and space. Advances in computer and
dd7e97da0707b48a1138d77ced56feba2b46 telecommunication technologies have led to the
7c398683c7dbeb86b854f120606a7ae1ed93 explosive growth of the Internet. This in turn is
Different Keys
4f5703672adab0d7be66dccde1a763c736cb affecting the methods of communication, work, study,
9001d0731d541106f50bb7e54240c40ba780 education, interaction, leisure, health, governance,
[Keys of a pair – Public and Private]
b7a553bea570b99c9ab3df13d75f8ccfdddea trade and commerce.
af3a749fd1411 ASYMMETRIC
[PKI]
Encryption Techniques…
• One-Way Function
– non-reversible “quick” encryption
– produces a fixed length value called a
hash or message digest
– used to authenticate contents of a
message
– Common message digest functions
• MD4 and MD5
– produces 128 bit hashes
• SHA
– produces 160 bit hashes
14
Building Blocks of Encryption
Techniques
• Two building blocks of all classical encryption
techniques are
substitution and transposition.
• M’
is called the ciphertext
The encrypted output
16
Cryptography...
• Mathematical Notation
Given
P=Plaintext
C=Ciphertext
C = E (P) Encryption
K
P = D (C) Decryption
K
17
Cryptanalytic Attacks
• Types of attacks
- An attacker having only the ciphertext and his goal
is to find the corresponding plaintext.
- An attacker having a ciphertext and the
corresponding plaintext and his goal is to find the
key.
• Modification
Modifying a plaintext is easy, but modifying encrypted
messages is more difficult
• Insertion of messages
Inserting new message into a ciphertext is difficult
19
Cryptography example:
Caesar cipher
• This is the earliest known example of a
substitution cipher.
• Each character of a message is replaced by a
character three position down in the alphabet.
• Shift of letters:
Plain: ABCDEFGHIJKLMNOPQRSTUVWXYZ
Cipher: DEFGHIJKLMNOPQRSTUVWXYZABC
Example
plaintext: are you ready
20
Cryptography example:
Caesar cipher
Example: Encipher the message
THIS MESSAGE IS TOP SECRET
• using the ordinary alphabet and a Caesar cipher with a shift
of 3.
• When each letter is converted to a number, and we group
into blocks of length 5, we get
19 7 8 18 12 4 18 18 0 6 4 8 18 19 14 15 18 4 2 17 4 19
• In transposition ciphering:
Key: 4 1 3 6 2 5
Plaintext: m e e t m e
a t s q u a
r e g u a r
d e n f o r
g o o d d i
n n e r o k
Ciphertext:
28
Substitution-Permutation Ciphers
• Permutation Operation
32
Symmetric DES...
• DES Utilizes block cipher.
- During the encryption process, the plaintext is divided into
fixed length blocks of 64 bits.
33
Symmetric DES...
34
Symmetric DES...
• DES Encryption starts with an initial permutation (IP) of
the 64 input bits.
37
Symmetric DES...
One Round of Processing in DES
• The algorithmic implementation of DES is known
as DEA for Data Encryption Algorithm.
38
Symmetric DES...
One Round of Processing in DEA
• The E-step involves the following:
– First divide the 32-bit block into eight 4-bit words
– attach an additional bit on the left to each 4-bit
word that is the last bit of the previous 4-bit word
– attach an additional bit to the right of each 4-bit
word that is the beginning bit of the next 4-bit
word.
• The 56-bit key is divided into two halves,
– each half shifted separately, and the combined
56-bit key permuted/contracted to yield a 48-bit
round key.
39
Symmetric DES...
One Round of Processing in DEA
• The 48 bits of the expanded output produced by the
E-step are XORed with the round key.
– This is referred to as key mixing.
NOTE
• The goal of the substitution step implemented by the S-
box is to introduce diffusion in the generation of the
output from the input.
– Diffusion means that each plaintext bit must affect as many
ciphertext bits as possible.
• The strategy used for creating the different round keys
from the main key is meant to introduce confusion into
the encryption process.
– Confusion in this context means that the relationship
between the encryption key and the ciphertext must be as
complex as possible.
42
Symmetric DES
The S-Box for the Substitution Step in Each
Round
• The 48-bit input word is divided into eight 6-bit
words and each 6-bit word fed into a separate S-
box.
43
Symmetric DES
The S-Box for the Substitution Step in Each Round
44
Symmetric DES
The S-Box for the Substitution Step in Each Round
The S-Box
45
The S-Box for the Substitution Step in Each Round
46
The S-Box for the Substitution Step in Each Round(cont’d…)
IP IP-1
58 50 42 34 26 18 10 2 40 8 48 16 56 24 64 32
60 52 44 36 28 20 12 4 39 7 47 15 55 23 63 31
62 54 46 38 30 22 14 6 38 6 46 14 54 22 62 30
64 56 48 40 32 24 16 8 37 5 45 13 53 21 61 29
57 49 41 33 25 17 9 1 36 4 44 12 52 20 60 28
59 51 43 35 27 19 11 3 35 3 43 11 51 19 59 27
61 53 45 37 29 21 13 5 34 2 42 10 50 18 58 26
63 55 47 39 31 23 15 7 33 1 41 9 49 17 57 25
49
First Bit of the output is taken from the 58th bit of the input, etc...”
Symmetric DES...
Round Key Generation
50
Symmetric DES...
Single round of DES Algorithm
51
Triple-DES with Three-Keys…
• With triple length key of three 56-bit keys K1, K2 & K3,
encryption is:
- Encrypt with K1
- Decrypt with K2
- Encrypt with K3
- Decrypt with K3
- Encrypt with K2
- Decrypt with K1 52
Triple DES…
53
Public Key Cryptography
• RSA
• RSA is from Rivesh, Shamir and Aldermen
• In RSA, the private and public keys are
constructed from very large prime numbers
(consists of hundred of decimal digits) One of
the keys can be made public.
• Breaking RSA is equivalent to finding the prime
factors: this is know to be computationally
infeasible. (NP-hard)
• It is only the person who has produced the keys
from the prime number can easily decrypt the
messages. 54
Asymmetric RSA
• Major Activities
- Key Generation
- Encryption
- Decryption
55
Asymmetric RSA
Key Generation Algorithm
1. Generate two large random primes, p and q
2. Compute n = pq and (φ) phi = (p-1)(q-1)
3. Choose an integer e, 1 < e < φ, such that gcd(e, phi) =
1
4. Compute the secret exponent d, 1 < d < φ, such that
d = e-1 mod φ , i.e. φ divides (ed-1)
5. The public key is (e, n) and the private key is (d, n).
Keep all the values d, p, q and φ secret
n is known as the modulus
e is known as the public exponent or encryption exponent
d is known as the secret exponent or decryption
exponent.
56
Asymmetric RSA
Encryption and Decryption
Encryption
• Sender A does the following
- Obtains the recipient B's public key (n, e)
- Represents the plaintext message as a positive integer
m
- Computes the ciphertext c = me mod n
- Sends the ciphertext c to B
Decryption
• Recipient B does the following
- Uses his private key (n, d) to compute m = cd mod n
- Extracts the plaintext from the message representative
m
57
Asymmetric RSA
Key Generation example
1. Select primes p=11, q=3.
2. n = pq = 11*3 = 33
phi = (p-1)(q-1) = 10*2 = 20
3. Choose e=3
Check gcd(e, p-1) = gcd(3, 10) = 1 (i.e. 3 and 10 are
relatively prime - have no common factors except 1) and
check gcd(e, q-1) = gcd(3, 2) = 1,
therefore gcd(e, phi) = gcd(e, (p-1)(q-1)) = gcd(3, 20) = 1
Encryption
• Now say we want to encrypt the message m= 7
- c = me mod n = 73 mod 33 = 343 mod 33 = 13
- Hence the ciphertext c = 13
Decryption
• To check decryption we compute
- m = cd mod n = 137 mod 33 = 7
59
Encryption and decryption of the word technology using the generated key
60
Encryption and decryption of the word technology using the generated key…
61
RSA Algorithm Summary
62
The DHA for generating a shared secret session
key
63
Diffie-Hellman Key Exchange
Algorithm
• a public-key distribution scheme
64
The DHA for generating a shared secret
session key
• The pair of numbers (q, α) is public.
• This pair of numbers may be used for several
runs of the protocol.
• These two numbers may even stay the same for
a large number of users for a long period of time.
• Subsequently, A and B use the algorithm
described below to calculate their public keys
that are then made available by each party to the
other:
– We will denote A’s and B’s private keys by XA
and XB.
– And their public keys by YA and YB.
– In other words, X stands for private and Y for
public. 65
The DHA for generating a shared secret
session key
• A selects a random number XA from the set {1, 2, .
. . , q − 2} to serve as his/her private key.
• A then calculates a public-key integer YA that is
guaranteed to exist:
YA = αXA mod q
• A makes the public key YA available to B.
• Similarly, B selects a random number XB from the
set
{1, 2, . . . , q − 2} to serve as his/her private key.
• B then calculates an integer YB that serves his/her
public key:
YB = αXB mod q
• B makes the public-key YB available to A.
66
The DHA for generating a shared secret session
key
• A now calculates the secret key K from his/her
private key XA and B’s public key YB :
K = (YB)XA mod q
K = (YA)XB mod q
67
Diffie-Hellman Key Exchange
• Shared session key for users A & B is KAB:
xA.xB
KAB = α mod q
xB
= yA mod q (which B can compute)
xA
= yB mod q (which A can compute)
• KAB is used as session key in private-key
encryption scheme between Alice and Bob
• if Alice and Bob subsequently
communicate, they will have the same
key as before, unless they choose new
public-keys
• attacker needs an x, must solve discrete
log 68
Diffie-Hellman Example
• users Alice & Bob who wish to swap keys:
• agree on prime q=353 and α=3
• select random secret keys:
– A chooses xA=97, B chooses xB=233
• compute public keys:
– yA=397 mod 353 = 40 (Alice)
– yB=3233 mod 353 = 248 (Bob)
• compute shared session key as:
xA 97
KAB= yB mod 353 = 248 mod 353= 160
(Alice)
xB 233
KAB= y A mod 353 = 40 mod 353= 160
(Bob) 69
Digital Signature
70
Why Digital Signatures?
71
Digital Signature using pubic key cryptography
(RSA)
• RSA may be used directly as a digital signature
scheme
–given an RSA scheme {(e,n), (d,n)}
• To sign a message, compute:
–s = md(mod n)
• To verify a signature, compute:
–m = se(mod n)=me.d(mod n)
• Thus know the message was signed by the
owner of the public-key.
• More commonly use a hash function to create
a separate Message Digest (MD) which is then
signed.
72
Hash Function Properties
• a Hash Function produces a fingerprint of some
file/message/data
h=H(M)
–condenses a variable-length message M
–to a fixed-sized fingerprint h
-
the length of h must be at least 128 bits.
-
given M, it must be easy to calculate H(M) = h
-
given h, it must be difficult to calculate M = H-
1
(h)
-
given M, it must be difficult to find M’ such that
H(M) = H(M’)
• Examples:
●
MD4/MD5: hash of 128 bits;
●
SHA : hash of 160,256 bits.
73
Digital Signatures – Authentication
using hash function
• Abe calculates the hash of the
message: a 128 bit value based
Abe
on the content of the message
• Abe encrypts the hash using his
private key: the encrypted hash
message Hash A message
is the digital signature.
signature
• Abe sends the signed message Digital Signature
Digital Signature
to Kebe.
• Kebe calculates the hash of the
message
• Decrypts A with Abe’s public Keb
key. e
Abe’s keys
• If hashes equal: Hash B
message
1. hash A is from =?
modified;
Digital Certificates
79
Using Authenticated Public Keys to Exchange a Secret
Session Key
• Having acquired the public keys, the two parties A and B
then proceed to exchange a secret session key.
Party Party
A B
80
Using Authenticated Public Keys to Exchange a
Secret Session Key…
• A uses B’s public key PUB to encrypt a message that
contains A’s identifier IDA and N1 as a transaction
identifier.
• A sends this encrypted message to B.
• This message can be ex-pressed as
E (PUB, [N1, IDA])
• B responds back with a message encrypted using
A’s public key PUA, the message containing A’s N1
and new N2 from B to A.
• The structure of this message can be expressed as
E (PUA, [N1, N2])
81
Using Authenticated Public Keys to
Exchange a Secret Session Key…
83
84
Public key infrastructure
• Public Key Infrastructure (PKI) is a framework
that manages digital keys and certificates used for
secure communication and authentication over
networks
85
Key Components of PKI
• End entity: A generic term used to denote end
users, devices (e.g., servers).
• Certificate Authority (CA):The CA is a trusted
organization that issues digital certificates.
• It verifies the identity of entities requesting a
certificate and signs their digital certificates to
validate their public keys.
• Registration Authority (RA):The RA acts as a
mediator between users and the CA.
• It receives certificate requests, verifies the
applicant’s identity, and forwards the request to
the CA for the issuance of a certificate.
86
Key Components of PKI…
• Digital Certificates: A digital certificate contains the
public key and other information about the entity, such as
its name, domain, and expiration date.
• It is digitally signed by the CA to prove its authenticity.
• Repository: A database or directory that stores public
keys and certificates for easy access.
• It allows users and systems to retrieve a certificate to verify
a public key.
• Certificate Revocation List (CRL):A list maintained by
the CA that includes certificates that have been revoked
before their expiration date.
• This helps prevent using invalid or compromised
certificates.
87
Delegation of authority
88
The X.509 Certificate format standard
• X.509 is one of the PKI standards.
– It is this standard that specifies the
format of digital certificates.
• The X.509 standard is based on a strict
hierarchical organization of the CAs in
which the trust can only flow downwards.
• The CAs at the top of the hierarchy are
known as root CAs.
• The CAs below the root are generally
referred to as intermediate-level CAs.
89
X.509 Certificate Format
90
X.509 Certificate Format
• Subject Public Key: This field
presents the public key that is
meant to be authenticated by this
certificate.
– This field also names the
algorithm used for public-key
generation.
• Issuer Unique Identifier:
(optional)With the help of this
identifier, two or more different CA’s
can operate as logically a single CA.
– The Issuer Name field will be
distinct for each such CA but they
will share the same value for the
Issuer Unique Identifier.
• Subject Unique Identifier:
(optional) With the help of this
identifier, two or more different
certificate holders can act as a
single logical entity. 91
X.509 Certificate Format
• Each holder will have a different
value for the Subject Name field but
they will share the same value for the
Subject Unique Identifier field.
• Extensions: (optional) This field
allows a CA to add additional private
information to a certificate.
• Signature: This field contains the
signature of the CA that issued the
certificate.
– This signature is obtained by first
computing a message digest from
the rest of the fields with a hashing
algorithm like SHA-1,
– Then CA will encrypt MD using
private key Signature
92