CFB and OFB Modes: Feedback Mechanisms
What you'll learn: How CFB and OFB modes use feedback to create stream-like encryption with different self-synchronization properties.
The Core Idea
Both Cipher Feedback (CFB) and Output Feedback (OFB) modes transform block ciphers into stream ciphers using feedback loops, but they differ in what gets fed back and how errors propagate.
CFB Mode: Feedback from Ciphertext
In CFB mode, you encrypt a shift register, XOR the output with your plaintext to get ciphertext, then feed that ciphertext back into the shift register for the next block. Think of it like a chain where each encrypted block depends on the previous ciphertext.
Key property: CFB is self-synchronizing. If you lose a few bytes during transmission (like network packet loss), CFB will automatically resynchronize after one full block passes through. However, bit errors propagate—a single corrupted ciphertext bit affects decryption of that byte and continues affecting subsequent blocks until it shifts out of the register.
OFB Mode: Feedback from Keystream
OFB mode encrypts an initialization vector repeatedly, feeding the encrypted output back into itself (not the ciphertext). This creates an independent keystream that you XOR with plaintext. Imagine a self-contained random number generator that ignores your actual data.
Key property: OFB is not self-synchronizing. If transmission loses even one bit, decryption fails permanently from that point forward. The advantage? Bit errors don't propagate—a corrupted ciphertext bit only corrupts the corresponding plaintext bit.
When to Use Each
- CFB: When you need self-synchronization (streaming protocols, error-prone channels)
- OFB: When you need predictable keystreams or can't tolerate error propagation (but must guarantee perfect synchronization)
Key Takeaway: CFB feeds back ciphertext and self-synchronizes but propagates errors; OFB feeds back keystream output, avoids error propagation, but cannot resynchronize after data loss.