|
@@ -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();
|
|
|
}
|