Struct strobe_rs::Strobe

source ·
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

source

pub fn new(proto: &[u8], sec: SecParam) -> Strobe

Makes a new Strobe object with a given protocol byte string and security parameter.

source

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.

source

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.

source

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.

source

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.

source

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.

source

pub fn send_enc(&mut self, data: &mut [u8], more: bool)

Sends an encrypted message.

source

pub fn meta_send_enc(&mut self, data: &mut [u8], more: bool)

Sends an encrypted message.

source

pub fn recv_enc(&mut self, data: &mut [u8], more: bool)

Receives an encrypted message.

source

pub fn meta_recv_enc(&mut self, data: &mut [u8], more: bool)

Receives an encrypted message.

source

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.

source

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.

source

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.

source

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.

source

pub fn send_clr(&mut self, data: &[u8], more: bool)

Sends a plaintext message.

source

pub fn meta_send_clr(&mut self, data: &[u8], more: bool)

Sends a plaintext message.

source

pub fn recv_clr(&mut self, data: &[u8], more: bool)

Receives a plaintext message.

source

pub fn meta_recv_clr(&mut self, data: &[u8], more: bool)

Receives a plaintext message.

source

pub fn ad(&mut self, data: &[u8], more: bool)

Mixes associated data into the internal state.

source

pub fn meta_ad(&mut self, data: &[u8], more: bool)

Mixes associated data into the internal state.

source

pub fn key(&mut self, data: &[u8], more: bool)

Sets a symmetric cipher key.

source

pub fn meta_key(&mut self, data: &[u8], more: bool)

Sets a symmetric cipher key.

Trait Implementations§

source§

impl Clone for Strobe

source§

fn clone(&self) -> Strobe

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<'de> Deserialize<'de> for Strobe

source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl Drop for Strobe

source§

fn drop(&mut self)

Executes the destructor for this type. Read more
source§

impl Serialize for Strobe

source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl Zeroize for Strobe

source§

fn zeroize(&mut self)

Zero out this object from memory using Rust intrinsics which ensure the zeroization operation is not “optimized away” by the compiler.

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> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> CloneToUninit for T
where T: Clone,

source§

default unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

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

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,