a block cipher takes a fixed-length block of text of length b bits and a key as input

and produces a b -bit block of ciphertext. If the amount of plaintext to be encrypted

is greater than b bits, then the block cipher can still be used by breaking the plaintext up into b -bit blocks

To apply a block cipher in a variety of applications, five modes of operation have been defined by NIST (SP 800-38A).

In essence, a mode of operation is a technique for enhancing the effect of a cryptographic

algorithm or adapting the algorithm for an application, such as applying

a block cipher to a sequence of data blocks or a data stream

**Modes operation**

- Electronic Code Book (ECB) mode
- Cipher block chaining (CBC) mode
- Cipher feedback (CFB) mode
- Output feedback (OFB) mode
- Counter (CTR) mode.

In ECB Patterns at the block level are preserved. Ie., each block in P becomes equal block in C , so this block dependency creates opportunities for attacker to exchange some ciphertext blocks without knowing the key . To overcome the security deficiencies of ECB, we would like a technique in which the same plaintext block, if repeated, produces different ciphertext blocks. A simple way to satisfy this requirement is the cipher block chaining (CBC ) mode . In this scheme, the input to the encryption algorithm is the XOR of the current plaintext block and the preceding ciphertext block; the same key is used for each block. In effect, we have chained together the processing of the sequence of plaintext blocks. The input to the encryption function for each plaintext block bears no fixed relationship to the plaintext block. Therefore, repeating patterns of b bits are not exposed. As with the ECB mode, the CBC mode requires that the last block be padded to a full b bits if it is a partial block.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. To produce the first block of ciphertext, an initialization vector (IV) is XORed with the first block of plaintext. On decryption, the IV is XORed with the output of the decryption algorithm to recover the first block of plaintext. The IV is a data block that is the same size as the cipher block. The IV must be known to both the sender and receiver but be unpredictable by a third party. In particular, for any given plaintext, it must not be possible to predict the IV that will be associated to the plaintext in advance of the generation of the IV. For maximum security, the IV should be protected against unauthorized changes. This could be done by sending the IV using ECB encryption. One reason for protecting the IV is as follows: If an opponent is able to fool the receiver into using a different value for IV, then the opponent is able to invert selected bits in the first block of plaintext. So long as it is unpredictable, the specific choice of IV is unimportant. SP800-38A recommends two possible methods: The first method is to apply the encryption function, under the same key that is used for the encryption of the plaintext, to a nonce . The nonce must be a data block that is unique to each execution of the encryption operation. For example, the nonce may be a counter, a timestamp, or a message number. The second method is to generate a random data block using a random number generator. In conclusion, because of the chaining mechanism of CBC, it is an appropriate mode for encrypting messages of length greater than b bits. In addition to its use to achieve confidentiality, the CBC mode can be used for authentication.

In CBC, the input to the encryption algorithm is the XOR of the current plaintext block and the preceding ciphertext block;

**Encryption:**

C_{i}= E_{ }(K, [P_{i} + C _{i-1}] )

and C_{0}= IV

**Decryption:**

P_{i}= D (K, C_{i} ) + C _{i-1}

and C_{0}= IV