mirror of
https://github.com/zama-ai/concrete.git
synced 2026-02-15 15:15:06 -05:00
rust: update rust security curves generation
This commit is contained in:
committed by
Quentin Bourgerie
parent
7e8792ed34
commit
732f2de57d
13
rust-security-curves/gen_table.py
Normal file
13
rust-security-curves/gen_table.py
Normal file
@@ -0,0 +1,13 @@
|
||||
import sys, json;
|
||||
|
||||
def print_curve(data):
|
||||
print(f' ({data["bits"]}, SecurityWeights {{ slope: {data["linear_term1"]}, bias: {data["linear_term2"]}, minimal_lwe_dimension: {data["n_alpha"]} }}),')
|
||||
|
||||
|
||||
def print_rust_curves_declaration(datas):
|
||||
print("[")
|
||||
for data in datas:
|
||||
print_curve(data)
|
||||
print("]")
|
||||
|
||||
print_rust_curves_declaration(json.load(open("json/curves.json")))
|
||||
@@ -1,4 +1,4 @@
|
||||
const SECURITY_WEIGHTS_ARRAY: [(f64, f64, u64, &str, u64); 9] = include!("../verified_curves.txt");
|
||||
const SECURITY_WEIGHTS_ARRAY: [(u64, SecurityWeights); 9] = include!("../verified_curves.txt");
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
pub struct SecurityWeights {
|
||||
@@ -27,29 +27,15 @@ impl SecurityWeights {
|
||||
pub fn supported_security_levels() -> impl std::iter::Iterator<Item = u64> {
|
||||
SECURITY_WEIGHTS_ARRAY
|
||||
.iter()
|
||||
.filter(|(_, _, _, status, _)| *status == "PASS")
|
||||
.map(|(_, _, security_level, _, _)| *security_level)
|
||||
.map(|(security_level, _)| *security_level)
|
||||
}
|
||||
|
||||
pub fn security_weight(security_level: u64) -> Option<SecurityWeights> {
|
||||
let index = SECURITY_WEIGHTS_ARRAY
|
||||
.binary_search_by_key(&security_level, |(_, _, security_level, _, _)| {
|
||||
*security_level
|
||||
})
|
||||
.binary_search_by_key(&security_level, |(security_level, _)| *security_level)
|
||||
.ok()?;
|
||||
|
||||
let (slope, bias, _security_level, status, minimal_lwe_dimension) =
|
||||
SECURITY_WEIGHTS_ARRAY[index];
|
||||
|
||||
if status == "PASS" {
|
||||
Some(SecurityWeights {
|
||||
slope,
|
||||
bias,
|
||||
minimal_lwe_dimension,
|
||||
})
|
||||
} else {
|
||||
None
|
||||
}
|
||||
Some(SECURITY_WEIGHTS_ARRAY[index].1)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
[(-0.04042633119364589, 1.6609788641436722, 80, "PASS", 450),
|
||||
(-0.03414780360867051, 2.017310258660345, 96, "PASS", 450),
|
||||
(-0.029670137081135885, 2.162463714083856, 112, "PASS", 450),
|
||||
(-0.02640502876522622, 2.4826422691043177, 128, "PASS", 450),
|
||||
(-0.023821437305989134, 2.7177789440636673, 144, "PASS", 450),
|
||||
(-0.02174358218716036, 2.938810548493322, 160, "PASS", 498),
|
||||
(-0.019904056582117684, 2.8161252801542247, 176, "PASS", 551),
|
||||
(-0.018610403247590085, 3.2996236848399008, 192, "PASS", 606),
|
||||
(-0.014606812351714953, 3.8493629234693003, 256, "PASS", 826)]
|
||||
[
|
||||
(80, SecurityWeights { slope: -0.0404263311936459, bias: 1.660978864143658, minimal_lwe_dimension: 450 }),
|
||||
(96, SecurityWeights { slope: -0.03414780360867054, bias: 2.0173102586603733, minimal_lwe_dimension: 450 }),
|
||||
(112, SecurityWeights { slope: -0.02967013708113588, bias: 2.16246371408387, minimal_lwe_dimension: 450 }),
|
||||
(128, SecurityWeights { slope: -0.026405028765226296, bias: 2.482642269104389, minimal_lwe_dimension: 450 }),
|
||||
(144, SecurityWeights { slope: -0.023821437305989134, bias: 2.7177789440636673, minimal_lwe_dimension: 450 }),
|
||||
(160, SecurityWeights { slope: -0.021743582187160406, bias: 2.9388105484933504, minimal_lwe_dimension: 498 }),
|
||||
(176, SecurityWeights { slope: -0.019904056582117705, bias: 2.8161252801542673, minimal_lwe_dimension: 551 }),
|
||||
(192, SecurityWeights { slope: -0.018610403247590064, bias: 3.2996236848399008, minimal_lwe_dimension: 606 }),
|
||||
(256, SecurityWeights { slope: -0.014606812351714961, bias: 3.8493629234693145, minimal_lwe_dimension: 826 }),
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user