diff --git a/ooniauth-core/benches/bench_server.rs b/ooniauth-core/benches/bench_server.rs index 4f83772..b2533bb 100644 --- a/ooniauth-core/benches/bench_server.rs +++ b/ooniauth-core/benches/bench_server.rs @@ -15,7 +15,7 @@ fn setup() -> (ThreadRng, UserState, ServerState) { // For now we will only care about server functions, specially handling submit and // registration, since those are the most important bottleneck for our backend fn bench_registration(c: &mut Criterion) { - let (mut rng, user, mut server) = setup(); + let (mut rng, user, server) = setup(); // Create the request let (registration_req, _) = user.request(&mut rng).unwrap(); @@ -25,14 +25,14 @@ fn bench_registration(c: &mut Criterion) { } fn bench_submit(c: &mut Criterion) { - let (mut rng, mut user, mut server) = setup(); + let (mut rng, mut user, server) = setup(); c.bench_function("server.handle_submit", |b| { let (registration_req, reg_state) = user.request(&mut rng).unwrap(); let resp = server.open_registration(registration_req).unwrap(); user.handle_response(reg_state, resp) .expect("Should handle response properly"); - let today = server.today(); + let today = ServerState::today(); let cc = "VE"; let asn = "AS1234"; @@ -52,8 +52,8 @@ fn bench_submit(c: &mut Criterion) { black_box(&mut rng), black_box(req.clone()), black_box(&nym), - black_box(cc.into()), - black_box(asn.into()), + black_box(cc), + black_box(asn), black_box(age_range.clone()), black_box(msm_range.clone()), ) diff --git a/ooniauth-core/src/registration.rs b/ooniauth-core/src/registration.rs index 8df2697..ee3cab8 100644 --- a/ooniauth-core/src/registration.rs +++ b/ooniauth-core/src/registration.rs @@ -21,6 +21,19 @@ CMZ! { UserAuthCredential: measurement_count } +impl UserAuthCredential { + /// Set the public key and private key for this credential. Assumes the keypair is well-formed. + pub(crate) fn set_keypair( + &mut self, + privkey: CMZPrivkey, + pubkey: CMZPubkey, + ) -> &mut Self { + self.privkey = privkey; + self.pubkey = pubkey; + self + } +} + muCMZProtocol! {open_registration, , UAC: UserAuthCredential { nym_id: J, age: S, measurement_count: I}, @@ -76,7 +89,7 @@ impl ServerState { SESSION_ID, recvreq, |UAC: &mut UserAuthCredential| { - UAC.set_privkey(&self.sk); + UAC.set_keypair(self.sk.clone(), self.pp.clone()); UAC.measurement_count = Some(Scalar::ZERO); UAC.age = Some(ServerState::today().into()); Ok(()) diff --git a/ooniauth-core/src/submit.rs b/ooniauth-core/src/submit.rs index 858a47d..3390383 100644 --- a/ooniauth-core/src/submit.rs +++ b/ooniauth-core/src/submit.rs @@ -170,14 +170,15 @@ impl ServerState { }; let server_sk = self.sk.clone(); + let server_pp = self.pp.clone(); match submit::handle( rng, SESSION_ID, recvreq, move |Old: &mut UserAuthCredential, New: &mut UserAuthCredential| { // Set the private key for the credentials - this is essential for the protocol - Old.set_privkey(&server_sk); - New.set_privkey(&server_sk); + Old.set_keypair(server_sk.clone(), server_pp.clone()); + New.set_keypair(server_sk.clone(), server_pp.clone()); // The protocol should populate Old and New from the client's proof // We don't set the values here - they come from the client's proof @@ -231,7 +232,7 @@ mod tests { let rng = &mut rand::thread_rng(); // Setup server and user - let mut server_state = ServerState::new(rng); + let server_state = ServerState::new(rng); let mut user_state = UserState::new(server_state.public_parameters()); // First do registration to get a credential