-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
commit 2f35271 Author: sinu.eth <[email protected]> Date: Fri May 31 06:36:31 2024 -0700 feat(mpz-common): scoped! macro (#143) commit 9b51bd4 Author: sinu.eth <[email protected]> Date: Fri May 31 06:35:16 2024 -0700 feat(mpz-common): Context::blocking (#141) * feat(mpz-common): Context::blocking * Apply suggestions from code review Co-authored-by: dan <[email protected]> --------- Co-authored-by: dan <[email protected]> commit 8f0b298 Author: th4s <[email protected]> Date: Fri May 31 10:30:08 2024 +0200 Add IO wrapper for OLE (#138) * Add `mpz-ole` content of old branch. * Reworked message enum. * Refactored to work with new `mpz-ole-core`. * Add part of feedback. * Add more feedback. * Add opaque error type. * Add `Display` for `OLEErrorKind` * Use `ok_or_elese` for lazy heap alloc. * Adapted `mpz-ole` to `hybrid-array`. * WIP: Improving API of const generics... * Add random OT for `hybrid-array`. * Adapt `mpz-ole` to use new random OT. * Added feedback. * Use random OT over field elements instead of arrays. * Refactored ideal implementation to use `mpz-common`. * Added more feedback.
- Loading branch information
Showing
14 changed files
with
573 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
[package] | ||
name = "mpz-ole" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[lib] | ||
name = "mpz_ole" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[features] | ||
ideal = ["mpz-common/ideal"] | ||
|
||
[dependencies] | ||
mpz-fields.workspace = true | ||
mpz-ot.workspace = true | ||
mpz-core.workspace = true | ||
mpz-ole-core.workspace = true | ||
mpz-common.workspace = true | ||
|
||
serio.workspace = true | ||
|
||
thiserror.workspace = true | ||
async-trait.workspace = true | ||
futures.workspace = true | ||
rand.workspace = true | ||
itybity.workspace = true | ||
|
||
[dev-dependencies] | ||
tokio = { workspace = true, features = [ | ||
"net", | ||
"macros", | ||
"rt", | ||
"rt-multi-thread", | ||
] } | ||
mpz-common = { workspace = true, features = ["test-utils", "ideal"] } | ||
mpz-ot = { workspace = true, features = ["ideal"] } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
//! Ideal OLE implementation. | ||
use crate::{OLEError, OLEReceiver, OLESender}; | ||
use async_trait::async_trait; | ||
use mpz_common::{ | ||
ideal::{ideal_f2p, Alice, Bob}, | ||
Context, | ||
}; | ||
use mpz_fields::Field; | ||
use rand::thread_rng; | ||
|
||
/// Ideal OLESender. | ||
pub struct IdealOLESender(Alice<()>); | ||
|
||
/// Ideal OLEReceiver. | ||
pub struct IdealOLEReceiver(Bob<()>); | ||
|
||
/// Returns an OLE sender and receiver pair. | ||
pub fn ideal_ole() -> (IdealOLESender, IdealOLEReceiver) { | ||
let (alice, bob) = ideal_f2p(()); | ||
|
||
(IdealOLESender(alice), IdealOLEReceiver(bob)) | ||
} | ||
|
||
fn ole<F: Field>(_: &mut (), alice_input: Vec<F>, bob_input: Vec<F>) -> (Vec<F>, Vec<F>) { | ||
let mut rng = thread_rng(); | ||
let alice_output: Vec<F> = (0..alice_input.len()).map(|_| F::rand(&mut rng)).collect(); | ||
|
||
let bob_output: Vec<F> = alice_input | ||
.iter() | ||
.zip(bob_input.iter()) | ||
.zip(alice_output.iter().copied()) | ||
.map(|((&a, &b), x)| a * b + x) | ||
.collect(); | ||
|
||
(alice_output, bob_output) | ||
} | ||
|
||
#[async_trait] | ||
impl<F: Field, Ctx: Context> OLESender<Ctx, F> for IdealOLESender { | ||
async fn send(&mut self, ctx: &mut Ctx, a_k: Vec<F>) -> Result<Vec<F>, OLEError> { | ||
Ok(self.0.call(ctx, a_k, ole).await) | ||
} | ||
} | ||
|
||
#[async_trait] | ||
impl<F: Field, Ctx: Context> OLEReceiver<Ctx, F> for IdealOLEReceiver { | ||
async fn receive(&mut self, ctx: &mut Ctx, b_k: Vec<F>) -> Result<Vec<F>, OLEError> { | ||
Ok(self.0.call(ctx, b_k, ole).await) | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use crate::{ideal::ideal_ole, OLEReceiver, OLESender}; | ||
use mpz_common::executor::test_st_executor; | ||
use mpz_core::{prg::Prg, Block}; | ||
use mpz_fields::{p256::P256, UniformRand}; | ||
use rand::SeedableRng; | ||
|
||
#[tokio::test] | ||
async fn test_ideal_ole() { | ||
let count = 12; | ||
let mut rng = Prg::from_seed(Block::ZERO); | ||
|
||
let a_k: Vec<P256> = (0..count).map(|_| P256::rand(&mut rng)).collect(); | ||
let b_k: Vec<P256> = (0..count).map(|_| P256::rand(&mut rng)).collect(); | ||
|
||
let (mut ctx_sender, mut ctx_receiver) = test_st_executor(10); | ||
|
||
let (mut sender, mut receiver) = ideal_ole(); | ||
|
||
let (x_k, y_k) = tokio::try_join!( | ||
sender.send(&mut ctx_sender, a_k.clone()), | ||
receiver.receive(&mut ctx_receiver, b_k.clone()) | ||
) | ||
.unwrap(); | ||
|
||
assert_eq!(x_k.len(), count); | ||
assert_eq!(y_k.len(), count); | ||
a_k.iter() | ||
.zip(b_k) | ||
.zip(x_k) | ||
.zip(y_k) | ||
.for_each(|(((&a, b), x), y)| assert_eq!(y, a * b + x)); | ||
} | ||
} |
Oops, something went wrong.