liveBook · Manning

ChaCha

As explained in Real-World Cryptography

ChaCha20 is a stream cipher that generates a pseudorandom keystream from a key, nonce, and counter.

ChaCha20 is a software-friendly stream cipher. It generates a keystream from a 256-bit key, 12-byte nonce, and counter, then XORs that keystream with plaintext to produce equal-length ciphertext. section 4.5.3

Encryption follows a short sequence:

  • Call the block function repeatedly, increasing the counter each time; each call produces 64 keystream bytes. section 4.5.3
  • Truncate the keystream to the plaintext length and XOR the two byte sequences. section 4.5.3
  • Decrypt by generating the same keystream and XORing it with the ciphertext. section 4.5.3

ChaCha20 is commonly paired with Poly1305 as ChaCha20-Poly1305: ChaCha20 encrypts and derives keys, while Poly1305 authenticates ciphertext and associated data. Never reuse a nonce with a key; doing so exposes relationships between plaintexts. section 4.5.3

Figure 4.18 ChaCha20 works by taking a symmetric key and a unique nonce. It then generates a keystream that is XORed with the plaintext (or ciphertext) to produce the ciphertext (or plaintext). The encryption is length-preserving as the ciphertext and the plaintext are of the same length.

Trace the key-and-nonce input, keystream generation, XOR operation, and length-preserving output. section 4.5.3

How Real-World Cryptography covers it

How deep it goes
Explains keystream production, block inputs, XOR flows, limits, and nonce-reuse consequences, but not the quarter-round internals in detail.
Examples
Uses encryption diagrams, 64-byte block generation, and deployments in OpenSSH, TLS, Noise, and Android.
What you can do after
Evaluate ChaCha20 encryption flows, distinguish encryption from authentication, and recognize nonce-reuse failures.
How it connects
Connects stream ciphers, Salsa20, XOR, Poly1305, authenticated encryption, and AES-GCM.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Real-World Cryptography. The section links point to the parts of the book it draws on.