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.
| Mode | Name | How It Works | Security |
|---|---|---|---|
| ECB | Electronic Codebook | Each block encrypted independently with the same key | โ Broken โ identical plaintext blocks produce identical ciphertext |
| CBC | Cipher Block Chaining | Each block XORed with previous ciphertext before encrypting; uses an IV | โ Good โ but requires random IV and is not parallelizable |
| CTR | Counter Mode | Encrypts a counter value to produce a keystream; XOR with plaintext | โ Fast, parallelizable, turns block cipher into stream cipher |
| GCM | Galois/Counter Mode | CTR 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?
๐ฎ Practice what you learned
โญ 0 XP๐ฅ 0 days