[][src]Struct monocypher::chacha20::Context

pub struct Context(_);

Methods

impl Context
[src]

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())

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.

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

Encrypts the given plaintext.

Decrypts the given ciphertext.

Same as encrypt but with plaintext beeing NULL. Usefull as a non cryptographic user space random number generator.

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

impl Send for Context

impl Sync for Context

Blanket Implementations

impl<T> From for T
[src]

impl<T, U> Into for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom for T where
    T: From<U>, 
[src]

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

impl<T> Borrow for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T, U> TryInto for T where
    U: TryFrom<T>, 
[src]

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

impl<T> BorrowMut for T where
    T: ?Sized
[src]