K027 / Cipher modes and AEAD
AES-CTR
A block cipher mode that encrypts counters to generate a keystream, which is XORed with plaintext.
CRYPTOGRAPHY LAB / K027
Cryptography Lab · AES-CTR
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-CTR (128-bit counter)
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
- A block cipher mode that encrypts counters to generate a keystream, which is XORed with plaintext. Source document ↗
- Classification and reversibility
- Symmetric mode using a block cipher as a stream cipher; decryption uses the same operation. Source document ↗
- Key or secret requirements
- Requires a symmetric AES key and IV/counter; never reuse a key-IV pair. Source document ↗
- Operating principle and structure
- Encrypt counter blocks to generate keystream, XOR with plaintext and increment counter. Source document ↗
- Key size, block size and parameters
- 128/192/256-bit AES keys and 128-bit blocks/counter length. Source document ↗
- Security strength and recommendation
- Described as a cryptographically strong mode. Source document ↗
- Known attacks and vulnerabilities
- Nonce/counter reuse with the same key repeats keystream and may break confidentiality. Source document ↗
- Standards and certification
- Standardized in 2001 in NIST SP 800-38A. Source document ↗
- Typical uses
- Specified as a COSE content-encryption algorithm. Source document ↗
- Implementations, libraries and tools
- Available for encryption/decryption in browser Web Crypto API. Source document ↗
- Decryption or decoding
- Generate the same keystream and XOR with ciphertext to decrypt. Source document ↗
- Advantages
- Independent keystream blocks enable parallelism and random access. Source document ↗
- Limitations and cautions
- Nonce/counter reuse is catastrophic; never repeat the same key and nonce. Source document ↗
- Distinguishing encryption, encoding and hashing
- CTR is encryption without authentication/integrity, not encoding or hashing. Source document ↗
Practical examples
Example
Sender chooses unique counter/IV, encrypts counter blocks using AES, XORs keystream and plaintext. Receiver regenerates identical keystream with key/counter/IV and XORs to recover. Manage actual keys and IVs securely using randomness or uniqueness, not examples.
Procedure
Prepare key and unique nonce/initial counter, encrypt counters, XOR plaintext, transmit nonce/counter with ciphertext. Decrypt using identical key and nonce/counter. Encoding is keyless; CTR requires key and nonce/counter.
Scenario
Can be used for COSE content encryption; separately design unique IV/counter management and integrity protection.
Pitfalls and alternatives
Never reuse nonce/counter under one key. CTR lacks authentication/integrity and is malleable; use AEAD (GCM/CCM) or encrypt-then-MAC when needed. Distinguish encoding and hashing.
References
- Modes of Operation | Cryptography Academy ↗
- Counter Block Layout and the Nonce Budget in CTR Mode — MerceMay ↗
- RFC 9459: CBOR Object Signing and Encryption (COSE): AES-CTR and AES-CBC ↗
- SSI Lecture 3 Symmetric Encryption ↗
- docs/hazmat/primitives/symmetric-encryption.rst ↗
- CTR Mode - Crypto++ Wiki ↗
- AES CTR with Web Cryptography and JavaScript ↗
- mod.rs - source ↗
- AES Encrypt / Decrypt - Examples ↗