Skip to content
This repository has been archived by the owner on Dec 20, 2019. It is now read-only.

Commit

Permalink
add mask for bundles
Browse files Browse the repository at this point in the history
  • Loading branch information
Brent Carmer committed Jun 3, 2019
1 parent 257b763 commit 8fe20f5
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/dummy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,25 @@ mod bundle {
}
}

#[test]
fn test_mask() {
let mut rng = thread_rng();
for _ in 0..NITERS {
let q = crate::util::modulus_with_nprimes(4 + rng.gen_usize() % 7);
let x = rng.gen_u128() % q;
let b = rng.gen_bool();
let mut d = Dummy::new();
{
let b = d.encode(b as u16, 2).unwrap();
let x = d.crt_encode(x, q).unwrap();
let z = d.mask(&b, &x).unwrap();
d.output_bundle(&z).unwrap();
}
let z = crt_inv_factor(&d.get_output(), q);
assert!(if b { z == x } else { z == 0 }, "b={} x={} z={}", b, x, z);
}
}

#[test]
fn binary_abs() {
let mut rng = thread_rng();
Expand Down
13 changes: 13 additions & 0 deletions src/fancy/bundle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,19 @@ pub trait BundleGadgets: Fancy {
.map(Bundle)
}

/// If b=0 then return 0, else return x.
fn mask(
&mut self,
b: &Self::Item,
x: &Bundle<Self::Item>,
) -> Result<Bundle<Self::Item>, Self::Error> {
x.wires()
.iter()
.map(|xwire| self.mul(xwire, b))
.collect::<Result<Vec<Self::Item>, Self::Error>>()
.map(Bundle)
}

/// Shift residues, replacing them with zeros in the modulus of the least signifigant residue.
fn shift(
&mut self,
Expand Down

0 comments on commit 8fe20f5

Please sign in to comment.