Skip to content

Commit

Permalink
Add more feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
th4s committed Feb 27, 2024
1 parent 34e0809 commit ad39a0a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 19 deletions.
2 changes: 2 additions & 0 deletions mpz-core/src/prg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ impl CryptoRng for PrgCore {}
#[derive(Clone)]
pub struct Prg(BlockRng<PrgCore>);

opaque_debug::implement!(Prg);

impl RngCore for Prg {
#[inline(always)]
fn next_u32(&mut self) -> u32 {
Expand Down
28 changes: 9 additions & 19 deletions ot/mpz-ot-core/src/ideal/ideal_rot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ pub struct RotMsgForReceiver {
}

/// An ideal functionality for random OT
#[derive(Debug)]
pub struct IdealROT {
counter: usize,
prg: Prg,
Expand Down Expand Up @@ -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 {
Expand All @@ -86,14 +70,20 @@ impl Default for IdealROT {

#[cfg(test)]
mod tests {
use super::IdealROT;
use super::{IdealROT, RotMsgForReceiver};

#[test]
fn ideal_rot_test() {
let num = 100;
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));
}
}

0 comments on commit ad39a0a

Please sign in to comment.