Module2 BLOCK - CIPHER - MODES - FINAL - PPTX
Module2 BLOCK - CIPHER - MODES - FINAL - PPTX
Module2 BLOCK - CIPHER - MODES - FINAL - PPTX
12
STREAM CIPHER
A stream cipher is one that encrypts a digital data stream one bit or
one byte at a time. Examples of classical stream ciphers are the
autokeyed Vigenère cipher and the Vernam cipher.
BLOCK CIPHER
A symmetric-key modern block cipher encrypts an n-bit block of plaintext
or decrypts an n-bit block of ciphertext.
The encryption or decryption algorithm uses a k-bit key.
The decryption algorithm must be the inverse of the encryption algorithm,
and both operations must use the same secret key so that Bob can retrieve
the message sent by Alice.
Figure shows the general idea of encryption and decryption in a modern
block cipher.
BLOCK CIPHER
If the message has fewer than n-bits, padding must be added to
make it an n-bit block; if the message has more than n-bits, it should
be divided into n-bit blocks and the appropriate padding must be
added to the last block if necessary. The common values
for n are 64, 128, 256, or 512 bits.
Block vs Stream Ciphers (imp slide)
Modern Block Ciphers
• The ciphers that perform encryption or decryption
at the bit level rather than character level are
referred to as bit-oriented ciphers.
• The modern block cipher is a bit-oriented cipher
that encrypts a m-bit block of plaintext at a time to
produce m-bit block of ciphertext.
• Reverse is followed during decryption.
• Each block of bits is encrypted or decrypted using
k-bit key.
• Use of extra bits (padding)
BLOCK CIPHER
Substitution or Transposition
A modern block cipher can be designed to act as a substitution
cipher or a transposition cipher. This is the same idea as is used in
traditional ciphers, except that the symbols to be substituted or
transposed are bits instead of characters.
ü If the cipher is designed as a substitution cipher, a 1-bit or a 0-
bit in the plaintext can be replaced by either a 0 or a 1. This
means that the plaintext and the ciphertext can have a different
number of 1’s.
ü A 64-bit plaintext block of 12 0’s and 52 1’s can be encrypted to a
ciphertext of 34 0’s and 30 1’s.
ü If the cipher is designed as a transposition cipher, the bits are
only reordered (transposed); there is the same number of 1’s in
the plaintext and in the ciphertext.
BLOCK CIPHER
ü In either case, the number of n-bit possible plaintexts or
ciphertexts is 2n, because each of the n bits in the block can have
one of the two values, 0 or 1.
• S- box
• P-box
• Straight P-box
• Compression P-box
• Expansion P-box
• Circular shift
S-box: It is equivalent to substitution cipher.
• This is a substitution box having the same characteristics as
that of the substitution cipher, except that the substitution of
several bits is performed in parallel.
• It takes n bits of plaintext at a time as input and produces m
bits of ciphertext as output, where the value of n and m may
be the same or different.
• An S-box can be keyed or keyless.
• In a keyed S-box, the mapping of n inputs to m outputs is
decided with the help of a key, whereas in a keyless S-box ,
the mapping from inputs to outputs is predetermined.
• Usually, keyless S-boxes are used in modern block ciphers.
P-box
ü Straight P-boxes
ü Expansion P-boxes and
ü Compression P-boxes
COMPONENTS OF BLOCK CIPHER
Note that inputs 7, 8, 9, 15, 16, 23, 24, and 25 are blocked.
Compression P-boxes are used when we need to permute bits and
the same time decrease the number of bits for the next stage.
COMPONENTS OF BLOCK CIPHER
Expansion P-Boxes
An expansion P-box is a P-box with n inputs and m outputs
where m > n. Some of the inputs are connected to more than one
input.
The expansion P-boxes used in modern block ciphers normally are
keyless, where a permutation table shows the rule for transposing
bits.
We need to know that a permutation table for an expansion P-box
has m entries, but m − n of the entries are repeated
(those inputs mapped to more than one output).
COMPONENTS OF BLOCK CIPHER
Expansion P-Boxes
Table shows an example of a permutation table for a 12 × 16
expansion P-box.
Table S-box 1
There are a total of eight S-box tables. The output of all eight s-
boxes is then combined in to 32-bit section.
DES FUNCTION
4. Straight P-Box Permutation :
The 32-bit output of S-boxes is then subjected to the straight
permutation with rule shown in the following illustration:
Bit
In AES, a bit is a binary digit with a value of 0 or 1. We use a
lowercase letter to refer to a bit.
AES
Data Units
Byte
A byte is a group of eight bits that can be treated as a single entity,
a row matrix (1 × 8) of eight bits, or a column matrix (8 × 1) of eight
bits.
When treated as a row matrix, the bits are inserted to the matrix
from left to right; when treated as a column matrix, the bits are
inserted into the matrix from top to bottom. We use a lowercase bold
letter to refer to a byte.
AES
Data Units
Word
A word is a group of 32 bits that can be treated as a single entity, a
row matrix of four bytes, or a column matrix of four bytes.
When it is treated as a row matrix, the bytes are inserted into the
matrix from left to right; when it is considered as a column matrix,
the bytes are inserted into the matrix from top to bottom.
We use the lowercase bold letter w to show a word.
Block
AES encrypts and decrypts data blocks. A block in AES is a group of
128 bits. However, a block can be represented as a row matrix of 16
bytes.
AES
AES STRUCTURE
AES STRUCTURE
AES STRUCTURE
AES STRUCTURE
Initial Array represent the given plaintext in
this 4 * 4 input array
Each cell represents 1 bytes (8 bits), so we
have 16 Bytes
4 Bytes represents 1 word, so we have 4
words
Example :
AES ROUNDS
Mix Columns
The inverse mix column transformation, called InvMixColumns, is
defined by the following matrix multiplication:
The first matrix is State, and the second matrix is the round key.
The inverse add round key transformation is identical to the forward
add round key transformation, because the XOR operation is its own
inverse.
STREAM CIPHER
• A typical stream cipher encrypts plaintext one byte at a time,
although a stream cipher may be designed to operate on one bit
at a time or on units larger than a byte at a time.
STREAM CIPHER
• In this structure, a key is input to a pseudorandom bit generator
that produces a stream of 8-bit numbers that are apparently
random. The output of the generator, called a keystream, is
combined one byte at a time with the plaintext stream using the
bitwise exclusive-OR (XOR) operation.
• For example, if the next byte generated by the generator is
01101100 and the next plaintext byte is 11001100, then the
resulting ciphertext byte is
STREAM CIPHER
• process message bit by bit (as a stream)
• have a pseudo random keystream
• combined (XOR) with plaintext bit by bit
• randomness of stream key completely destroys statistically
properties in message
• Ci = Mi XOR StreamKeyi
• but must never reuse stream key
• otherwise can recover messages
STREAM CIPHER RC4
RC4 is a byte-oriented stream cipher in which a byte (8 bits) of a
plaintext is exclusive-ored with a byte of key to produce a byte of a
ciphertext.
• a proprietary cipher owned by RSA
• another Ron Rivest design, simple but effective
• variable key size, byte-oriented stream cipher
• widely used (web SSL/TLS, wireless WEP)
• key forms random permutation of all 8-bit values
• uses that permutation to scramble input info processed a byte at
a time
STREAM CIPHER RC4
• A variable length key of from 1 to 256 bytes (8 to 2048 bits) is
used to initialize a 256-byte state vector S, with elements
S[0],S[1], …….,S[255].
• At all times, S contains a permutation of all 8-bit numbers from 0
through 255.
• For encryption and decryption, a byte k is generated from S by
selecting one of the 255 entries in a systematic fashion. As each
value of k is generated, the entries in S are once again permuted
STREAM CIPHER RC4
State
RC4 is based on the concept of a state.
Solution:
Initialization of S:
S[4] = [S0, S1, S2, S3] = [0,1,2,3]
K = [5,1,0,7]
T = [5,1,0,7]
STREAM CIPHER RC4
Initial Permutation of S:
T 5 1 0 7
i j S0 S1 S2 S3
0 0 1 2 3
0 j = j + S[i] + T[i] 1 0 2 3
j=0+0+5
j = 5 mod 4 = 1
Swap(S[i], S[j])
Swap(S[0],S[1])
1 j = j + S[i] + T[i] 1 2 0 3
j=1+0+1
j = 2 mod 4 = 2
Swap(S[1],S[2])
STREAM CIPHER RC4
Initial Permutation of S:
T 5 1 0 7
i j S0 S1 S2 S3
1 2 0 3
2 j = j + S[i] + T[i] 1 2 0 3
j=2+0+0
j = 2 mod 4 = 2
Swap(S[2],S[2])
3 j = j + S[i] + T[i] 3 2 0 1
j=2+3+7
j = 12 mod 4 = 0
Swap(S[3],S[0])
STREAM CIPHER RC4
Example:
S = [0,1,2,3,4,5,6,7]
K = [1,2,3,6]
K/ T = [1,2,3,6,1,2,3,6]
Plaintext PT = [1,2,2,2]
When i = 0,
j = [0 + 0 + 1] mod 8 = 1 mod 8 = 1,
Swap S[0],S[1]
S = [1,0,2,3,4,5,6,7]
When i = 1,
j = [1 + 0 + 2] mod 8 = 3 mod 8 = 3,
Swap S[1],S[3]
S = [1,3,2,0,4,5,6,7]
STREAM CIPHER RC4
Example:
When i = 2,
j = [3 + 2 + 2] mod 8 = 8 mod 8 = 0,
Swap S[2],S[0]
S = [2,3,1,0,4,5,6,7]
When i = 3,
j = [0 + 0 + 6] mod 8 = 6 mod 8 = 6,
Swap S[3],S[6]
S = [2,3,1,6,4,5,0,7]
When i = 4,
j = [6 + 4 + 1] mod 8 = 11 mod 8 = 3,
Swap S[4],S[3]
S = [2,3,1,4,6,5,0,7]
STREAM CIPHER RC4
Example:
When i = 5,
j = [3 + 5 + 2] mod 8 = 10 mod 8 = 2,
Swap S[5],S[2]
S = [2,3,5,4,6,1,0,7]
When i = 6,
j = [2 + 0 + 3] mod 8 = 5 mod 8 = 5,
Swap S[6],S[5]
S = [2,3,5,4,6,0,1,7]
When i = 7,
j = [5 + 7 + 6] mod 8 = 18 mod 8 = 2,
Swap S[7],S[2]
S = [2,3,7,4,6,0,1,5]
STREAM CIPHER RC4
Example: Key Stream Generation
When i = 1
j = 0 + 3 mod 8 = 3 mod 8 = 3
Swap S[1],S[3]
S = [2,4,7,3,6,0,1,5],
t = 4 + 3 mod 8 = 7 mod 8 = 7
k=5
When i = 2
j = 3 + 7 mod 8 = 10 mod 8 = 2
Swap S[2],S[2]
S = [2,4,7,3,6,0,1,5],
t = 7 + 7 mod 8 = 14 mod 8 = 6
k=1
STREAM CIPHER RC4
Example: Key Stream Generation
When i = 3
j = 2 + 3 mod 8 = 5 mod 8 = 5
Swap S[3],S[5]
S = [2,4,7,0,6,3,1,5],
t = 0 + 3 mod 8 = 3 mod 8 = 3
k=0
When i = 4
j = 5 + 6 mod 8 = 11 mod 8 = 3
Swap S[4],S[3]
S = [2,4,7,6,0,3,1,5],
t = 0 + 6 mod 8 = 6 mod 8 = 6
k=1
STREAM CIPHER RC4
Example: Encryption
KS = [5, 1, 0, 1]
PT = [1,2,2,2]
CT = PT XOR KS
CT = [4, 3, 2, 3]
STREAM CIPHER RC4
Example: Decryption
PT = CT XOR KS
PT = [1, 2, 2, 2]
STREAM CIPHER RC4
Example:
Suppose an S-Array is of length 8
[S0, S1, S2, S3, S4, S5, S6, S7] = [0,1,2,3,4,5,6,7]
K = [3,1,4,1,5]
K/ T-Array is [K0, K1, K2, K3, K4, K5, K6, K7] = [3,1,4,1,5,3,1,4]
Plaintext PT = [6,1,5,4]
STREAM CIPHER RC4
Example: Key Scheduling
T -- 3 1 4 1 5 3 1 4
i j S0 S1 S2 S3 S4 S5 S6 S7
- 0 0 1 2 3 4 5 6 7
When i = 0
j = 0 + 0 + 3 = 3 Swap S[0],S[3] = 0, 3
0 3 3 1 2 0 4 5 6 7
When i = 1
j = 3 + 1 + 1 = 5 Swap S[1],S[5] = 1, 5
1 5 3 5 2 0 4 1 6 7
STREAM CIPHER RC4
Example: Key Scheduing
T -- 3 1 4 1 5 3 1 4
i j S0 S1 S2 S3 S4 S5 S6 S7
- 0 0 1 2 3 4 5 6 7
0 3 3 1 2 0 4 5 6 7
1 5 3 5 2 0 4 1 6 7
2 3 3 5 0 2 4 1 6 7
3 6 3 5 0 6 4 1 2 7
4 7 3 5 0 6 7 1 2 4
5 3 3 5 0 1 7 6 2 4
6 6 3 5 0 1 7 6 2 4
7 6 3 5 0 1 7 6 4 2
STREAM CIPHER RC4
Example: Key Stream Generation
The new S-Array is [3,5,0,1,7,6,4,2], PT = [6,1,5,4]
Take the length of PT
STREAM CIPHER RC4
Example: Key Stream Generation
i j t KStr S0 S1 S2 S3 S4 S5 S6 S7
- 0 - - 3 5 0 1 7 6 4 2
When i = 1
j = 0 + 5 mod 8 = 5, Swap S[1],S[5] = 5, 6
1 5 - - 3 6 0 1 7 5 4 2
When i = 1
t = 6 + 5 mod 8 = 3, Swap S[1],S[5] = 5, 6
KStr = S[3] = 1
1 5 3 1 3 6 0 1 7 5 4 2
STREAM CIPHER RC4
Example: Key Stream Generation
i j t KStr S0 S1 S2 S3 S4 S5 S6 S7
- 0 - - 3 5 0 1 7 6 4 2
1 5 3 1 3 6 0 1 7 5 4 2
2 5 5 0 3 6 5 1 7 0 4 2
3 6 5 0 3 6 5 4 7 0 1 2
4 5 7 2 3 6 5 4 0 7 1 2
STREAM CIPHER RC4
Example: Encryption
KS = [1, 0, 0, 2]
PT = [6,1,5,4]
CT = PT XOR KS
CT = [7, 1, 5, 6]
STREAM CIPHER RC4
Example: Decryption
PT = CT XOR KS
PT = [6, 1, 5, 4]
STREAM CIPHER RC4
Example:
S = [0,1,2,3,4,5,6,7]
K = [6,5,2,3,1,4]
Plaintext PT = [5,2,2,4,1,3]
STREAM CIPHER RC4