← Cryptography guide

K027 / Cipher modes and AEAD

AES-CTR

CTR counter mode · Survey date 2026-12-05

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.

Scope: Limited implementation

AES-CTR (128-bit counter)

See the scope above for fixed examples, reduced parameters and supported variants. Standard operation names and formulas are retained.

Reference ↗

Open lab →

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

Examples are illustrative; they are not execution-tested implementations or operational recommendations.

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