比较 block ciphers and stream ciphers
阻止 ciphers 加密固定-大小 blocks 具有 padding; 流式处理 ciphers 加密字节-通过-字节. Understand 权衡在 速度, padding, 和错误 propagation.
- 1
阻止 ciphers (AES, Blowfish) 加密固定-大小 blocks (128 bits 为 AES, 64 bits 为 Blowfish). 它们 require padding 为 non-aligned 输入和 模式的 操作 (CBC, CTR, GCM). 流式处理 ciphers (RC4, ChaCha20) 生成 keystream 和 XOR — 否 padding, ciphertext equals plaintext 长度.
- 2 AES 加密器 →
加密 data with AES (block cipher). Note the ciphertext is padded to a multiple of the block size (16 bytes for AES). This padding must be removed on decryption.
- 3 RC4 加密器 →
加密 the same data with RC4 (stream cipher). The ciphertext is exactly the same length as the input — no padding. This is the defining property of stream ciphers.
- 4 Blowfish 加密器 →
加密 with Blowfish to compare a 64-bit block cipher. The block size is smaller (8 bytes), so padding granularity differs from AES.
- 5
键 insight: AES 在 CTR 或 GCM 模式有效 becomes 流式处理 cipher — 它 generates keystream 从 counter blocks 和 XORs 具有 plaintext. 现代实践罕见我们 raw 阻止 cipher modes; AES-GCM (已认证流式处理-like 模式) 是标准.
常见问题
- 哪个是 faster?
- 它 depends 开 hardware. AES 具有 AES-NI hardware acceleration 是 very 快. 开 devices 无它, ChaCha20 (流式处理) 是 faster. Raw 速度是 罕见 deciding 因子 — 安全和 认证 matter 更多.
- 流式处理 ciphers need padding?
- 否. 流式处理 ciphers 处理 one 字节在 时间, 所以 ciphertext 是总是相同长度 as plaintext. 此是 优势为 变量-长度数据和 streaming protocols.