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