pub struct ChaCha8Poly1305 { /* private fields */ }Expand description
The ChaCha8-Poly1305 AEAD, derived from ChaCha20-Poly1305 as standardized in RFC 8439 but with a reduced number of ChaCha rounds for embedded platforms.
§Parameters
- Key: 256 bits (32 bytes)
- Nonce: 96 bits (12 bytes)
- Tag: 128 bits (16 bytes)
§Example
use crypto::{Aead, chacha::ChaCha8Poly1305};
let key = [0x55; 32];
let nonce = [0xaa; 12];
let aead = ChaCha8Poly1305::new(&key);
let aad = b"authenticated but not encrypted";
let plaintext = b"hello, world!";
let mut buf = plaintext.to_vec();
let tag = aead.encrypt_in_place(&mut buf, &nonce, aad);
let result = aead.decrypt_in_place(&mut buf, &nonce, aad, tag.as_ref());
assert!(result.is_ok());
assert_eq!(&buf, plaintext);Implementations§
Source§impl ChaCha8Poly1305
impl ChaCha8Poly1305
Sourcepub fn new(key: &[u8; 32]) -> ChaCha8Poly1305
pub fn new(key: &[u8; 32]) -> ChaCha8Poly1305
Creates a new AEAD instance from a 32-byte key.
Trait Implementations§
Source§impl Aead for ChaCha8Poly1305
impl Aead for ChaCha8Poly1305
const TAG_SIZE: usize = 16
const NONCE_SIZE: usize = 12
fn encrypt_in_place(&self, in_out: &mut [u8], nonce: &[u8], aad: &[u8]) -> Hash
fn decrypt_in_place( &self, in_out: &mut [u8], nonce: &[u8], aad: &[u8], tag: &[u8], ) -> Result<(), AeadError>
fn encrypt(&self, plaintext: &[u8], nonce: &[u8], aad: &[u8]) -> Vec<u8> ⓘ
fn decrypt( &self, ciphertext: &[u8], nonce: &[u8], aad: &[u8], ) -> Result<Vec<u8>, AeadError>
Source§impl Drop for ChaCha8Poly1305
impl Drop for ChaCha8Poly1305
Auto Trait Implementations§
impl Freeze for ChaCha8Poly1305
impl RefUnwindSafe for ChaCha8Poly1305
impl Send for ChaCha8Poly1305
impl Sync for ChaCha8Poly1305
impl Unpin for ChaCha8Poly1305
impl UnsafeUnpin for ChaCha8Poly1305
impl UnwindSafe for ChaCha8Poly1305
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more