Skip to content

Commit

Permalink
refactor: deprecate 'WithIo' OT traits (#93)
Browse files Browse the repository at this point in the history
  • Loading branch information
sinui0 authored Jan 17, 2024
1 parent 6e63852 commit a874783
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 124 deletions.
61 changes: 16 additions & 45 deletions ot/mpz-ot/src/ideal/owned.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use crate::{
CommittedOTReceiver, CommittedOTSender, CommittedOTSenderWithIo, OTError, OTReceiver,
OTReceiverWithIo, OTSender, OTSenderWithIo, OTSetup, VerifiableOTReceiver,
VerifiableOTReceiverWithIo, VerifiableOTSender,
CommittedOTReceiver, CommittedOTSender, OTError, OTReceiver, OTSender, OTSetup,
VerifiableOTReceiver, VerifiableOTSender,
};
use async_trait::async_trait;
use futures::{
Expand Down Expand Up @@ -79,16 +78,6 @@ where
_stream: &mut St,
msgs: &[[T; 2]],
) -> Result<(), OTError> {
<Self as OTSenderWithIo<[T; 2]>>::send(self, msgs).await
}
}

#[async_trait]
impl<T> OTSenderWithIo<[T; 2]> for IdealOTSender<T>
where
T: Send + Sync + Clone + 'static,
{
async fn send(&mut self, msgs: &[[T; 2]]) -> Result<(), OTError> {
self.msgs.extend(msgs.iter().cloned());

self.sender
Expand Down Expand Up @@ -124,16 +113,6 @@ where
_stream: &mut St,
choices: &[bool],
) -> Result<Vec<T>, OTError> {
<Self as OTReceiverWithIo<bool, T>>::receive(self, choices).await
}
}

#[async_trait]
impl<T> OTReceiverWithIo<bool, T> for IdealOTReceiver<T>
where
T: Send + Sync + 'static,
{
async fn receive(&mut self, choices: &[bool]) -> Result<Vec<T>, OTError> {
self.choices.extend(choices.iter().copied());

let payload = self
Expand Down Expand Up @@ -174,16 +153,6 @@ where
}
}

#[async_trait]
impl<T> VerifiableOTReceiverWithIo<[T; 2]> for IdealOTReceiver<T>
where
T: Send + Sync + 'static,
{
async fn verify(&mut self, _msgs: &[[T; 2]]) -> Result<(), OTError> {
Ok(())
}
}

#[async_trait]
impl<T> CommittedOTSender<[T; 2]> for IdealOTSender<T>
where
Expand All @@ -198,16 +167,6 @@ where
}
}

#[async_trait]
impl<T> CommittedOTSenderWithIo for IdealOTSender<T>
where
T: Send + 'static,
{
async fn reveal(&mut self) -> Result<(), OTError> {
Ok(())
}
}

#[async_trait]
impl<T> CommittedOTReceiver<bool, T> for IdealOTReceiver<T>
where
Expand Down Expand Up @@ -249,20 +208,32 @@ where

#[cfg(test)]
mod tests {
use utils_aio::duplex::MemoryDuplex;

use super::*;

// Test that the sender and receiver can be used to send and receive values
#[tokio::test]
async fn test_ideal_ot_owned() {
let (send_channel, recv_channel) = MemoryDuplex::<()>::new();

let (mut send_sink, mut send_stream) = send_channel.split();
let (mut recv_sink, mut recv_stream) = recv_channel.split();

let values = vec![[0, 1], [2, 3]];
let choices = vec![false, true];
let (mut sender, mut receiver) = ideal_ot_pair::<u8>();

OTSenderWithIo::send(&mut sender, &values).await.unwrap();
sender
.send(&mut send_sink, &mut send_stream, &values)
.await
.unwrap();

let received = OTReceiverWithIo::receive(&mut receiver, &choices)
let received = receiver
.receive(&mut recv_sink, &mut recv_stream, &choices)
.await
.unwrap();

assert_eq!(received, vec![0, 3]);
}
}
79 changes: 0 additions & 79 deletions ot/mpz-ot/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -291,82 +291,3 @@ pub trait VerifiableOTReceiverShared<T, U, V>: OTReceiverShared<T, U> {
/// * `msgs` - The purported messages sent by the sender.
async fn verify(&self, id: &str, msgs: &[V]) -> Result<(), OTError>;
}

// ########################################################################
// ############################## With IO #################################
// ########################################################################

/// An oblivious transfer sender that owns its own IO channels.
#[async_trait]
pub trait OTSenderWithIo<T>
where
T: Send + Sync,
{
/// Obliviously transfers the messages to the receiver.
///
/// # Arguments
///
/// * `msgs` - The messages to obliviously transfer.
async fn send(&mut self, msgs: &[T]) -> Result<(), OTError>;
}

/// An oblivious transfer sender that owns its own IO channels, and
/// can reveal its messages.
#[async_trait]
pub trait CommittedOTSenderWithIo {
/// Reveals all messages sent to the receiver.
///
/// # Warning
///
/// Obviously, you should be sure you want to do this before calling this function!
async fn reveal(&mut self) -> Result<(), OTError>;
}

/// An oblivious transfer sender that owns its own IO Channels,
/// and can verify the receiver's choices.
#[async_trait]
pub trait VerifiableOTSenderWithIo<T> {
/// Receives the purported choices made by the receiver and verifies them.
async fn verify_choices(&mut self) -> Result<T, OTError>;
}

/// An oblivious transfer receiver that owns its own IO channels.
#[async_trait]
pub trait OTReceiverWithIo<T, U>
where
T: Send + Sync,
U: Send + Sync,
{
/// Obliviously receives data from the sender.
///
/// # Arguments
///
/// * `choices` - The choices made by the receiver.
async fn receive(&mut self, choices: &[T]) -> Result<Vec<U>, OTError>;
}

/// An oblivious transfer receiver that can reveal its choices.
#[async_trait]
pub trait CommittedOTReceiverWithIo {
/// Reveals the choices made by the receiver.
///
/// # Warning
///
/// Obviously, you should be sure you want to do this before calling this function!
async fn reveal_choices(&mut self) -> Result<(), OTError>;
}

/// An oblivious transfer receiver that owns its own IO channels, and
/// can verify the sender's messages.
#[async_trait]
pub trait VerifiableOTReceiverWithIo<T>
where
T: Send + Sync,
{
/// Verifies purported messages sent by the sender.
///
/// # Arguments
///
/// * `msgs` - The purported messages sent by the sender.
async fn verify(&mut self, msgs: &[T]) -> Result<(), OTError>;
}

0 comments on commit a874783

Please sign in to comment.