Cipher Block Chaining (CBC) is the commonly used mode of operation for encryption and decryption of block ciphers which is a set of bits encrypted or decrypted as a single block. An Initialization Vector (IV) and a key are used in the process. An Initialising Vector is a unique sequence of bits that are used to prevent a repetition of ciphertexts even for the same plaintexts being encrypted multiple times independently with the same key. It has different security requirements than a key, so it need not be a secret. However, it should be noted that the same IV must not be used with the same key because of security issues as doing the same may help hackers in cracking the code and thus may lead to information leakage. Ideally, the IV should be different for messages with the same key.
In CBC, the common practice of using the ciphertext of the previous block as the IV of the present message is followed which is considered to be a little unsafe. This is because if a hacker knows the ciphertext of a previous block, then the next plaintext can be guessed if the key used for it is the same as that of the previous block.
In CBC mode encryption, a chaining mechanism is followed in which each plaintext is XORed with the ciphertext of the last block before being encrypted such that each ciphertext depends on all the plaintexts blocks processed up to that point.
With the first block marked with index 1, CBC encryption can be formulated by:
The decryption can be formulated by:
The main disadvantage of CBC encryption is that it is sequential; each encryption depends on the preceding ciphertext. One-bit change in a ciphertext block may affect all the following ciphertexts block.
However, decrypting with a changed IV or ciphertext may affect the first block of plaintext but not the ones following it. Hence, decryption with CBC has the advantage of being parallelized rather than being entirely sequential which makes a plaintext block recoverable from two adjacent ciphertexts block.