K026 / Cipher modes and AEAD
AES-CBC
CBC encrypts fixed-length blocks by XORing each plaintext block with the preceding ciphertext block before encryption.
CRYPTOGRAPHY LAB / K026
Cryptography Lab · AES-CBC
Run real computations and inspect intermediate states step by step.
Educational only. Never enter real passwords or secret keys. Computation stays in your browser; input and trace values are not sent to a server. Do not use this implementation in production.
AES-CBC (raw, no padding)
See the scope above for fixed examples, reduced parameters and supported variants. Standard operation names and formulas are retained.Output
Previous state
- Definition and overview
- CBC encrypts fixed-length blocks by XORing each plaintext block with the preceding ciphertext block before encryption. Source document ↗
- Classification and reversibility
- Reversible symmetric block-cipher mode with defined decryption. Source document ↗
- Key or secret requirements
- Requires a symmetric key. Source document ↗
- Operating principle and structure
- XOR first plaintext block with IV, subsequent blocks with preceding ciphertext, then encrypt each. Source document ↗
- Key size, block size and parameters
- AES-CBC requires a 16-octet IV and block-aligned padding. Source document ↗
- Security strength and recommendation
- Valid for some uses such as static content; TLS MAC-then-encrypt CBC is problematic and not recommended. Source document ↗
- Known attacks and vulnerabilities
- Known attacks include BEAST exploiting predictable TLS 1.0 IVs and padding oracles/Lucky Thirteen. Source document ↗
- Standards and certification
- NIST SP 800-38A defines confidentiality modes including CBC. Source document ↗
- Typical uses
- Historically widespread in SSL/TLS cipher suites. Source document ↗
- Implementations, libraries and tools
- PyCryptodome Crypto.Cipher provides CBC objects. Source document ↗
- Decryption or decoding
- Decrypt each block, then XOR with preceding ciphertext (IV for first block). Source document ↗
- Advantages
- Chaining makes each ciphertext depend on all preceding plaintext blocks, reducing exposure of repeated patterns. Source document ↗
- Limitations and cautions
- CBC does not authenticate ciphertext integrity; susceptible to tampering, so AEAD is recommended. Source document ↗
- Distinguishing encryption, encoding and hashing
- CBC provides confidentiality only, distinct from Base64, hashing and AEAD. Source document ↗
Practical examples
Example
Split plaintext into AES blocks, XOR the first with IV and encrypt, then XOR each following block with previous ciphertext before encryption. Decrypt using key and IV and remove padding.
Procedure
Prepare key and fresh IV per message, pad plaintext, encrypt first block after XOR with IV, remaining after XOR with previous ciphertext, store/send IV and ciphertext. Decrypt each block and XOR with previous ciphertext or IV, verify/remove padding. Base64 is separate keyless encoding.
Scenario
For legacy TLS or stored CBC data, confirm key, IV, padding rules and integrity protection. Prefer AEAD for new designs; if CBC is unavoidable for static content, add authentication/tamper verification.
Pitfalls and alternatives
Avoid reused/predictable IVs, padding oracles and MAC-then-encrypt; migrate to AES-GCM/ChaCha20-Poly1305. Distinguish encoding/hash and provide separate CBC integrity protection.
References
- Block cipher mode of operation ↗
- SSI Lecture 3 Symmetric Encryption ↗
- Classic modes of operation for symmetric block ciphers - PyCryptodome ↗
- RFC 9459: CBOR Object Signing and Encryption (COSE): AES-CTR and AES-CBC | RFC Editor ↗
- Padding oracles and the decline of CBC-mode cipher suites | Cloudflare Blog ↗
- RFC 7457: Summarizing Known Attacks on Transport Layer Security (TLS) and Datagram TLS (DTLS) | RFC Editor ↗
- SP 800-38A, Recommendation for Block Cipher Modes of Operation: Methods and Techniques | CSRC ↗
- Developer's QuickStart ↗
- lib.rs - source ↗
- CBC Mode - Crypto++ Wiki ↗