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