Unit 2 - Symmetric Key Cryptography
Unit 2 - Symmetric Key Cryptography
An entity, Alice, can send a message to another entity, Bob, over an insecure channel with
the assumption that an adversary, Eve, cannot understand the contents of the message by
simply eavesdropping over the channel.
The original message from Alice to Bob is called plaintext; the message that is sent
through the channel is called the ciphertext. To create the ciphertext from the plaintext,
Alice uses an encryption algorithm and a shared secret key. To create the plaintext from
ciphertext, Bob uses a decryption algorithm and the same secret key. We refer to
encryption and decryption algorithms as ciphers. A key is a set of values (numbers) that
the cipher, as an algorithm, operates on.
The symmetric-key encipherment uses a single key (the key itself may be a set of values)
for both encryption and decryption. In addition, the encryption and decryption algorithms
are inverses of each other. If P is the plaintext, C is the ciphertext, and K is the key, the
encryption algorithm Ek(x) creates the ciphertext from the plaintext; the decryption
algorithm Dk(x) creates the plaintext from the ciphertext.
Encryption: C = Ek(P) Decryption: P = Dk(C)
1
Prof.Andleeb Sahar
UNIT II CRYPTOGRAPHY & NETWORK SECURITY
Figure shows the general idea of encryption and decryption in a modern 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.
Modern block ciphers are designed as substitution ciphers because the inherent
characteristics of transposition vulnerable to exhaustive-search attacks.
2
Prof.Andleeb Sahar
UNIT II CRYPTOGRAPHY & NETWORK SECURITY
2.S-Boxes:
3
Prof.Andleeb Sahar
UNIT II CRYPTOGRAPHY & NETWORK SECURITY
The following table defines the input/output relationship for an S-box of size 3 × 2.
The leftmost bit of the input defines the row; the two rightmost bits of the input
define the column. The two output bits are values on the cross section of the
selected row and column.
Based on the table, an input of 010 yields the output 01. An input of 101 yields the
output of 00.
3.Exclusive-Or:
4.Circular Shift
Another component found in some modern block ciphers is the circular shift
operation. Shifting can be to the left or to the right. The circular left-shift operation
shifts each bit in an n-bit word k positions to the left; the leftmost k bits are
removed from the left and become the rightmost bits. The circular right-shift
operation shifts each bit in an n-bit word k positions to the right; the rightmost k
bits are removed from the right and become the leftmost bits.
4
Prof.Andleeb Sahar
UNIT II CRYPTOGRAPHY & NETWORK SECURITY
Swap
Two other operations found in some block ciphers are split and combine. The split
operation normally splits an n-bit word in the middle, creating two equal-length
words. The combine operation normally concatenates two equal-length words to
create an n-bit word. These two operations are inverses of each other and can be
used as a pair to cancel each other out.
5
Prof.Andleeb Sahar
UNIT II CRYPTOGRAPHY & NETWORK SECURITY
In a modern stream cipher, encryption and decryption are done r bits at a time. We
have a plaintext bit stream P = pn...p2p1, a ciphertext bit stream C
=cn...c2c1, and a key bit stream K = kn...k2k1, in which pi, ci, and ki are r-bit
words.
Stream ciphers are faster than block ciphers. The hardware implementation of a
stream cipher is also easier. When we need to encrypt binary streams and transmit
them at a constant rate, a stream cipher is the better choice to use. Stream ciphers
are also more immune to the corruption of bits during transmission.
In a nonsynchronous stream cipher, each key in the key stream depends on previous
plaintext or ciphertext.
6
Prof.Andleeb Sahar
UNIT II CRYPTOGRAPHY & NETWORK SECURITY
Overview
At the encryption site, DES takes a 64-bit plaintext and creates a 64-bit ciphertext;
at the decryption site, DES takes a 64-bit ciphertext and creates a 64-bit block of
plaintext. The same 56-bit cipher key is used for both encryption and decryption.
We have mentioned that DES uses a 56-bit key. Actually, the initial key consists of
64 bits. However, before the DES process even starts, every 8th bit of the key is
discarded to produce a 56-bit key. That is bit positions 8, 16, 24, 32, 40, 48, 56, and
64 are discarded.
7
Prof.Andleeb Sahar
UNIT II CRYPTOGRAPHY & NETWORK SECURITY
Thus, the discarding of every 8th bit of the key produces a 56-bit key from the
original 64-bit key.
DES STRUCTURE
The basic process in enciphering a 64-bit data block using the DES consists of:
● an initial permutation (IP)
● 16 rounds of a complex key dependent calculation f
● a final permutation, being the inverse of IP
● Step3: Next, the initial permutation (IP) produces two halves of the permuted
block; saying Left Plain Text (LPT) and Right Plain Text (RPT).
● Step4: Now each LPT and RPT go through 16 rounds of the encryption process.
8
Prof.Andleeb Sahar
UNIT II CRYPTOGRAPHY & NETWORK SECURITY
● Step5: In the end, LPT and RPT are rejoined and a Final Permutation (FP) is
performed on the combined block
The initial and final permutations (P-boxes). Each of these permutations takes a
64-bit input and permutes them according to a predefined rule.
Below Figure shows only a few input ports and the corresponding output ports.
These permutations are keyless straight permutations that are the inverse of each
other.
For example, in the initial permutation, the 58th bit in the input becomes the first bit
in the output. Similarly, in the final permutation, the first bit in the input becomes
the 58th bit in the output.
9
Prof.Andleeb Sahar
UNIT II CRYPTOGRAPHY & NETWORK SECURITY
Rounds
After IP is done, the resulting 64-bit permuted text block is divided into two half
blocks.
Each half-block consists of 32 bits, and each of the 16 rounds, in turn, consists
of the broad-level steps outlined in the figure.
The initial 64-bit key is transformed into a 56-bit key by discarding every 8th bit of
the initial key. Thus, for each a 56-bit key is available. From this 56-bit key, a
different 48-bit Sub Key is generated during each round using a process called key
transformation.
For this, the 56-bit key is divided into two halves, each of 28 bits. These halves are
circularly shifted left by one or two positions, depending on the round.
10
Prof.Andleeb Sahar
UNIT II CRYPTOGRAPHY & NETWORK SECURITY
For example: if the round numbers 1, 2, 9, or 16 the shift is done by only one position for
other rounds, the circular shift is done by two positions.
After an appropriate shift, 48 of the 56 bits are selected. for selecting 48 of the 56
bits the table is shown in the figure given below. For instance, after the shift, bit
number 14 moves to the first position, bit number 17 moves to the second position,
and so on. If we observe the table carefully, we will realize that it contains only
48-bit positions. Bit number 18 is discarded (we will not find it in the table), like 7
others, to reduce a 56-bit key to a 48-bit key. Since the key transformation process
involves permutation as well as a selection of a 48-bit subset of the original 56-bit
key it is called Compression Permutation.
After the initial permutation, we had two 32-bit plain text areas called Left Plain
Text(LPT) and Right Plain Text(RPT). During the expansion permutation, the RPT is
expanded from 32 bits to 48 bits. Bits are permuted as well hence called expansion
permutation. This happens as the 32-bit RPT is divided into 8 blocks, with each block
consisting of 4 bits. Then, each 4-bit block of the previous step is then expanded to a
corresponding 6-bit block, i.e., per 4-bit block, 2 more bits are added.
This process results in expansion as well as a permutation of the input bit while
creating output. the expansion permutation process expands the 32-bit RPT to 48-bits.
11
Prof.Andleeb Sahar
UNIT II CRYPTOGRAPHY & NETWORK SECURITY
XOR: After the expansion permutation, DES uses the XOR operation on the expanded
right section and the round key.
The 48-bit data from the second operation is divided into eight 6-bit chunks, and each
chunk is fed into a box.
The result of each box is a 4-bit chunk; when these are combined the result is a 32-bit text.
The substitution in each box follows a pre-determined rule based on a 4-row by
16-column table.
12
Prof.Andleeb Sahar
UNIT II CRYPTOGRAPHY & NETWORK SECURITY
Solution: If we write the first and the sixth bits together, we get 11 in binary, which is 3 in
decimal. The remaining bits are 0001 in binary, which is 1 in decimal. We look for the
value in row 3, column 1.
The result is 12 in decimal, which in binary is 1100. So the input 100011 yields the output
1100.
4.P-Box Permutation (Straight Permutation): The last operation in the DES function is
a straight permutation with a 32-bit input and a 32-bit output.
The input/output relationship for this operation is shown in Table
5.XOR and Swap: We have been performing all the operations only on 32 bit RPT. The
LPT was untouched so far. At this time the LPT is XORed with the output produced by
P-Box permutations.
The result of this XOR operation will become the new RPT. The old RPT becomes the
new LPT, in the process of swapping.
13
Prof.Andleeb Sahar
UNIT II CRYPTOGRAPHY & NETWORK SECURITY
DES Weaknesses
S-boxes:
1. In S-box , the last three output bits can be derived in the same way as the first
output bit by complementing some of the input bits.
2. Two specifically chosen inputs to an S-box array can create the same output.
3. It is possible to obtain the same output in a single round by changing bits in
only three neighboring S-boxes.
P-boxes:
1. It is not clear why the designers of DES used the initial and final
permutations; these have no security benefits.
2. In the expansion permutation (inside the function), the first and fourth bits of
every 4-bit series are repeated.
Key Size:
DES with a cipher key of 56 bits is not safe enough to be used comfortably.
Variations of DES:
One solution is to use double DES (2DES) with two keys (112 bits) or triple
DES with three keys (168 bits).
Double DES:
Double DES is an encryption approach which need two instance of DES on same plain
text. In both instances it uses multiple keys to encrypt the plain text. Both keys are
needed at the time of decryption.
14
Prof.Andleeb Sahar
UNIT II CRYPTOGRAPHY & NETWORK SECURITY
The 64 bit plain text goes into first DES instance which than transformed into a 64 bit
middle text utilizing the first key and thus it goes to second DES instance which
provides 64 bit cipher text by utilizing second key.
Double DES is easy as it does that normal DES does. Double DES need two keys to
say K1 and K2 in this algorithm. It can implement DES on the original plain text using
K1 to receive the encrypted text in cryptography. Therefore, it again implements DES
on the encrypted text but this time with the other key K2 in this algorithm.
Triple DES:
In Triple DES, the plain text block P is first encrypted with a key K1 then encrypts
with a second key K2 and finally with a third key K3 where K1, K2, and K3 are
distinct from each other in this algorithm. This is Decryption is completed in reverse
order in this method. Hence, this algorithm is generally used in PGP and S/MIME in
cryptography.
15
Prof.Andleeb Sahar
UNIT II CRYPTOGRAPHY & NETWORK SECURITY
In the AES encryption process. The cipher takes a plaintext block size of 128 bits, or 16
bytes. The key length can be 16, 24, or 32 bytes (128, 192, or 256 bits).
The algorithm is referred to as AES-128, AES-192, or AES-256, depending on the key
length.
The input to the encryption and decryption algorithms is a single 128-bit block. This block
is depicted as a 4 * 4 square matrix of bytes. This block is copied into the State array,
which is modified at each stage of encryption or decryption. After the final stage, State is
copied to an output matrix.
The key is expanded into an array of key schedule words. In our example the expansion
for the 128-bit key. Each word is four bytes, and the total key schedule is 44 words for the
128-bit key. Note that the ordering of bytes within a matrix is by column. So, for example,
the first four bytes of a 128-bit plaintext input to the encryption cipher occupy the first
column of the in matrix, the second four bytes occupy the second column, and so on.
Similarly, the first four bytes of the expanded key, which form a word, occupy the first
column of the w matrix.
The cipher consists of N rounds, where the number of rounds depends on the key length:
10 rounds for a 16-byte key, 12 rounds for a 24-byte key, and 14 rounds for a 32-byte key.
The first N - 1 rounds consist of four distinct transformation functions: SubBytes,
ShiftRows, MixColumns, and AddRoundKey. The final round contains only three
transformations, and there is a initial single transformation (AddRoundKey) before the
first round, which can be considered Round 0. Each transformation takes one or more 4 *
4 matrices as input and produces a 4 * 4 matrix as output.
16
Prof.Andleeb Sahar
UNIT II CRYPTOGRAPHY & NETWORK SECURITY
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 uses several rounds in which each round is made of several stages. Data block
is transformed from one stage to another. At the beginning and end of the cipher,
AES uses the term data block; before and after each stage, the data block is referred
to as a state.
17
Prof.Andleeb Sahar
UNIT II CRYPTOGRAPHY & NETWORK SECURITY
● AES processes the entire data block as a single matrix during each round using
substitutions and permutation.
● The key that is provided as input is expanded into an array of forty-four 32-bit (words)
w[i]. Four distinct words (128 bits) serve as a round key for each round.
● For both encryption and decryption, the cipher begins with an AddRoundKey stage,
followed by nine rounds that each includes all four stages, followed by a tenth round of
three stages.
18
Prof.Andleeb Sahar
UNIT II CRYPTOGRAPHY & NETWORK SECURITY
● Only the AddRoundKey stage makes use of the key. For this reason, the cipher begins
and ends with an AddRoundKey stage. Any other stage, applied at the beginning or
end, is reversible without knowledge of the key and so would add no security.
ii) ShiftRows Transformation: The forward shift row transformation, called ShiftRows.
The first row of State is not altered. For the second row, a 1-byte circular left shift is
performed. For the third row, a 2-byte circular left shift is performed. For the fourth row, a
3-byte circular left shift is performed. The following is an example of ShiftRows.
19
Prof.Andleeb Sahar
UNIT II CRYPTOGRAPHY & NETWORK SECURITY
An example of MixColumns:
iv) AddRoundKey Transformation: In the forward add round key transformation, called
AddRoundKey, the 128 bits of State are bitwise XORed with the 128 bits of the round
key. the operation is a columnwise operation between the 4 bytes of a State column and
one word of the round key.
example of AddRoundKey:
20
Prof.Andleeb Sahar
UNIT II CRYPTOGRAPHY & NETWORK SECURITY
[cipher text]
● This is the final cipher text for this round. Depending on the key length you
repeat the above steps until you complete the round 10, after which you
receive the final cipher text.
Key Expansion Algorithm: The AES key expansion algorithm takes as input a four-word
(16-byte) key and produces a linear array of 44 words (176 bytes). This is sufficient to
provide a fourword round key for the initial AddRoundKey stage and each of the 10
rounds of the cipher. The pseudocode on the next page describes the expansion. The key is
copied into the first four words of the expanded key. The remainder of the expanded key is
filled in four words at a time. 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 is used. Using the symbol g to represent that complex function.
The function g consists of the following subfunctions.
● RotWord performs a one-byte circular left shift on a word. This means that an input
word [B0, B1, B2, B3] is transformed into [B1, B2, B3, B0].
● SubWord performs a byte substitution on each byte of its input word, using the S-box.
● The result of steps 1 and 2 is XORed with a round constant, Rcon[j].
21
Prof.Andleeb Sahar
UNIT II CRYPTOGRAPHY & NETWORK SECURITY
22
Prof.Andleeb Sahar
UNIT II CRYPTOGRAPHY & NETWORK SECURITY
ANALYSIS OF AES
Brute-Force Attack
AES is definitely more secure than DES due to the larger-size key (128, 192, and
256 bits). Let us compare DES with 56-bit cipher key and AES with 128-bit
cipher key. For DES we need 256(ignoring the key complement issue) tests to
find the key; for AES we need 2128 tests to find the key. This means that if we
can break DES in t seconds, we need (272 × t) seconds to break AES. This
would be almost impossible.
23
Prof.Andleeb Sahar
UNIT II CRYPTOGRAPHY & NETWORK SECURITY
3) Blowfish:
Blowfish is an encryption technique designed by Bruce Schneier in 1993 as an
alternative to DES Encryption Technique.
It is significantly faster than DES and provides a good encryption rate with no
effective cryptanalysis technique found to date. It is one of the first, secure block
ciphers not subject to any patents and hence freely available for anyone to use.
It is symmetric block cipher algorithm.
1. blockSize: 64-bits
3. number of rounds: 16
each]
24
Prof.Andleeb Sahar
UNIT II CRYPTOGRAPHY & NETWORK SECURITY
Data Encryption −
25
Prof.Andleeb Sahar
UNIT II CRYPTOGRAPHY & NETWORK SECURITY
Swap L and R
After the 16th round,
Function F (4 S-Boxes)
26
Prof.Andleeb Sahar
UNIT II CRYPTOGRAPHY & NETWORK SECURITY
4) RC4
RC4 is a stream cipher that was designed in 1984 by Ronald Rivest for RSA Data
Security.
RC4 is used in many data communication and networking protocols.
The RC4 algorithm is remarkably simple and quite easy to explain.
RC4 is a byte-oriented stream cipher in which a byte (8 bits) of a plaintext is
exclusive-ored (XOR) with a byte of key to produce a byte of a ciphertext.
The secret key, from which the one-byte keys in the key stream are generated, can
contain anywhere from 1 to 256 bytes.
State
RC4 is based on the concept of a state. At each moment, a state of 256 bytes is
active, from which one of the bytes is randomly selected to serve as the key for
encryption.
The idea can be shown as an array of bytes:
S[0], S[1] ,S[2], ... S[255]
Initialization:
To begin, the entries of S are set equal to the values from 0 through 255 in
ascending order; that is, S[0] = 0, S[1] = 1, S[255] = 255 . A temporary vector, T, is
also created. If the length of the key K is 256 bytes, then K is transferred to T.
Otherwise, for a key of length keylen bytes, the first keylen elements of T are
copied from K, and then K is repeated as many times as necessary to fill out T.
for (i = 0 to 255)
{
S[i] ← i
27
Prof.Andleeb Sahar
UNIT II CRYPTOGRAPHY & NETWORK SECURITY
In the first step, the state is initialized to values 0, 1, ..., 255. A key array, K[0],
K[1],..., K[255] is also created. If the secret key has exactly 256 bytes, the bytes are
copied to the K array; otherwise, the bytes are repeated until the K array is filled.
In the second step, the initialized state goes through a permutation (swapping the
elements) based on the value of the bytes in K[i]. The key byte is used only in this
step to define which elements are to be swapped. After this step, the state bytes are
completely shuffled.
j←0
for (i = 0 to 255)
{
j ← (j + S[i] + K[i]) mod 256
swap (S[i] , S[j])
}
28
Prof.Andleeb Sahar
UNIT II CRYPTOGRAPHY & NETWORK SECURITY
RC4_Encryption Algorithm:
RC4_Encryption (K){
// Creation of initial state and key bytes
for (i = 0 to 255)
{
S[i] ← i
K[i] ← Key [i mod KeyLength]
}
// Permuting state bytes based on values of key bytes
j←0
for (i = 0 to 255)
{
j ← (j + S[i] + K[i]) mod 256
swap (S[i] , S[j])
}
// Continuously permuting state bytes, generating keys, and encrypting
i←0
j←0
while (more byte to encrypt)
{
i ← (i + 1) mod 256
j ← (j + S[i]) mod 256
swap (S [i] , S[j])
k ← S [(S[i] + S[j]) mod 256]
// Key is ready, encrypt
input P
C←P⊕k
output C
}}
29
Prof.Andleeb Sahar
UNIT II CRYPTOGRAPHY & NETWORK SECURITY
Key Distribution:
Symmetric cryptography refers to a type of cryptography whereby the key that is
used to encrypt the data is the same for decrypting the data, and thus it is also
known as a shared key cryptography.
The key must be established or agreed on before the data exchange between the
communicating parties. This is the reason it is also called secret key cryptography.
Keys can be distributed by any one of the following ways:
1. Sender can select the key and physically deliver it to receiver.
2. A trusted third party can select the key and physically deliver it to the sender and the
receiver.
3. If sender and receiver have previously and recently used a key, one party can
transmit the new key to the other, encrypted using the old key.
4. If sender and receiver each has an encrypted connection to a third party, then the
third party can deliver a key on the encrypted links to sender and receiver.
30
Prof.Andleeb Sahar