Struct ssh_cipher::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:

  • The input of Poly1305 is not padded.
  • AAD is unsupported.
  • The lengths of ciphertext (and AAD) are not authenticated using Poly1305.

Implementations§

source§

impl ChaCha20Poly1305

source

pub fn new(key: &[u8], nonce: &[u8]) -> Result<Self>

Create a new ChaCha20Poly1305 instance with a 32-byte key.

source

pub fn encrypt(self, buffer: &mut [u8]) -> Tag

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

source

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

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

In the event tag verification fails, Error::Crypto is returned, and buffer is not modified.

Upon success, Ok(()) is returned and buffer is rewritten with the decrypted plaintext.

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

§

type Output = T

Should always be Self
source§

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

§

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>,

§

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.