What is Block cipher mode of operation?
The way the block transformations of a block cipher are combined to encrypt data longer than one block. Examples are ECB, which encrypts each block independently; CBC, which XORs each block with the previous ciphertext block before encrypting it; CTR, which XORs the data with a keystream made by encrypting a counter; and GCM, which adds authentication to CTR. ECB is not used for general data because identical plaintext blocks become identical ciphertext blocks. CBC and CTR require initialization vectors and nonces to be handled correctly.
Japanese name: 暗号利用モード
Block cipher mode of operation appears in 11 practice questions across 1 topic, including Applied Cryptography.
Field: Applied Cryptography
Comparing the main modes
ECB can be processed in parallel but leaves the patterns of the plaintext visible. CBC needs padding, and its encryption cannot be parallelized because each block waits for the result of the previous one, though decryption can. CTR needs no padding, both encryption and decryption can be parallelized, and decryption can start at any position. However, CBC and CTR only encrypt and cannot detect tampering.
FAQ
Which mode should I choose?
Unless there is a special reason, use authenticated encryption such as AES-GCM or ChaCha20-Poly1305 and make sure nonces never repeat under the same key. Do not use ECB. Using the authenticated encryption that a library provides is less error-prone than combining CBC or CTR with a MAC yourself.
Why does CTR mode need no padding?
CTR mode just XORs the plaintext with a keystream made by the block cipher, so the keystream of the last block can simply be cut to the length of the plaintext. What goes through the block cipher is the counter value, not the plaintext itself.