Crate salsa20

source ·
Expand description

The Salsa20 stream cipher.

Cipher functionality is accessed using traits from re-exported cipher crate.

Security Warning

This crate does not ensure ciphertexts are authentic! Thus ciphertext integrity is not verified, which can lead to serious vulnerabilities!

USE AT YOUR OWN RISK!

Diagram

This diagram illustrates the Salsa quarter round function. Each round consists of four quarter-rounds:

Legend:

  • ⊞ add
  • ‹‹‹ rotate
  • ⊕ xor

Usage

use salsa20::{Salsa20, Key, Nonce};
use salsa20::cipher::{NewCipher, StreamCipher, StreamCipherSeek};

let mut data = [1, 2, 3, 4, 5, 6, 7];

let key = Key::from_slice(b"an example very very secret key.");
let nonce = Nonce::from_slice(b"a nonce.");

// create cipher instance
let mut cipher = Salsa20::new(&key, &nonce);

// apply keystream (encrypt)
cipher.apply_keystream(&mut data);
assert_eq!(data, [182, 14, 133, 113, 210, 25, 165]);

// seek to the keystream beginning and apply it again to the `data` (decrypt)
cipher.seek(0);
cipher.apply_keystream(&mut data);
assert_eq!(data, [1, 2, 3, 4, 5, 6, 7]);

Re-exports

pub use cipher;

Structs

The Salsa20 core function.
8-rounds (Salsa20/8)
12-rounds (Salsa20/12)
20-rounds (Salsa20/20)
The Salsa20 family of stream ciphers (implemented generically over a number of rounds).

Constants

Size of a Salsa20 block in bytes
Size of a Salsa20 key in bytes

Type Definitions

Key type.
Nonce type.
Salsa20/8 stream cipher (reduced-round variant of Salsa20 with 8 rounds, not recommended)
Salsa20/12 stream cipher (reduced-round variant of Salsa20 with 12 rounds, not recommended)
Salsa20/20 stream cipher (20 rounds; recommended)