arnaucube
arnaucube/phantom-zonePublic Self-hosted repository
phantom-zone/src/bool/mod.rs
src/bool/mod.rsRaw
 1pub(crate) mod evaluator;
 2mod keys;
 3pub(crate) mod parameters;
 4
 5#[cfg(feature = "interactive_mp")]
 6mod mp_api;
 7#[cfg(feature = "non_interactive_mp")]
 8mod ni_mp_api;
 9
10#[cfg(feature = "non_interactive_mp")]
11pub use ni_mp_api::*;
12
13#[cfg(feature = "interactive_mp")]
14pub use mp_api::*;
15
16pub type ClientKey = keys::ClientKey<[u8; 32], u64>;
17
18mod common_mp_enc_dec {
19    use super::BoolEvaluator;
20    use crate::{
21        pbs::{sample_extract, PbsInfo},
22        utils::WithLocal,
23        Matrix, MultiPartyDecryptor, RowEntity, SampleExtractor,
24    };
25
26    type Mat = Vec<Vec<u64>>;
27
28    impl<E> MultiPartyDecryptor<bool, <Mat as Matrix>::R> for super::keys::ClientKey<[u8; 32], E> {
29        type DecryptionShare = <Mat as Matrix>::MatElement;
30
31        /// Generate multi-party decryption share for LWE ciphertext `c`
32        fn gen_decryption_share(&self, c: &<Mat as Matrix>::R) -> Self::DecryptionShare {
33            BoolEvaluator::with_local(|e| e.multi_party_decryption_share(c, self))
34        }
35
36        /// Aggregate mult-party decryptions shares of all parties, decrypt LWE
37        /// ciphertext `c`, and return the bool plaintext
38        fn aggregate_decryption_shares(
39            &self,
40            c: &<Mat as Matrix>::R,
41            shares: &[Self::DecryptionShare],
42        ) -> bool {
43            BoolEvaluator::with_local(|e| e.multi_party_decrypt(shares, c))
44        }
45    }
46
47    impl SampleExtractor<<Mat as Matrix>::R> for Mat {
48        /// Sample extract coefficient at `index` as a LWE ciphertext from RLWE
49        /// ciphertext `Self`
50        fn extract(&self, index: usize) -> <Mat as Matrix>::R {
51            // input is RLWE ciphertext
52            assert!(self.dimension().0 == 2);
53
54            let ring_size = self.dimension().1;
55            assert!(index < ring_size);
56
57            BoolEvaluator::with_local(|e| {
58                let mut lwe_out = <Mat as Matrix>::R::zeros(ring_size + 1);
59                sample_extract(&mut lwe_out, self, e.pbs_info().modop_rlweq(), index);
60                lwe_out
61            })
62        }
63    }
64}
65
66#[cfg(test)]
67mod print_noise;