Stream ciphers

Chacha8

Bernstein's ARX stream cipher; ChaCha20 secures much of today's TLS, SSH and VPN traffic

research Root API only
Research tier.

Experimental or unclassified. Root API only. Reach it with NextSSL(root=True) in Python or the nextssl_root_* functions in C.

About Chacha8

Chacha8 is one of 4 ChaCha variants in the NextSSL registry, a stream cipher. It uses a 32-byte (256-bit) key and a 12-byte nonce. It takes the parameter initial_counter (default 0). Its registry entry cites ChaCha (Bernstein 2008). NextSSL lists it in the research tier and exposes it through the root API only (NextSSL(root=True) in Python, nextssl_root_* in C).

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–2018
  1. Salsa20 submitted to eSTREAM

  2. ChaCha published by Daniel J. Bernstein

  3. ChaCha20-Poly1305 specified in RFC 7539

  4. One of the TLS 1.3 AEADs

  5. Specified in RFC 8439

How it works

  1. Load constants, key, counter and nonce into a 4x4 word matrix
  2. Apply 20 (or 8/12) rounds of quarter-rounds on columns and diagonals
  3. Add the input state to the output
  4. 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

ChaCha20-Poly1305 AEAD in TLS 1.3, SSH and WireGuardEncryption on devices without AES hardwareFast CSPRNGs (e.g. Linux getrandom)

Sizes

FieldBytesMeaning
key32Secret key
nonce12Nonce / IV

Parameters

NameTypeRangeDefaultRequired
initial_counter u32 0 – 4294967295 0 no

Parameters are passed as a string, for example nextssl_mac("hmac", "hash=sha512", …). Omitted parameters take their declared default.

Use it

from nextssl_demo import NextSSL

root = NextSSL(root=True)   # tier 'research' is reachable from the root API only
ct = root.call("stream_apply", "chacha8", None, key, nonce, b"secret")[0]   # same call decrypts

Calls follow the NextSSL C ABI and its language bindings. Buffer sizes are validated against the sizes above.

Other ChaCha variants

3

Similar names

Looking for something else?

Frequently asked questions

What is Chacha8?

Chacha8 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 Chacha8 sizes?

In NextSSL, Chacha8 uses: key 32 bytes, nonce 12 bytes.

Who designed Chacha8 and when?

Chacha8 belongs to the ChaCha family, first published in 2008 by Daniel J. Bernstein. Its origin: RFC 8439; draft-irtf-cfrg-xchacha.

Which standards define Chacha8?

Chacha8 is referenced by ChaCha (Bernstein 2008).

Is Chacha8 safe to use?

Chacha8 is in the research tier. Experimental or unclassified. Root API only. It is only reachable through the root API (NextSSL(root=True) in Python, nextssl_root_* in C).

What other ChaCha variants are there?

NextSSL also registers chacha12, chacha20, xchacha20 in the ChaCha family.