phantom-zone/src/bool/mod.rs
src/bool/mod.rsRaw
1pub(crate) mod evaluator;
2mod keys;
3mod noise;
4pub(crate) mod parameters;
5
6use keys::tests;
7pub(crate) use keys::PublicKey;
8
9#[cfg(feature = "interactive_mp")]
10#[cfg(not(feature = "non_interactive_mp"))]
11mod mp_api;
12#[cfg(feature = "non_interactive_mp")]
13mod ni_mp_api;
14
15#[cfg(feature = "non_interactive_mp")]
16pub use ni_mp_api::*;
17
18#[cfg(feature = "interactive_mp")]
19#[cfg(not(feature = "non_interactive_mp"))]
20pub use mp_api::*;
21
22pub type ClientKey = keys::ClientKey<[u8; 32], u64>;
23
24pub enum ParameterSelector {
25 HighCommunicationButFast2Party,
26 MultiPartyLessThanOrEqualTo16,
27 NonInteractiveMultiPartyLessThanOrEqualTo16,
28}
29
30mod common_mp_enc_dec {
31 use super::BoolEvaluator;
32 use crate::{
33 pbs::{sample_extract, PbsInfo},
34 utils::WithLocal,
35 Matrix, MultiPartyDecryptor, RowEntity, SampleExtractor,
36 };
37
38 type Mat = Vec<Vec<u64>>;
39
40 impl<E> MultiPartyDecryptor<bool, <Mat as Matrix>::R> for super::keys::ClientKey<[u8; 32], E> {
41 type DecryptionShare = <Mat as Matrix>::MatElement;
42
43 fn gen_decryption_share(&self, c: &<Mat as Matrix>::R) -> Self::DecryptionShare {
44 BoolEvaluator::with_local(|e| e.multi_party_decryption_share(c, self))
45 }
46
47 fn aggregate_decryption_shares(
48 &self,
49 c: &<Mat as Matrix>::R,
50 shares: &[Self::DecryptionShare],
51 ) -> bool {
52 BoolEvaluator::with_local(|e| e.multi_party_decrypt(shares, c))
53 }
54 }
55
56 impl SampleExtractor<<Mat as Matrix>::R> for Mat {
57 fn extract(&self, index: usize) -> <Mat as Matrix>::R {
58 // input is RLWE ciphertext
59 assert!(self.dimension().0 == 2);
60
61 let ring_size = self.dimension().1;
62 assert!(index < ring_size);
63
64 BoolEvaluator::with_local(|e| {
65 let mut lwe_out = <Mat as Matrix>::R::zeros(ring_size + 1);
66 sample_extract(&mut lwe_out, self, e.pbs_info().modop_rlweq(), index);
67 lwe_out
68 })
69 }
70 }
71}
72
73#[cfg(test)]
74mod print_noise;