remove num.rs and fix mp parameter selector

This commit is contained in:
Janmajaya Mall
2024-06-11 17:53:00 +05:30
parent 1e0fb86782
commit eab9cd90c1
13 changed files with 17 additions and 47 deletions

View File

@@ -11,7 +11,7 @@ fn fhe_circuit(fhe_a: &FheUint8, fhe_b: &FheUint8, fhe_c: &FheUint8) -> FheUint8
}
fn main() {
set_parameter_set(ParameterSelector::MultiPartyLessThan16);
set_parameter_set(ParameterSelector::MultiPartyLessThanOrEqualTo16);
let no_of_parties = 2;
let client_keys = (0..no_of_parties)
.into_iter()

View File

@@ -1,6 +1,6 @@
use num_traits::ToPrimitive;
use crate::{Matrix, Row, RowMut};
use crate::Row;
mod modulus_u64;
mod power_of_2;
@@ -8,7 +8,6 @@ mod word_size;
pub use modulus_u64::ModularOpsU64;
pub(crate) use power_of_2::ModulusPowerOf2;
pub use word_size::WordSizeModulus;
pub trait Modulus {
type Element;

View File

@@ -1,12 +1,10 @@
use std::marker::PhantomData;
use itertools::izip;
use num_traits::{PrimInt, Signed, ToPrimitive, WrappingAdd, WrappingMul, WrappingSub, Zero};
use num_traits::WrappingMul;
use super::{
ArithmeticLazyOps, ArithmeticOps, GetModulus, ModInit, Modulus, ShoupMatrixFMA, VectorOps,
};
use crate::{utils::ShoupMul, Matrix, RowMut};
use crate::RowMut;
pub struct ModularOpsU64<T> {
q: u64,

View File

@@ -1,10 +1,7 @@
use itertools::izip;
use num_traits::{PrimInt, Signed, ToPrimitive, WrappingAdd, WrappingMul, WrappingSub, Zero};
use num_traits::{WrappingAdd, WrappingMul, WrappingSub, Zero};
use super::{
ArithmeticLazyOps, ArithmeticOps, GetModulus, ModInit, Modulus, ShoupMatrixFMA, VectorOps,
};
use crate::{utils::ShoupMul, Matrix, RowMut};
use super::{ArithmeticOps, GetModulus, ModInit, Modulus, VectorOps};
pub struct WordSizeModulus<T> {
modulus: T,

View File

@@ -1299,7 +1299,6 @@ mod tests {
use rand_distr::Uniform;
use crate::{
backend::{GetModulus, ModInit, ModularOpsU64, WordSizeModulus},
bool::{
self, CommonReferenceSeededMultiPartyServerKeyShare, PublicKey,
SeededMultiPartyServerKey,

View File

@@ -27,12 +27,12 @@ static BOOL_SERVER_KEY: OnceLock<ShoupServerKeyEvaluationDomain<Vec<Vec<u64>>>>
static MULTI_PARTY_CRS: OnceLock<MultiPartyCrs<[u8; 32]>> = OnceLock::new();
pub enum ParameterSelector {
MultiPartyLessThan16,
MultiPartyLessThanOrEqualTo16,
}
pub fn set_parameter_set(select: ParameterSelector) {
match select {
ParameterSelector::MultiPartyLessThan16 => {
ParameterSelector::MultiPartyLessThanOrEqualTo16 => {
BOOL_EVALUATOR.with_borrow_mut(|v| *v = Some(BoolEvaluator::new(SMALL_MP_BOOL_PARAMS)));
}
}

View File

@@ -1,10 +1,7 @@
use std::{iter::Once, sync::OnceLock};
use itertools::{izip, Itertools};
use num::UnsignedInteger;
use num_traits::{abs, Zero};
use rand::CryptoRng;
use utils::TryConvertFrom1;
mod backend;
mod bool;
@@ -13,7 +10,6 @@ mod lwe;
mod multi_party;
mod noise;
mod ntt;
mod num;
mod pbs;
mod random;
mod rgsw;

View File

@@ -1,6 +1,6 @@
use itertools::{izip, Itertools};
use rand::{thread_rng, Rng, RngCore, SeedableRng};
use rand_chacha::{rand_core::le, ChaCha8Rng};
use rand::{Rng, RngCore, SeedableRng};
use rand_chacha::ChaCha8Rng;
use crate::{
backend::{ArithmeticOps, ModInit, ModularOpsU64, Modulus},

View File

@@ -1,3 +0,0 @@
use num_traits::{Num, PrimInt, WrappingShl, WrappingShr, Zero};
pub trait UnsignedInteger: Zero + Num {}

View File

@@ -8,9 +8,7 @@ use crate::{
lwe::lwe_key_switch,
ntt::Ntt,
random::DefaultSecureRng,
rgsw::{
galois_auto, galois_auto_shoup, rlwe_by_rgsw, rlwe_by_rgsw_shoup, IsTrivial, RlweCiphertext,
},
rgsw::{galois_auto_shoup, rlwe_by_rgsw_shoup, IsTrivial, RlweCiphertext},
Matrix, MatrixEntity, MatrixMut, RowMut,
};
pub(crate) trait PbsKey {

View File

@@ -2,7 +2,7 @@ use std::cell::RefCell;
use itertools::izip;
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_distr::{uniform::SampleUniform, Distribution};
@@ -17,11 +17,6 @@ pub trait NewWithSeed {
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> {
/// Sample Random element of type T in range [0, modulus)
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
where
T: Zero + SampleUniform,

View File

@@ -316,7 +316,7 @@ mod tests {
#[test]
fn all_uint8_apis() {
set_parameter_set(crate::ParameterSelector::MultiPartyLessThan16);
set_parameter_set(crate::ParameterSelector::MultiPartyLessThanOrEqualTo16);
let (ck, sk) = gen_keys();
sk.set_server_key();
@@ -464,7 +464,7 @@ mod tests {
#[test]
fn fheuint8_test_multi_party() {
set_parameter_set(crate::ParameterSelector::MultiPartyLessThan16);
set_parameter_set(crate::ParameterSelector::MultiPartyLessThanOrEqualTo16);
set_mp_seed([0; 32]);
let parties = 8;

View File

@@ -1,11 +1,11 @@
use std::{fmt::Debug, usize, vec};
use itertools::{izip, Itertools};
use num_traits::{FromPrimitive, PrimInt, Signed, Unsigned};
use num_traits::{FromPrimitive, PrimInt, Signed};
use crate::{
backend::Modulus,
random::{RandomElement, RandomElementInModulus, RandomFill},
random::{RandomElementInModulus, RandomFill},
Matrix,
};
pub trait WithLocal {
@@ -118,7 +118,7 @@ fn is_probably_prime(candidate: u64) -> bool {
/// - $prime \lt upper_bound$
/// - $\log{prime} = num_bits$
/// - `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 mut tentative_prime = upper_bound - 1;