-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* refactor co15 * fix comments * remove old message type * fix comments * fix itybity dep * update OT traits * seed receiver with cointoss * updated comments and error * cointoss -> coin toss * change choice log to Vec<bool> * comments * last PR feedback
- Loading branch information
Showing
43 changed files
with
2,248 additions
and
3,444 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,71 +1,36 @@ | ||
use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion}; | ||
use itybity::IntoBits; | ||
use criterion::{black_box, criterion_group, criterion_main, BenchmarkId, Criterion}; | ||
use mpz_core::Block; | ||
use mpz_ot_core::{DhOtReceiver, DhOtSender, Kos15Receiver, Kos15Sender}; | ||
use mpz_ot_core::chou_orlandi; | ||
use rand::{RngCore, SeedableRng}; | ||
use rand_chacha::ChaCha12Rng; | ||
|
||
fn base_ot(c: &mut Criterion) { | ||
let mut group = c.benchmark_group("base_ot"); | ||
for n in [256, 1024, 4096] { | ||
fn chou_orlandi(c: &mut Criterion) { | ||
let mut group = c.benchmark_group("chou_orlandi"); | ||
for n in [128, 256, 1024] { | ||
group.bench_with_input(BenchmarkId::from_parameter(n), &n, |b, &n| { | ||
let msgs = vec![[Block::ONES; 2]; n]; | ||
let mut rng = ChaCha12Rng::from_entropy(); | ||
let mut choice = vec![0u8; n / 8]; | ||
rng.fill_bytes(&mut choice); | ||
let choice = choice.into_msb0_vec(); | ||
let mut choices = vec![0u8; n / 8]; | ||
rng.fill_bytes(&mut choices); | ||
b.iter(|| { | ||
let mut sender = DhOtSender::default(); | ||
let sender_setup = sender.setup(&mut rng).unwrap(); | ||
let sender = chou_orlandi::Sender::default(); | ||
let receiver = chou_orlandi::Receiver::default(); | ||
|
||
let mut receiver = DhOtReceiver::default(); | ||
let (sender_setup, mut sender) = sender.setup(); | ||
let mut receiver = receiver.setup(sender_setup); | ||
|
||
let receiver_setup = receiver.setup(&mut rng, &choice, sender_setup).unwrap(); | ||
let send = sender.send(&msgs, receiver_setup).unwrap(); | ||
let _ = receiver.receive(send).unwrap(); | ||
}) | ||
}); | ||
} | ||
} | ||
|
||
fn ext_ot(c: &mut Criterion) { | ||
let mut group = c.benchmark_group("ext_ot"); | ||
for n in [256, 1024, 4096, 12288, 40960] { | ||
group.bench_with_input(BenchmarkId::from_parameter(n), &n, |b, &n| { | ||
let msgs = vec![[Block::ONES; 2]; n]; | ||
let mut rng = ChaCha12Rng::from_entropy(); | ||
let mut choice = vec![0u8; n / 8]; | ||
rng.fill_bytes(&mut choice); | ||
let choice = choice.into_msb0_vec(); | ||
b.iter(|| { | ||
let receiver = Kos15Receiver::default(); | ||
let (receiver, base_sender_setup) = receiver.base_setup().unwrap(); | ||
|
||
let sender = Kos15Sender::default(); | ||
let (sender, base_receiver_setup) = sender.base_setup(base_sender_setup).unwrap(); | ||
|
||
let (receiver, send_seeds) = receiver.base_send(base_receiver_setup).unwrap(); | ||
let sender = sender.base_receive(send_seeds).unwrap(); | ||
let (mut receiver, receiver_setup) = receiver.extension_setup(&choice).unwrap(); | ||
let mut sender = sender | ||
.extension_setup(choice.len(), receiver_setup) | ||
.unwrap(); | ||
|
||
let send = sender.send(&msgs).unwrap(); | ||
let _received = receiver.receive(send).unwrap(); | ||
let receiver_payload = receiver.receive_random(choices.as_slice()); | ||
let sender_payload = sender.send(&msgs, receiver_payload).unwrap(); | ||
black_box(receiver.receive(sender_payload).unwrap()) | ||
}) | ||
}); | ||
} | ||
} | ||
|
||
criterion_group! { | ||
name = base_ot_benches; | ||
name = chou_orlandi_benches; | ||
config = Criterion::default().sample_size(50); | ||
targets = base_ot | ||
targets = chou_orlandi | ||
} | ||
criterion_group! { | ||
name = ext_ot_benches; | ||
config = Criterion::default().sample_size(50); | ||
targets = ext_ot | ||
} | ||
criterion_main!(base_ot_benches, ext_ot_benches); | ||
|
||
criterion_main!(chou_orlandi_benches); |
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 |
---|---|---|
@@ -1,46 +1,33 @@ | ||
// This example demonstrates how to securely and privately transfer data using OT extension. | ||
// This example demonstrates how to securely and privately transfer data using OT. | ||
// In practical situations data would be communicated over a channel such as TCP. | ||
// For simplicity, this example shows how to use OT components in memory. | ||
// For simplicity, this example shows how to use CO15 OT in memory. | ||
|
||
use mpz_core::Block; | ||
use mpz_ot_core::dh_ot::{DhOtReceiver, DhOtSender}; | ||
use rand::thread_rng; | ||
use mpz_ot_core::chou_orlandi::{Receiver, Sender}; | ||
|
||
pub fn main() { | ||
let mut rng = thread_rng(); | ||
|
||
// Receiver choice bits | ||
let choice = vec![false, true, false, false, true, true, false, true]; | ||
let choices = vec![false, true, false, false, true, true, false, true]; | ||
|
||
println!("Receiver choices: {:?}", &choice); | ||
println!("Receiver choices: {:?}", &choices); | ||
|
||
// Sender messages the receiver chooses from | ||
let inputs = [ | ||
[Block::new(0), Block::new(1)], | ||
[Block::new(2), Block::new(3)], | ||
[Block::new(4), Block::new(5)], | ||
[Block::new(6), Block::new(7)], | ||
[Block::new(8), Block::new(9)], | ||
[Block::new(10), Block::new(11)], | ||
[Block::new(12), Block::new(13)], | ||
[Block::new(14), Block::new(15)], | ||
]; | ||
let inputs = [[Block::ZERO, Block::ONES]; 8]; | ||
|
||
println!("Sender inputs: {:?}", &inputs); | ||
|
||
// First the sender creates a setup message and passes it to sender | ||
let mut sender = DhOtSender::default(); | ||
let setup = sender.setup(&mut rng).unwrap(); | ||
// First the sender creates a setup message and passes it to receiver | ||
let (sender_setup, mut sender) = Sender::default().setup(); | ||
|
||
// Receiver takes sender's setup and creates its own setup message | ||
let mut receiver = DhOtReceiver::default(); | ||
let setup = receiver.setup(&mut rng, &choice, setup).unwrap(); | ||
// Receiver takes sender's setup and generates the receiver payload | ||
let mut receiver = Receiver::default().setup(sender_setup); | ||
let receiver_payload = receiver.receive_random(&choices); | ||
|
||
// Finally, sender encrypts their inputs and sends them to receiver | ||
let payload = sender.send(&inputs, setup).unwrap(); | ||
let sender_payload = sender.send(&inputs, receiver_payload).unwrap(); | ||
|
||
// Receiver takes the encrypted inputs and is able to decrypt according to their choice bits | ||
let received = receiver.receive(payload).unwrap(); | ||
let received = receiver.receive(sender_payload).unwrap(); | ||
|
||
println!("Transferred messages: {:?}", received); | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.