Struct ChaCha20Poly1305

Source
pub struct ChaCha20Poly1305 { /* private fields */ }
Available on crate feature chacha20poly1305 only.
Expand description

OpenSSH variant of ChaCha20Poly1305: chacha20-poly1305@openssh.com as described in PROTOCOL.chacha20poly1305.

Differences from ChaCha20Poly1305-IETF as described in RFC8439:

  • Nonce is 64-bit instead of 96-bit (i.e. uses legacy “djb” ChaCha20 variant).
  • The AAD and ciphertext inputs of Poly1305 are not padded.
  • The lengths of ciphertext and AAD are not authenticated using Poly1305.

Implementations§

Source§

impl ChaCha20Poly1305

Source

pub fn encrypt( &self, nonce: &ChaChaNonce, buffer: &mut [u8], aad_len: usize, ) -> Result<Tag>

Encrypt the provided buffer in-place, returning the Poly1305 authentication tag.

The input buffer should contain the concatenation of any additional associated data (AAD) and the plaintext to be encrypted, where in the context of the SSH packet encryption protocol the AAD represents an encrypted packet length, which is itself 4-bytes / 64-bits.

aad_len is the length of the AAD in bytes:

  • In the context of SSH packet encryption, this should be 4.
  • In the context of SSH key encryption, aad_len should be 0.

The first aad_len bytes of buffer will be unmodified after encryption is completed. Only the data after aad_len will be encrypted.

The resulting Tag authenticates both the AAD and the ciphertext in the buffer.

Source

pub fn decrypt( &self, nonce: &ChaChaNonce, buffer: &mut [u8], tag: Tag, aad_len: usize, ) -> Result<()>

Decrypt the provided buffer in-place, verifying it against the provided Poly1305 authentication tag.

The input buffer should contain the concatenation of any additional associated data (AAD) and the ciphertext to be authenticated, where in the context of the SSH packet encryption protocol the AAD represents an encrypted packet length, which is itself 4-bytes / 64-bits.

aad_len is the length of the AAD in bytes:

  • In the context of SSH packet encryption, this should be 4.
  • In the context of SSH key encryption, aad_len should be 0.

The first aad_len bytes of buffer will be unmodified after decryption completes successfully. Only data after aad_len will be decrypted.

Trait Implementations§

Source§

impl AeadCore for ChaCha20Poly1305

Source§

const TAG_POSITION: TagPosition = TagPosition::Postfix

The AEAD tag position.
Source§

type NonceSize = UInt<UInt<UInt<UInt<UTerm, B1>, B0>, B0>, B0>

The length of a nonce.
Source§

type TagSize = UInt<UInt<UInt<UInt<UInt<UTerm, B1>, B0>, B0>, B0>, B0>

The maximum length of the tag.
Source§

impl Clone for ChaCha20Poly1305

Source§

fn clone(&self) -> ChaCha20Poly1305

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Drop for ChaCha20Poly1305

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl KeyInit for ChaCha20Poly1305

Source§

fn new(key: &ChaChaKey) -> Self

Create new value from fixed size key.
Source§

fn weak_key_test(_key: &Array<u8, Self::KeySize>) -> Result<(), WeakKeyError>

Check if the key might be considered weak.
Source§

fn new_checked(key: &Array<u8, Self::KeySize>) -> Result<Self, WeakKeyError>

Create new value from fixed size key after checking it for weakness.
Source§

fn new_from_slice(key: &[u8]) -> Result<Self, InvalidLength>

Create new value from variable size key.
Source§

impl KeySizeUser for ChaCha20Poly1305

Source§

type KeySize = UInt<UInt<UInt<UInt<UInt<UInt<UTerm, B1>, B0>, B0>, B0>, B0>, B0>

Key size in bytes.
Source§

fn key_size() -> usize

Return key size in bytes.
Source§

impl ZeroizeOnDrop for ChaCha20Poly1305

Available on crate feature zeroize only.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.