Meow

Struct Meow 

Source
pub struct Meow { /* private fields */ }
Expand description

Represents the state of a Meow instance.

This is the main object you interact with when using Meow, and all of the functionalities of the framework are derived from methods on this object.

The basic idea is that each party creates their own local instance of Meow, and then performs various operations in sync, allowing them to hash data, encrypt it, verify its integrity, etc.

This crate contains examples of composite operations like that in its main documentation.

This object is cloneable, and that’s very useful in certain situations, but one should be careful that the states are identical, and so some operations may not be secure because of common randomness between the states.

For example, the PRF output from both states will be the same right after forking them.

Many operations are divided into send and recv pairs. The idea is that one party performs send, sends some data, and then the other party uses recv with this data.

Many operations have a meta variant. These variants basically do the same thing as their normal variants, but have a bit of domain separation so that their result is separate.

Many operations also have a more argument. This can be used to split up an operation over multiple calls. For example, you might want to encrypt 1 GB of data as a single logical operation, but without having to store this entire piece of data in memory. Using more allows you to do this chunk by chunk, as if it were a single large operation. Each call after the first would set more = true, in order to indicate that it’s a continuation of the previous call.

Implementations§

Source§

impl Meow

Source

pub fn new(protocol: &[u8]) -> Self

Create a new Meow instance.

This function takes in a protocol string, which gets hashed into the state. The intention is to use this for domain separation of different protocols based on Meow.

Source

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

Absorb additional data into this state.

This can be used as a way to hash in additional data, such as when implementing an AEAD, or just a simple hash function.

The semantics of this are also that each party already knows the data, and doesn’t have to send it to the other person.

Source

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

Absorb additional metadata into this state.

This is intended to be used to describe additional data, or for framing: describing the operations being done.

Source

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

Include a secret key into the state.

This makes further operations dependent on knowing this secret key.

For forward secrecy, the state is also ratcheted.

Source

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

Send some plaintext data to the other party.

This is similar to ad, except the semantics are that the other person will not already know this information, and so we additionally have to send it to them.

Source

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

Send some plaintext metadata to the other party.

Similarly to send_clr, the semantics are that the other party doesn’t know this information, and we need to send it to them.

Source

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

Receive plaintext data.

This is the counterpart to send_clr.

Source

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

Receive plaintext metadata.

This is the counterpart to meta_recv_clr.

Source

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

Send encrypted data.

This function takes in the plaintext data to encrypt, and modifies it in place to contain the encrypted data. This should then be sent to the other party.

Source

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

Send encrypted metadata.

The intention of this operation is to send encrypted framing data, which might be useful for some situations.

Source

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

Receive encrypted data.

This is the counterpart to send_enc.

We start with a buffer of encrypted data, and then modify it to contain the plaintext.

Source

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

Received encrypted metadata.

Source

pub fn send_mac(&mut self, data: &mut [u8])

Send a MAC to the other party.

The buffer will be filled with a MAC, which verifies the integrity of the operations done so far. This MAC is then intended to be sent to the other party.

This operation intentionally does not allow more to be used. This is to match recv_mac.

Source

pub fn meta_send_mac(&mut self, data: &mut [u8])

Send a MAC of metadata to the other party.

This is very similar to send_mac.

Source

pub fn recv_mac(&mut self, data: &mut [u8]) -> Result<(), MacError>

Receive and verify a MAC.

The buffer contains the MAC to verify, and we need to mutate it to be able to more conveniently check its correctness.

This operation intentionally does not allow more to be used. This is because a MAC should always be verified all at once, rather than in chunks.

Source

pub fn meta_recv_mac(&mut self, data: &mut [u8]) -> Result<(), MacError>

Receive and verify a MAC of metadata.

This is very similar to recv_mac.

Source

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

Generate random bytes from the state.

Source

pub fn ratchet(&mut self)

Ratchet the state forward.

Because the state is modified with a permutation, we can use new states to derive information about old states. Ratcheting prevents this flow of information backwards.

Source

pub fn ratchet_many(&mut self, len: usize, more: bool)

Ratchet the state forward many times.

The difference with ratchet is that you can specify how far to ratchet the state. For S bits of security, you want to ratchet at least S / 8 bytes. Ratcheting more can function as a kind of “difficulty”, like you might want for password hashing.

That said, you probably want a function dedicated for hashing passwords, which have other security features, like being memory hard, and things like that.

Trait Implementations§

Source§

impl Clone for Meow

Source§

fn clone(&self) -> Meow

Returns a duplicate 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 Drop for Meow

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl Freeze for Meow

§

impl RefUnwindSafe for Meow

§

impl Send for Meow

§

impl Sync for Meow

§

impl Unpin for Meow

§

impl UnwindSafe for Meow

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§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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,

Source§

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>,

Source§

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>,

Source§

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.