Ins 4
Ins 4
C1 C2 CN
64-bit 64-bit 64-bit
K K K
Decrypt Decrypt … Decrypt
C1 C2 CN
C1 C2 CN
K K K
Decrypt Decrypt … Decrypt
IV CN-1
P1 P2 PN
Cipher Block Chaining (CBC) (cont…)
Cipher Block Chaining (CBC) (cont…)
▪ CBC is a technique in which the same plaintext block, if repeated,
produces different ciphertext blocks.
▪ In this scheme, the input to the encryption algorithm is the XOR of
the current plaintext block and the preceding ciphertext block and
the same key is used for each block.
▪ To produce the first block of ciphertext, an initialization vector (IV)
is XORed with the first block of plaintext.
Cipher Block Chaining (CBC) (cont…)
▪ Initialisation Vector (IV) must be known by sender/receiver, but it
should be kept secret from attacker.
▪ On decryption, the IV is XORed with the output of the decryption
algorithm to recover the first block of plaintext.
Substitution Attack on CBC
▪ Consider the last example (electronic bank transfer).
▪ If the IV is properly chosen for every wire transfer, the attack will
not work at all.
▪ If the IV is kept the same for several transfers, the attacker would
recognize the transfers from his account at bank A to back B.
Cipher Block Chaining (CBC) (cont…)
▪ Strength: because of the chaining mechanism of CBC, it is an
appropriate mode for encrypting messages of length greater than
b bits.
▪ Typical application:
• General-purpose block oriented transmission
• Authentication
3. Cipher Feedback Mode (CFB)
▪ For AES, DES, or any block cipher, encryption is performed on a
block of b bits. In DES, b = 64 and in AES, b = 128.
▪ However, it is possible to convert a block cipher into a stream
cipher, using cipher feedback (CFB) mode, output feedback (OFB)
mode, and counter (CTR) mode.
▪ A stream cipher eliminates the need to pad a message to be an
integral number of blocks.
CFB Encryption
CN-1
Shift register Shift register
IV b-s bits | s bits b-s bits | s bits
K K K
Encrypt Encrypt Encrypt
Select Discard
s bits b-s bits
Select Discard
s bits b-s bits
… Select Discard
s bits b-s bits
S bits S bits S bits
P1 P2 PN
C1 C2 CN
S bits S bits S bits
CFB Encryption (cont…)
CFB Decryption
CN-1
Shift register Shift register
IV b-s bits | s bits b-s bits | s bits
K K K
Encrypt Encrypt Encrypt
Select Discard
s bits b-s bits
Select Discard
s bits b-s bits
… Select Discard
s bits b-s bits
C1 C2 CN
S bits S bits S bits
P1 P2 PN
S bits S bits S bits
CFB Decryption (Cont…)
Cipher Feedback Mode (CFB) (cont…)
▪ The input to the encryption function is a b-bit shift register that is
initially set to some initialization vector (IV).
▪ The leftmost (most significant) s bits of the output of the
encryption function are XORed with the first segment of plaintext
P1 to produce the first unit of ciphertext C1 , which is then
transmitted.
▪ In addition, the contents of the shift register are shifted left by s
bits, and C1 is placed in the rightmost (least significant) s bits of
the shift register.
▪ 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.
4. OFB Encryption
Nonce
K K K
Encrypt Encrypt … Encrypt
P1 P2 PN
C1 C2 CN
OFB Decryption
Nonce
K K K
Encrypt Encrypt … Encrypt
C1 C2 CN
P1 P2 PN
Output Feedback Mode(OFB) (cont..)
▪ The output feedback (OFB) mode is similar in structure to that of
CFB.
▪ For OFB, the output of the encryption function is fed back to
become the input for encrypting the next block of plaintext.
▪ In CFB, the output of the XOR unit is fed back to become input for
encrypting the next block.
▪ The other difference is that the OFB mode operates on full blocks
of plaintext and ciphertext, whereas CFB operates on an s-bit
subset.
OFB Mode (cont..)
▪ Nonce: A time-varying value that has at most a negligible chance
of repeating, for example, a random value that is generated anew
for each use, a timestamp, a sequence number, or some
combination of these.
▪ Each bit in the ciphertext is independent of the previous bit or
bits.
▪ This avoids error propagation.
▪ Pre-compute of forward cipher is possible.
5. CTR Encryption
Counter 1 Counter 2 Counter N
K K K
Encrypt Encrypt … Encrypt
P1 P2 PN
C1 C2 CN
CTR Decryption
Counter 1 Counter 2 Counter N
K K K
Encrypt Encrypt … Encrypt
C1 C2 CN
P1 P2 PN
Counter Mode (CTR) (cont…)
▪ Counter (CTR) mode has increased recently with applications to
ATM (asynchronous transfer mode) network security and IP sec
(IP security).
▪ A counter equal to the plaintext block size is used.
▪ 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.
Advantages of the CTR Mode
▪ Strengths:
• Needs only the encryption algorithm.
• Random access to encrypted data blocks.
• blocks can be processed (encrypted or decrypted) in parallel.
• Simple and fast encryption/decryption.
▪ Counter must be
• Must be unknown and unpredictable.
• pseudo-randomness in the key stream is a goal.
Summary of all modes
Operation Description Type of
Mode Result
ECB Each n-bit block is encrypted Block Cipher
independently with same key.
CBC Same as ECB, but each block is XORed Block Cipher
with previous cipher text.
CFB Each s-bit block is XORed with s-bit key Stream Cipher
which is part of previous cipher text.
OFB Same as CFB, but input to the encryption Stream Cipher
is preceding encryption output.
CTR Same as OFB, but a counter is used Stream Cipher
instead of nonce.
Multiple Encryption
▪ Given the potential vulnerability of DES to a brute-force attack,
there has been considerable interest in finding an alternative.
▪ For DES requires 256 operations for brute force attack.
▪ One approach is to design a completely new algorithm, of which
AES is a prime example.
▪ Another alternative, which would preserve the existing
investment in software and equipment, is to use multiple
encryption with DES and multiple keys.
Double DES
Key K1 Key K2
Encryption
Key K2 Key K1
C=E(K2,E(K1, P))
X = E(K1, P) = D(K2, C)
P=D(K1,D(K2, C))
Double DES
▪ For double DES, 2 × 56-bit keys, meaning 112-bit key length.
▪ Requires 2112 operations for brute force attack.
▪ Meet-in-the-middle attack makes it easier.
Meet in the Middle Attack
▪ This attack involves encryption from one end, decryption from the
other and matching the results in the middle.
▪ Suppose cryptanalyst knows Pi and corresponding Ci.
▪ Now, the aim is to obtain the values of K1 and K2.
All Possible keys All Possible keys
K1 = 256 K2 = 256
Known Known
Plaintext Middle Ciphertext
Encryption Decryption
Text
Cryptanalyst encryption
operation
Meet in the Middle Attack Step-2
▪ Cryptanalyst decrypt the known ciphertext with all possible values of
K2.
▪ In each case cryptanalyst will compare the resulting value with the all
values in the table of ciphertext.
Cryptanalyst decryption
operation
Triple DES
C=E(K1,D(K2, E(K1,P)))
P=D(K1,E(K2, D(K1,C)))
Meet in the Middle Attack
Possible Possible
Keys P Table of Table of C Keys
(Key = K1) Cipher Text Cipher Text (Key = K1)
00 010 111 00
Find equal
01 110 match and store 011 01
10
E 101 corresponding 001
D 10
K1 and K2.
11 000 110 11
A B
Plaintext E D E Ciphertext
B A
Ciphertext D E D Plaintext