arnaucube
arnaucube/phantom-zonePublic Self-hosted repository
add shoup repre non-interactive multiparty server key eval domain
Janmajaya Mall janmajayamall@protonmail.com
Mon, 17 Jun 2024 14:10:36 +0530
commit

0e95653698f18a165e05cf36ef0f840e0e6f308f

parent

6aabfbfd719a1ba2e03046e709f29c6c6574c1fb

2 files changed, 102 insertions(+), 27 deletions(-)

jump to
M src/bool/evaluator.rs → src/bool/evaluator.rs

@@ -54,7 +54,7 @@ SeededSinglePartyServerKey, ServerKeyEvaluationDomain, ShoupServerKeyEvaluationDomain,

ThrowMeAwayKey, }; -pub struct NonInteractiveMultiPartyServerKeyShare<M: Matrix, S> { +pub struct SeededNonInteractiveMultiPartyServerKeyShare<M: Matrix, S> { /// (ak*si + e + \beta ui, ak*si + e) ni_rgsw_cts: (Vec<M>, Vec<M>), ui_to_s_ksk: M,

@@ -67,7 +67,7 @@ user_index: usize,

cr_seed: S, } -impl<M: Matrix, S> NonInteractiveMultiPartyServerKeyShare<M, S> { +impl<M: Matrix, S> SeededNonInteractiveMultiPartyServerKeyShare<M, S> { fn ui_to_s_ksk_zero_encs_for_user_i(&self, user_i: usize) -> &M { assert!(user_i != self.user_index); if user_i < self.user_index {

@@ -916,7 +916,7 @@ pub(super) fn aggregate_non_interactive_multi_party_key_share(

&self, cr_seed: &NonInteractiveMultiPartyCrs<[u8; 32]>, total_users: usize, - key_shares: &[NonInteractiveMultiPartyServerKeyShare< + key_shares: &[SeededNonInteractiveMultiPartyServerKeyShare< M, NonInteractiveMultiPartyCrs<[u8; 32]>, >],

@@ -1439,7 +1439,8 @@ cr_seed: &NonInteractiveMultiPartyCrs<[u8; 32]>,

self_index: usize, total_users: usize, client_key: &ThrowMeAwayKey, - ) -> NonInteractiveMultiPartyServerKeyShare<M, NonInteractiveMultiPartyCrs<[u8; 32]>> { + ) -> SeededNonInteractiveMultiPartyServerKeyShare<M, NonInteractiveMultiPartyCrs<[u8; 32]>> + { // TODO: check whether parameters support `total_users` let nttop = self.pbs_info().nttop_rlweq(); let rlwe_modop = self.pbs_info().modop_rlweq();

@@ -1556,7 +1557,7 @@ client_key.sk_lwe(),

) }; - NonInteractiveMultiPartyServerKeyShare { + SeededNonInteractiveMultiPartyServerKeyShare { ni_rgsw_cts, ui_to_s_ksk, others_ksk_zero_encs: zero_encs_for_others,
M src/bool/keys.rs → src/bool/keys.rs

@@ -930,38 +930,89 @@ }

} } -/// Server key in evaluation domain with Shoup representations -pub(crate) struct ShoupServerKeyEvaluationDomain<M> { - /// Rgsw cts of LWE secret elements +pub(crate) struct ShoupNonInteractiveServerKeyEvaluationDomain<M> { + /// RGSW ciphertexts ideal lwe secret key elements under ideal rlwe secret rgsw_cts: Vec<NormalAndShoup<M>>, - /// Auto keys. Key corresponding to g^{k} is at index `k`. Key corresponding - /// to -g is at 0 - galois_keys: HashMap<usize, NormalAndShoup<M>>, - /// LWE ksk to key switching LWE ciphertext from RLWE secret to LWE secret + /// Automorphism keys under ideal rlwe secret + auto_keys: HashMap<usize, NormalAndShoup<M>>, + /// LWE key switching key from Q -> Q_{ks} lwe_ksk: M, + /// Key switching key from user j to ideal secret key s. User j's ksk is at + /// j'th element + ui_to_s_ksks: Vec<NormalAndShoup<M>>, } -/// Stores normal and shoup representation of Matrix elements (Normal, Shoup) -pub(crate) struct NormalAndShoup<M>(M, M); +mod impl_shoup_non_interactive_server_key_eval_domain { + use itertools::Itertools; + use num_traits::{FromPrimitive, PrimInt, ToPrimitive}; + + use super::*; + use crate::{backend::Modulus, pbs::PbsKey}; + + impl<M: Matrix + ToShoup<Modulus = M::MatElement>, R, N> + From<NonInteractiveServerKeyEvaluationDomain<M, BoolParameters<M::MatElement>, R, N>> + for ShoupNonInteractiveServerKeyEvaluationDomain<M> + where + M::MatElement: FromPrimitive + ToPrimitive + PrimInt, + { + fn from( + value: NonInteractiveServerKeyEvaluationDomain<M, BoolParameters<M::MatElement>, R, N>, + ) -> Self { + let rlwe_q = value.parameters.rlwe_q().q().unwrap(); + + let rgsw_cts = value + .rgsw_cts + .into_iter() + .map(|m| NormalAndShoup::new_with_modulus(m, rlwe_q)) + .collect_vec(); + + let mut auto_keys = HashMap::new(); + value.auto_keys.into_iter().for_each(|(k, v)| { + auto_keys.insert(k, NormalAndShoup::new_with_modulus(v, rlwe_q)); + }); + + let ui_to_s_ksks = value + .ui_to_s_ksks + .into_iter() + .map(|m| NormalAndShoup::new_with_modulus(m, rlwe_q)) + .collect_vec(); -impl<M: ToShoup> NormalAndShoup<M> { - fn new_with_modulus(value: M, modulus: <M as ToShoup>::Modulus) -> Self { - let value_shoup = M::to_shoup(&value, modulus); - NormalAndShoup(value, value_shoup) + Self { + rgsw_cts, + auto_keys, + lwe_ksk: value.lwe_ksk, + ui_to_s_ksks, + } + } } -} + + impl<M: Matrix> PbsKey for ShoupNonInteractiveServerKeyEvaluationDomain<M> { + type AutoKey = NormalAndShoup<M>; + type LweKskKey = M; + type RgswCt = NormalAndShoup<M>; -impl<M> AsRef<M> for NormalAndShoup<M> { - fn as_ref(&self) -> &M { - &self.0 + fn galois_key_for_auto(&self, k: usize) -> &Self::AutoKey { + self.auto_keys.get(&k).unwrap() + } + fn rgsw_ct_lwe_si(&self, si: usize) -> &Self::RgswCt { + &self.rgsw_cts[si] + } + + fn lwe_ksk(&self) -> &Self::LweKskKey { + &self.lwe_ksk + } } } -impl<M> WithShoupRepr for NormalAndShoup<M> { - type M = M; - fn shoup_repr(&self) -> &Self::M { - &self.1 - } +/// Server key in evaluation domain with Shoup representations +pub(crate) struct ShoupServerKeyEvaluationDomain<M> { + /// Rgsw cts of LWE secret elements + rgsw_cts: Vec<NormalAndShoup<M>>, + /// Auto keys. Key corresponding to g^{k} is at index `k`. Key corresponding + /// to -g is at 0 + galois_keys: HashMap<usize, NormalAndShoup<M>>, + /// LWE ksk to key switching LWE ciphertext from RLWE secret to LWE secret + lwe_ksk: M, } mod shoup_server_key_eval_domain {

@@ -1018,3 +1069,26 @@ &self.lwe_ksk

} } } + +/// Stores normal and shoup representation of Matrix elements (Normal, Shoup) +pub(crate) struct NormalAndShoup<M>(M, M); + +impl<M: ToShoup> NormalAndShoup<M> { + fn new_with_modulus(value: M, modulus: <M as ToShoup>::Modulus) -> Self { + let value_shoup = M::to_shoup(&value, modulus); + NormalAndShoup(value, value_shoup) + } +} + +impl<M> AsRef<M> for NormalAndShoup<M> { + fn as_ref(&self) -> &M { + &self.0 + } +} + +impl<M> WithShoupRepr for NormalAndShoup<M> { + type M = M; + fn shoup_repr(&self) -> &Self::M { + &self.1 + } +}