Every encryption algorithm falls into one of two categories: stream ciphers or block ciphers. The distinction seems simple — stream ciphers encrypt one byte at a time, block ciphers encrypt chunks of data. But the reality is more nuanced, especially when you consider that AES, the most widely used block cipher, is often operated in a mode that makes it behave like a stream cipher.
Understanding this distinction matters for anyone building or using encryption systems. The choice between stream and block ciphers affects performance, security properties, and how the cipher handles data of different sizes.
What Is a Block Cipher
A block cipher encrypts fixed-size blocks of data. The block size is a fundamental property of the algorithm — it is baked into the design and cannot be changed. AES uses 128-bit (16-byte) blocks. DES used 64-bit blocks. Blowfish uses 64-bit blocks.
To encrypt data with a block cipher, the algorithm takes a block of plaintext and a key, and produces a block of ciphertext of the same size. The same key and plaintext block always produce the same ciphertext block. This determinism is a property of the block cipher itself — it is not a vulnerability, but it becomes one if you encrypt multiple blocks without a proper mode of operation.
### How AES Works as a Block Cipher
AES processes each 128-bit block through a series of transformations called rounds. AES-128 uses 10 rounds, AES-192 uses 12 rounds, and AES-256 uses 14 rounds. Each round applies four operations:
1. **SubBytes:** A nonlinear substitution where each byte is replaced according to an S-box lookup table. 2. **ShiftRows:** The 16 bytes are arranged in a 4x4 matrix, and each row is shifted left by a different amount. 3. **MixColumns:** Each column of the matrix is transformed using a polynomial multiplication over a finite field. 4. **AddRoundKey:** The current state is XORed with a round key derived from the master key.
These operations provide confusion (SubBytes) and diffusion (ShiftRows + MixColumns), the two properties Claude Shannon identified as essential for secure encryption. You can see the result of AES encryption with the AES text encryptor, and learn more about the algorithm in our AES-256-GCM explainer.
What Is a Stream Cipher
A stream cipher generates a keystream — a sequence of pseudo-random bytes — from a key and a nonce. The keystream is XORed with the plaintext to produce ciphertext. Decryption is identical: generate the same keystream and XOR it with the ciphertext.
``` ciphertext = plaintext XOR keystream plaintext = ciphertext XOR keystream ```
The keystream is generated by a pseudo-random function that takes the key and nonce as inputs. As long as both parties have the same key and nonce, they generate the same keystream and can encrypt and decrypt.
### How ChaCha20 Works as a Stream Cipher
ChaCha20 is the most widely used stream cipher today. It was designed by Daniel J. Bernstein and is used in TLS, IPSec, and SSH. ChaCha20 operates on a 512-bit state divided into 16 32-bit words. The state includes the key (256 bits), nonce (96 bits), counter (32 bits), and four constants.
The state is mixed through 20 rounds (10 double rounds) of add-rotate-XOR operations. After each block of 64 bytes of keystream is generated, the counter increments, producing the next 64 bytes. This continues until enough keystream has been generated to cover the plaintext.
ChaCha20 is fast in software because it uses only addition, rotation, and XOR — operations that all CPUs perform efficiently. It does not require lookup tables (unlike AES's S-box), which also makes it resistant to cache-timing attacks.
Block Cipher Modes of Operation
A block cipher alone can only encrypt one block. To encrypt data longer than one block, you need a mode of operation. The mode determines how multiple blocks are chained together and how the block cipher's deterministic output is made unpredictable across blocks.
| Mode | Type | Security | Parallelizable | Authenticated | Common Use | | --- | --- | --- | --- | --- | --- | | ECB | Block | Insecure — reveals patterns | Yes | No | Never use | | CBC | Block | Secure with random IV | Encryption only | No | Legacy systems | | CTR | Stream-like | Secure with unique nonce | Yes | No | General purpose | | GCM | Stream-like | Secure with unique nonce | Yes | Yes | TLS, IPSec, NovelCrypt | | CCM | Stream-like | Secure with unique nonce | No | Yes | Wireless (WPA2) |
### ECB (Electronic Codebook) — Never Use
ECB encrypts each block independently. Identical plaintext blocks produce identical ciphertext blocks. This reveals patterns in the data — the classic ECB penguin image demonstrates how ECB leaks the structure of the input. ECB should never be used for any practical application.
### CBC (Cipher Block Chaining) — Legacy
CBC XORs each plaintext block with the previous ciphertext block before encryption. This chains the blocks together so identical plaintext blocks produce different ciphertext blocks. CBC requires a random initialization vector (IV) and is vulnerable to padding oracle attacks if the implementation does not verify padding correctly.
### CTR (Counter) — Stream-Like
CTR mode turns a block cipher into a stream cipher. It encrypts a counter value with the block cipher to produce keystream blocks, then XORs the keystream with the plaintext. CTR is parallelizable (each block is independent) and handles data of any size without padding. CTR mode is the foundation of GCM.
### GCM (Galois/Counter Mode) — The Modern Standard
GCM is CTR mode with added authentication. It uses the Galois field multiplication to compute an authentication tag over the ciphertext and associated data. This tag allows the receiver to verify that the ciphertext was not modified in transit.
GCM is the mode used by TLS 1.3, IPSec, and NovelCrypt's own encryption tools. It provides both confidentiality and integrity in a single operation — this is called authenticated encryption with associated data (AEAD).
Why AES-GCM Blurs the Line
Here is the nuance that most explanations miss: AES is a block cipher, but AES-GCM does not operate like a traditional block cipher. In GCM mode, AES encrypts counter values to generate a keystream, which is then XORed with the plaintext. This is stream cipher behavior.
So when NovelCrypt encrypts your message with AES-256-GCM, the process is:
1. AES-256 (block cipher) encrypts a counter value to produce 16 bytes of keystream. 2. The keystream is XORed with the first 16 bytes of plaintext. 3. The counter increments, and AES encrypts the new counter to produce the next 16 bytes of keystream. 4. This continues until all plaintext is covered. 5. GCM computes an authentication tag over the ciphertext.
The block cipher (AES) is used as a keystream generator. The actual encryption is the XOR operation — which is stream cipher behavior. This is why AES-GCM can handle data of any size without padding, just like a stream cipher.
### Why This Matters
If you are choosing between "stream cipher" and "block cipher" for a project, the answer is usually: use AES-GCM. It gives you the security of a well-studied block cipher (AES) with the flexibility of a stream cipher (any data size, no padding) plus authentication. The symmetric vs asymmetric encryption guide covers how AES fits into the broader cryptographic landscape.
Stream Cipher vs Block Cipher: Key Differences
| Property | Stream Cipher | Block Cipher | | --- | --- | --- | | Data unit | 1 byte at a time | Fixed-size block (128 bits for AES) | | Padding | Not needed | Required for non-block-aligned data (CBC) | | Parallelization | Inherently sequential | Some modes allow parallel blocks | | Hardware acceleration | Limited (ChaCha20 is software-optimized) | AES-NI on modern CPUs | | Key reuse | Catastrophic — same nonce + key = broken | Depends on mode | | Error propagation | 1 bit error affects 1 byte | CBC: 1 bit affects 2 blocks, GCM: 1 bit fails auth | | Browser support | Limited (no WebCrypto ChaCha20) | Full (WebCrypto AES-GCM) |
Browser-Based Encryption: WebCrypto Considerations
If you are building encryption in the browser, your choices are constrained by what the Web Crypto API supports:
- **AES-GCM:** Fully supported, hardware-accelerated, authenticated. This is the best default choice for browser encryption. - **AES-CBC:** Supported but not authenticated. You would need to add HMAC separately. - **ChaCha20-Poly1305:** Not supported by the Web Crypto API. You would need a JavaScript implementation, which is slower than native AES-GCM. - **AES-CTR:** Supported but not authenticated. Use GCM instead.
This is why NovelCrypt uses AES-256-GCM for all browser-based encryption. It is the most performant and secure option available in the Web Crypto API. You can test it directly with the AES text encryptor and the file encryptor.
For encryption key generation, NovelCrypt uses the Web Crypto API's `crypto.subtle.generateKey` function, which produces cryptographically secure keys that never leave the browser.
When to Use Each
### Use AES-GCM (Block Cipher in Stream Mode) When
- You are encrypting in the browser (WebCrypto support is excellent) - You need authenticated encryption (GCM provides this) - You have hardware AES acceleration (all modern Intel and ARM processors) - You want the most widely deployed and analyzed cipher
### Use ChaCha20-Poly1305 (Stream Cipher) When
- You are on a platform without AES hardware acceleration (older ARM devices, IoT) - You are building a protocol that needs software-only performance (some VPN protocols) - You need resistance to cache-timing attacks (ChaCha20 does not use lookup tables)
### Never Use
- ECB mode (reveals patterns) - CBC without authenticated padding (vulnerable to padding oracle attacks) - Any stream cipher with a reused nonce (catastrophic failure) - DES or 3DES (obsolete — read why DES is obsolete)
A Decision Framework
``` Need encryption in a browser? → AES-256-GCM via WebCrypto (try the AES encryptor)
Need encryption on a server with AES-NI? → AES-256-GCM
Need encryption on a device without AES hardware? → ChaCha20-Poly1305
Need authenticated encryption? → GCM (AES) or Poly1305 (ChaCha20) — both provide this
Need to encrypt streaming data (byte-by-byte)? → ChaCha20 or AES-CTR (but add HMAC for authentication)
Need maximum performance for bulk data? → AES-256-GCM with hardware acceleration ```
The Bottom Line
The distinction between stream ciphers and block ciphers is less important than it appears. AES-GCM — the most widely used cipher mode today — is a block cipher operating in a stream cipher mode. The real choice is not "stream vs. block" but "authenticated vs. non-authenticated" and "hardware-accelerated vs. software-only." For browser-based encryption, AES-256-GCM is the clear winner: it is supported by WebCrypto, hardware-accelerated, authenticated, and battle-tested in TLS and IPSec. For software-only environments without AES hardware, ChaCha20-Poly1305 is the best alternative. The one rule that applies to both: never reuse a nonce with the same key, and always use authenticated encryption.