[−][src]Struct chacha::ChaCha
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 = *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]
impl ChaCha
pub fn new_ietf(key: &[u8; 32], nonce: &[u8; 12]) -> 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.
pub fn new_chacha20(key: &[u8; 32], nonce: &[u8; 8]) -> ChaCha | [src] |
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.
pub fn new_chacha12(key: &[u8; 32], nonce: &[u8; 8]) -> ChaCha | [src] |
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.
pub fn new_chacha8(key: &[u8; 32], nonce: &[u8; 8]) -> ChaCha | [src] |
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.
pub fn new_xchacha20(key: &[u8; 32], nonce: &[u8; 24]) -> ChaCha | [src] |
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 Clone for ChaCha
[src]
impl Clone for ChaCha
fn clone(&self) -> ChaCha | [src] |
fn clone_from(&mut self, source: &Self) | 1.0.0 [src] |
Performs copy-assignment from source
. Read more
impl KeyStream for ChaCha
[src]
impl KeyStream for ChaCha
impl SeekableKeyStream for ChaCha
[src]
impl SeekableKeyStream for ChaCha
Auto Trait Implementations
Blanket Implementations
impl<T> From for T
[src]
impl<T> From for T
impl<T, U> TryFrom for T where
T: From<U>,
[src]
impl<T, U> TryFrom for T where
T: From<U>,
type Error = !
try_from
)The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error> | [src] |
impl<T, U> TryInto for T where
U: TryFrom<T>,
[src]
impl<T, U> TryInto for T where
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
try_from
)The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error> | [src] |
impl<T, U> Into for T where
U: From<T>,
[src]
impl<T, U> Into for T where
U: From<T>,
impl<T> Borrow for T where
T: ?Sized,
[src]
impl<T> Borrow for T where
T: ?Sized,
impl<T> BorrowMut for T where
T: ?Sized,
[src]
impl<T> BorrowMut for T where
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T | [src] |
impl<T> Any for T where
T: 'static + ?Sized,
[src]
impl<T> Any for T where
T: 'static + ?Sized,
fn get_type_id(&self) -> TypeId | [src] |
impl<T> ToOwned for T where
T: Clone,
[src]
impl<T> ToOwned for T where
T: Clone,