Skip to content

Commit

Permalink
refactor: mpz-ot
Browse files Browse the repository at this point in the history
  • Loading branch information
sinui0 committed Mar 7, 2024
1 parent 91be7e6 commit d62a404
Show file tree
Hide file tree
Showing 34 changed files with 776 additions and 3,265 deletions.
23 changes: 1 addition & 22 deletions ot/mpz-ot-core/src/chou_orlandi/msgs.rs
Original file line number Diff line number Diff line change
@@ -1,30 +1,9 @@
//! Messages for the Chou-Orlandi protocol.
use curve25519_dalek::RistrettoPoint;
use enum_try_as_inner::EnumTryAsInner;
use mpz_core::{cointoss, Block};
use mpz_core::Block;
use serde::{Deserialize, Serialize};

/// A CO15 protocol message.
#[derive(Debug, Clone, EnumTryAsInner, Serialize, Deserialize)]
#[derive_err(Debug)]
#[allow(missing_docs)]
pub enum Message {
SenderSetup(SenderSetup),
SenderPayload(SenderPayload),
ReceiverPayload(ReceiverPayload),
ReceiverReveal(ReceiverReveal),
CointossSenderCommitment(cointoss::msgs::SenderCommitment),
CointossSenderPayload(cointoss::msgs::SenderPayload),
CointossReceiverPayload(cointoss::msgs::ReceiverPayload),
}

impl From<MessageError> for std::io::Error {
fn from(err: MessageError) -> Self {
std::io::Error::new(std::io::ErrorKind::InvalidData, err.to_string())
}
}

/// Sender setup message.
#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize)]
pub struct SenderSetup {
Expand Down
1 change: 1 addition & 0 deletions ot/mpz-ot-core/src/kos/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ mod tests {

use rand::Rng;
use rand_chacha::ChaCha12Rng;
use rand_core::SeedableRng;

#[fixture]
fn choices() -> Vec<bool> {
Expand Down
33 changes: 1 addition & 32 deletions ot/mpz-ot-core/src/kos/msgs.rs
Original file line number Diff line number Diff line change
@@ -1,39 +1,8 @@
//! Messages for the KOS15 protocol.
use enum_try_as_inner::EnumTryAsInner;
use mpz_core::{
cointoss::msgs::{
ReceiverPayload as CointossReceiverPayload, SenderCommitment,
SenderPayload as CointossSenderPayload,
},
Block,
};
use mpz_core::Block;
use serde::{Deserialize, Serialize};

use crate::msgs::Derandomize;

/// A KOS15 protocol message.
#[derive(Debug, Clone, EnumTryAsInner, Serialize, Deserialize)]
#[derive_err(Debug)]
#[allow(missing_docs)]
pub enum Message<BaseMsg> {
BaseMsg(BaseMsg),
StartExtend(StartExtend),
Extend(Extend),
Check(Check),
Derandomize(Derandomize),
SenderPayload(SenderPayload),
CointossCommit(SenderCommitment),
CointossReceiverPayload(CointossReceiverPayload),
CointossSenderPayload(CointossSenderPayload),
}

impl<BaseMsg> From<MessageError<BaseMsg>> for std::io::Error {
fn from(err: MessageError<BaseMsg>) -> Self {
std::io::Error::new(std::io::ErrorKind::InvalidData, err.to_string())
}
}

/// Extension message sent by the receiver to agree upon the number of OTs to set up.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct StartExtend {
Expand Down
11 changes: 8 additions & 3 deletions ot/mpz-ot-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,14 @@
//!
//! USE AT YOUR OWN RISK.
#![deny(missing_docs, unreachable_pub, unused_must_use)]
#![deny(unsafe_code)]
#![deny(clippy::all)]
#![deny(
unsafe_code,
missing_docs,
unused_imports,
unused_must_use,
unreachable_pub,
clippy::all
)]

pub mod chou_orlandi;
pub mod ferret;
Expand Down
13 changes: 7 additions & 6 deletions ot/mpz-ot/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,20 @@ edition = "2021"
name = "mpz_ot"

[features]
default = ["ideal", "rayon", "actor"]
default = ["ideal", "rayon"]
rayon = ["mpz-ot-core/rayon"]
actor = ["dep:serde"]
ideal = []

[dependencies]
mpz-core.workspace = true
mpz-common.workspace = true
mpz-cointoss.workspace = true
mpz-ot-core.workspace = true

tlsn-utils-aio.workspace = true

async-trait.workspace = true
prost.workspace = true
futures.workspace = true
futures-util.workspace = true
aes.workspace = true
cipher.workspace = true
rand.workspace = true
rand_core.workspace = true
rand_chacha.workspace = true
Expand All @@ -32,9 +31,11 @@ itybity.workspace = true
enum-try-as-inner.workspace = true
opaque-debug.workspace = true
serde = { workspace = true, optional = true }
serio.workspace = true
cfg-if.workspace = true

[dev-dependencies]
mpz-common = { workspace = true, features = ["test-utils"] }
rstest = { workspace = true }
criterion = { workspace = true, features = ["async_tokio"] }
tokio = { workspace = true, features = [
Expand Down
43 changes: 18 additions & 25 deletions ot/mpz-ot/benches/ot.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
use criterion::{black_box, criterion_group, criterion_main, BenchmarkId, Criterion};
use futures_util::StreamExt;
use mpz_common::executor::test_st_executor;
use mpz_core::Block;
use mpz_ot::{
chou_orlandi::{Receiver, ReceiverConfig, Sender, SenderConfig},
chou_orlandi::{Receiver, Sender},
OTReceiver, OTSender, OTSetup,
};
use utils_aio::duplex::MemoryDuplex;

fn chou_orlandi(c: &mut Criterion) {
let rt = tokio::runtime::Runtime::new().unwrap();
Expand All @@ -15,28 +14,22 @@ fn chou_orlandi(c: &mut Criterion) {
let msgs = vec![[Block::ONES; 2]; n];
let choices = vec![false; n];
b.to_async(&rt).iter(|| async {
let (sender_channel, receiver_channel) = MemoryDuplex::new();
let (mut sender_sink, mut sender_stream) = sender_channel.split();
let (mut receiver_sink, mut receiver_stream) = receiver_channel.split();

let mut sender = Sender::new(SenderConfig::default());
let mut receiver = Receiver::new(ReceiverConfig::default());

let (sender_res, receiver_res) = futures::join!(
sender.setup(&mut sender_sink, &mut sender_stream),
receiver.setup(&mut receiver_sink, &mut receiver_stream)
);

sender_res.unwrap();
receiver_res.unwrap();

let (sender_res, receiver_res) = futures::join!(
sender.send(&mut sender_sink, &mut sender_stream, &msgs),
receiver.receive(&mut receiver_sink, &mut receiver_stream, &choices)
);

sender_res.unwrap();
let received = receiver_res.unwrap();
let (mut sender_ctx, mut receiver_ctx) = test_st_executor(8);

let mut sender = Sender::default();
let mut receiver = Receiver::default();

futures::try_join!(
sender.setup(&mut sender_ctx),
receiver.setup(&mut receiver_ctx)
)
.unwrap();

let (_, received) = futures::try_join!(
sender.send(&mut sender_ctx, &msgs),
receiver.receive(&mut receiver_ctx, &choices)
)
.unwrap();

black_box(received)
})
Expand Down
144 changes: 0 additions & 144 deletions ot/mpz-ot/src/actor/kos/error.rs

This file was deleted.

Loading

0 comments on commit d62a404

Please sign in to comment.