← Cryptography guide

K008 / Symmetric ciphers (block and stream)

ChaCha20

ChaCha20 stream cipher · Survey date 2026-12-05

ChaCha20 is a stream cipher developed by Daniel J. Bernstein.

CRYPTOGRAPHY LAB / K008

Cryptography Lab · ChaCha20

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: Standard operation

ChaCha20 (IETF)

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
ChaCha20 is a stream cipher developed by Daniel J. Bernstein. Source document ↗
Classification and reversibility
A reversible stream cipher; decryption uses the same XOR operation as encryption. Source document ↗
Key or secret requirements
Requires a secret key, described in the excerpt as the cipher's only secret input. Source document ↗
Operating principle and structure
Repeated quarter rounds over four 32-bit words. Source document ↗
Key size, block size and parameters
Parameters include a 64-byte (512-bit) block, 256-bit key and 96-bit nonce. Source document ↗
Security strength and recommendation
Designed to target 256-bit security strength. Source document ↗
Known attacks and vulnerabilities
Reusing a key and nonce can destroy confidentiality, for example by revealing the XOR of plaintexts through the XOR of ciphertexts. Source document ↗
Standards and certification
IETF RFC 7539/8439 specify a 256-bit key, 96-bit nonce and 32-bit counter. Source document ↗
Typical uses
Typical uses include TLS. Source document ↗
Implementations, libraries and tools
Implemented by libraries including RustCrypto. Source document ↗
Decryption or decoding
Regenerate the keystream with the same key and nonce and XOR it with ciphertext to decrypt. Source document ↗
Advantages
No lookup tables are required, helping avoid timing attacks. Source document ↗
Limitations and cautions
Not subject to FIPS-140 certification; caution is required in regulated and compliance environments. Source document ↗
Distinguishing encryption, encoding and hashing
Key-and-nonce-based stream encryption, distinct from simple encoding and hashing. Source document ↗

Practical examples

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

Example

XOR plaintext with a keystream generated using a 256-bit key, unique nonce and counter if needed. Regenerate the keystream with the same key, nonce and counter and XOR it to recover plaintext. No actual keys or secrets are included.

Procedure

Encryption: prepare key, nonce and counter, generate a ChaCha20 keystream, XOR with plaintext. Decryption: regenerate the keystream with identical parameters and XOR with ciphertext. Base64 encoding/decoding is a separate transformation.

Scenario

Can be used in an AEAD construction for TLS/SSH transport encryption. Consider it as a software stream cipher where AES hardware acceleration is absent. For file or message encryption, manage the random nonce together with the authentication tag.

Pitfalls and alternatives

Do not reuse key and nonce; manage the 32-bit counter limit (about 256 GB) and counter overflow. If authentication is required, use AEAD such as ChaCha20-Poly1305 and separately review FIPS-140 regulatory environments. Do not mistake encoding or hashing for encryption.

References