Struct chacha20poly1305::XChaCha20Poly1305
source · [−]pub struct XChaCha20Poly1305 { /* private fields */ }
Expand description
ChaCha20Poly1305 variant with an extended 192-bit (24-byte) nonce.
The xchacha20poly1305
Cargo feature must be enabled in order to use this
(which it is by default).
The construction is an adaptation of the same techniques used by XSalsa20 as described in the paper “Extending the Salsa20 Nonce” to the 96-bit nonce variant of ChaCha20, which derive a separate subkey/nonce for each extended nonce:
https://cr.yp.to/snuffle/xsalsa-20081128.pdf
No authoritative specification exists for XChaCha20Poly1305, however the construction has “rough consensus and running code” in the form of several interoperable libraries and protocols (e.g. libsodium, WireGuard) and is documented in an (expired) IETF draft, which also applies the proof from the XSalsa20 paper to the construction in order to demonstrate that XChaCha20 is secure if ChaCha20 is secure (see Section 3.1):
https://tools.ietf.org/html/draft-arciszewski-xchacha-03
It is worth noting that NaCl/libsodium’s default “secretbox” algorithm is
XSalsa20Poly1305, not XChaCha20Poly1305, and thus not compatible with
this library. If you are interested in that construction, please see the
xsalsa20poly1305
crate:
https://docs.rs/xsalsa20poly1305/
Usage
use chacha20poly1305::{XChaCha20Poly1305, Key, XNonce};
use chacha20poly1305::aead::{Aead, NewAead};
let key = Key::from_slice(b"an example very very secret key."); // 32-bytes
let aead = XChaCha20Poly1305::new(key);
let nonce = XNonce::from_slice(b"extra long unique nonce!"); // 24-bytes; unique
let ciphertext = aead.encrypt(nonce, b"plaintext message".as_ref()).expect("encryption failure!");
let plaintext = aead.decrypt(nonce, ciphertext.as_ref()).expect("decryption failure!");
assert_eq!(&plaintext, b"plaintext message");
Trait Implementations
sourceimpl AeadInPlace for XChaCha20Poly1305
impl AeadInPlace for XChaCha20Poly1305
type CiphertextOverhead = U0
type CiphertextOverhead = U0
The upper bound amount of additional space required to support a ciphertext vs. a plaintext. Read more
sourcefn encrypt_in_place_detached(
&self,
nonce: &XNonce,
associated_data: &[u8],
buffer: &mut [u8]
) -> Result<Tag, Error>
fn encrypt_in_place_detached(
&self,
nonce: &XNonce,
associated_data: &[u8],
buffer: &mut [u8]
) -> Result<Tag, Error>
Encrypt the data in-place, returning the authentication tag
sourcefn decrypt_in_place_detached(
&self,
nonce: &XNonce,
associated_data: &[u8],
buffer: &mut [u8],
tag: &Tag
) -> Result<(), Error>
fn decrypt_in_place_detached(
&self,
nonce: &XNonce,
associated_data: &[u8],
buffer: &mut [u8],
tag: &Tag
) -> Result<(), Error>
Decrypt the message in-place, returning an error in the event the provided authentication tag does not match the given ciphertext (i.e. ciphertext is modified/unauthentic) Read more
sourceimpl Clone for XChaCha20Poly1305
impl Clone for XChaCha20Poly1305
sourcefn clone(&self) -> XChaCha20Poly1305
fn clone(&self) -> XChaCha20Poly1305
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
sourceimpl Drop for XChaCha20Poly1305
impl Drop for XChaCha20Poly1305
sourceimpl NewAead for XChaCha20Poly1305
impl NewAead for XChaCha20Poly1305
Auto Trait Implementations
impl RefUnwindSafe for XChaCha20Poly1305
impl Send for XChaCha20Poly1305
impl Sync for XChaCha20Poly1305
impl Unpin for XChaCha20Poly1305
impl UnwindSafe for XChaCha20Poly1305
Blanket Implementations
sourceimpl<Alg> Aead for Alg where
Alg: AeadInPlace,
impl<Alg> Aead for Alg where
Alg: AeadInPlace,
type NonceSize = <Alg as AeadInPlace>::NonceSize
type NonceSize = <Alg as AeadInPlace>::NonceSize
The length of a nonce.
type TagSize = <Alg as AeadInPlace>::TagSize
type TagSize = <Alg as AeadInPlace>::TagSize
The maximum length of the nonce.
type CiphertextOverhead = <Alg as AeadInPlace>::CiphertextOverhead
type CiphertextOverhead = <Alg as AeadInPlace>::CiphertextOverhead
The upper bound amount of additional space required to support a ciphertext vs. a plaintext. Read more
sourceimpl<Alg> AeadMut for Alg where
Alg: AeadMutInPlace,
impl<Alg> AeadMut for Alg where
Alg: AeadMutInPlace,
type NonceSize = <Alg as AeadMutInPlace>::NonceSize
type NonceSize = <Alg as AeadMutInPlace>::NonceSize
The length of a nonce.
type TagSize = <Alg as AeadMutInPlace>::TagSize
type TagSize = <Alg as AeadMutInPlace>::TagSize
The maximum length of the nonce.
type CiphertextOverhead = <Alg as AeadMutInPlace>::CiphertextOverhead
type CiphertextOverhead = <Alg as AeadMutInPlace>::CiphertextOverhead
The upper bound amount of additional space required to support a ciphertext vs. a plaintext. Read more
sourceimpl<Alg> AeadMutInPlace for Alg where
Alg: AeadInPlace,
impl<Alg> AeadMutInPlace for Alg where
Alg: AeadInPlace,
type NonceSize = <Alg as AeadInPlace>::NonceSize
type NonceSize = <Alg as AeadInPlace>::NonceSize
The length of a nonce.
type TagSize = <Alg as AeadInPlace>::TagSize
type TagSize = <Alg as AeadInPlace>::TagSize
The maximum length of the nonce.
type CiphertextOverhead = <Alg as AeadInPlace>::CiphertextOverhead
type CiphertextOverhead = <Alg as AeadInPlace>::CiphertextOverhead
The upper bound amount of additional space required to support a ciphertext vs. a plaintext. Read more
sourcepub fn encrypt_in_place(
&mut self,
nonce: &GenericArray<u8, <Alg as AeadMutInPlace>::NonceSize>,
associated_data: &[u8],
buffer: &mut impl Buffer
) -> Result<(), Error>
pub fn encrypt_in_place(
&mut self,
nonce: &GenericArray<u8, <Alg as AeadMutInPlace>::NonceSize>,
associated_data: &[u8],
buffer: &mut impl Buffer
) -> Result<(), Error>
Encrypt the given buffer containing a plaintext message in-place. Read more
sourcepub fn encrypt_in_place_detached(
&mut self,
nonce: &GenericArray<u8, <Alg as AeadMutInPlace>::NonceSize>,
associated_data: &[u8],
buffer: &mut [u8]
) -> Result<GenericArray<u8, <Alg as AeadMutInPlace>::TagSize>, Error>
pub fn encrypt_in_place_detached(
&mut self,
nonce: &GenericArray<u8, <Alg as AeadMutInPlace>::NonceSize>,
associated_data: &[u8],
buffer: &mut [u8]
) -> Result<GenericArray<u8, <Alg as AeadMutInPlace>::TagSize>, Error>
Encrypt the data in-place, returning the authentication tag
sourcepub fn decrypt_in_place(
&mut self,
nonce: &GenericArray<u8, <Alg as AeadMutInPlace>::NonceSize>,
associated_data: &[u8],
buffer: &mut impl Buffer
) -> Result<(), Error>
pub fn decrypt_in_place(
&mut self,
nonce: &GenericArray<u8, <Alg as AeadMutInPlace>::NonceSize>,
associated_data: &[u8],
buffer: &mut impl Buffer
) -> Result<(), Error>
Decrypt the message in-place, returning an error in the event the provided authentication tag does not match the given ciphertext. Read more
sourcepub fn decrypt_in_place_detached(
&mut self,
nonce: &GenericArray<u8, <Alg as AeadMutInPlace>::NonceSize>,
associated_data: &[u8],
buffer: &mut [u8],
tag: &GenericArray<u8, <Alg as AeadMutInPlace>::TagSize>
) -> Result<(), Error>
pub fn decrypt_in_place_detached(
&mut self,
nonce: &GenericArray<u8, <Alg as AeadMutInPlace>::NonceSize>,
associated_data: &[u8],
buffer: &mut [u8],
tag: &GenericArray<u8, <Alg as AeadMutInPlace>::TagSize>
) -> Result<(), Error>
Decrypt the data in-place, returning an error in the event the provided authentication tag does not match the given ciphertext (i.e. ciphertext is modified/unauthentic) Read more
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcepub fn to_owned(&self) -> T
pub fn to_owned(&self) -> T
Creates owned data from borrowed data, usually by cloning. Read more
sourcepub fn clone_into(&self, target: &mut T)
pub fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more