Unit 2 and 3
Unit 2 and 3
Unit 2 and 3
Security
(3170720)
UNIT 2 AND 3: STREAM CIPHERS AND BLOCK CIPHERS, BLOCK CIPHER
STRUCTURE, D ATA E N C RY P T I O N S TA N D A R D (DES) WITH EXAMPLE,
STRENGTH OF DES, DESIGN PRINCIPLES OF BLOCK CIPHER, AES WITH
S T R U C T U R E , I T S T R A N S F O R M AT I O N F U N C T I O N S , K E Y E X PA N S I O N , E X A M P L E
A N D I M P L E M E N TAT I O N , M U LT I P L E E N C RY P T I O N A N D T R I P L E D E S , B L O C K
CIPHER MODE
R E F E R E N C E B O O K - C RY P T O G R A P H Y A N D N E T W O R K S E C U R I T Y, P R I N C I P L E S
A N D P R A C T I C E S I X T H E D I T I O N , W I L L I A M S TA L L I N G S , P E A R S O N
CHAPTER -3 , CHAPTER-5 AND CHAPTER -6
Road Map
Stream ciphers and block ciphers
Block Cipher structure
Data Encryption standard (DES) with example
strength of DES
Multiple DES (2-DES and 3-DES)
Block Cipher Mode
Design principles of block cipher
AES with structure, its transformation
functions, key expansion, example
Classical vs. Modern Cryptography
Modern Cryptography
An arbitrary reversible substitution cipher (the ideal block cipher) for a large block size
is not practical, however, from an implementation and performance point of view.
Component of Modern Block Cipher
Modern Block ciphers normally are not designed as a single unit.
To provide required properties of a modern block cipher, such as
diffusion and confusion, a modern block cipher is made of a
combination of
Transposition units(P-boxes)
Substitution units (S-boxes)
Some other units (such as XOR operation, circular shift
operation, swap operation etc..)
Confusion and Diffusion
In cryptography, confusion and diffusion are two properties of the
operation of a secure cipher which were identified by Claude
Shannon.
Confusion and Diffusion
Diffusion
It hides the relationship between plaintext and ciphertext.
Diffusion implies that each symbol (character or bit) in the ciphertext
is dependent on some or all symbols in plaintext.
In other words, if single symbol in plaintext is changed, several or all
symbols in the ciphertext will be changed.
It is achieved by use of transposition or permutation algorithm.
it is used by block ciphers.
It increases the redundancy of plain text by spreading it across the
rows and column
Confusion and Diffusion
Confusion
Confusion refers to making the relationship between the key and the
ciphertext as complex and involved as possible
It hides the relationship between key and ciphertext.
In other words, if single bit in key is changed, most or all bits in the
ciphertext will be changed.
It is achieved by use of complex substitution algorithm.
One aim of confusion is to make it very hard to find the key even if
one has a large number of plaintext-ciphertext pairs produced with
the same key.
it is used by both block and stream ciphers
Confusion Diffusion
Confusion andWhile
Diffusion
Confusion is a cryptographic technique
diffusion is used to create
which is used to create faint cipher
cryptic plain texts.
texts.
In confusion, if one bit within the While in diffusion, if one image within
secret’s modified, most or all bits the plain text is modified, many or all
within the cipher text also will be image within the cipher text also will
modified. be modified
Y= X K X= Y K
Circular Shift
Circular Shift
Product Cipher
Product Cipher
Product Cipher
Two Classes of Product Cipher
Input
Plaintext: 2w bit
A Key K
Output
Ciphertext: 2w bit
LE1 = RE0
RE1= LE0 F(K1, RE0)
Final Version of
Feistel Cipher
Structure
Input
Plaintext: 2w bit
A Key K
Output
Ciphertext: 2w bit
LE1 = RE0
RE1= LE0 F(K1, RE0)
Feistel Cipher Structure-Encryption Process
Feistel Cipher is not a specific scheme of block cipher.
It is a design model from which many different block ciphers are
derived. DES is just one example of a Feistel Cipher.
A cryptographic system based on Feistel cipher structure uses the
same algorithm for both encryption and decryption.
The encryption process uses the Feistel structure consisting multiple
rounds of processing of the plaintext, each round consisting of a
“substitution” step followed by a permutation step.
Separate Subkey is generated from KEY K using Subkey generation
algorithm.
The plaintext block is divided into two halves, L0 and R0 and they pass
through n round.
Feistel Cipher Structure-Encryption Process
Here the 58th bit of M is "1", which becomes the first bit of IP. The 50th bit of M is "1",
which becomes the second bit of IP. The 7th bit of M is "0", which becomes the last bit of IP.
Initial Permutation
58 50 42 34 26 18 10 2
60 52 44 36 28 20 12 4
the first bit of the output is taken from the
58th bit of the input; the second bit from the 62 54 46 38 30 22 14 6
50th bit, and so on, with the last bit of the 64 56 48 40 32 24 16 8
output taken from the 7th bit of the input.
57 49 41 33 25 17 9 1
59 51 43 35 27 19 11 3
61 53 45 37 29 21 13 5
63 55 47 39 31 23 15 7
Final Permutation (IP-1)
the first bit of the output is taken from the 40th bit of the input; the second bit
from the 8th bit, and so on, with the last bit of the output taken from the 25th
bit of the input.
(PC2)
(PC2)
Parity Drop Table -Permuted Choice -1
M = 0000 0001 0010 0011 0100 0101 0110 0111 1000 1001 1010 1011 1100 1101 1110 1111
PC-1
Parity Drop
C0 D0
C0 = 1111000011001100101010101111
D0 = 0101010101100110011110001111
C1 = 1110000110011001010101011111
D1 = 1010101011001100111100011110
C2 = 1100001100110010101010111111
D2 = 0101010110011001111000111101
Step 1: Create 16 subkeys, each of which is 48-bits long
Left Shift Operation
C3 = 0000110011001010101011111111 C10 = 0101010111111110000110011001
D3 = 0101011001100111100011110101 D10 = 1111000111101010101011001100
C4 = 0011001100101010101111111100 C11 = 0101011111111000011001100101
D4 = 0101100110011110001111010101 D11 = 1100011110101010101100110011
C5 = 1100110010101010111111110000 C12 = 0101111111100001100110010101
D5 = 0110011001111000111101010101 D12 = 0001111010101010110011001111
C6 = 0011001010101011111111000011 C13 = 0111111110000110011001010101
D6 = 1001100111100011110101010101 D13 = 0111101010101011001100111100
C7 = 1100101010101111111100001100 C14 = 1111111000011001100101010101
D7 = 0110011110001111010101010110 D14 = 1110101010101100110011110001
C8 = 0010101010111111110000110011 C15 = 1111100001100110010101010111
D8 = 1001111000111101010101011001 D15 = 1010101010110011001111000111
C9 = 0101010101111111100001100110 C16 = 1111000011001100101010101111
D9 = 0011110001111010101010110011 D16 = 0101010101100110011110001111
Step 1: Create 16 subkeys, each of which is 48-bits long
PC-2 – Compression P-box (56bit to 48bit)
We now form the keys Kn, for 1<=n<=16, by applying the following permutation table to
each of the concatenated pairs CnDn. Each pair has 56 bits, but PC-2 only uses 48 of these.
Ln = Rn-1
Rn = Ln-1 f(Rn-1,Kn)
Round 1:
K1 = 000110 110000 001011 101111 111111 000111 000001 110010
L1 = R0 = 1111 0000 1010 1010 1111 0000 1010 1010
R1 = L0 f(R0,K1) -> First expansion to convert 32bit Right half into 48bit
16 -rounds
K1 = 000110 110000 001011 101111 111111 000111 000001 110010
L1 = R0 = 1111 0000 1010 1010 1111 0000 1010 1010
R1 = L0 f(R0,K1)
Calculation of f(R0,K1)
1. First expansion to convert 32bit Right half into 48bit
Example: We calculate E(R0) from R0 as follows:
R0 = 1111 0000 1010 1010 1111 0000 1010 1010
E(R0) = 011110 100001 010101 010101 011110 100001 010101 010101
Calculation of f(R0,K1)
3. Substitution units (S-Boxes)
Write the previous result, which is 48 bits, in the form:
Kn E(Rn-1) =B1B2B3B4B5B6B7B8,
S1(B1)S2(B2)S3(B3)S4(B4)S5(B5)S6(B6)S7(B7)S8(B8)
Calculation of f(R0,K1)
3. S-Boxes
For S1 Box:
011000 0101
Row: 0
Column : 12
Final result of S-Boxes
S1(B1)S2(B2)S3(B3)S4(B4)S5(B5)S6(B6)S7(B7)S8(B8) = 0101 1100 1000
0010 1011 0101 1001 0111
16 -rounds
K1 = 000110 110000 001011 101111 111111 000111 000001 110010
L1 = R0 = 1111 0000 1010 1010 1111 0000 1010 1010
R1 = L0 f(R0,K1)
Calculation of f(R0,K1)
4. Permutation of f= P(S1(B1)S2(B2)S3(B3)S4(B4)S5(B5)S6(B6)S7(B7)S8(B8))
The permutation P is defined in the following table. P yields a 32-bit output from
a 32-bit input by permuting the bits of the input bloc
S1(B1)S2(B2)S3(B3)S4(B4)S5(B5)S6(B6)S7(B7)S8(B8) =
0101 1100 1000 0010 1011 0101 1001 0111
we get
f = 0010 0011 0100 1010 1010 1001 1011 1011
16 -rounds
K1 = 000110 110000 001011 101111 111111 000111 000001 110010
L1 = R0 = 1111 0000 1010 1010 1111 0000 1010 1010
R1 = L0 f(R0,K1)
====================================================================
L0 = 1100 1100 0000 0000 1100 1100 1111 1111
f = 0010 0011 0100 1010 1010 1001 1011 1011
At the end of the sixteenth round we have the blocks L16 and R16.
We then reverse the order of the two blocks into the 64-bit block R16L16
We reverse the order of these two blocks and apply the final permutation to
•Double DES
•Triple DES
Double DES
Apply two iterations of DES with two keys K1 and K2
It only takes twice as long to break double DES using brute force. Because DES has 56-bit
security, double DES has 2× 256= 257 security
Meet in middle attack on Double DES
Using a known-plaintext attack called meet-in-the-middle
attack is possible on Double DES.
This attack involves encryption from one end and decryption
from other end and matching the results in the middle.
1010001…10 1100110…00
Triple DES
There are two variants of Triple DES known as 3-key Triple DES
(3TDES) and 2-key Triple DES (2TDES).
P = DK1[EK2[DK3[C]]]
3-key Triple DES
C = EK3[DK2[EK1[P]]]
P = DK1[EK2[DK3[C]]]
Block Cipher Mode
Mode of Operation:- In Cryptography, an algorithm used in
conjunction with a block cipher that make up complete encryption
algorithm
How to use Block Cipher?
• Block ciphers encrypt fixed-size blocks
– e.g. DES encrypts 64-bit blocks
• We need some way to encrypt a message of
arbitrary length
– e.g. a message of 1000 bytes
• NIST (National Institute of Standards and
Technology ) defines several ways to do it
– called modes of operation
Five Mode of Operation
C0=IV C0=IV
Ci= E(K, Pi Ci-1) Pi= D(K, Ci ) Ci-1
Cipher block chaining mode (CBC)
An initialization vector (IV) or starting variable is a block of
bits that is used by several modes to randomize the
encryption and hence to produce distinct cipher texts even if
the same plain text is encrypted multiple times.
The initialization vector (IV) should be known by the sender
and the receiver.
Typically, IV is either a fixed value or is sent encrypted in ECB
mode before the rest of ciphertext.
Cipher Block Chaining mode (CBC)
Decryption
Output FeedBack mode (OFB)
Each bit in the cipher text is independent of the previous bit or bits.
This avoids error propagation.
If an error occur in transmission , it does not affect the bits that
follow.
Advantage:
more resistant to transmission errors; a bit error in a ciphertext segment
affects only the decryption of that segment.
IV should be generated randomly each time and sent with the ciphertext.
Output FeedBack mode (OFB)
Each bit in the cipher text is independent of the previous bit or bits.
This avoids error propagation.
If an error occur in transmission , it does not affect the bits that
follow.
Advantage:
more resistant to transmission errors; a bit error in a ciphertext segment
affects only the decryption of that segment.
Disadvantage:
Cannot recover from lost ciphertext segments; if a ciphertext segment
is lost, all following segments will be decrypted incorrectly (if the
receiver is not aware of the segment loss).
IV should be generated randomly each time and sent with the ciphertext.
Output FeedBack mode (OFB)
Output FeedBack mode (OFB)
CounTeR mode (CTR)
Encryption
Decryption
Encryption
Decryption
CounTeR mode (CTR)
Strengths:
Needs only the encryption algorithm
Fast encryption/decryption; blocks can be processed
(encrypted or decrypted) in parallel; good for high speed links
Random access to encrypted data blocks
Summary of all modes
BLOCK CIPHER DESIGN PRINCIPLES
There are following three design principle of Block ciphers are
concerned.
Number of rounds
Design of Function F
Key scheduling mechanism
BLOCK CIPHER DESIGN PRINCIPLES
Number of rounds
Initial
• AddRoundKey : Each byte of the state is combined
Transformation with the round key [w0, w1, w2, w3] using bitwise XOR
/Pre-Round
• SubBytes : non-linear substitution step (Use-S-
box)
Rounds • ShiftRows : transposition step
• MixColumns : mixing operation of each column.
• AddRoundKey : bitwise XOR between state and key
• SubBytes
Final Round • ShiftRows
• AddRoundKey
AES Encryption and Decryption
Key Expansion
Algorithm
Initial Transformation - AddRoundKey
AddRoundKey proceeds one column at a time. AddRoundKey adds a round key word
with each state column matrix;
State State
Key
AddRoundKey
Structure of each round
To provide security, AES uses four types of
transformations: substitution, permutation,
mixing, and key-adding.
SubBytes- Byte Substitutions
A simple substitution of each byte
provide a confusion
Uses one S-box of 16x16 bytes containing a permutation of all 256 8-bit values
Each byte of state is replaced by byte indexed by row (left 4-bits) & column
(right 4-bits)
eg. byte {95} is replaced by byte in row 9 column 5
which has value {2A}
SubBytes- Byte Substitutions
The SubBytes operation involves 16 independent byte-to-byte transformations.
X= First four bits determine Row in S-Box • Interpret the byte as two hexadecimal
Y= Last four bits determine Col in S-Box digits xy
• SW implementation, use row (x) and
column (y) as lookup pointer
S1,1 = xy16
x’y’16
Encryption
S- table
SubByte Operation
Decryption
S- table
InvSubByte
Operation
SubBytes- Byte Substitutions
Shift Rows
• A circular byte shift in each
1st row is unchanged
2nd row does 1 byte circular shift to left
3rd row does 2 byte circular shift to left
4th row does 3 byte circular shift to left
• Since state is processed by columns, this step permutes bytes
between the columns
Shift Rows
• A circular byte shift in each
1st row is unchanged
2nd row does 1 byte circular shift to left
3rd row does 2 byte circular shift to left
4th row does 3 byte circular shift to left
Shift Rows
Shift Rows
Inverse Shift Rows
• Inverse shift row rotates bytes to the right instead of left as in
case of encryption
• Therefore a circular byte shift in each
1st row is unchanged
2nd row does 1 byte circular shift to right
3rd row does 2 byte circular shift to right
4th row does 3 byte circular shift to right
Mix Column
• ShiftRows and MixColumns provide diffusion to the cipher
• Each column of state is processed separately.
• Each byte is replaced by a value dependent on all 4 bytes in
the column
• Effectively a matrix multiplication in Galois Field GF(28) using
prime polynomial m(x) =x8+x4+x3+x+1
Mix Column
02=0000 0010
63=0110 0011
In GF(28)
Number represents as x7+x6+x5+x4+x3+x2+x+1
So 02 = x7+x6+x5+x4+x3+x2+x+1 x
Similarly, 63 = x7+x6+x5+x4+x3+x2+x+1 = x6+x5+ x+1
But in GF(28) = {0, ….. , x7+x6+x5+x4+x3+x2+x+1 } that is higher than 7 power of x is not
allowed
Mix Column – Finite Field(28) multiplication
= x8+x4+x3+x2 = 100011100
Hence needs to divide it with x8+x4+x3+x+1 =100011011
Inverse Mix Column
Constant matrices used by MixColumns and InvMixColumns
Inverse Mix Column
Inputs for single
AES round
Key Expansion Algorithm
Key Expansion Algorithm
Key Expansion Algorithm
W4= W0 g(W3)
Key Expansion Algorithm
W5= W1 W4
Key Expansion Algorithm
W6= W2 W5
Key Expansion Algorithm
W7= W3 W6
Each added word w[i] depends on the
immediately preceding word, w[i- 1], and the
word four positions back, w[i-4].
In three out of four cases, a simple XOR is
used.
For a word whose position in the w array is a
multiple of 4, a more complex function g is
used
Similarly,
Round 2 Keys
W8= W4 g(W7)
W9= W5 W8
W10= W6 W9
W11= W7 W10
What is function g()?
The function g consists of the following sub-
function:
1. RotWord
It performs a one-byte circular left shift
on a word.
RotWord[b0,b1,b2,b3] =
[b1,b2,b3,b0]
2. SubWord performs a byte substitution on
each byte of its input word using the S-
box
3. SubWord(RotWord(temp)) is XORed with
RCon[j] – the round constant
What is function g()?
1. RotWord
It performs a one-byte circular left shift
on a word.
RotWord[b0,b1,b2,b3] =
[b1,b2,b3,b0]
What is function g()?
2. SubWord performs a byte substitution on
each byte of its input word using the S-
box
What is function g()?
3. SubWord(RotWord(temp)) is XORed with
RCon[j] – the round constant
What is function g()?
RCON is a word in which the three rightmost bytes are zero
It is different for each round and defined as:
RCon[j] = (RCon[j],0,0,0)
where RCon[1] =1 , RCon[j] = 2 * RCon[j-1]
Multiplication is defined over GF(28) but can be implement in Table
Lookup
Key Expansion Example (1st round)
Initial Round
Round 1
Round 2
Round 3
Round 4
Round 5
Round output
Round 6
Round 7
Round 8
Round 9
Round 10
Ciphertext
AES Security
AES was designed after DES.
Most of the known attacks on DES were already tested on AES.
Brute-Force Attack
AES is definitely more secure than DES due to the larger-size key.
Statistical Attacks
Numerous tests have failed to do statistical analysis of the
ciphertext
Differential and Linear Attacks
There are no differential and linear attacks on AES as yet.
Implementation Aspects
The algorithms used in AES are so simple that they can be
easily implemented using cheap processors and a minimum
amount of memory.
Very efficient
AES animation:
https://www.youtube.com/watch?v=gP4PqVGudtg
Which is the largest disadvantage of the symmetric Encryption?
A. More complex and therefore more time-consuming calculation
B. Problem of the secure transmission of the Secret Key.
C. Less secure encryption function.
D. Isn't used any more.
Triple-DES procedure is C = E (k1, D (k2, E (k1,m))).
A. True
B. False
The Data Encryption Standard (DES) is an example of a ...
A. Conventional cryptosystem
B. Asymmetric cryptosystem
C. Caesar's cryptosystem
D. All of these
In the AES-128 algorithm there are mainly __________ similar rounds and _________
round is different from other round.
A. 5 similar rounds having 2 pair ; every alternate
B. 9 ; the last
C. 8 ; the first and last
D. 10 ; no
All the below-stated processes are performed in the AES (Advanced Encryption
Standard) Algorithm. Which of the following process(s) are not performed in the
final round of the AES?
A. Substitution bytes
B. Shift rows
C. Mix columns
D. Add round key
For which of the following should EBC (Electronic Code Book) process not be used
for encryption?
A. For large block sizes
B. For fixed block sizes
C. For small block sizes
D. None of the above
Which of the following is the main disadvantage of the ECB (Electronic Code
Book)?
A. It requires large block size
B. Padding is done to make the plain text divisible into blocks of fixed size
C. It is prone to cryptanalysis since there is a direct relationship between plain text and
cipher text.
D. None of the above
Which of the following options is not correct according to the definition of the Cipher Block
Chaining (CBC)?
E. CBC is a mode of operation for stream ciphers.
F. Initialization vector (IV) is used in CBC in the initial phase.
G. It has better resistive nature towards cryptanalysis than ECB
H. None of the above
Which of the following modes of operations can be followed for both stream ciphers as well
as block ciphers?
I. CBC (Cipher Block Chaining)
J. ECB (Electronic Code Book)
K. CFB (Cipher text Feed Back)
L. All of the above
Which of the following properties are the characteristic properties of a block cipher
technique which differs from stream cipher?
A. Avalanche effect
B. Completeness
C. Both a. and b.
D. None of the above
Which one of the following is not a possible key length for the Advanced Encryption Standard
Rijndael cipher?
A. 56 bits
B. 128 bits
C. 192 bits
D. 256 bits
What is the minimum number of cryptographic keys required to achieve a higher level of
security than DES with the Triple DES algorithm?
A. 1
B. 2
C. 3
D. 4
TDES means:
E. Triple digital encryption standard
F. Triangulardata encryption standard
G. Triple data encryption standard
H. Triangular digital encryption standard