Cipher Modes
Cipher Modes of Operation
Overview
Cipher modes of operation, also known as block cipher modes of operation, are used to encrypt a fixed block of plaintext using a secret key and, in some modes, an initialization vector. These modes of operation can ensure the confidentiality and authenticity of data. The client and server exchange an encrypted symmetric key securely to facilitate encryption and decryption. Discussed below are the four block cipher modes of operation that explain how source-side encryption and destination-side decryption work.
Cipher Modes Comparison
![]()
| Cipher Mode | Description |
|---|---|
| Electronic Code Book (ECB) mode | ECB mode is generally not recommended for use due to its susceptibility to certain types of attacks. Furthermore, it does not hide data patterns efficiently. As a result, statistical analysis can reveal elements of clear-text messages, for example, in web applications. |
| Cipher Block Chaining (CBC) mode | CBC mode is generally used to encrypt messages like disk encryption and e-mail communication. This is the default mode for AES and is also used in software like TrueCrypt, VeraCrypt, net/sec/PKI/TLS, and SSL. |
| Cipher Feedback (CFB) mode | CFB mode is well suited for real-time encryption of a data stream, e.g., network communication encryption or encryption/decryption of files in transit like Public-Key Cryptography Standards (PKCS) and Microsoft's BitLocker. |
| Output Feedback (OFB) mode | OFB mode is also used to encrypt a data stream, e.g., to encrypt real-time communication. However, this mode is considered better for the data stream because of how the key stream is generated. We can find this mode in PKCS but also in the SSH protocol. |
| Counter (CTR) mode | CTR mode encrypts real-time data streams AES uses, e.g., network communication, disk encryption, and other real-time scenarios where data is processed. An example of this would be IPSec or Microsoft's BitLocker. |
| Galois/Counter (GCM) mode | GCM is used in cases where confidentiality and integrity need to be protected together, such as wireless communications, VPNs, and other secure communication protocols. |
Detailed Mode Descriptions
Electronic Code Book (ECB) Mode
The ECB mode is a straightforward process of encryption and decryption that requires plaintext, a secret key, and a block cipher encryption algorithm. The plaintext is divided into a fixed length of blocks, which is equal to the size of the secret key. In the first stage, the encryption starts by taking the first block of the plaintext, and the secret key is taken as input to the block cipher encryption algorithm; the output is the first block of ciphertext. The process is repeated for all the plaintext blocks. On the destination side, decryption is performed in the same manner as generation of the first block of ciphertext. The secret key is taken as input to the block cipher decryption algorithm, which outputs the first block of plaintext. This process is repeated for all the ciphertext blocks. However, this mode has a flaw: if the equally partitioned blocks of plaintext contain the same data, then the output cipher blocks also contain the same ciphertext, providing analysts a chance to predict the plaintext.

Cipher Block Chaining (CBC) Mode
The CBC mode is an improvement over ECB that rectifies most of the security flaws in ECB. In the CBC mode, the process of encryption requires an initialization vector and a secret key. First, the plaintext is divided into blocks of the same size. The first block is XOR with the initialization vector (IV), and the resultant is sent as input to the block cipher encryption algorithm, along with the secret key. The output is the first block of ciphertext. This cipher block is used to perform XOR with the next plaintext block; the chain process continues till the last block of plaintext.
On the destination side, the first block of ciphertext and secret key is sent to the block cipher decryption algorithm, and the result is XOR with the same IV. The output is the first block of plaintext. For the next cipher blocks, in the place of the IV, the previously used cipher block is input to perform XOR; this process continues for the remaining cipher blocks. However, this mode also has a problem: if one generated ciphertext block has an error, it propagates to the subsequent cipher blocks.

Cipher Feedback Mode (CFB)
In the CFB mode, previously generated ciphertext is used as feedback for the encryption algorithm to encrypt the next plaintext block to ciphertext. First, the initialization vector (IV) is stored in a shift register and sent to the encryption algorithm, along with a secret key. ==From the result of that encryption, the first S bits are selected, and the XOR operation is performed with a plaintext block of size ==S. The resultant output is the ciphertext block. For the next encryption block, the previous cipher block is given as the input to the shift register; it shifts S bits to the left, and the process is continued till the end of the plaintext. On the destination side, the decryption process is the same till the XOR operation. The XOR operation is performed for the first S bits from the result of the encryption algorithm and the first cipher block, and the output is the first block of plaintext. For the subsequent blocks, the previously used cipher block is taken as the input for the shift register, and the process continues till the last cipher block. The advantage of this mode is that it makes cryptanalysis difficult as it has some data loss because of the use of shift registers.

Counter Mode
The counter mode is a block cipher mode of operation that uses a counter value in the Encryption and decryption process. A counter value is initiated and sent as the input to the block cipher encryption algorithm with a secret key, and the result is subjected to the XOR operation with a block of plaintext. The output is the ciphertext block. This process is performed in a sequential manner to encrypt all the other plaintext blocks.
On the destination side, this mode uses the same counter values and secret keys. The same encryption algorithm is used to encrypt the counter value and secret key, the result is subjected to the XOR operation with the obtained ciphertext block, and the output contains plaintext.
The counter mode eliminates the problem of error propagation because it does not use previously generated ciphertext in encryption or decryption. The counter mode requires synchronized counter values on both the source and destination sides.
