mirror of
https://github.com/arnaucube/phantom-zone.git
synced 2026-01-09 23:51:30 +01:00
remove num.rs and fix mp parameter selector
This commit is contained in:
@@ -11,7 +11,7 @@ fn fhe_circuit(fhe_a: &FheUint8, fhe_b: &FheUint8, fhe_c: &FheUint8) -> FheUint8
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
set_parameter_set(ParameterSelector::MultiPartyLessThan16);
|
set_parameter_set(ParameterSelector::MultiPartyLessThanOrEqualTo16);
|
||||||
let no_of_parties = 2;
|
let no_of_parties = 2;
|
||||||
let client_keys = (0..no_of_parties)
|
let client_keys = (0..no_of_parties)
|
||||||
.into_iter()
|
.into_iter()
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
use num_traits::ToPrimitive;
|
use num_traits::ToPrimitive;
|
||||||
|
|
||||||
use crate::{Matrix, Row, RowMut};
|
use crate::Row;
|
||||||
|
|
||||||
mod modulus_u64;
|
mod modulus_u64;
|
||||||
mod power_of_2;
|
mod power_of_2;
|
||||||
@@ -8,7 +8,6 @@ mod word_size;
|
|||||||
|
|
||||||
pub use modulus_u64::ModularOpsU64;
|
pub use modulus_u64::ModularOpsU64;
|
||||||
pub(crate) use power_of_2::ModulusPowerOf2;
|
pub(crate) use power_of_2::ModulusPowerOf2;
|
||||||
pub use word_size::WordSizeModulus;
|
|
||||||
|
|
||||||
pub trait Modulus {
|
pub trait Modulus {
|
||||||
type Element;
|
type Element;
|
||||||
|
|||||||
@@ -1,12 +1,10 @@
|
|||||||
use std::marker::PhantomData;
|
|
||||||
|
|
||||||
use itertools::izip;
|
use itertools::izip;
|
||||||
use num_traits::{PrimInt, Signed, ToPrimitive, WrappingAdd, WrappingMul, WrappingSub, Zero};
|
use num_traits::WrappingMul;
|
||||||
|
|
||||||
use super::{
|
use super::{
|
||||||
ArithmeticLazyOps, ArithmeticOps, GetModulus, ModInit, Modulus, ShoupMatrixFMA, VectorOps,
|
ArithmeticLazyOps, ArithmeticOps, GetModulus, ModInit, Modulus, ShoupMatrixFMA, VectorOps,
|
||||||
};
|
};
|
||||||
use crate::{utils::ShoupMul, Matrix, RowMut};
|
use crate::RowMut;
|
||||||
|
|
||||||
pub struct ModularOpsU64<T> {
|
pub struct ModularOpsU64<T> {
|
||||||
q: u64,
|
q: u64,
|
||||||
|
|||||||
@@ -1,10 +1,7 @@
|
|||||||
use itertools::izip;
|
use itertools::izip;
|
||||||
use num_traits::{PrimInt, Signed, ToPrimitive, WrappingAdd, WrappingMul, WrappingSub, Zero};
|
use num_traits::{WrappingAdd, WrappingMul, WrappingSub, Zero};
|
||||||
|
|
||||||
use super::{
|
use super::{ArithmeticOps, GetModulus, ModInit, Modulus, VectorOps};
|
||||||
ArithmeticLazyOps, ArithmeticOps, GetModulus, ModInit, Modulus, ShoupMatrixFMA, VectorOps,
|
|
||||||
};
|
|
||||||
use crate::{utils::ShoupMul, Matrix, RowMut};
|
|
||||||
|
|
||||||
pub struct WordSizeModulus<T> {
|
pub struct WordSizeModulus<T> {
|
||||||
modulus: T,
|
modulus: T,
|
||||||
|
|||||||
@@ -1299,7 +1299,6 @@ mod tests {
|
|||||||
use rand_distr::Uniform;
|
use rand_distr::Uniform;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
backend::{GetModulus, ModInit, ModularOpsU64, WordSizeModulus},
|
|
||||||
bool::{
|
bool::{
|
||||||
self, CommonReferenceSeededMultiPartyServerKeyShare, PublicKey,
|
self, CommonReferenceSeededMultiPartyServerKeyShare, PublicKey,
|
||||||
SeededMultiPartyServerKey,
|
SeededMultiPartyServerKey,
|
||||||
|
|||||||
@@ -27,12 +27,12 @@ static BOOL_SERVER_KEY: OnceLock<ShoupServerKeyEvaluationDomain<Vec<Vec<u64>>>>
|
|||||||
static MULTI_PARTY_CRS: OnceLock<MultiPartyCrs<[u8; 32]>> = OnceLock::new();
|
static MULTI_PARTY_CRS: OnceLock<MultiPartyCrs<[u8; 32]>> = OnceLock::new();
|
||||||
|
|
||||||
pub enum ParameterSelector {
|
pub enum ParameterSelector {
|
||||||
MultiPartyLessThan16,
|
MultiPartyLessThanOrEqualTo16,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_parameter_set(select: ParameterSelector) {
|
pub fn set_parameter_set(select: ParameterSelector) {
|
||||||
match select {
|
match select {
|
||||||
ParameterSelector::MultiPartyLessThan16 => {
|
ParameterSelector::MultiPartyLessThanOrEqualTo16 => {
|
||||||
BOOL_EVALUATOR.with_borrow_mut(|v| *v = Some(BoolEvaluator::new(SMALL_MP_BOOL_PARAMS)));
|
BOOL_EVALUATOR.with_borrow_mut(|v| *v = Some(BoolEvaluator::new(SMALL_MP_BOOL_PARAMS)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,7 @@
|
|||||||
use std::{iter::Once, sync::OnceLock};
|
use std::{iter::Once, sync::OnceLock};
|
||||||
|
|
||||||
use itertools::{izip, Itertools};
|
use itertools::{izip, Itertools};
|
||||||
use num::UnsignedInteger;
|
|
||||||
use num_traits::{abs, Zero};
|
use num_traits::{abs, Zero};
|
||||||
use rand::CryptoRng;
|
|
||||||
use utils::TryConvertFrom1;
|
|
||||||
|
|
||||||
mod backend;
|
mod backend;
|
||||||
mod bool;
|
mod bool;
|
||||||
@@ -13,7 +10,6 @@ mod lwe;
|
|||||||
mod multi_party;
|
mod multi_party;
|
||||||
mod noise;
|
mod noise;
|
||||||
mod ntt;
|
mod ntt;
|
||||||
mod num;
|
|
||||||
mod pbs;
|
mod pbs;
|
||||||
mod random;
|
mod random;
|
||||||
mod rgsw;
|
mod rgsw;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
use itertools::{izip, Itertools};
|
use itertools::{izip, Itertools};
|
||||||
use rand::{thread_rng, Rng, RngCore, SeedableRng};
|
use rand::{Rng, RngCore, SeedableRng};
|
||||||
use rand_chacha::{rand_core::le, ChaCha8Rng};
|
use rand_chacha::ChaCha8Rng;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
backend::{ArithmeticOps, ModInit, ModularOpsU64, Modulus},
|
backend::{ArithmeticOps, ModInit, ModularOpsU64, Modulus},
|
||||||
|
|||||||
@@ -1,3 +0,0 @@
|
|||||||
use num_traits::{Num, PrimInt, WrappingShl, WrappingShr, Zero};
|
|
||||||
|
|
||||||
pub trait UnsignedInteger: Zero + Num {}
|
|
||||||
@@ -8,9 +8,7 @@ use crate::{
|
|||||||
lwe::lwe_key_switch,
|
lwe::lwe_key_switch,
|
||||||
ntt::Ntt,
|
ntt::Ntt,
|
||||||
random::DefaultSecureRng,
|
random::DefaultSecureRng,
|
||||||
rgsw::{
|
rgsw::{galois_auto_shoup, rlwe_by_rgsw_shoup, IsTrivial, RlweCiphertext},
|
||||||
galois_auto, galois_auto_shoup, rlwe_by_rgsw, rlwe_by_rgsw_shoup, IsTrivial, RlweCiphertext,
|
|
||||||
},
|
|
||||||
Matrix, MatrixEntity, MatrixMut, RowMut,
|
Matrix, MatrixEntity, MatrixMut, RowMut,
|
||||||
};
|
};
|
||||||
pub(crate) trait PbsKey {
|
pub(crate) trait PbsKey {
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ use std::cell::RefCell;
|
|||||||
|
|
||||||
use itertools::izip;
|
use itertools::izip;
|
||||||
use num_traits::{PrimInt, Zero};
|
use num_traits::{PrimInt, Zero};
|
||||||
use rand::{distributions::Uniform, thread_rng, CryptoRng, Rng, RngCore, SeedableRng};
|
use rand::{distributions::Uniform, Rng, RngCore, SeedableRng};
|
||||||
use rand_chacha::ChaCha8Rng;
|
use rand_chacha::ChaCha8Rng;
|
||||||
use rand_distr::{uniform::SampleUniform, Distribution};
|
use rand_distr::{uniform::SampleUniform, Distribution};
|
||||||
|
|
||||||
@@ -17,11 +17,6 @@ pub trait NewWithSeed {
|
|||||||
fn new_with_seed(seed: Self::Seed) -> Self;
|
fn new_with_seed(seed: Self::Seed) -> Self;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait RandomElement<T> {
|
|
||||||
/// Sample Random element of type T
|
|
||||||
fn random(&mut self) -> T;
|
|
||||||
}
|
|
||||||
|
|
||||||
pub trait RandomElementInModulus<T, M> {
|
pub trait RandomElementInModulus<T, M> {
|
||||||
/// Sample Random element of type T in range [0, modulus)
|
/// Sample Random element of type T in range [0, modulus)
|
||||||
fn random(&mut self, modulus: &M) -> T;
|
fn random(&mut self, modulus: &M) -> T;
|
||||||
@@ -153,15 +148,6 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T> RandomElement<T> for DefaultSecureRng
|
|
||||||
where
|
|
||||||
T: PrimInt + SampleUniform,
|
|
||||||
{
|
|
||||||
fn random(&mut self) -> T {
|
|
||||||
Uniform::new_inclusive(T::zero(), T::max_value()).sample(&mut self.rng)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<T> RandomElementInModulus<T, T> for DefaultSecureRng
|
impl<T> RandomElementInModulus<T, T> for DefaultSecureRng
|
||||||
where
|
where
|
||||||
T: Zero + SampleUniform,
|
T: Zero + SampleUniform,
|
||||||
|
|||||||
@@ -316,7 +316,7 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn all_uint8_apis() {
|
fn all_uint8_apis() {
|
||||||
set_parameter_set(crate::ParameterSelector::MultiPartyLessThan16);
|
set_parameter_set(crate::ParameterSelector::MultiPartyLessThanOrEqualTo16);
|
||||||
|
|
||||||
let (ck, sk) = gen_keys();
|
let (ck, sk) = gen_keys();
|
||||||
sk.set_server_key();
|
sk.set_server_key();
|
||||||
@@ -464,7 +464,7 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn fheuint8_test_multi_party() {
|
fn fheuint8_test_multi_party() {
|
||||||
set_parameter_set(crate::ParameterSelector::MultiPartyLessThan16);
|
set_parameter_set(crate::ParameterSelector::MultiPartyLessThanOrEqualTo16);
|
||||||
set_mp_seed([0; 32]);
|
set_mp_seed([0; 32]);
|
||||||
|
|
||||||
let parties = 8;
|
let parties = 8;
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
use std::{fmt::Debug, usize, vec};
|
use std::{fmt::Debug, usize, vec};
|
||||||
|
|
||||||
use itertools::{izip, Itertools};
|
use itertools::{izip, Itertools};
|
||||||
use num_traits::{FromPrimitive, PrimInt, Signed, Unsigned};
|
use num_traits::{FromPrimitive, PrimInt, Signed};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
backend::Modulus,
|
backend::Modulus,
|
||||||
random::{RandomElement, RandomElementInModulus, RandomFill},
|
random::{RandomElementInModulus, RandomFill},
|
||||||
Matrix,
|
Matrix,
|
||||||
};
|
};
|
||||||
pub trait WithLocal {
|
pub trait WithLocal {
|
||||||
@@ -118,7 +118,7 @@ fn is_probably_prime(candidate: u64) -> bool {
|
|||||||
/// - $prime \lt upper_bound$
|
/// - $prime \lt upper_bound$
|
||||||
/// - $\log{prime} = num_bits$
|
/// - $\log{prime} = num_bits$
|
||||||
/// - `prime % modulo == 1`
|
/// - `prime % modulo == 1`
|
||||||
pub fn generate_prime(num_bits: usize, modulo: u64, upper_bound: u64) -> Option<u64> {
|
pub(crate) fn generate_prime(num_bits: usize, modulo: u64, upper_bound: u64) -> Option<u64> {
|
||||||
let leading_zeros = (64 - num_bits) as u32;
|
let leading_zeros = (64 - num_bits) as u32;
|
||||||
|
|
||||||
let mut tentative_prime = upper_bound - 1;
|
let mut tentative_prime = upper_bound - 1;
|
||||||
|
|||||||
Reference in New Issue
Block a user