pub struct Protocol { /* private fields */ }Expand description
A stateful object providing fine-grained symmetric-key cryptographic services like hashing, message authentication codes, pseudo-random functions, authenticated encryption, and more.
Implementations§
Source§impl Protocol
impl Protocol
Sourcepub fn mix(&mut self, label: &str, input: &[u8])
pub fn mix(&mut self, label: &str, input: &[u8])
Mixes the given label and slice into the protocol state.
Sourcepub fn mix_writer<W: Write>(self, label: &str, inner: W) -> MixWriter<W> ⓘ
pub fn mix_writer<W: Write>(self, label: &str, inner: W) -> MixWriter<W> ⓘ
Moves the protocol into a std::io::Write implementation, mixing all written data in a
single operation and passing all writes to inner.
Equivalent to buffering all written data in a slice and passing it to Protocol::mix.
Use MixWriter::into_inner to finish the operation and recover the protocol and inner.
Sourcepub fn derive(&mut self, label: &str, out: &mut [u8])
pub fn derive(&mut self, label: &str, out: &mut [u8])
Derives pseudorandom output from the protocol’s current state, the label, and the output length, then ratchets the protocol’s state with the label and output length.
Sourcepub fn derive_array<const N: usize>(&mut self, label: &str) -> [u8; N]
pub fn derive_array<const N: usize>(&mut self, label: &str) -> [u8; N]
Derives output from the protocol’s current state and returns it as an N-byte array.
Sourcepub fn encrypt(&mut self, label: &str, in_out: &mut [u8])
pub fn encrypt(&mut self, label: &str, in_out: &mut [u8])
Encrypts the given slice in place using the protocol’s current state as the key, then ratchets the protocol’s state using the label and input.
Sourcepub fn decrypt(&mut self, label: &str, in_out: &mut [u8])
pub fn decrypt(&mut self, label: &str, in_out: &mut [u8])
Decrypts the given slice in place using the protocol’s current state as the key, then ratchets the protocol’s state using the label and input.
Sourcepub fn seal(&mut self, label: &str, in_out: &mut [u8])
pub fn seal(&mut self, label: &str, in_out: &mut [u8])
Encrypts the given slice in place using the protocol’s current state as the key, appending
an authentication tag of TAG_LEN bytes, then ratchets the protocol’s state using the
label and input.
Sourcepub fn open<'ct>(
&mut self,
label: &str,
in_out: &'ct mut [u8],
) -> Option<&'ct [u8]>
pub fn open<'ct>( &mut self, label: &str, in_out: &'ct mut [u8], ) -> Option<&'ct [u8]>
Decrypts the given slice in place using the protocol’s current state as the key, verifying
the final TAG_LEN bytes as an authentication tag, then ratchets the protocol’s state
using the label and input.
Returns the plaintext slice of in_out if the input was authenticated.