mirror of
https://github.com/arnaucube/phantom-zone.git
synced 2026-01-12 00:51:29 +01:00
change decomp_iter last check
This commit is contained in:
@@ -230,7 +230,7 @@ pub(super) struct BoolPbsInfo<M: Matrix, Ntt, RlweModOp, LweModOp> {
|
|||||||
|
|
||||||
impl<M: Matrix, NttOp, RlweModOp, LweModOp> PbsInfo for BoolPbsInfo<M, NttOp, RlweModOp, LweModOp>
|
impl<M: Matrix, NttOp, RlweModOp, LweModOp> PbsInfo for BoolPbsInfo<M, NttOp, RlweModOp, LweModOp>
|
||||||
where
|
where
|
||||||
M::MatElement: PrimInt + WrappingSub + NumInfo + FromPrimitive + From<bool>,
|
M::MatElement: PrimInt + WrappingSub + NumInfo + FromPrimitive + From<bool> + Display,
|
||||||
RlweModOp: ArithmeticOps<Element = M::MatElement> + VectorOps<Element = M::MatElement>,
|
RlweModOp: ArithmeticOps<Element = M::MatElement> + VectorOps<Element = M::MatElement>,
|
||||||
LweModOp: ArithmeticOps<Element = M::MatElement> + VectorOps<Element = M::MatElement>,
|
LweModOp: ArithmeticOps<Element = M::MatElement> + VectorOps<Element = M::MatElement>,
|
||||||
NttOp: Ntt<Element = M::MatElement>,
|
NttOp: Ntt<Element = M::MatElement>,
|
||||||
|
|||||||
@@ -103,13 +103,13 @@ mod test {
|
|||||||
println!("Gate time: {:?}", now.elapsed());
|
println!("Gate time: {:?}", now.elapsed());
|
||||||
|
|
||||||
// mp decrypt
|
// mp decrypt
|
||||||
// let decryption_shares = cks
|
let decryption_shares = cks
|
||||||
// .iter()
|
.iter()
|
||||||
// .map(|c| evaluator.multi_party_decryption_share(&c_out, c))
|
.map(|c| evaluator.multi_party_decryption_share(&c_out, c))
|
||||||
// .collect_vec();
|
.collect_vec();
|
||||||
// let m_out = evaluator.multi_party_decrypt(&decryption_shares, &c_out);
|
let m_out = evaluator.multi_party_decrypt(&decryption_shares, &c_out);
|
||||||
let m_expected = (m0 ^ m1);
|
let m_expected = (m0 ^ m1);
|
||||||
// assert_eq!(m_expected, m_out, "Expected {m_expected} but got {m_out}");
|
assert_eq!(m_expected, m_out, "Expected {m_expected} but got {m_out}");
|
||||||
|
|
||||||
// // find noise update
|
// // find noise update
|
||||||
// {
|
// {
|
||||||
|
|||||||
@@ -1,6 +1,10 @@
|
|||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
use num_traits::{AsPrimitive, FromPrimitive, Num, One, PrimInt, ToPrimitive, WrappingSub, Zero};
|
use num_traits::{AsPrimitive, FromPrimitive, Num, One, PrimInt, ToPrimitive, WrappingSub, Zero};
|
||||||
use std::{fmt::Debug, marker::PhantomData, ops::Rem};
|
use std::{
|
||||||
|
fmt::{Debug, Display},
|
||||||
|
marker::PhantomData,
|
||||||
|
ops::Rem,
|
||||||
|
};
|
||||||
|
|
||||||
use crate::backend::{ArithmeticOps, ModularOpsU64};
|
use crate::backend::{ArithmeticOps, ModularOpsU64};
|
||||||
|
|
||||||
@@ -106,8 +110,8 @@ impl<T: PrimInt + NumInfo + Debug> DefaultDecomposer<T> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: PrimInt + ToPrimitive + FromPrimitive + WrappingSub + NumInfo + From<bool>> Decomposer
|
impl<T: PrimInt + ToPrimitive + FromPrimitive + WrappingSub + NumInfo + From<bool> + Display>
|
||||||
for DefaultDecomposer<T>
|
Decomposer for DefaultDecomposer<T>
|
||||||
{
|
{
|
||||||
type Element = T;
|
type Element = T;
|
||||||
type Iter = DecomposerIter<T>;
|
type Iter = DecomposerIter<T>;
|
||||||
@@ -212,7 +216,7 @@ pub struct DecomposerIter<T> {
|
|||||||
b: T,
|
b: T,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: PrimInt + From<bool>> Iterator for DecomposerIter<T> {
|
impl<T: PrimInt + From<bool> + WrappingSub + Display> Iterator for DecomposerIter<T> {
|
||||||
type Item = T;
|
type Item = T;
|
||||||
|
|
||||||
fn next(&mut self) -> Option<Self::Item> {
|
fn next(&mut self) -> Option<Self::Item> {
|
||||||
@@ -235,14 +239,16 @@ impl<T: PrimInt + From<bool>> Iterator for DecomposerIter<T> {
|
|||||||
// Suprisingly the improvement does not show up when I benchmark
|
// Suprisingly the improvement does not show up when I benchmark
|
||||||
// `decomposer_iter` in isolation. Putting this remark here as a
|
// `decomposer_iter` in isolation. Putting this remark here as a
|
||||||
// future task to investiage (TODO).
|
// future task to investiage (TODO).
|
||||||
let carry = <T as From<bool>>::from(
|
let carry_bool =
|
||||||
k_i > self.bby2 || (k_i == self.bby2 && ((self.value & T::one()) == T::one())),
|
k_i > self.bby2 || (k_i == self.bby2 && ((self.value & T::one()) == T::one()));
|
||||||
);
|
let carry = <T as From<bool>>::from(carry_bool);
|
||||||
|
let neg_carry = (T::zero().wrapping_sub(&carry)) >> 9;
|
||||||
self.value = self.value + carry;
|
self.value = self.value + carry;
|
||||||
|
Some((neg_carry & self.q) + k_i - (carry << self.logb))
|
||||||
|
|
||||||
Some(
|
// Some(
|
||||||
(self.q & ((carry << self.logq) - (T::one() & carry))) + k_i - (carry << self.logb),
|
// (self.q & ((carry << self.logq) - (T::one() & carry))) + k_i
|
||||||
)
|
// - (carry << self.logb), )
|
||||||
|
|
||||||
// Some(k_i)
|
// Some(k_i)
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -240,7 +240,7 @@ fn blind_rotation<
|
|||||||
let s_indices = &gk_to_si[q_by_4 + i];
|
let s_indices = &gk_to_si[q_by_4 + i];
|
||||||
|
|
||||||
s_indices.iter().for_each(|s_index| {
|
s_indices.iter().for_each(|s_index| {
|
||||||
let new = std::time::Instant::now();
|
// let new = std::time::Instant::now();
|
||||||
rlwe_by_rgsw(
|
rlwe_by_rgsw(
|
||||||
trivial_rlwe_test_poly,
|
trivial_rlwe_test_poly,
|
||||||
pbs_key.rgsw_ct_lwe_si(*s_index),
|
pbs_key.rgsw_ct_lwe_si(*s_index),
|
||||||
@@ -249,14 +249,14 @@ fn blind_rotation<
|
|||||||
ntt_op,
|
ntt_op,
|
||||||
mod_op,
|
mod_op,
|
||||||
);
|
);
|
||||||
println!("Rlwe x Rgsw time: {:?}", new.elapsed());
|
// println!("Rlwe x Rgsw time: {:?}", new.elapsed());
|
||||||
});
|
});
|
||||||
v += 1;
|
v += 1;
|
||||||
|
|
||||||
if gk_to_si[q_by_4 + i - 1].len() != 0 || v == w || i == 1 {
|
if gk_to_si[q_by_4 + i - 1].len() != 0 || v == w || i == 1 {
|
||||||
let (auto_map_index, auto_map_sign) = parameters.rlwe_auto_map(v);
|
let (auto_map_index, auto_map_sign) = parameters.rlwe_auto_map(v);
|
||||||
|
|
||||||
let now = std::time::Instant::now();
|
// let now = std::time::Instant::now();
|
||||||
galois_auto(
|
galois_auto(
|
||||||
trivial_rlwe_test_poly,
|
trivial_rlwe_test_poly,
|
||||||
pbs_key.galois_key_for_auto(v),
|
pbs_key.galois_key_for_auto(v),
|
||||||
@@ -267,7 +267,7 @@ fn blind_rotation<
|
|||||||
ntt_op,
|
ntt_op,
|
||||||
auto_decomposer,
|
auto_decomposer,
|
||||||
);
|
);
|
||||||
println!("Auto time: {:?}", now.elapsed());
|
// println!("Auto time: {:?}", now.elapsed());
|
||||||
|
|
||||||
count += 1;
|
count += 1;
|
||||||
v = 0;
|
v = 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user