From ad39a0a9ffbbb76cbb999f69957e7ec0b6728c8a Mon Sep 17 00:00:00 2001 From: th4s Date: Wed, 21 Feb 2024 23:25:07 +0100 Subject: [PATCH] Add more feedback --- mpz-core/src/prg.rs | 2 ++ ot/mpz-ot-core/src/ideal/ideal_rot.rs | 28 +++++++++------------------ 2 files changed, 11 insertions(+), 19 deletions(-) diff --git a/mpz-core/src/prg.rs b/mpz-core/src/prg.rs index 0d909f45..a32c4edb 100644 --- a/mpz-core/src/prg.rs +++ b/mpz-core/src/prg.rs @@ -50,6 +50,8 @@ impl CryptoRng for PrgCore {} #[derive(Clone)] pub struct Prg(BlockRng); +opaque_debug::implement!(Prg); + impl RngCore for Prg { #[inline(always)] fn next_u32(&mut self) -> u32 { diff --git a/ot/mpz-ot-core/src/ideal/ideal_rot.rs b/ot/mpz-ot-core/src/ideal/ideal_rot.rs index cff321af..a5f2dfb8 100644 --- a/ot/mpz-ot-core/src/ideal/ideal_rot.rs +++ b/ot/mpz-ot-core/src/ideal/ideal_rot.rs @@ -20,6 +20,7 @@ pub struct RotMsgForReceiver { } /// An ideal functionality for random OT +#[derive(Debug)] pub struct IdealROT { counter: usize, prg: Prg, @@ -59,23 +60,6 @@ impl IdealROT { self.counter += counter; (RotMsgForSender { qs }, RotMsgForReceiver { rs, ts }) } - - /// Checks if the receiver gets the choices he made - /// - /// # Arguments - /// - /// * `sender_msg` - The message that the ideal ROT sends to the sender. - /// * `receiver_msg` - The message that the ideal ROT sends to the receiver. - #[cfg(test)] - fn check(&self, sender_msg: RotMsgForSender, receiver_msg: RotMsgForReceiver) -> bool { - let RotMsgForSender { qs } = sender_msg; - let RotMsgForReceiver { rs, ts } = receiver_msg; - - qs.into_iter() - .zip(ts) - .zip(rs) - .all(|((q, t), r)| if r { q[1] == t } else { q[0] == t }) - } } impl Default for IdealROT { @@ -86,7 +70,7 @@ impl Default for IdealROT { #[cfg(test)] mod tests { - use super::IdealROT; + use super::{IdealROT, RotMsgForReceiver}; #[test] fn ideal_rot_test() { @@ -94,6 +78,12 @@ mod tests { let mut ideal_rot = IdealROT::new(); let (sender, receiver) = ideal_rot.extend(num); - assert!(ideal_rot.check(sender, receiver)); + let qs = sender.qs; + let RotMsgForReceiver { rs, ts } = receiver; + + qs.iter() + .zip(ts) + .zip(rs) + .for_each(|((q, t), r)| assert_eq!(q[r as usize], t)); } }