p_ot.rs 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. use criterion::{black_box, criterion_group, criterion_main, BenchmarkId, Criterion};
  2. use oram::p_ot::{POTIndexParty, POTKeyParty, POTReceiverParty};
  3. use rand::{thread_rng, Rng};
  4. use utils::field::Fp;
  5. use utils::permutation::FisherYatesPermutation;
  6. const LOG_DOMAIN_SIZES: [u32; 4] = [8, 12, 16, 20];
  7. pub fn bench_pot(c: &mut Criterion) {
  8. let mut group = c.benchmark_group("POT");
  9. for log_domain_size in LOG_DOMAIN_SIZES {
  10. group.bench_with_input(
  11. BenchmarkId::new("init", log_domain_size),
  12. &log_domain_size,
  13. |b, &log_domain_size| {
  14. let mut key_party =
  15. POTKeyParty::<Fp, FisherYatesPermutation>::new(1 << log_domain_size);
  16. let mut index_party =
  17. POTIndexParty::<Fp, FisherYatesPermutation>::new(1 << log_domain_size);
  18. let mut receiver_party = POTReceiverParty::<Fp>::new(1 << log_domain_size);
  19. b.iter(|| {
  20. key_party.reset();
  21. index_party.reset();
  22. receiver_party.reset();
  23. let (msg_to_index_party, msg_to_receiver_party) = key_party.init();
  24. index_party.init(msg_to_index_party.0, msg_to_index_party.1);
  25. receiver_party.init(msg_to_receiver_party);
  26. });
  27. },
  28. );
  29. group.bench_with_input(
  30. BenchmarkId::new("expand", log_domain_size),
  31. &log_domain_size,
  32. |b, &log_domain_size| {
  33. let mut key_party =
  34. POTKeyParty::<Fp, FisherYatesPermutation>::new(1 << log_domain_size);
  35. key_party.init();
  36. b.iter(|| {
  37. black_box(key_party.expand());
  38. });
  39. },
  40. );
  41. group.bench_with_input(
  42. BenchmarkId::new("access", log_domain_size),
  43. &log_domain_size,
  44. |b, &log_domain_size| {
  45. let mut key_party =
  46. POTKeyParty::<Fp, FisherYatesPermutation>::new(1 << log_domain_size);
  47. let mut index_party =
  48. POTIndexParty::<Fp, FisherYatesPermutation>::new(1 << log_domain_size);
  49. let mut receiver_party = POTReceiverParty::<Fp>::new(1 << log_domain_size);
  50. let (msg_to_index_party, msg_to_receiver_party) = key_party.init();
  51. index_party.init(msg_to_index_party.0, msg_to_index_party.1);
  52. receiver_party.init(msg_to_receiver_party);
  53. let index = thread_rng().gen_range(0..1 << log_domain_size);
  54. b.iter(|| {
  55. let msg_to_receiver_party = index_party.access(index);
  56. let output =
  57. receiver_party.access(msg_to_receiver_party.0, msg_to_receiver_party.1);
  58. black_box(output);
  59. });
  60. },
  61. );
  62. }
  63. group.finish();
  64. }
  65. criterion_group!(
  66. name = benches;
  67. config = Criterion::default().sample_size(10);
  68. targets = bench_pot
  69. );
  70. criterion_main!(benches);