Block Encryption Cipher Modes

Block cipher modes define how block ciphers like AES process data larger than a single block (typically 128 bits). Each mode has different security and performance characteristics.

Here’s a brief summary of common block cipher modes:

1. ECB (Electronic Codebook)

  • Each block is encrypted independently.
  • Simple but insecure: identical plaintext blocks produce identical ciphertext blocks.
  • Not recommended for real-world use.

2. CBC (Cipher Block Chaining)

  • Each block is XORed with the previous ciphertext block before encryption.
  • Requires an IV (Initialization Vector) for the first block.
  • Better security than ECB.
  • Sensitive to bit-flipping and padding oracle attacks if not handled properly.

3. CTR (Counter Mode)

  • Turns a block cipher into a stream cipher.
  • Encrypts a counter value for each block and XORs it with the plaintext.
  • Does not require padding.
  • Must never reuse the same key and counter pair.

4. CFB (Cipher Feedback Mode)

  • Encrypts previous ciphertext (or IV) and XORs with plaintext.
  • Acts like a stream cipher.
  • Good for streaming data.

5. OFB (Output Feedback Mode)

  • Similar to CFB, but feeds the output of encryption (not the ciphertext) back in.
  • Produces a keystream independent of plaintext.
  • Errors in transmission do not propagate.
  • Reusing IVs is dangerous.

6. GCM (Galois/Counter Mode)

  • Based on CTR mode, but adds authentication (AEAD) using a Galois field hash.
  • Encrypts and authenticates simultaneously.
  • Fast and widely used in TLS and modern protocols.
  • Nonce reuse compromises security.

7. XTS (XEX-based Tweaked CodeBook mode with ciphertext stealing)

  • Designed for disk encryption.
  • Encrypts blocks with a tweak (usually the block’s index).
  • Protects against block swapping attacks.
  • Not suitable for general-purpose encryption (e.g., messages).

Summary Table

Mode Stream-like? Authenticated? Common Use
ECB Never recommended
CBC Legacy data encryption
CTR High-speed data
CFB Streaming
OFB Legacy/streaming
GCM TLS, modern protocols
XTS Disk encryption