Struct cryptoxide::chacha20poly1305::Context [−][src]
pub struct Context { /* fields omitted */ }
Expand description
Chacha20Poly1305 Incremental Context for Authenticated Data (AAD)
The initial context set the key and nonce, and the authenticated data (if any),
then it needs to converted either to a ContextEncryption
or ContextDecryption
using the Context::to_encryption
or Context::to_decryption
methods (respectively).
use cryptoxide::chacha20poly1305::Context;
let key : [u8; 16] = [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15];
let nonce : [u8; 8] = [1,2,3,4,5,6,7,8];
let mut context = Context::new(&key, &nonce);
// Add incrementally 2 slices of data
context.add_data(b"authenticated");
context.add_data(b"data");
let mut encrypted_input = [0u8; 10+16];
let mut context = context.to_encryption();
// Encrypt incrementally 2 slices and append the encrypted data to the output buffer
context.encrypt(b"hello", &mut encrypted_input[0..5]);
context.encrypt(b"world", &mut encrypted_input[5..10]);
// Finalize the context, and append the tag to the end of the output buffer
let tag = context.finalize();
encrypted_input[10..26].copy_from_slice(&tag.0);
Implementations
Create a new context given the key and nonce.
use cryptoxide::chacha20poly1305::Context;
let key : [u8; 16] = [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15];
let nonce : [u8; 8] = [1,2,3,4,5,6,7,8];
let context = Context::new(&key, &nonce);
Add Authenticated Data to the MAC Context
This can be called multiple times
Finish authenticated part and move to the encryption phase
Finish authenticated part and move to the decryption phase
Trait Implementations
Auto Trait Implementations
impl RefUnwindSafe for Context
impl UnwindSafe for Context
Blanket Implementations
Mutably borrows from an owned value. Read more