mirror of
https://github.com/zama-ai/tfhe-rs.git
synced 2026-01-08 22:28:01 -05:00
refactor!: gate wops behind "experimental" feature
This puts the WOPBS features of shortint and integer modules behind the "experimental" feature. Due to the versioning feature, the structs definitions are not gated behind the "experimental" feature, however they are only pub(crate) in that case.
This commit is contained in:
9
Makefile
9
Makefile
@@ -285,12 +285,18 @@ clippy_shortint: install_rs_check_toolchain
|
|||||||
RUSTFLAGS="$(RUSTFLAGS)" cargo "$(CARGO_RS_CHECK_TOOLCHAIN)" clippy \
|
RUSTFLAGS="$(RUSTFLAGS)" cargo "$(CARGO_RS_CHECK_TOOLCHAIN)" clippy \
|
||||||
--features=$(TARGET_ARCH_FEATURE),shortint \
|
--features=$(TARGET_ARCH_FEATURE),shortint \
|
||||||
-p $(TFHE_SPEC) -- --no-deps -D warnings
|
-p $(TFHE_SPEC) -- --no-deps -D warnings
|
||||||
|
RUSTFLAGS="$(RUSTFLAGS)" cargo "$(CARGO_RS_CHECK_TOOLCHAIN)" clippy \
|
||||||
|
--features=$(TARGET_ARCH_FEATURE),shortint,experimental \
|
||||||
|
-p $(TFHE_SPEC) -- --no-deps -D warnings
|
||||||
|
|
||||||
.PHONY: clippy_integer # Run clippy lints enabling the integer features
|
.PHONY: clippy_integer # Run clippy lints enabling the integer features
|
||||||
clippy_integer: install_rs_check_toolchain
|
clippy_integer: install_rs_check_toolchain
|
||||||
RUSTFLAGS="$(RUSTFLAGS)" cargo "$(CARGO_RS_CHECK_TOOLCHAIN)" clippy \
|
RUSTFLAGS="$(RUSTFLAGS)" cargo "$(CARGO_RS_CHECK_TOOLCHAIN)" clippy \
|
||||||
--features=$(TARGET_ARCH_FEATURE),integer \
|
--features=$(TARGET_ARCH_FEATURE),integer \
|
||||||
-p $(TFHE_SPEC) -- --no-deps -D warnings
|
-p $(TFHE_SPEC) -- --no-deps -D warnings
|
||||||
|
RUSTFLAGS="$(RUSTFLAGS)" cargo "$(CARGO_RS_CHECK_TOOLCHAIN)" clippy \
|
||||||
|
--features=$(TARGET_ARCH_FEATURE),integer,experimental \
|
||||||
|
-p $(TFHE_SPEC) -- --no-deps -D warnings
|
||||||
|
|
||||||
.PHONY: clippy # Run clippy lints enabling the boolean, shortint, integer
|
.PHONY: clippy # Run clippy lints enabling the boolean, shortint, integer
|
||||||
clippy: install_rs_check_toolchain
|
clippy: install_rs_check_toolchain
|
||||||
@@ -339,6 +345,9 @@ clippy_all_targets: install_rs_check_toolchain
|
|||||||
RUSTFLAGS="$(RUSTFLAGS)" cargo "$(CARGO_RS_CHECK_TOOLCHAIN)" clippy --all-targets \
|
RUSTFLAGS="$(RUSTFLAGS)" cargo "$(CARGO_RS_CHECK_TOOLCHAIN)" clippy --all-targets \
|
||||||
--features=$(TARGET_ARCH_FEATURE),boolean,shortint,integer,internal-keycache,zk-pok \
|
--features=$(TARGET_ARCH_FEATURE),boolean,shortint,integer,internal-keycache,zk-pok \
|
||||||
-p $(TFHE_SPEC) -- --no-deps -D warnings
|
-p $(TFHE_SPEC) -- --no-deps -D warnings
|
||||||
|
RUSTFLAGS="$(RUSTFLAGS)" cargo "$(CARGO_RS_CHECK_TOOLCHAIN)" clippy --all-targets \
|
||||||
|
--features=$(TARGET_ARCH_FEATURE),boolean,shortint,integer,internal-keycache,zk-pok,experimental \
|
||||||
|
-p $(TFHE_SPEC) -- --no-deps -D warnings
|
||||||
|
|
||||||
.PHONY: clippy_concrete_csprng # Run clippy lints on concrete-csprng
|
.PHONY: clippy_concrete_csprng # Run clippy lints on concrete-csprng
|
||||||
clippy_concrete_csprng: install_rs_check_toolchain
|
clippy_concrete_csprng: install_rs_check_toolchain
|
||||||
|
|||||||
@@ -155,7 +155,7 @@ cargo "${RUST_TOOLCHAIN}" nextest run \
|
|||||||
--cargo-profile "${cargo_profile}" \
|
--cargo-profile "${cargo_profile}" \
|
||||||
--package "${tfhe_package}" \
|
--package "${tfhe_package}" \
|
||||||
--profile ci \
|
--profile ci \
|
||||||
--features="${ARCH_FEATURE}",integer,internal-keycache,zk-pok,"${avx512_feature}","${gpu_feature}" \
|
--features="${ARCH_FEATURE}",integer,internal-keycache,zk-pok,experimental,"${avx512_feature}","${gpu_feature}" \
|
||||||
--test-threads "${test_threads}" \
|
--test-threads "${test_threads}" \
|
||||||
-E "$filter_expression"
|
-E "$filter_expression"
|
||||||
|
|
||||||
@@ -163,7 +163,7 @@ if [[ -z ${multi_bit_argument} ]]; then
|
|||||||
cargo "${RUST_TOOLCHAIN}" test \
|
cargo "${RUST_TOOLCHAIN}" test \
|
||||||
--profile "${cargo_profile}" \
|
--profile "${cargo_profile}" \
|
||||||
--package "${tfhe_package}" \
|
--package "${tfhe_package}" \
|
||||||
--features="${ARCH_FEATURE}",integer,internal-keycache,"${avx512_feature}","${gpu_feature}" \
|
--features="${ARCH_FEATURE}",integer,internal-keycache,experimental,"${avx512_feature}","${gpu_feature}" \
|
||||||
--doc \
|
--doc \
|
||||||
-- --test-threads="${doctest_threads}" integer::"${gpu_feature}"
|
-- --test-threads="${doctest_threads}" integer::"${gpu_feature}"
|
||||||
fi
|
fi
|
||||||
|
|||||||
@@ -101,7 +101,7 @@ if [[ "${BIG_TESTS_INSTANCE}" != TRUE ]]; then
|
|||||||
--cargo-profile "${cargo_profile}" \
|
--cargo-profile "${cargo_profile}" \
|
||||||
--package "${tfhe_package}" \
|
--package "${tfhe_package}" \
|
||||||
--profile ci \
|
--profile ci \
|
||||||
--features="${ARCH_FEATURE}",shortint,internal-keycache,zk-pok \
|
--features="${ARCH_FEATURE}",shortint,internal-keycache,zk-pok,experimental \
|
||||||
--test-threads "${n_threads_small}" \
|
--test-threads "${n_threads_small}" \
|
||||||
-E "${filter_expression_small_params}"
|
-E "${filter_expression_small_params}"
|
||||||
|
|
||||||
@@ -118,7 +118,7 @@ and not test(~smart_add_and_mul)"""
|
|||||||
--cargo-profile "${cargo_profile}" \
|
--cargo-profile "${cargo_profile}" \
|
||||||
--package "${tfhe_package}" \
|
--package "${tfhe_package}" \
|
||||||
--profile ci \
|
--profile ci \
|
||||||
--features="${ARCH_FEATURE}",shortint,internal-keycache \
|
--features="${ARCH_FEATURE}",shortint,internal-keycache,experimental \
|
||||||
--test-threads "${n_threads_big}" \
|
--test-threads "${n_threads_big}" \
|
||||||
-E "${filter_expression_big_params}"
|
-E "${filter_expression_big_params}"
|
||||||
|
|
||||||
@@ -126,7 +126,7 @@ and not test(~smart_add_and_mul)"""
|
|||||||
cargo "${RUST_TOOLCHAIN}" test \
|
cargo "${RUST_TOOLCHAIN}" test \
|
||||||
--profile "${cargo_profile}" \
|
--profile "${cargo_profile}" \
|
||||||
--package "${tfhe_package}" \
|
--package "${tfhe_package}" \
|
||||||
--features="${ARCH_FEATURE}",shortint,internal-keycache \
|
--features="${ARCH_FEATURE}",shortint,internal-keycache,experimental \
|
||||||
--doc \
|
--doc \
|
||||||
-- shortint::
|
-- shortint::
|
||||||
fi
|
fi
|
||||||
@@ -140,7 +140,7 @@ else
|
|||||||
--cargo-profile "${cargo_profile}" \
|
--cargo-profile "${cargo_profile}" \
|
||||||
--package "${tfhe_package}" \
|
--package "${tfhe_package}" \
|
||||||
--profile ci \
|
--profile ci \
|
||||||
--features="${ARCH_FEATURE}",shortint,internal-keycache \
|
--features="${ARCH_FEATURE}",shortint,internal-keycache,experimental \
|
||||||
--test-threads "${n_threads_big}" \
|
--test-threads "${n_threads_big}" \
|
||||||
-E "${filter_expression}"
|
-E "${filter_expression}"
|
||||||
|
|
||||||
@@ -148,7 +148,7 @@ else
|
|||||||
cargo "${RUST_TOOLCHAIN}" test \
|
cargo "${RUST_TOOLCHAIN}" test \
|
||||||
--profile "${cargo_profile}" \
|
--profile "${cargo_profile}" \
|
||||||
--package "${tfhe_package}" \
|
--package "${tfhe_package}" \
|
||||||
--features="${ARCH_FEATURE}",shortint,internal-keycache \
|
--features="${ARCH_FEATURE}",shortint,internal-keycache,experimental \
|
||||||
--doc \
|
--doc \
|
||||||
-- --test-threads="${n_threads_big}" shortint::
|
-- --test-threads="${n_threads_big}" shortint::
|
||||||
fi
|
fi
|
||||||
|
|||||||
@@ -2,7 +2,9 @@ use clap::{Arg, ArgAction, Command};
|
|||||||
use tfhe::boolean;
|
use tfhe::boolean;
|
||||||
use tfhe::boolean::parameters::{BooleanParameters, DEFAULT_PARAMETERS, DEFAULT_PARAMETERS_KS_PBS};
|
use tfhe::boolean::parameters::{BooleanParameters, DEFAULT_PARAMETERS, DEFAULT_PARAMETERS_KS_PBS};
|
||||||
use tfhe::keycache::NamedParam;
|
use tfhe::keycache::NamedParam;
|
||||||
use tfhe::shortint::keycache::{KEY_CACHE, KEY_CACHE_KSK, KEY_CACHE_WOPBS};
|
#[cfg(feature = "experimental")]
|
||||||
|
use tfhe::shortint::keycache::KEY_CACHE_WOPBS;
|
||||||
|
use tfhe::shortint::keycache::{KEY_CACHE, KEY_CACHE_KSK};
|
||||||
#[cfg(tarpaulin)]
|
#[cfg(tarpaulin)]
|
||||||
use tfhe::shortint::parameters::coverage_parameters::{
|
use tfhe::shortint::parameters::coverage_parameters::{
|
||||||
COVERAGE_PARAM_MESSAGE_2_CARRY_2_COMPACT_PK_KS_PBS,
|
COVERAGE_PARAM_MESSAGE_2_CARRY_2_COMPACT_PK_KS_PBS,
|
||||||
@@ -14,14 +16,16 @@ use tfhe::shortint::parameters::key_switching::p_fail_2_minus_64::ks_pbs::PARAM_
|
|||||||
use tfhe::shortint::parameters::key_switching::ShortintKeySwitchingParameters;
|
use tfhe::shortint::parameters::key_switching::ShortintKeySwitchingParameters;
|
||||||
|
|
||||||
use tfhe::shortint::parameters::{
|
use tfhe::shortint::parameters::{
|
||||||
ClassicPBSParameters, WopbsParameters, ALL_MULTI_BIT_PARAMETER_VEC,
|
ClassicPBSParameters, ALL_MULTI_BIT_PARAMETER_VEC, PARAM_MESSAGE_1_CARRY_1_KS_PBS,
|
||||||
PARAM_MESSAGE_1_CARRY_1_KS_PBS, PARAM_MESSAGE_1_CARRY_2_KS_PBS, PARAM_MESSAGE_1_CARRY_3_KS_PBS,
|
PARAM_MESSAGE_1_CARRY_2_KS_PBS, PARAM_MESSAGE_1_CARRY_3_KS_PBS, PARAM_MESSAGE_1_CARRY_4_KS_PBS,
|
||||||
PARAM_MESSAGE_1_CARRY_4_KS_PBS, PARAM_MESSAGE_1_CARRY_5_KS_PBS, PARAM_MESSAGE_1_CARRY_6_KS_PBS,
|
PARAM_MESSAGE_1_CARRY_5_KS_PBS, PARAM_MESSAGE_1_CARRY_6_KS_PBS, PARAM_MESSAGE_2_CARRY_1_KS_PBS,
|
||||||
PARAM_MESSAGE_2_CARRY_1_KS_PBS, PARAM_MESSAGE_2_CARRY_2_KS_PBS, PARAM_MESSAGE_2_CARRY_3_KS_PBS,
|
PARAM_MESSAGE_2_CARRY_2_KS_PBS, PARAM_MESSAGE_2_CARRY_3_KS_PBS, PARAM_MESSAGE_3_CARRY_1_KS_PBS,
|
||||||
PARAM_MESSAGE_3_CARRY_1_KS_PBS, PARAM_MESSAGE_3_CARRY_2_KS_PBS, PARAM_MESSAGE_3_CARRY_3_KS_PBS,
|
PARAM_MESSAGE_3_CARRY_2_KS_PBS, PARAM_MESSAGE_3_CARRY_3_KS_PBS, PARAM_MESSAGE_4_CARRY_4_KS_PBS,
|
||||||
PARAM_MESSAGE_4_CARRY_4_KS_PBS, WOPBS_PARAM_MESSAGE_1_CARRY_1_KS_PBS,
|
};
|
||||||
WOPBS_PARAM_MESSAGE_2_CARRY_2_KS_PBS, WOPBS_PARAM_MESSAGE_3_CARRY_3_KS_PBS,
|
#[cfg(feature = "experimental")]
|
||||||
WOPBS_PARAM_MESSAGE_4_CARRY_4_KS_PBS,
|
use tfhe::shortint::parameters::{
|
||||||
|
WopbsParameters, WOPBS_PARAM_MESSAGE_1_CARRY_1_KS_PBS, WOPBS_PARAM_MESSAGE_2_CARRY_2_KS_PBS,
|
||||||
|
WOPBS_PARAM_MESSAGE_3_CARRY_3_KS_PBS, WOPBS_PARAM_MESSAGE_4_CARRY_4_KS_PBS,
|
||||||
};
|
};
|
||||||
use tfhe::shortint::MultiBitPBSParameters;
|
use tfhe::shortint::MultiBitPBSParameters;
|
||||||
|
|
||||||
@@ -89,11 +93,14 @@ fn client_server_keys() {
|
|||||||
|
|
||||||
generate_ksk_keys(&KSK_PARAMS);
|
generate_ksk_keys(&KSK_PARAMS);
|
||||||
|
|
||||||
const WOPBS_PARAMS: [(ClassicPBSParameters, WopbsParameters); 1] = [(
|
#[cfg(feature = "experimental")]
|
||||||
PARAM_MESSAGE_2_CARRY_2_KS_PBS,
|
{
|
||||||
WOPBS_PARAM_MESSAGE_2_CARRY_2_KS_PBS,
|
const WOPBS_PARAMS: [(ClassicPBSParameters, WopbsParameters); 1] = [(
|
||||||
)];
|
PARAM_MESSAGE_2_CARRY_2_KS_PBS,
|
||||||
generate_wopbs_keys(&WOPBS_PARAMS);
|
WOPBS_PARAM_MESSAGE_2_CARRY_2_KS_PBS,
|
||||||
|
)];
|
||||||
|
generate_wopbs_keys(&WOPBS_PARAMS);
|
||||||
|
}
|
||||||
|
|
||||||
const BOOLEAN_PARAMS: [BooleanParameters; 2] =
|
const BOOLEAN_PARAMS: [BooleanParameters; 2] =
|
||||||
[DEFAULT_PARAMETERS, DEFAULT_PARAMETERS_KS_PBS];
|
[DEFAULT_PARAMETERS, DEFAULT_PARAMETERS_KS_PBS];
|
||||||
@@ -116,26 +123,29 @@ fn client_server_keys() {
|
|||||||
];
|
];
|
||||||
generate_pbs_keys(&PBS_KEYS);
|
generate_pbs_keys(&PBS_KEYS);
|
||||||
|
|
||||||
const WOPBS_PARAMS: [(ClassicPBSParameters, WopbsParameters); 4] = [
|
#[cfg(feature = "experimental")]
|
||||||
(
|
{
|
||||||
PARAM_MESSAGE_1_CARRY_1_KS_PBS,
|
const WOPBS_PARAMS: [(ClassicPBSParameters, WopbsParameters); 4] = [
|
||||||
WOPBS_PARAM_MESSAGE_1_CARRY_1_KS_PBS,
|
(
|
||||||
),
|
PARAM_MESSAGE_1_CARRY_1_KS_PBS,
|
||||||
(
|
WOPBS_PARAM_MESSAGE_1_CARRY_1_KS_PBS,
|
||||||
PARAM_MESSAGE_2_CARRY_2_KS_PBS,
|
),
|
||||||
WOPBS_PARAM_MESSAGE_2_CARRY_2_KS_PBS,
|
(
|
||||||
),
|
PARAM_MESSAGE_2_CARRY_2_KS_PBS,
|
||||||
(
|
WOPBS_PARAM_MESSAGE_2_CARRY_2_KS_PBS,
|
||||||
PARAM_MESSAGE_3_CARRY_3_KS_PBS,
|
),
|
||||||
WOPBS_PARAM_MESSAGE_3_CARRY_3_KS_PBS,
|
(
|
||||||
),
|
PARAM_MESSAGE_3_CARRY_3_KS_PBS,
|
||||||
(
|
WOPBS_PARAM_MESSAGE_3_CARRY_3_KS_PBS,
|
||||||
PARAM_MESSAGE_4_CARRY_4_KS_PBS,
|
),
|
||||||
WOPBS_PARAM_MESSAGE_4_CARRY_4_KS_PBS,
|
(
|
||||||
),
|
PARAM_MESSAGE_4_CARRY_4_KS_PBS,
|
||||||
];
|
WOPBS_PARAM_MESSAGE_4_CARRY_4_KS_PBS,
|
||||||
|
),
|
||||||
|
];
|
||||||
|
|
||||||
generate_wopbs_keys(&WOPBS_PARAMS);
|
generate_wopbs_keys(&WOPBS_PARAMS);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -219,6 +229,7 @@ fn generate_ksk_keys(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "experimental")]
|
||||||
fn generate_wopbs_keys(params: &[(ClassicPBSParameters, WopbsParameters)]) {
|
fn generate_wopbs_keys(params: &[(ClassicPBSParameters, WopbsParameters)]) {
|
||||||
println!("Generating woPBS keys");
|
println!("Generating woPBS keys");
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
|
#[cfg(feature = "experimental")]
|
||||||
use crate::integer::wopbs::WopbsKey;
|
use crate::integer::wopbs::WopbsKey;
|
||||||
use crate::integer::{ClientKey, IntegerKeyKind, ServerKey};
|
use crate::integer::{ClientKey, IntegerKeyKind, ServerKey};
|
||||||
use crate::shortint::{PBSParameters, WopbsParameters};
|
use crate::shortint::PBSParameters;
|
||||||
|
#[cfg(feature = "experimental")]
|
||||||
|
use crate::shortint::WopbsParameters;
|
||||||
use lazy_static::lazy_static;
|
use lazy_static::lazy_static;
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
@@ -39,8 +42,10 @@ impl IntegerKeyCache {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
|
#[cfg(feature = "experimental")]
|
||||||
pub struct WopbsKeyCache;
|
pub struct WopbsKeyCache;
|
||||||
|
|
||||||
|
#[cfg(feature = "experimental")]
|
||||||
impl WopbsKeyCache {
|
impl WopbsKeyCache {
|
||||||
pub fn get_from_params<P>(&self, (pbs_params, wopbs_params): (P, WopbsParameters)) -> WopbsKey
|
pub fn get_from_params<P>(&self, (pbs_params, wopbs_params): (P, WopbsParameters)) -> WopbsKey
|
||||||
where
|
where
|
||||||
@@ -65,5 +70,8 @@ impl WopbsKeyCache {
|
|||||||
|
|
||||||
lazy_static! {
|
lazy_static! {
|
||||||
pub static ref KEY_CACHE: IntegerKeyCache = IntegerKeyCache;
|
pub static ref KEY_CACHE: IntegerKeyCache = IntegerKeyCache;
|
||||||
|
}
|
||||||
|
#[cfg(feature = "experimental")]
|
||||||
|
lazy_static! {
|
||||||
pub static ref KEY_CACHE_WOPBS: WopbsKeyCache = WopbsKeyCache;
|
pub static ref KEY_CACHE_WOPBS: WopbsKeyCache = WopbsKeyCache;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -63,7 +63,10 @@ pub mod parameters;
|
|||||||
pub mod prelude;
|
pub mod prelude;
|
||||||
pub mod public_key;
|
pub mod public_key;
|
||||||
pub mod server_key;
|
pub mod server_key;
|
||||||
|
#[cfg(feature = "experimental")]
|
||||||
pub mod wopbs;
|
pub mod wopbs;
|
||||||
|
#[cfg(not(feature = "experimental"))]
|
||||||
|
pub(crate) mod wopbs;
|
||||||
|
|
||||||
#[cfg(feature = "gpu")]
|
#[cfg(feature = "gpu")]
|
||||||
pub mod gpu;
|
pub mod gpu;
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -24,6 +24,7 @@ use std::fmt::Debug;
|
|||||||
mod client_side;
|
mod client_side;
|
||||||
mod public_side;
|
mod public_side;
|
||||||
mod server_side;
|
mod server_side;
|
||||||
|
#[cfg(feature = "experimental")]
|
||||||
mod wopbs;
|
mod wopbs;
|
||||||
|
|
||||||
thread_local! {
|
thread_local! {
|
||||||
@@ -263,8 +264,6 @@ impl std::fmt::Display for EngineError {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) type EngineResult<T> = Result<T, EngineError>;
|
|
||||||
|
|
||||||
/// ShortintEngine
|
/// ShortintEngine
|
||||||
///
|
///
|
||||||
/// This 'engine' holds the necessary engines from [`core_crypto`](crate::core_crypto)
|
/// This 'engine' holds the necessary engines from [`core_crypto`](crate::core_crypto)
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
use crate::core_crypto::algorithms::*;
|
use crate::core_crypto::algorithms::*;
|
||||||
use crate::core_crypto::entities::*;
|
use crate::core_crypto::entities::*;
|
||||||
use crate::shortint::ciphertext::{MaxDegree, MaxNoiseLevel};
|
use crate::shortint::ciphertext::{MaxDegree, MaxNoiseLevel};
|
||||||
use crate::shortint::engine::{EngineResult, ShortintEngine};
|
use crate::shortint::engine::ShortintEngine;
|
||||||
use crate::shortint::server_key::ShortintBootstrappingKey;
|
use crate::shortint::server_key::ShortintBootstrappingKey;
|
||||||
use crate::shortint::wopbs::{WopbsKey, WopbsKeyCreationError};
|
use crate::shortint::wopbs::{WopbsKey, WopbsKeyCreationError};
|
||||||
use crate::shortint::{ClientKey, ServerKey, WopbsParameters};
|
use crate::shortint::{ClientKey, ServerKey, WopbsParameters};
|
||||||
@@ -13,12 +13,15 @@ impl ShortintEngine {
|
|||||||
&mut self,
|
&mut self,
|
||||||
cks: &ClientKey,
|
cks: &ClientKey,
|
||||||
sks: &ServerKey,
|
sks: &ServerKey,
|
||||||
) -> EngineResult<WopbsKey> {
|
) -> crate::Result<WopbsKey> {
|
||||||
if matches!(
|
if matches!(
|
||||||
sks.bootstrapping_key,
|
sks.bootstrapping_key,
|
||||||
ShortintBootstrappingKey::MultiBit { .. }
|
ShortintBootstrappingKey::MultiBit { .. }
|
||||||
) {
|
) {
|
||||||
return Err(WopbsKeyCreationError::UnsupportedMultiBit.into());
|
return Err(crate::Error::new(format!(
|
||||||
|
"{}",
|
||||||
|
WopbsKeyCreationError::UnsupportedMultiBit
|
||||||
|
)));
|
||||||
}
|
}
|
||||||
|
|
||||||
let wop_params = cks.parameters.wopbs_parameters().unwrap();
|
let wop_params = cks.parameters.wopbs_parameters().unwrap();
|
||||||
|
|||||||
@@ -412,55 +412,60 @@ impl Keycache {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Copy, Clone, Debug, PartialEq, Serialize, Deserialize)]
|
#[cfg(feature = "experimental")]
|
||||||
pub struct WopbsParamPair(pub PBSParameters, pub WopbsParameters);
|
mod wopbs {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
impl<P> From<(P, WopbsParameters)> for WopbsParamPair
|
#[derive(Copy, Clone, Debug, PartialEq, Serialize, Deserialize)]
|
||||||
where
|
pub struct WopbsParamPair(pub PBSParameters, pub WopbsParameters);
|
||||||
P: Into<PBSParameters>,
|
|
||||||
{
|
|
||||||
fn from(tuple: (P, WopbsParameters)) -> Self {
|
|
||||||
Self(tuple.0.into(), tuple.1)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl NamedParam for WopbsParamPair {
|
impl<P> From<(P, WopbsParameters)> for WopbsParamPair
|
||||||
fn name(&self) -> String {
|
where
|
||||||
self.1.name()
|
P: Into<PBSParameters>,
|
||||||
}
|
{
|
||||||
}
|
fn from(tuple: (P, WopbsParameters)) -> Self {
|
||||||
|
Self(tuple.0.into(), tuple.1)
|
||||||
/// The KeyCache struct for shortint.
|
|
||||||
///
|
|
||||||
/// You should not create an instance yourself,
|
|
||||||
/// but rather use the global variable defined: [static@KEY_CACHE_WOPBS]
|
|
||||||
pub struct KeycacheWopbsV0 {
|
|
||||||
inner: ImplKeyCache<WopbsParamPair, WopbsKey, FileStorage>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Default for KeycacheWopbsV0 {
|
|
||||||
fn default() -> Self {
|
|
||||||
Self {
|
|
||||||
inner: ImplKeyCache::new(FileStorage::new("../keys/shortint/wopbs_v0".to_string())),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl KeycacheWopbsV0 {
|
|
||||||
pub fn get_from_param<T: Into<WopbsParamPair>>(&self, params: T) -> SharedWopbsKey {
|
|
||||||
let params = params.into();
|
|
||||||
let key = KEY_CACHE.get_from_param(params.0);
|
|
||||||
let wk = self.inner.get_with_closure(params, &mut |_| {
|
|
||||||
WopbsKey::new_wopbs_key(&key.inner.0, &key.inner.1, ¶ms.1)
|
|
||||||
});
|
|
||||||
SharedWopbsKey {
|
|
||||||
inner: key.inner,
|
|
||||||
wopbs: wk,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn clear_in_memory_cache(&self) {
|
impl NamedParam for WopbsParamPair {
|
||||||
self.inner.clear_in_memory_cache();
|
fn name(&self) -> String {
|
||||||
|
self.1.name()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The KeyCache struct for shortint.
|
||||||
|
///
|
||||||
|
/// You should not create an instance yourself,
|
||||||
|
/// but rather use the global variable defined: [static@KEY_CACHE_WOPBS]
|
||||||
|
pub struct KeycacheWopbsV0 {
|
||||||
|
inner: ImplKeyCache<WopbsParamPair, WopbsKey, FileStorage>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for KeycacheWopbsV0 {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self {
|
||||||
|
inner: ImplKeyCache::new(FileStorage::new("../keys/shortint/wopbs_v0".to_string())),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl KeycacheWopbsV0 {
|
||||||
|
pub fn get_from_param<T: Into<WopbsParamPair>>(&self, params: T) -> SharedWopbsKey {
|
||||||
|
let params = params.into();
|
||||||
|
let key = KEY_CACHE.get_from_param(params.0);
|
||||||
|
let wk = self.inner.get_with_closure(params, &mut |_| {
|
||||||
|
WopbsKey::new_wopbs_key(&key.inner.0, &key.inner.1, ¶ms.1)
|
||||||
|
});
|
||||||
|
SharedWopbsKey {
|
||||||
|
inner: key.inner,
|
||||||
|
wopbs: wk,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn clear_in_memory_cache(&self) {
|
||||||
|
self.inner.clear_in_memory_cache();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -531,6 +536,10 @@ impl KeycacheKeySwitchingKey {
|
|||||||
|
|
||||||
lazy_static! {
|
lazy_static! {
|
||||||
pub static ref KEY_CACHE: Keycache = Keycache::default();
|
pub static ref KEY_CACHE: Keycache = Keycache::default();
|
||||||
pub static ref KEY_CACHE_WOPBS: KeycacheWopbsV0 = KeycacheWopbsV0::default();
|
|
||||||
pub static ref KEY_CACHE_KSK: KeycacheKeySwitchingKey = KeycacheKeySwitchingKey::default();
|
pub static ref KEY_CACHE_KSK: KeycacheKeySwitchingKey = KeycacheKeySwitchingKey::default();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "experimental")]
|
||||||
|
lazy_static! {
|
||||||
|
pub static ref KEY_CACHE_WOPBS: wopbs::KeycacheWopbsV0 = wopbs::KeycacheWopbsV0::default();
|
||||||
|
}
|
||||||
|
|||||||
@@ -60,7 +60,10 @@ pub mod parameters;
|
|||||||
pub mod prelude;
|
pub mod prelude;
|
||||||
pub mod public_key;
|
pub mod public_key;
|
||||||
pub mod server_key;
|
pub mod server_key;
|
||||||
|
#[cfg(feature = "experimental")]
|
||||||
pub mod wopbs;
|
pub mod wopbs;
|
||||||
|
#[cfg(not(feature = "experimental"))]
|
||||||
|
pub(crate) mod wopbs;
|
||||||
|
|
||||||
pub use ciphertext::{Ciphertext, CompressedCiphertext, PBSOrder};
|
pub use ciphertext::{Ciphertext, CompressedCiphertext, PBSOrder};
|
||||||
pub use client_key::ClientKey;
|
pub use client_key::ClientKey;
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user