Symmetric Cryptography ยท 2.2

๐Ÿ“ฆ Block Ciphers vs Stream Ciphers

Two fundamentally different ways to process dataโฑ ~2 min

Block Cipher
  • โ€ขEncrypts data in fixed-size chunks (blocks)
  • โ€ขCommon block sizes: 64 bits (DES), 128 bits (AES)
  • โ€ขRequires padding if data isn't a multiple of block size
  • โ€ขExamples: AES, DES, 3DES, Blowfish
  • โ€ขBehavior depends heavily on mode of operation
Stream Cipher
  • โ€ขEncrypts one bit or byte at a time
  • โ€ขGenerates a keystream and XORs it with plaintext
  • โ€ขNo padding needed โ€” works on any length data
  • โ€ขExamples: ChaCha20, RC4 (broken), A5/1 (GSM)
  • โ€ขFaster for small or continuous data (voice, video)

Block Cipher Modes of Operation

A block cipher by itself only encrypts exactly one block. Modes of operation define how to encrypt data longer than one block, and crucially, whether the encryption is secure in practice.

ModeNameHow It WorksSecurity
ECBElectronic CodebookEach block encrypted independently with the same keyโŒ Broken โ€” identical plaintext blocks produce identical ciphertext
CBCCipher Block ChainingEach block XORed with previous ciphertext before encrypting; uses an IVโœ“ Good โ€” but requires random IV and is not parallelizable
CTRCounter ModeEncrypts a counter value to produce a keystream; XOR with plaintextโœ“ Fast, parallelizable, turns block cipher into stream cipher
GCMGalois/Counter ModeCTR mode + authentication tag; encrypts AND authenticates simultaneouslyโœ“โœ“ Best โ€” provides both confidentiality and integrity (AEAD)
โš  WarningNever use ECB mode. The classic demonstration: encrypt a bitmap image with AES-ECB and the image's structure is still clearly visible in the ciphertext. Identical plaintext blocks produce identical ciphertext blocks, leaking structural information about the data.

AEAD โ€” Authenticated Encryption with Associated Data

๐Ÿ”’ SecurityAES-GCM is an AEAD (Authenticated Encryption with Associated Data) cipher. It both encrypts the data AND produces a short authentication tag. If any bit of the ciphertext is modified in transit, decryption fails and the tag mismatch is detected. This prevents attackers from tampering with encrypted data without being caught. Always prefer AEAD modes.

Initialization Vectors (IVs) and Nonces

๐Ÿ’ก TipCBC and GCM require an IV (initialization vector) or nonce โ€” a random value that makes each encryption unique even for identical plaintexts with the same key. The IV doesn't need to be secret, but it must never be reused with the same key. IV reuse in GCM is catastrophic โ€” it leaks the authentication key and destroys both confidentiality and integrity.
๐Ÿง Quick Checkfirst try = +5 XP

Why is ECB mode broken?

โญ 0 XP๐Ÿ”ฅ 0 days