pub struct Strobe { /* private fields */ }
Expand description
The main Strobe object. This is currently limited to using Keccak-f[1600] (the highest security level) as the internal permutation function. For more information on this object, the protocol specification is a great resource.
§Description of method input
Most operations exposed by Strobe
take the same set of inputs. The arguments are
data
- The input data to the operation.more
- For streaming purposes. Specifies whether you’re trying to add more input / get more output to/from the previous operation. For example:
s.ad(b"hello world", false);
is equivalent to
s.ad(b"hello ", false);
s.ad(b"world", true);
NOTE: If you try to set the more
flag for an operation that is not preceded by the same
operation (e.g., if you try ad
followed by send_enc
with more=true
), then the function
will panic, since that is an invalid use of the more
flag.
Finally, ratchet
and meta_ratchet
take a usize
argument instead of bytes. These functions
are individually commented below.
Implementations§
Source§impl Strobe
impl Strobe
Sourcepub fn new(proto: &[u8], sec: SecParam) -> Strobe
pub fn new(proto: &[u8], sec: SecParam) -> Strobe
Makes a new Strobe
object with a given protocol byte string and security parameter.
Sourcepub fn version_str(&self) -> [u8; 29]
pub fn version_str(&self) -> [u8; 29]
Returns a bytestring of the form Strobe-Keccak-SEC/B-vVER
where SEC
is the bits of
security (128 or 256), B
is the block size (in bits) of the Keccak permutation function,
and VER
is the protocol version.
Sourcepub fn recv_mac<const N: usize>(
&mut self,
mac: &[u8; N],
) -> Result<(), AuthError>
pub fn recv_mac<const N: usize>( &mut self, mac: &[u8; N], ) -> Result<(), AuthError>
Attempts to authenticate the current state against the given MAC. On failure, it returns an
AuthError
.
Sourcepub fn meta_recv_mac<const N: usize>(
&mut self,
mac: &[u8; N],
) -> Result<(), AuthError>
pub fn meta_recv_mac<const N: usize>( &mut self, mac: &[u8; N], ) -> Result<(), AuthError>
Attempts to authenticate the current state against the given MAC. On failure, it returns an
AuthError
.
Sourcepub fn ratchet(&mut self, num_bytes_to_zero: usize, more: bool)
pub fn ratchet(&mut self, num_bytes_to_zero: usize, more: bool)
Ratchets the internal state forward in an irreversible way by zeroing bytes.
Takes a usize
argument specifying the number of bytes of public state to zero. If the
size exceeds self.rate
, Keccak-f will be called before more bytes are zeroed.
Sourcepub fn meta_ratchet(&mut self, num_bytes_to_zero: usize, more: bool)
pub fn meta_ratchet(&mut self, num_bytes_to_zero: usize, more: bool)
Ratchets the internal state forward in an irreversible way by zeroing bytes.
Takes a usize
argument specifying the number of bytes of public state to zero. If the
size exceeds self.rate
, Keccak-f will be called before more bytes are zeroed.
Sourcepub fn meta_send_enc(&mut self, data: &mut [u8], more: bool)
pub fn meta_send_enc(&mut self, data: &mut [u8], more: bool)
Sends an encrypted message.
Sourcepub fn meta_recv_enc(&mut self, data: &mut [u8], more: bool)
pub fn meta_recv_enc(&mut self, data: &mut [u8], more: bool)
Receives an encrypted message.
Sourcepub fn send_mac(&mut self, data: &mut [u8], more: bool)
pub fn send_mac(&mut self, data: &mut [u8], more: bool)
Sends a MAC of the internal state. The output is independent of the initial contents of the input buffer.
Sourcepub fn meta_send_mac(&mut self, data: &mut [u8], more: bool)
pub fn meta_send_mac(&mut self, data: &mut [u8], more: bool)
Sends a MAC of the internal state. The output is independent of the initial contents of the input buffer.
Sourcepub fn prf(&mut self, data: &mut [u8], more: bool)
pub fn prf(&mut self, data: &mut [u8], more: bool)
Extracts pseudorandom data as a function of the internal state. The output is independent of the initial contents of the input buffer.
Sourcepub fn meta_prf(&mut self, data: &mut [u8], more: bool)
pub fn meta_prf(&mut self, data: &mut [u8], more: bool)
Extracts pseudorandom data as a function of the internal state. The output is independent of the initial contents of the input buffer.
Sourcepub fn meta_send_clr(&mut self, data: &[u8], more: bool)
pub fn meta_send_clr(&mut self, data: &[u8], more: bool)
Sends a plaintext message.
Sourcepub fn meta_recv_clr(&mut self, data: &[u8], more: bool)
pub fn meta_recv_clr(&mut self, data: &[u8], more: bool)
Receives a plaintext message.