[−][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 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::stream_cipher::{NewStreamCipher, SyncStreamCipher, SyncStreamCipherSeek}; 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 stream_cipher; |
Structs
Salsa | The Salsa20 family of stream ciphers (implemented generically over a number of rounds). |
XSalsa20 | feature="xsalsa20" XSalsa20 is a Salsa20 variant with an extended 192-bit (24-byte) nonce. |
Constants
BLOCK_SIZE | Size of a Salsa20 block in bytes |
KEY_SIZE | Size of a Salsa20 key in bytes |
Functions
hsalsa20 | feature="hsalsa20" The HSalsa20 function defined in the paper "Extending the Salsa20 nonce" |
Type Definitions
Key | Key type. |
Nonce | Nonce type. |
Salsa8 | Salsa20/8 stream cipher (reduced-round variant of Salsa20 with 8 rounds, not recommended) |
Salsa12 | Salsa20/12 stream cipher (reduced-round variant of Salsa20 with 12 rounds, not recommended) |
Salsa20 | Salsa20/20 stream cipher (20 rounds; recommended) |
XNonce | feature="xsalsa20" EXtended Salsa20 nonce (192-bit/24-byte) |