Struct noise_protocol::CipherState
[−]
[src]
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.
Methods
impl<C> CipherState<C> where C: Cipher
[src]
fn name() -> &'static str
Name of cipher, e.g. “ChaChaPoly”.
fn new(key: &[u8], n: u64) -> Self
Create a new CipherState
with a key
and a nonce n
.
fn encrypt_ad(&mut self, authtext: &[u8], plaintext: &[u8], out: &mut [u8])
fn decrypt_ad(&mut self,
authtext: &[u8],
ciphertext: &[u8],
out: &mut [u8])
-> Result<(), ()>
authtext: &[u8],
ciphertext: &[u8],
out: &mut [u8])
-> Result<(), ()>
fn encrypt(&mut self, plaintext: &[u8], out: &mut [u8])
Encryption.
fn encrypt_vec(&mut self, plaintext: &[u8]) -> Vec<u8>
Encryption, returns ciphertext as Vec<u8>
.
fn decrypt(&mut self, ciphertext: &[u8], out: &mut [u8]) -> Result<(), ()>
Decryption.
fn decrypt_vec(&mut self, ciphertext: &[u8]) -> Result<Vec<u8>, ()>
Decryption, returns plaintext as Vec<u8>
.
fn extract(self) -> (C::Key, u64)
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.