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.
Trait Implementations§
source§impl<'de> Deserialize<'de> for Strobe
impl<'de> Deserialize<'de> for Strobe
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Auto Trait Implementations§
impl Freeze for Strobe
impl RefUnwindSafe for Strobe
impl Send for Strobe
impl Sync for Strobe
impl Unpin for Strobe
impl UnwindSafe for Strobe
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)