Struct chacha::ChaCha [] [src]

pub struct ChaCha { /* fields omitted */ }

A ChaCha keystream.

After being initialized with a key and nonce, a ChaCha instance will generate a long stream of bytes that is indistinguishable from random for anyone not knowing the key and nonce.

Examples

use chacha::{ChaCha, KeyStream};

let secret_key = [
    0x29, 0xfa, 0x35, 0x60, 0x88, 0x45, 0xc6, 0xf9, 
    0xd8, 0xfe, 0x65, 0xe3, 0x22, 0x0e, 0x5b, 0x05, 
    0x03, 0x4a, 0xa0, 0x9f, 0x9e, 0x27, 0xad, 0x0f, 
    0x6c, 0x90, 0xa5, 0x73, 0xa8, 0x10, 0xe4, 0x94, 
];
let nonce = [0u8; 8];
let mut stream = ChaCha::new_chacha20(&secret_key, &nonce);

let mut buffer = [0u8; 6];
buffer = *b"abcdef";
stream.xor_read(&mut buffer[..]).expect("hit end of stream far too soon");
let expected_ciphertext = [0xde, 0x87, 0xa5, 0xbe, 0x1d, 0x77];
assert_eq!(buffer, expected_ciphertext);

Methods

impl ChaCha
[src]

Create a ChaCha stream conforming to the IETF's RFC 7539. The stream takes a 12-byte nonce and has a length of 238 bytes, or 256 GiB.

Create a ChaCha stream with an 8-byte nonce and has a length of 270 bytes. This is compatible with libsodium's ChaCha20 implementation and Daniel Bernstein's original specification.

Create a ChaCha stream with an 8-byte nonce and has a length of 270 bytes. This is compatible with libsodium's ChaCha12 implementation. ChaCha12 decreases security margin relative to ChaCha20 in favor of speed.

Create a ChaCha stream with an 8-byte nonce and has a length of 270 bytes. This is compatible with libsodium's ChaCha12 implementation. ChaCha8 decreases security margin relative to ChaCha20 in favor of speed.

Create a ChaCha stream with a 24-byte nonce and a length of 270 bytes. This stream's initialization relates to ChaCha20 in the same way that that XSalsa20 relates to Salsa20.

Trait Implementations

impl KeyStream for ChaCha
[src]

XORs keystream bytes with dest. Read more

impl SeekableKeyStream for ChaCha
[src]

Seeks to a position, with byte resolution, in the keystream. Read more