CNS Unit-2.1 Notes
CNS Unit-2.1 Notes
UNIT- II
Symmetric key Ciphers: Block Cipher principles &Algorithms (DES, AES, Blowfish),
Differential and Linear Cryptanalysis, Block cipher modes of operation, Stream ciphers, RC4,
Location and placement of encryption function, Key distribution
Asymmetric key Ciphers: Principles of public key cryptosystems, Algorithms (RSA, Diffie-
Hellman, ECC), Key Distribution
For Example, The Data Encryption Standard (DES) has been the most widely used Block Cipher
encryption algorithm until recently. It exhibits the classic Feistel structure. DES uses a 64-bit block
and a 56-bit key.
The Feistel Cipher:
Many block ciphers have a Feistel structure. Such a structure consists of a number of identical
rounds of processing.
In each round, a substitution is performed on one half of the data being processed, followed by a
permutation that interchanges the two halves.
The original key is expanded so that a different key is produced and used for each round.
In particular, Feistel proposed the use of a cipher that alternates substitutions and permutations,
Feistel’s is a practical application of a proposal by Claude Shannon to develop a product cipher that
alternates confusion and diffusion functions
Block Cipher Design Principles:
There are three critical aspects of block cipher design:
-the number of rounds,
-design of the function F, and
-key scheduling Algorithm.
Number of Rounds:
The greater the number of rounds, the more difficult it is to perform cryptanalysis,
even for a relatively weak function F.
In general, the criterion should be that the number of rounds is chosen so that known
cryptanalytic efforts require greater effort than a simple brute-force key search
attack. This criterion was certainly used in the design of DES.
Design of Function F:
The heart of a Feistel block cipher is the function F, which provides the element of
confusion in a Feistel cipher. Thus, it must be difficult to “unscramble” the
substitution performed by F.
F must be nonlinear. The more nonlinear F, the more difficult any type of
cryptanalysis will be.
Key Schedule Algorithm:
With any Feistel block cipher, the key is used to generate one subkey for each round.
In general, we would like to select subkeys to maximize the difficulty of deducing
individual subkeys and the difficulty of working back to the main key.
1
P.Srinivasulu, CSE, PBRVITS. Cryptography and Network Security
2
P.Srinivasulu, CSE, PBRVITS. Cryptography and Network Security
The exact realization of a Feistel network depends on the choice of the following parameters and
design features:
Block size: Larger block sizes mean greater security but reduced encryption /
decryption speed for a given algorithm. The greater security is achieved by greater
diffusion. Traditionally, a block size of 64 bits has been considered a reasonable
tradeoff and was nearly universal in block cipher design. However, the new AES
uses a 128-bit block size.
Key size: Larger key size means greater security but may decrease encryption/
decryption speed. The greater security is achieved by greater resistance to brute-force
attacks and greater confusion. Key sizes of 64 bits or less are now widely considered
to be inadequate, and 128 bits has become a common size.
Number of rounds: The essence of the Feistel cipher is that a single round offers
inadequate security but that multiple rounds offer increasing security. A typical size is
16 rounds.
Subkey generation algorithm: Greater complexity in this algorithm should lead to
greater difficulty of cryptanalysis.
Round function F: Greater complexity in Round Function generally means greater
resistance to cryptanalysis.
3
P.Srinivasulu, CSE, PBRVITS. Cryptography and Network Security
4
P.Srinivasulu, CSE, PBRVITS. Cryptography and Network Security
Looking at the left-hand side of the above diagram, we can see that the processing of the
plaintext proceeds in three phases.
First, the 64-bit plaintext passes through an initial permutation (IP) that rearranges the
bits to produce the permuted input.
This is followed by a phase consisting of sixteen rounds of the same function, which
involves both permutation and substitution functions. The output of the last (sixteenth)
round consists of 64 bits that are a function of the input plaintext and the key. The left
and right halves of the output are swapped to produce the preoutput.
Finally, the preoutput is passed through a permutation that is the inverse of the initial
permutation function, to produce the 64-bit cipher text.
The right-hand portion of above diagram shows the way in which the 56-bit key is used.
Initially, the key is passed through a permutation function.
Then, for each of the sixteen rounds, a subkey (Ki) is produced by the combination of a left
circular shift and a permutation.
The permutation function is the same for each round, but a different subkey is produced
because of the repeated shifts of the key bits.
Inner workings of DES:
Below figure shows the internal structure of a single round.
The left and right halves of each 64-bit intermediate value are treated as separate 32-bit
quantities, labeled L (left) and R (right).
The overall processing at each round can be summarized in the following formulas:
Key Generation: -
A 64-bit key is used as input to the algorithm. The bits of the key are numbered from 1
through 64; every eighth bit is ignored to obtain 56-bit key, and then it is followed by a
permutation called Permuted Choice One.
The resulting 56-bit key is then treated as two 28-bit quantities, labelled C0 and D0. At each
round, Ci-1 and Di-1 are separately subjected to a circular left shift or (rotation) of 1 or 2 bits.
These shifted values serve as input to the next round.
They also serve as input to the part labeled Permuted Choice Two, which produces a 48-bit
output that serves as input to the Function F(Ri-1, Ki).
5
P.Srinivasulu, CSE, PBRVITS. Cryptography and Network Security
DES Decryption:-
Decryption uses the same algorithm as encryption, except that the application of the subkeys is
reversed.
That means, Whatever process we following in the encryption that process is used for
decryption also but the order of key is reversed and the process is applied on Cipher Text
message.
i.e. Reverse order of keys are K16, K15 ,……, K1.
The Triple DES then breaks the user provided key into three subkeys, padding the
keys if necessary so they are each 64 bits long.
The procedure for encryption is exactly the same as regular DES, but it is repeated
three times. Hence the name Triple DES. The data is encrypted with the first key, decrypted
with the second key, and finally encrypted again with the third key.
6
P.Srinivasulu, CSE, PBRVITS. Cryptography and Network Security
AES does not use a Feistel structure. Instead, each full round consists of four separate
functions: byte substitution, permutation, arithmetic operations over a finite field, and XOR
with a key.
It was designed to have the following characteristics:
Resistance against all known attacks
Speed and code compactness on a wide range of platforms
Design simplicity
AES Structure :-
The input to the encryption and decryption algorithms is a single 128-bit block, this block is
depicted as a square matrix of bytes as shown below:
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.
AES Parameters:
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; as
shown below:
Key size(words/bytes/bits) 4/16/128 6/24/192 8/32/256
Number of rounds 10 12 14
7
P.Srinivasulu, CSE, PBRVITS. Cryptography and Network Security
There is a initial single transformation (AddRoundKey) before the first round, which can be
considered Round 0, and the final round contains only three transformations.
Each transformation takes one or more matrices as input and produces a 4 x 4 matrix as output.
This applies for both encryption and decryption with the exception that each stage of a round
in the decryption algorithm is the inverse of its counterpart in the encryption algorithm.
The first nine rounds of the decryption algorithm consist of the following:
1. Inverse Shift rows
2. Inverse Substitute bytes
3. Inverse Add Round Key
4. Inverse Mix Columns
Again, the tenth round simply leaves out the Inverse Mix Columns stage. Each of these
stages will now be considered in more detail.
8
P.Srinivasulu, CSE, PBRVITS. Cryptography and Network Security
Substitute Bytes
This stage (known as SubBytes) is simply a table lookup using a 16×16 matrix of byte values
called an s-box.
The s-box is not just a random permutation of these values and there is a well- defined method
for creating the s-box tables. The designers of Rijndael showed how this was done.
In this particular stage each byte is mapped into a new byte in the following way:
9
P.Srinivasulu, CSE, PBRVITS. Cryptography and Network Security
For example, the byte {95} (curly brackets selects row 9 column 5. This is then used to update
the state matrix. Figure 7.3 depicts this idea.
10
P.Srinivasulu, CSE, PBRVITS. Cryptography and Network Security
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 inverse add round key transformation is identical to the forward add round key
transformation, because the XOR operation is its own inverse.
Example:
▶ First 128 bit key is arranged as a 4x4 matrix each value size is 8-bits
▶ The first 32 bits (k0,k1,k2,k3) is considered as w0.
▶ The first 32 bits (k4,k5,k6,k7) is considered as w1.
▶ The first 32 bits (k8,k9,k10,k11) is considered as w2.
▶ The first 32 bits (k12,k13,k14,k15) is considered as w4.
▶ Next 4 words w4,w5,w6,w7 are followed as
w4=w0 ⊕ w3
w5=w1 ⊕ w4
w6=w2 ⊕ w5
w7=w3 ⊕ w6
11
P.Srinivasulu, CSE, PBRVITS. Cryptography and Network Security
Blowfish Algorithm
Introduction: -
Blow fish is a symmetric block cipher developed by bruce schner in year 1993.
Blowfish is a Feistel Structure type model.
Blow fish is designed to have following characteristics
Speed: Blowfish encrypts data on 32-bit microprocessor
Compact: it can run in less than 5k memory.
Simple: very easy to implement.
Variably secure: the key length is variable and can be as long as 448 bits.
This allows a trade-off between higher speed and higher security.
Encryption and Decryption:-
Blow fish Algorithm encrypts 64bits blocks of plaintext into 64-bit block of ciphertext.
The encryption makes use of 16 times.
Blow fish make use of a key that ranges from 32-bits to 448-bits (multiple of 32-bits)
The key is stored into a k-array (32 bits for each) K1, K2, … Kj where 1≤ j ≤14.
That key is used to generate 18 no. of 32-bit subkeys & 4 no. of 256 32-bit Entries in S-boxes.
The subkeys are stored in the p-array P1, P2, …. P18
There are four s-boxes each with 256 32-bit Entries.
In the encryption process, plaintext is divided into two 32-bit halves LE0, and RE0. We use
the variables LEi, and REi, to refer to the left and right half of the data after round i has
completed. The Encryption and Decryption process is shown below:
12
P.Srinivasulu, CSE, PBRVITS. Cryptography and Network Security
The encryption of a 64-bit block plain-text block input PT is shown in an algorithmic form
as shown below:
1.Divide plain text PT into two blocks LE0 and LR0 of equal size, both LE0 and LR0 will
consists of 32 bits each.
2.For i=1 to 16
LEi = LEi-1 XOR Pi
Subkeys Generation:-
Blow fish make use of a key that ranges from 32-bits to 448-bits (multiple of 32-bits)
The key is stored into a k-array (32 bits for each) K1, K2, … Kj where 1≤ j ≤14.
That key is used to generate 18 no. of 32-bit subkeys, and the subkeys are stored in the p-array
P1, P2, …. P18
Step1 initialize the P-array using the bits of fractional part of the constant п.
Step 2 Perform a bitwise XOR of the P-array & k-array, reusing words from the
k-array as needed.
13
P.Srinivasulu, CSE, PBRVITS. Cryptography and Network Security
The decryption process is quite similar to the encryption process, which uses the reversal of
P-array values.
Blowfish is not suitable for applications in which the secret key changes frequently.
Further, for rapid execution, the P- and S-arrays can be stored rather than rederived from
the key each time the algorithm is used.
This requires over 4 kilobytes of memory. Thus, Blowfish is not appropriate for
applications with limited memory, such as smart cards.
14
P.Srinivasulu, CSE, PBRVITS. Cryptography and Network Security
Linear Cryptanalysis:
Differential cryptanalysis is a general form of cryptanalysis applicable primarily to stream
ciphers.
Invented by Mitsuru Matsui in 1993.
In cryptography, linear cryptanalysis is a general form of cryptanalysis based on finding linear,
parallel relationships.& linear approximations to the action of a cipher
15
P.Srinivasulu, CSE, PBRVITS. Cryptography and Network Security
Decryption is performed one block at a time, always using the same key.
16
P.Srinivasulu, CSE, PBRVITS. Cryptography and Network Security
The ECB method is ideal for a short amount of data encryption key. Thus, if you want
to transmit a DES key securely, ECB is the appropriate mode to use.
The most significant characteristic of ECB is that the same b-bit block of plaintext, if it
appears more than once in the message, always produces the same ciphertext.
For lengthy messages, the ECB mode may not be secure. If the message is highly
structured, it may be possible for a cryptanalyst to exploit these regularities.
For decryption, each cipher block is passed through the decryption algorithm. The
result is XORed with the preceding ciphertext block to produce the plaintext block.
The IV is a data block that is that same size as the cipher block. The IV must be knownto
both the sender and receiver but be unpredictable by a third party
17
P.Srinivasulu, CSE, PBRVITS. Cryptography and Network Security
In the figure, it is assumed that the unit of transmission is s bits; a common value is s =
8. As with CBC, the units of plaintext are chained together, so that the ciphertext of any
plaintext unit is a function of all the preceding plaintext. In this case, rather than units of b bits,
the plaintext is divided into segments of s bits. Formula to generate Cipher Text is:
For decryption, the same scheme is used, except that the received ciphertext unit is
XORed with the output of the encryption function to produce the plaintext unit.
18
P.Srinivasulu, CSE, PBRVITS. Cryptography and Network Security
As can be seen, it is the output of the encryption function that is fed back to the shift register
in OFB, whereas in CFB the cipher text unit is fed back to the shift register. One advantage of
the OFB method is that bit errors in transmission do not propagate.
For example, if a bit error occurs in C1 only the recovered value of is P1 affected; subsequent
plaintext units are not corrupted. With CFB, C1 also serves as input to the shift register and
therefore causes additional corruption downstream. The disadvantage of OFB is that it is
more vulnerable to a message stream modification attack than is CFB.
19
P.Srinivasulu, CSE, PBRVITS. Cryptography and Network Security
5)Counter Mode:-
In CTR mode a counter, equal to the plaintext block size is used. The only requirement is that
the counter value must be different for each plaintext block that is encrypted. Typically, the
counter is initialized to some value and then incremented by 1 for each subsequent block.
For encryption, the counter is encrypted and then XORed with the plaintext block to produce
the ciphertext block; there is no chaining.
For decryption, the same sequence of counter values is used, with each encrypted counter
XORed with a ciphertext block to recover the corresponding plaintext block.
Advantages:
a)Hardware efficiency
b)Software efficiency
c)Preprocessing
d)Random access
e)Provable security
f)Simplicity
20
P.Srinivasulu, CSE, PBRVITS. Cryptography and Network Security
Stream ciphers
Introduction: -
A stream cipher encrypts or decrypts a digital data one bit or one byte at a time as shown
below:
Examples:
Examples of classical stream ciphers are
--the auto keyed Vigenère cipher,
--the Vernam cipher
--RC4 Algorithm.
21
P.Srinivasulu, CSE, PBRVITS. Cryptography and Network Security
RC4 Algorithm
Introduction: -
RC4 designed in 1987 by Ronald Rivest.
It is a symmetric key encryption algorithm and is example of Stream Cipher.
It is mainly used in
-Data communication and networking protocols
-IEEE 802.11 wireless LAN std:
WEP (Wired Equivalent Privacy), WPA (WiFi Protocol Access)
-SSL-Secure socket Layer Protocol and
TLS-Transport Layer Security between web browsers and servers
A stream cipher generates what is called a key stream (a sequence of bits used as a
key).
Encryption is accomplished by combining the key stream with the plaintext, usually
with the bitwise XOR operation.
22
P.Srinivasulu, CSE, PBRVITS. Cryptography and Network Security
1)Initialization of array:
23
P.Srinivasulu, CSE, PBRVITS. Cryptography and Network Security
1)Link Encryption:
-At the lowest practical level, the encryption function could be performed at the network layer.
- Encryption occurs independently on every link
- It implies that decryption must done at every link
- Required may devices to perform encryption an decryption
24
P.Srinivasulu, CSE, PBRVITS. Cryptography and Network Security
Symmetric -key cryptography uses one key for Encryption and Decryption process. The Secret
Key must be shared by both sender and receiver.
Advantages:
A symmetric cryptosystem is faster.
A system only which possesses the secret key can decrypt a message.
Disadvantages:
Symmetric cryptosystems have a problem of key transportation.
Cannot provide digital signatures that cannot be repudiated.
General Idea: -
The general structure of the Public key cryptography is shown below:
25
P.Srinivasulu, CSE, PBRVITS. Cryptography and Network Security
The essential steps involved in a public-key encryption scheme are given below:
1) Each user generates a pair of keys to be used for encryption and decryption.
2) Each user places one of the two keys in a public register and the other key is kept
private.
3) If B wants to send a confidential message to A, B encrypts the message using A’s
public key.
4) When A receives the message, decrypts it using private key. Nobody else can
decrypt the message because that can only be done using A’s private key
5) If a user wishes to change his keys –generate another pair of keys and publish the
public one: no interaction with other users is needed.
C = f (K , P)
public
P = g(K , C)
private
Security relies on a large enough difference in difficulty between easy (en/decrypt) and hard
(cryptanalyse) problems. More generally the hard problem is known, its just made too hard to do
in practise.
Requires the use of very large numbers, hence isslow compared to private key schemes
26
P.Srinivasulu, CSE, PBRVITS. Cryptography and Network Security
RSA Algorithm
Introduction: -
RSA Algorithm follows principles of Public Key Cryptography.
It is Used by modern computers to encrypt and decrypt messages.
RSA stands for Ron Rivest, Adi Shamir and Leonard Adleman, in 1978.
Uses large integers (eg. 1024 bits) as keys
security due to cost of factoring large numbers
2. Encryption Process:
3. Decryption Process:
27
P.Srinivasulu, CSE, PBRVITS. Cryptography and Network Security
Example: Convert Plain Text M=5 into Cipher Text using RSA Algorithm.
28
P.Srinivasulu, CSE, PBRVITS. Cryptography and Network Security
Here sender sends the ciphertext obtained after performing encryption process.
The Receiver gets the plain text after performing Decryption.
29
P.Srinivasulu, CSE, PBRVITS. Cryptography and Network Security
Algorithm Steps: -
30
P.Srinivasulu, CSE, PBRVITS. Cryptography and Network Security
31
P.Srinivasulu, CSE, PBRVITS. Cryptography and Network Security
32
P.Srinivasulu, CSE, PBRVITS. Cryptography and Network Security
33
P.Srinivasulu, CSE, PBRVITS. Cryptography and Network Security
34