Browse Source

Construct PIR preprocess queries in parallel

This relies on the client_mt multithreaded client fork of the spiral-rs
crate.
Ian Goldberg 1 year ago
parent
commit
8232fabb6d
2 changed files with 15 additions and 9 deletions
  1. 2 1
      Cargo.toml
  2. 13 8
      src/client.rs

+ 2 - 1
Cargo.toml

@@ -16,11 +16,12 @@ curve25519-dalek = { package = "curve25519-dalek-ng", version = "3", default-fea
 lazy_static = "1"
 sha2 = "0.9"
 subtle = { package = "subtle-ng", version = "2.4" }
-spiral-rs = { git = "https://github.com/menonsamir/spiral-rs/", rev = "0f9bdc157" }
+spiral-rs = { git = "https://git-crysp.uwaterloo.ca/iang/spiral-rs-fork/", branch = "client_mt" }
 rayon = "1.5"
 bincode = "1"
 serde = "1"
 serde_with = "2"
+rand_chacha = "0.3"
 
 [lib]
 crate_type = ["lib", "staticlib"]

+ 13 - 8
src/client.rs

@@ -12,6 +12,9 @@ use rayon::prelude::*;
 
 use subtle::Choice;
 
+use rand::SeedableRng;
+use rand_chacha::ChaCha20Rng;
+
 use curve25519_dalek::scalar::Scalar;
 
 use crate::dbentry_decrypt;
@@ -61,9 +64,7 @@ impl Client {
         let (outgoing_resp_send, outgoing_resp) = sync_channel(0);
         spawn(move || {
             let spiral_params = params::get_spiral_params(r);
-            let mut clientrng = rand::thread_rng();
-            let mut rng = rand::thread_rng();
-            let mut spiral_client = spiral_rs::client::Client::init(&spiral_params, &mut clientrng);
+            let mut spiral_client = spiral_rs::client::Client::init(&spiral_params, ChaCha20Rng::from_entropy);
             let num_records = 1 << r;
             let num_records_mask = num_records - 1;
             let spiral_blocking_factor = spiral_params.db_item_size / mem::size_of::<DbEntry>();
@@ -92,17 +93,21 @@ impl Client {
                         // preprocessing state
                         assert!(preproc_out_state.is_empty());
                         let mut preproc_msg: Vec<PreProcSingleMsg> = Vec::new();
-                        for _ in 0..num_preproc {
+                        (0..num_preproc)
+                        .into_par_iter()
+                        .map(|_| {
+                            let mut rng = rand::thread_rng();
                             let rand_idx = (rng.next_u64() as usize) & num_records_mask;
                             let rand_pir_idx = rand_idx / spiral_blocking_factor;
                             let spc_query = spiral_client.generate_query(rand_pir_idx).serialize();
                             let (ot_state, ot_query) = otkey_request(rand_idx, r);
-                            preproc_out_state.push(PreProcOutSingleState { rand_idx, ot_state });
-                            preproc_msg.push(PreProcSingleMsg {
+                            (PreProcOutSingleState { rand_idx, ot_state },
+                            PreProcSingleMsg {
                                 ot_query,
                                 spc_query,
-                            });
-                        }
+                            })
+                        })
+                        .unzip_into_vecs(&mut preproc_out_state, &mut preproc_msg);
                         let ret: Vec<u8> = bincode::serialize(&preproc_msg).unwrap();
                         outgoing_resp_send.send(Response::PreProcMsg(ret)).unwrap();
                     }