[−][src]Struct monocypher::chacha20::Context
Methods
impl Context
[src]
impl Context
These functions provide an incremental interface for the Chacha20 encryption primitive.
Example
use monocypher::chacha20::Context; use monocypher::utils::wipe; let mut key: [u8; 32] = [ 171, 107, 219, 186, 0, 173, 209, 50, 252, 77, 93, 85, 99, 106, 222, 162, 122, 140, 150, 228, 61, 93, 186, 251, 45, 23, 222, 14, 121, 172, 147, 241, ]; let nonce: [u8; 8] = [0, 0, 0, 0, 0, 0, 0, 1]; let mut ctx = Context::new(&key, nonce); let mut ctx2 = Context::new(&key, nonce); let ciphertext = ctx.encrypt("test".as_bytes()); let plaintext = ctx2.decrypt(&ciphertext); wipe(&mut key); assert_eq!(&plaintext, &"test".as_bytes())
pub fn new(key: &[u8], nonce: [u8; 8]) -> Context
[src]
pub fn new(key: &[u8], nonce: [u8; 8]) -> Context
Initialises a new context with the given key and nonce. Uses an 8-byte nonce, which is too small to be selected at random. Use a counter.
pub fn new_x(key: &[u8], nonce: [u8; 24]) -> Context
[src]
pub fn new_x(key: &[u8], nonce: [u8; 24]) -> Context
Initialises a new context with the given key and nonce. Uses a 24-byte nonce, which is big enough to be selected at random. Use your operating system to generate cryptographic secure random numbers. Read the about random number generators in the documentation
pub fn encrypt(&mut self, plaintext: &[u8]) -> Vec<u8>
[src]
pub fn encrypt(&mut self, plaintext: &[u8]) -> Vec<u8>
Encrypts the given plaintext.
pub fn decrypt(&mut self, ciphertext: &[u8]) -> Vec<u8>
[src]
pub fn decrypt(&mut self, ciphertext: &[u8]) -> Vec<u8>
Decrypts the given ciphertext.
pub fn stream(&mut self, stream: &mut [u8])
[src]
pub fn stream(&mut self, stream: &mut [u8])
Same as encrypt but with plaintext beeing NULL. Usefull as a non cryptographic user space random number generator.
pub fn chacha20_set_ctr(&mut self, ctr: u64)
[src]
pub fn chacha20_set_ctr(&mut self, ctr: u64)
Resets the internal counter of the context to the given number. Resuming the encryption will use the stream at the block number. May be used to en/decrypt part of a long message. Can also be used to implement AEAD constructions like the ones explained in RFC 7539.
Auto Trait Implementations
Blanket Implementations
impl<T> From for T
[src]
impl<T> From for T
impl<T, U> Into for T where
U: From<T>,
[src]
impl<T, U> Into for T where
U: From<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]
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
impl<T> Borrow for T where
T: ?Sized,
[src]
impl<T> Borrow for T where
T: ?Sized,
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]
fn get_type_id(&self) -> TypeId
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]
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
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]
fn borrow_mut(&mut self) -> &mut T