[][src]Struct noise_protocol::CipherState

pub struct CipherState<C: Cipher> { /* fields omitted */ }

A CipherState can encrypt and decrypt data.

Mostly like CipherState in the spec, but must be created with a key.

Panics

Encryption and decryption methods will panic if nonce reaches maximum u64, i.e., 2 ^ 64 - 1.

Methods

impl<C> CipherState<C> where
    C: Cipher
[src]

pub fn name() -> &'static str[src]

Name of cipher, e.g. “ChaChaPoly”.

pub fn new(key: &[u8], n: u64) -> Self[src]

Create a new CipherState with a key and a nonce n.

pub fn rekey(&mut self)[src]

Rekey. Set our key to REKEY(old key).

pub fn encrypt_ad(&mut self, authtext: &[u8], plaintext: &[u8], out: &mut [u8])[src]

AEAD encryption.

pub fn decrypt_ad(
    &mut self,
    authtext: &[u8],
    ciphertext: &[u8],
    out: &mut [u8]
) -> Result<(), ()>
[src]

AEAD decryption.

pub fn encrypt(&mut self, plaintext: &[u8], out: &mut [u8])[src]

Encryption.

pub fn encrypt_vec(&mut self, plaintext: &[u8]) -> Vec<u8>[src]

Encryption, returns ciphertext as Vec<u8>.

pub fn decrypt(&mut self, ciphertext: &[u8], out: &mut [u8]) -> Result<(), ()>[src]

Decryption.

pub fn decrypt_vec(&mut self, ciphertext: &[u8]) -> Result<Vec<u8>, ()>[src]

Decryption, returns plaintext as Vec<u8>.

pub fn get_next_n(&self) -> u64[src]

Get the next value of n. Could be used to decide on whether to re-key, etc.

pub fn extract(self) -> (C::Key, u64)[src]

Get underlying cipher and nonce.

This is useful for e.g. WireGuard. Because packets may be lost or arrive out of order, they would likely want to deal with nonces themselves.

Trait Implementations

impl<C> Clone for CipherState<C> where
    C: Cipher
[src]

Auto Trait Implementations

impl<C> RefUnwindSafe for CipherState<C> where
    <C as Cipher>::Key: RefUnwindSafe

impl<C> Send for CipherState<C> where
    <C as Cipher>::Key: Send

impl<C> Sync for CipherState<C> where
    <C as Cipher>::Key: Sync

impl<C> Unpin for CipherState<C> where
    <C as Cipher>::Key: Unpin

impl<C> UnwindSafe for CipherState<C> where
    <C as Cipher>::Key: UnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.