mirror of
https://github.com/zama-ai/tfhe-rs.git
synced 2026-01-11 07:38:08 -05:00
Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c3c4615dfa | ||
|
|
ea5af20694 | ||
|
|
66f81f7376 | ||
|
|
710e8e9edd |
28
ci/lattice_estimator.sage
Executable file
28
ci/lattice_estimator.sage
Executable file
@@ -0,0 +1,28 @@
|
||||
import sys
|
||||
sys.path.insert(1, 'lattice-estimator')
|
||||
from estimator import *
|
||||
|
||||
|
||||
model = RC.BDGL16
|
||||
|
||||
load("boolean_parameters_lattice_estimator.sage")
|
||||
|
||||
params_to_update = []
|
||||
|
||||
for param in all_params:
|
||||
print("parameters = {}".format(param.tag))
|
||||
try:
|
||||
usvp_level = LWE.primal_usvp(param, red_cost_model = model)
|
||||
dual_level = LWE.dual_hybrid(param, red_cost_model = model)
|
||||
estimator_level = log(min(usvp_level["rop"], dual_level["rop"]),2)
|
||||
if 128 > estimator_level:
|
||||
print("target security level = 128")
|
||||
print("attained security level = {}".format(estimator_level))
|
||||
params_to_update.append(param)
|
||||
else:
|
||||
print("pass.")
|
||||
except Exception as e:
|
||||
print(e)
|
||||
print("fail.")
|
||||
|
||||
print(params_to_update)
|
||||
@@ -18,11 +18,16 @@
|
||||
//! Failing to properly fix the parameters will potentially result with an incorrect and/or insecure
|
||||
//! computation.
|
||||
|
||||
use crate::core_crypto::commons::dispersion::DispersionParameter;
|
||||
pub use crate::core_crypto::commons::dispersion::StandardDev;
|
||||
pub use crate::core_crypto::commons::parameters::{
|
||||
DecompositionBaseLog, DecompositionLevelCount, GlweDimension, LweDimension, PolynomialSize,
|
||||
};
|
||||
|
||||
use crate::shortint::keycache::NamedParam;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::fs;
|
||||
use std::fs::File;
|
||||
|
||||
/// A set of cryptographic parameters for homomorphic Boolean circuit evaluation.
|
||||
#[derive(Copy, Clone, Debug, PartialEq, Serialize, Deserialize)]
|
||||
@@ -106,15 +111,15 @@ impl BooleanKeySwitchingParameters {
|
||||
/// This parameter set allows to evaluate faster Boolean circuits than the `TFHE_LIB_PARAMETERS`
|
||||
/// one.
|
||||
pub const DEFAULT_PARAMETERS: BooleanParameters = BooleanParameters {
|
||||
lwe_dimension: LweDimension(777),
|
||||
glwe_dimension: GlweDimension(3),
|
||||
lwe_dimension: LweDimension(722),
|
||||
glwe_dimension: GlweDimension(2),
|
||||
polynomial_size: PolynomialSize(512),
|
||||
lwe_modular_std_dev: StandardDev(0.000003725679281679651),
|
||||
glwe_modular_std_dev: StandardDev(0.0000000000034525330484572114),
|
||||
pbs_base_log: DecompositionBaseLog(18),
|
||||
pbs_level: DecompositionLevelCount(1),
|
||||
ks_base_log: DecompositionBaseLog(4),
|
||||
ks_level: DecompositionLevelCount(3),
|
||||
lwe_modular_std_dev: StandardDev(0.000013071021089943935),
|
||||
glwe_modular_std_dev: StandardDev(0.00000004990272175010415),
|
||||
pbs_base_log: DecompositionBaseLog(6),
|
||||
pbs_level: DecompositionLevelCount(3),
|
||||
ks_base_log: DecompositionBaseLog(3),
|
||||
ks_level: DecompositionLevelCount(4),
|
||||
};
|
||||
|
||||
/// The secret keys generated with this parameter set are uniform binary.
|
||||
@@ -123,13 +128,85 @@ pub const DEFAULT_PARAMETERS: BooleanParameters = BooleanParameters {
|
||||
/// They are updated to the last security standards, so they differ from the original
|
||||
/// publication.
|
||||
pub const TFHE_LIB_PARAMETERS: BooleanParameters = BooleanParameters {
|
||||
lwe_dimension: LweDimension(830),
|
||||
lwe_dimension: LweDimension(767),
|
||||
glwe_dimension: GlweDimension(2),
|
||||
polynomial_size: PolynomialSize(1024),
|
||||
lwe_modular_std_dev: StandardDev(0.000001412290588219445),
|
||||
glwe_modular_std_dev: StandardDev(0.00000000000000029403601535432533),
|
||||
pbs_base_log: DecompositionBaseLog(23),
|
||||
pbs_level: DecompositionLevelCount(1),
|
||||
ks_base_log: DecompositionBaseLog(5),
|
||||
ks_level: DecompositionLevelCount(3),
|
||||
lwe_modular_std_dev: StandardDev(0.000005104350373791501),
|
||||
glwe_modular_std_dev: StandardDev(0.0000000009313225746154785),
|
||||
pbs_base_log: DecompositionBaseLog(10),
|
||||
pbs_level: DecompositionLevelCount(2),
|
||||
ks_base_log: DecompositionBaseLog(3),
|
||||
ks_level: DecompositionLevelCount(5),
|
||||
};
|
||||
|
||||
pub const VEC_BOOLEAN_PARAM: [BooleanParameters; 2] = [DEFAULT_PARAMETERS, TFHE_LIB_PARAMETERS];
|
||||
|
||||
///Function to print in the lattice_estimator format the parameters
|
||||
/// Format: LWE.Parameters(n=722, q=2^32, Xs=ND.UniformMod(2), Xe=ND.DiscreteGaussian(56139.60810663548), tag='test_lattice_estimator')
|
||||
pub fn format_lwe_parameters_to_lattice_estimator(param: BooleanParameters) -> String {
|
||||
let log_ciphertext_modulus = 32;
|
||||
let modular_std_dev = param
|
||||
.lwe_modular_std_dev
|
||||
.get_modular_standard_dev(log_ciphertext_modulus);
|
||||
|
||||
format!(
|
||||
"{}_LWE = LWE.Parameters(\n n = {},\n q ={},\n Xs=ND.UniformMod(2), \n Xe=ND.DiscreteGaussian({}),\n tag='{}_lwe' \n)\n\n",
|
||||
param.name(), param.lwe_dimension.0, (1u128<<log_ciphertext_modulus as u128), modular_std_dev, param.name())
|
||||
}
|
||||
|
||||
///Function to print in the lattice_estimator format the parameters
|
||||
/// Format: LWE.Parameters(n=722, q=2^32, Xs=ND.UniformMod(2), Xe=ND.DiscreteGaussian(56139.60810663548), tag='test_lattice_estimator')
|
||||
pub fn format_glwe_parameters_to_lattice_estimator(param: BooleanParameters) -> String {
|
||||
let log_ciphertext_modulus = 32;
|
||||
let modular_std_dev = param
|
||||
.glwe_modular_std_dev
|
||||
.get_modular_standard_dev(log_ciphertext_modulus);
|
||||
|
||||
format!(
|
||||
"{}_GLWE = LWE.Parameters(\n n = {},\n q = {},\n Xs=ND.UniformMod(2), \n Xe=ND.DiscreteGaussian({}),\n tag='{}_glwe' \n)\n\n",
|
||||
param.name(), param.glwe_dimension.0*param.polynomial_size.0, (1u128<<log_ciphertext_modulus as u128), modular_std_dev, param.name())
|
||||
}
|
||||
|
||||
pub fn write_all_param_in_file(vec_boolean_param: &[BooleanParameters]) {
|
||||
let path = "../ci/boolean_parameters_lattice_estimator.sage";
|
||||
|
||||
for params in vec_boolean_param.iter().copied() {
|
||||
fs::write(path, format_lwe_parameters_to_lattice_estimator(params))
|
||||
.expect("Unable to write file");
|
||||
fs::write(path, format_glwe_parameters_to_lattice_estimator(params))
|
||||
.expect("Unable to write file");
|
||||
}
|
||||
fs::write(path, "all_params = [\n");
|
||||
for (i, params) in vec_boolean_param.iter().copied().enumerate() {
|
||||
let param_lwe_name = format!("{}_LWE,", params.name());
|
||||
let param_glwe_name = format!("{}_GLWE,", params.name());
|
||||
fs::write(path, param_lwe_name).expect("Unable to write file");
|
||||
fs::write(path, param_glwe_name).expect("Unable to write file");
|
||||
|
||||
if i < (vec_boolean_param.len() - 1) {
|
||||
fs::write(path, ", ").expect("Unable to write file");
|
||||
}
|
||||
}
|
||||
fs::write(path, "]").expect("Unable to write file");
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn test_format_le() {
|
||||
//write_all_param_in_file(&VEC_BOOLEAN_PARAM);
|
||||
println!(
|
||||
"{}",
|
||||
format_glwe_parameters_to_lattice_estimator(DEFAULT_PARAMETERS)
|
||||
);
|
||||
panic!();
|
||||
}
|
||||
impl NamedParam for BooleanParameters {
|
||||
fn name(&self) -> &'static str {
|
||||
if *self == DEFAULT_PARAMETERS {
|
||||
"DEFAULT_PARAMETERS"
|
||||
} else if *self == TFHE_LIB_PARAMETERS {
|
||||
"TFHE_LIB_PARAMETERS"
|
||||
} else {
|
||||
panic!("Unknown parameters, missing name implementation")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user