fancy_garbling/fancy/
reveal.rs1use super::*;
2use crate::util;
3use swanky_channel::Channel;
4
5pub trait FancyReveal: Fancy {
10 fn reveal(&mut self, x: &Self::Item, channel: &mut Channel) -> swanky_error::Result<u16>;
12
13 fn reveal_many(
15 &mut self,
16 xs: &[Self::Item],
17 channel: &mut Channel,
18 ) -> swanky_error::Result<Vec<u16>> {
19 let mut zs = Vec::with_capacity(xs.len());
20 for x in xs.iter() {
21 zs.push(self.reveal(x, channel)?);
22 }
23 Ok(zs)
24 }
25
26 fn reveal_bundle(
28 &mut self,
29 x: &Bundle<Self::Item>,
30 channel: &mut Channel,
31 ) -> swanky_error::Result<Vec<u16>> {
32 self.reveal_many(x.wires(), channel)
33 }
34
35 fn reveal_many_bundles(
37 &mut self,
38 xs: &[Bundle<Self::Item>],
39 channel: &mut Channel,
40 ) -> swanky_error::Result<Vec<Vec<u16>>> {
41 let mut zs = Vec::with_capacity(xs.len());
42 for x in xs.iter() {
43 zs.push(self.reveal_bundle(x, channel)?);
44 }
45 Ok(zs)
46 }
47
48 fn crt_reveal(
50 &mut self,
51 x: &CrtBundle<Self::Item>,
52 channel: &mut Channel,
53 ) -> swanky_error::Result<u128> {
54 let q = x.composite_modulus();
55 let xs = self.reveal_many(x.wires(), channel)?;
56 Ok(util::crt_inv_factor(&xs, q))
57 }
58
59 fn crt_reveal_many(
61 &mut self,
62 xs: &[CrtBundle<Self::Item>],
63 channel: &mut Channel,
64 ) -> swanky_error::Result<Vec<u128>> {
65 let mut zs = Vec::with_capacity(xs.len());
66 for x in xs.iter() {
67 zs.push(self.crt_reveal(x, channel)?);
68 }
69 Ok(zs)
70 }
71
72 fn bin_reveal(
74 &mut self,
75 x: &BinaryBundle<Self::Item>,
76 channel: &mut Channel,
77 ) -> swanky_error::Result<u128> {
78 let bits = self.reveal_many(x.wires(), channel)?;
79 Ok(util::u128_from_bits(&bits))
80 }
81
82 fn bin_reveal_many(
84 &mut self,
85 xs: &[BinaryBundle<Self::Item>],
86 channel: &mut Channel,
87 ) -> swanky_error::Result<Vec<u128>> {
88 let mut zs = Vec::with_capacity(xs.len());
89 for x in xs.iter() {
90 zs.push(self.bin_reveal(x, channel)?);
91 }
92 Ok(zs)
93 }
94}