[][src]Crate salsa20

The Salsa20 stream cipher.

Cipher functionality is accessed using traits from re-exported stream-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 salsa20::Salsa20;
use salsa20::stream_cipher::generic_array::GenericArray;
use salsa20::stream_cipher::{NewStreamCipher, SyncStreamCipher, SyncStreamCipherSeek};

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

let key = GenericArray::from_slice(b"an example very very secret key.");
let nonce = GenericArray::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.apply_keystream(&mut data);
assert_eq!(data, [1, 2, 3, 4, 5, 6, 7]);


pub extern crate stream_cipher;



The Salsa20 cipher.


XSalsa20 is a Salsa20 variant with an extended 192-bit (24-byte) nonce.