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    InteractiveLTE2Party,
24    NonInteractiveLTE2Party,
25    NonInteractiveLTE4Party,
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        /// Generate multi-party decryption share for LWE ciphertext `c`
42        fn gen_decryption_share(&self, c: &<Mat as Matrix>::R) -> Self::DecryptionShare {
43            BoolEvaluator::with_local(|e| e.multi_party_decryption_share(c, self))
44        }
45
46        /// Aggregate mult-party decryptions shares of all parties, decrypt LWE
47        /// ciphertext `c`, and return the bool plaintext
48        fn aggregate_decryption_shares(
49            &self,
50            c: &<Mat as Matrix>::R,
51            shares: &[Self::DecryptionShare],
52        ) -> bool {
53            BoolEvaluator::with_local(|e| e.multi_party_decrypt(shares, c))
54        }
55    }
56
57    impl SampleExtractor<<Mat as Matrix>::R> for Mat {
58        /// Sample extract coefficient at `index` as a LWE ciphertext from RLWE
59        /// ciphertext `Self`
60        fn extract(&self, index: usize) -> <Mat as Matrix>::R {
61            // input is RLWE ciphertext
62            assert!(self.dimension().0 == 2);
63
64            let ring_size = self.dimension().1;
65            assert!(index < ring_size);
66
67            BoolEvaluator::with_local(|e| {
68                let mut lwe_out = <Mat as Matrix>::R::zeros(ring_size + 1);
69                sample_extract(&mut lwe_out, self, e.pbs_info().modop_rlweq(), index);
70                lwe_out
71            })
72        }
73    }
74}
75
76#[cfg(test)]
77mod print_noise;