pub(crate) mod alsz;
pub(crate) mod chou_orlandi;
pub(crate) mod kos;
use curve25519_dalek::RistrettoPoint;
use rand::{CryptoRng, Rng};
use rand_chacha::ChaCha20Rng;
use crate::{block::Block, channel::Channel, mpc::faand::Error};
pub(crate) fn hash_pt(tweak: u128, pt: &RistrettoPoint) -> Block {
let h = blake3::keyed_hash(pt.compress().as_bytes(), &tweak.to_le_bytes());
Block::from(<[u8; 16]>::try_from(&h.as_bytes()[0..16]).unwrap())
}
pub(crate) type ChouOrlandiSender = chou_orlandi::Sender;
pub(crate) type ChouOrlandiReceiver = chou_orlandi::Receiver;
pub(crate) type KosSender = kos::Sender<ChouOrlandiReceiver>;
pub(crate) type KosReceiver = kos::Receiver<ChouOrlandiSender>;
pub(crate) trait Sender
where
Self: Sized,
{
type Msg: Sized + AsMut<[u8]>;
async fn init<C: Channel, RNG: CryptoRng + Rng>(
channel: &C,
rng: &mut RNG,
p_to: usize,
shared_rand: &mut ChaCha20Rng,
) -> Result<Self, Error>;
async fn send<C: Channel, RNG: CryptoRng + Rng>(
&mut self,
channel: &C,
inputs: &[(Self::Msg, Self::Msg)],
rng: &mut RNG,
p_to: usize,
shared_rand: &mut ChaCha20Rng,
) -> Result<(), Error>;
}
pub(crate) trait FixedKeyInitializer
where
Self: Sized,
{
async fn init_fixed_key<C: Channel, RNG: CryptoRng + Rng>(
channel: &C,
s_: [u8; 16],
rng: &mut RNG,
p_to: usize,
shared_rand: &mut ChaCha20Rng,
) -> Result<Self, Error>;
}
pub(crate) trait Receiver
where
Self: Sized,
{
type Msg: Sized + AsMut<[u8]>;
async fn init<C: Channel, RNG: CryptoRng + Rng>(
channel: &C,
rng: &mut RNG,
p_to: usize,
shared_rand: &mut ChaCha20Rng,
) -> Result<Self, Error>;
async fn recv<C: Channel, RNG: CryptoRng + Rng>(
&mut self,
channel: &C,
inputs: &[bool],
rng: &mut RNG,
p_to: usize,
shared_rand: &mut ChaCha20Rng,
) -> Result<Vec<Self::Msg>, Error>;
}
#[allow(clippy::type_complexity)]
pub(crate) trait CorrelatedSender: Sender
where
Self: Sized,
{
async fn send_correlated<C: Channel, RNG: CryptoRng + Rng>(
&mut self,
channel: &C,
deltas: &[Self::Msg],
rng: &mut RNG,
p_to: usize,
shared_rand: &mut ChaCha20Rng,
) -> Result<Vec<(Self::Msg, Self::Msg)>, Error>;
}
pub(crate) trait CorrelatedReceiver: Receiver
where
Self: Sized,
{
async fn recv_correlated<C: Channel, RNG: CryptoRng + Rng>(
&mut self,
channel: &C,
inputs: &[bool],
rng: &mut RNG,
p_to: usize,
shared_rand: &mut ChaCha20Rng,
) -> Result<Vec<Self::Msg>, Error>;
}
pub(crate) trait SemiHonest {}
pub(crate) trait Malicious: SemiHonest {}