1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
use super::*;
use crate::util;
pub trait FancyReveal: Fancy {
fn reveal(&mut self, x: &Self::Item) -> Result<u16, Self::Error>;
fn reveal_many(&mut self, xs: &[Self::Item]) -> Result<Vec<u16>, Self::Error> {
let mut zs = Vec::with_capacity(xs.len());
for x in xs.iter() {
zs.push(self.reveal(x)?);
}
Ok(zs)
}
fn reveal_bundle(&mut self, x: &Bundle<Self::Item>) -> Result<Vec<u16>, Self::Error> {
self.reveal_many(x.wires())
}
fn reveal_many_bundles(
&mut self,
xs: &[Bundle<Self::Item>],
) -> Result<Vec<Vec<u16>>, Self::Error> {
let mut zs = Vec::with_capacity(xs.len());
for x in xs.iter() {
zs.push(self.reveal_bundle(x)?);
}
Ok(zs)
}
fn crt_reveal(&mut self, x: &CrtBundle<Self::Item>) -> Result<u128, Self::Error> {
let q = x.composite_modulus();
let xs = self.reveal_many(x.wires())?;
Ok(util::crt_inv_factor(&xs, q))
}
fn crt_reveal_many(&mut self, xs: &[CrtBundle<Self::Item>]) -> Result<Vec<u128>, Self::Error> {
let mut zs = Vec::with_capacity(xs.len());
for x in xs.iter() {
zs.push(self.crt_reveal(x)?);
}
Ok(zs)
}
fn bin_reveal(&mut self, x: &BinaryBundle<Self::Item>) -> Result<u128, Self::Error> {
let bits = self.reveal_many(x.wires())?;
Ok(util::u128_from_bits(&bits))
}
fn bin_reveal_many(
&mut self,
xs: &[BinaryBundle<Self::Item>],
) -> Result<Vec<u128>, Self::Error> {
let mut zs = Vec::with_capacity(xs.len());
for x in xs.iter() {
zs.push(self.bin_reveal(x)?);
}
Ok(zs)
}
}