K009 / Symmetric ciphers (block and stream)
Salsa20
Salsa20 is a symmetric stream cipher by Daniel J. Bernstein that expands a 256-bit key into a large keystream.
CRYPTOGRAPHY LAB / K009
Cryptography Lab · Salsa20
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.
Salsa20/20 (256-bit key, counter starts at 0)
See the scope above for fixed examples, reduced parameters and supported variants. Standard operation names and formulas are retained.Output
Previous state
- Definition and overview
- Salsa20 is a symmetric stream cipher by Daniel J. Bernstein that expands a 256-bit key into a large keystream. Source document ↗
- Classification and reversibility
- A symmetric stream cipher; XOR with the same keystream makes decryption possible with the same key and nonce. Source document ↗
- Key or secret requirements
- Requires a secret key and nonce: 256-bit key, 64-bit nonce and 64-bit counter; XSalsa20 uses an extended nonce. Source document ↗
- Operating principle and structure
- Hashes key, nonce and block number to produce a 64-byte keystream, then XORs it with plaintext. Source document ↗
- Key size, block size and parameters
- 256-bit key (128-bit variants also exist), 64-bit nonce and counter, 512-bit (64-byte) keystream blocks. Source document ↗
- Security strength and recommendation
- No practical attack is known with a 256-bit key; authenticated encryption is recommended in practice. Source document ↗
- Known attacks and vulnerabilities
- Distinguishers and security degradation are known for reduced-round variants such as Salsa20/8. Source document ↗
- Standards and certification
- Reduced-round Salsa20/12 was selected for the eSTREAM software portfolio. Source document ↗
- Typical uses
- Typically used in authenticated-encryption constructions such as XSalsa20-Poly1305. Source document ↗
- Implementations, libraries and tools
- Implementations include python-salsa20, libsodium/NaCl, PyCryptodome and RustCrypto. Source document ↗
- Decryption or decoding
- For decryption, reinitialize with the same key and nonce, then call decrypt. Source document ↗
- Advantages
- No lookup tables are required, reducing timing-attack risk in software implementations. Source document ↗
- Limitations and cautions
- Standalone use without authentication must be prohibited because it does not ensure integrity or authenticity. Source document ↗
- Distinguishing encryption, encoding and hashing
- Despite its internal hash core, Salsa20 is a stream cipher, not keyless encoding or ordinary hashing. Source document ↗
Practical examples
Example
Prepare a secret key and unique nonce, initialize a Salsa20-family cipher and XOR plaintext with the keystream. Decryption repeats the process with the same key and nonce. No actual secrets are included.
Procedure
Encryption: prepare a 256-bit key and unique nonce per message; preferably use authenticated encryption such as XSalsa20-Poly1305; store ciphertext and tag together. Decrypt with the same key and nonce and verify the tag. Base64/Hex encoding and decoding are separate representation transformations.
Scenario
If legacy integration requires Salsa20, use a vetted authenticated wrapper such as libsodium secretbox. Manage unique nonces per message and treat Base64/Hex as a separate storage or transmission layer. Consider ChaCha20-Poly1305 for new designs.
Pitfalls and alternatives
Do not reuse nonces or use unauthenticated raw Salsa20 or reduced-round Salsa20/8. For new systems prefer XSalsa20-Poly1305 or ChaCha20-Poly1305; distinguish encoding, hashing and encryption.