XChaCha20
Bernstein's ARX stream cipher; ChaCha20 secures much of today's TLS, SSH and VPN traffic
About XChaCha20
XChaCha20 is one of 4 ChaCha variants in the NextSSL registry, a stream cipher. It uses a 32-byte (256-bit) key and a 24-byte nonce. Its registry entry cites draft-irtf-cfrg-xchacha. NextSSL lists it in the standard tier and exposes it through the safe API.
Overview
ChaCha is a family of stream ciphers designed by Daniel J. Bernstein in 2008 as a refinement of Salsa20. ChaCha20, standardised in RFC 8439 together with Poly1305, is one of the two main ciphers of TLS 1.3 and is used in WireGuard, SSH and Android.
ChaCha's state is a 4x4 matrix of 32-bit words holding constants, a 256-bit key, a block counter and a nonce. The quarter-round function updates four words with additions, XORs and rotations by 16, 12, 8 and 7 bits. Rounds alternate between columns and diagonals, and after all rounds the original state is added back to produce a 64-byte keystream block. Using only ARX operations makes ChaCha fast and constant-time in software without special hardware.
NextSSL includes ChaCha8, ChaCha12 and ChaCha20, named by their round counts, and XChaCha20, which uses HChaCha20 to derive a subkey from the first 128 bits of a 192-bit nonce so that random nonces can be used safely. The construction is a hash in counter mode. Each block depends only on its counter, so ChaCha is fully parallel and seekable.
History
2005–2018Salsa20 submitted to eSTREAM
ChaCha published by Daniel J. Bernstein
ChaCha20-Poly1305 specified in RFC 7539
One of the TLS 1.3 AEADs
Specified in RFC 8439
How it works
- Load constants, key, counter and nonce into a 4x4 word matrix
- Apply 20 (or 8/12) rounds of quarter-rounds on columns and diagonals
- Add the input state to the output
- XOR the 64-byte block with plaintext and increment the counter
Security notes
No practical attacks on ChaCha20 are known; the best attacks reach about seven rounds. ChaCha8 and ChaCha12 have smaller margins but are still unbroken. As a stream cipher, ChaCha must never reuse a key and nonce pair and provides no integrity on its own.
Typical uses
Sizes
| Field | Bytes | Meaning |
|---|---|---|
| key | 32 | Secret key |
| nonce | 24 | Nonce / IV |
Use it
from nextssl_demo import NextSSL
ns = NextSSL() # safe API: safe and standard tiers
ct = ns.call("stream_apply", "xchacha20", None, key, nonce, b"secret")[0] # same call decrypts
nextssl_stream_apply("xchacha20", NULL, key, nonce, data, out);
use nextssl_core::Params;
use nextssl_registry::{self as reg, Policy};
let alg = reg::new_streamcipher_in(reg::all(), Policy::Safe, "xchacha20", &Params::new())?;
let ct = alg.apply_keystream(&key, &nonce, b"secret")?;
Calls follow the NextSSL C ABI and its language bindings. Buffer sizes are validated against the sizes above.
Other ChaCha variants
3Similar names
Looking for something else?More stream ciphers
All 37Frequently asked questions
What is XChaCha20?
XChaCha20 is a stream cipher in the ChaCha family. ChaCha is a family of stream ciphers designed by Daniel J. Bernstein in 2008 as a refinement of Salsa20.
What are the XChaCha20 sizes?
In NextSSL, XChaCha20 uses: key 32 bytes, nonce 24 bytes.
Who designed XChaCha20 and when?
XChaCha20 belongs to the ChaCha family, first published in 2008 by Daniel J. Bernstein. Its origin: RFC 8439; draft-irtf-cfrg-xchacha.
Which standards define XChaCha20?
XChaCha20 is referenced by draft-irtf-cfrg-xchacha.
Is XChaCha20 safe to use?
XChaCha20 is in the standard tier. Standardised and sound. Reachable from the safe API. It can be called from the safe API.
What other ChaCha variants are there?
NextSSL also registers chacha12, chacha20, chacha8 in the ChaCha family.
Related families
A fast, secure successor to BLAKE with built-in keying, salting and tree hashing
BLAKE2A fast, secure successor to BLAKE with built-in keying, salting and tree hashing
Poly1305Bernstein's fast one-time authenticator, paired with ChaCha20 in RFC 8439
AES-CTRCounter mode: turns AES into a fast, parallel stream cipher
Salsa20Bernstein's eSTREAM-portfolio ARX stream cipher and the core of scrypt and NaCl