mirror of
https://github.com/arnaucube/phantom-zone.git
synced 2026-01-11 08:31:30 +01:00
add example
This commit is contained in:
@@ -26,8 +26,16 @@ static BOOL_SERVER_KEY: OnceLock<ShoupServerKeyEvaluationDomain<Vec<Vec<u64>>>>
|
||||
|
||||
static MULTI_PARTY_CRS: OnceLock<MultiPartyCrs<[u8; 32]>> = OnceLock::new();
|
||||
|
||||
pub fn set_parameter_set(parameter: &BoolParameters<u64>) {
|
||||
BOOL_EVALUATOR.with_borrow_mut(|v| *v = Some(BoolEvaluator::new(parameter.clone())));
|
||||
pub enum ParameterSelector {
|
||||
MultiPartyLessThan16,
|
||||
}
|
||||
|
||||
pub fn set_parameter_set(select: ParameterSelector) {
|
||||
match select {
|
||||
ParameterSelector::MultiPartyLessThan16 => {
|
||||
BOOL_EVALUATOR.with_borrow_mut(|v| *v = Some(BoolEvaluator::new(SMALL_MP_BOOL_PARAMS)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_mp_seed(seed: [u8; 32]) {
|
||||
|
||||
@@ -3,7 +3,7 @@ use num_traits::{ConstZero, FromPrimitive, PrimInt};
|
||||
use crate::{backend::Modulus, decomposer::Decomposer};
|
||||
|
||||
#[derive(Clone, PartialEq)]
|
||||
pub(crate) struct BoolParameters<El> {
|
||||
pub struct BoolParameters<El> {
|
||||
rlwe_q: CiphertextModulus<El>,
|
||||
lwe_q: CiphertextModulus<El>,
|
||||
br_q: usize,
|
||||
@@ -181,7 +181,7 @@ pub(crate) struct PolynomialSize(pub(crate) usize);
|
||||
|
||||
/// T equals modulus when modulus is non-native. Otherwise T equals 0. bool is
|
||||
/// true when modulus is native, false otherwise.
|
||||
pub(crate) struct CiphertextModulus<T>(T, bool);
|
||||
pub struct CiphertextModulus<T>(T, bool);
|
||||
|
||||
impl<T: ConstZero> CiphertextModulus<T> {
|
||||
const fn new_native() -> Self {
|
||||
|
||||
11
src/lib.rs
11
src/lib.rs
@@ -23,8 +23,13 @@ mod utils;
|
||||
pub use backend::{
|
||||
ArithmeticLazyOps, ArithmeticOps, ModInit, ModularOpsU64, ShoupMatrixFMA, VectorOps,
|
||||
};
|
||||
pub use bool::{
|
||||
aggregate_public_key_shares, aggregate_server_key_shares, gen_client_key, gen_mp_keys_phase1,
|
||||
gen_mp_keys_phase2, set_mp_seed, set_parameter_set, ParameterSelector,
|
||||
};
|
||||
pub use decomposer::{Decomposer, DecomposerIter, DefaultDecomposer};
|
||||
pub use ntt::{Ntt, NttBackendU64, NttInit};
|
||||
pub use shortint::FheUint8;
|
||||
|
||||
pub trait Matrix: AsRef<[Self::R]> {
|
||||
type MatElement;
|
||||
@@ -165,15 +170,15 @@ impl<T: Zero + Clone> RowEntity for Vec<T> {
|
||||
}
|
||||
}
|
||||
|
||||
trait Encryptor<M: ?Sized, C> {
|
||||
pub trait Encryptor<M: ?Sized, C> {
|
||||
fn encrypt(&self, m: &M) -> C;
|
||||
}
|
||||
|
||||
trait Decryptor<M, C> {
|
||||
pub trait Decryptor<M, C> {
|
||||
fn decrypt(&self, c: &C) -> M;
|
||||
}
|
||||
|
||||
trait MultiPartyDecryptor<M, C> {
|
||||
pub trait MultiPartyDecryptor<M, C> {
|
||||
type DecryptionShare;
|
||||
|
||||
fn gen_decryption_share(&self, c: &C) -> Self::DecryptionShare;
|
||||
|
||||
@@ -12,7 +12,7 @@ thread_local! {
|
||||
pub(crate) static DEFAULT_RNG: RefCell<DefaultSecureRng> = RefCell::new(DefaultSecureRng::new_seeded([0u8;32]));
|
||||
}
|
||||
|
||||
pub(crate) trait NewWithSeed {
|
||||
pub trait NewWithSeed {
|
||||
type Seed;
|
||||
fn new_with_seed(seed: Self::Seed) -> Self;
|
||||
}
|
||||
@@ -59,7 +59,7 @@ where
|
||||
fn random_fill(&mut self, modulus: &P, container: &mut M);
|
||||
}
|
||||
|
||||
pub(crate) struct DefaultSecureRng {
|
||||
pub struct DefaultSecureRng {
|
||||
rng: ChaCha8Rng,
|
||||
}
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ use crate::{
|
||||
mod ops;
|
||||
mod types;
|
||||
|
||||
type FheUint8 = types::FheUint8<Vec<u64>>;
|
||||
pub type FheUint8 = types::FheUint8<Vec<u64>>;
|
||||
|
||||
impl Encryptor<u8, FheUint8> for ClientKey {
|
||||
fn encrypt(&self, m: &u8) -> FheUint8 {
|
||||
@@ -308,9 +308,7 @@ mod tests {
|
||||
use crate::{
|
||||
bool::{
|
||||
aggregate_public_key_shares, aggregate_server_key_shares, gen_client_key, gen_keys,
|
||||
gen_mp_keys_phase1, gen_mp_keys_phase2,
|
||||
parameters::{MP_BOOL_PARAMS, SMALL_MP_BOOL_PARAMS, SP_BOOL_PARAMS},
|
||||
set_mp_seed, set_parameter_set,
|
||||
gen_mp_keys_phase1, gen_mp_keys_phase2, set_mp_seed, set_parameter_set,
|
||||
},
|
||||
shortint::types::FheUint8,
|
||||
Decryptor, Encryptor, MultiPartyDecryptor,
|
||||
@@ -318,7 +316,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn all_uint8_apis() {
|
||||
set_parameter_set(&SP_BOOL_PARAMS);
|
||||
set_parameter_set(crate::ParameterSelector::MultiPartyLessThan16);
|
||||
|
||||
let (ck, sk) = gen_keys();
|
||||
sk.set_server_key();
|
||||
@@ -466,7 +464,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn fheuint8_test_multi_party() {
|
||||
set_parameter_set(&SMALL_MP_BOOL_PARAMS);
|
||||
set_parameter_set(crate::ParameterSelector::MultiPartyLessThan16);
|
||||
set_mp_seed([0; 32]);
|
||||
|
||||
let parties = 8;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#[derive(Clone)]
|
||||
pub(super) struct FheUint8<C> {
|
||||
pub struct FheUint8<C> {
|
||||
pub(super) data: Vec<C>,
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user