Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mz/integer compression key #22

Merged
merged 2 commits into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 22 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,20 @@ edition = "2021"
[dependencies]
# This is a list of tfhe-rs versions we will generate data for. This list will grow over time.
# They are only activated when generating data, with the binary target and the "generate" feature.
tfhe_0_6 = { version = "0.6", features = ["boolean", "integer", "shortint", "x86_64-unix", "experimental-force_fft_algo_dif4"], package = "tfhe", optional = true }
tfhe_0_7 = { version = "0.7", features = ["boolean", "integer", "shortint", "x86_64-unix", "experimental-force_fft_algo_dif4"], package = "tfhe", optional = true }
tfhe_0_6 = { version = "0.6", features = [
"boolean",
"integer",
"shortint",
"x86_64-unix",
"experimental-force_fft_algo_dif4",
], package = "tfhe", optional = true }
tfhe_0_7 = { version = "0.7", features = [
"boolean",
"integer",
"shortint",
"x86_64-unix",
"experimental-force_fft_algo_dif4",
], package = "tfhe", optional = true }

tfhe-versionable_0_1 = { version = "0.1", optional = true, package = "tfhe-versionable" }
tfhe-versionable_0_2 = { version = "0.2", optional = true, package = "tfhe-versionable" }
Expand All @@ -30,5 +42,12 @@ required-features = ["generate"]
[features]
default = ["generate"]

generate = ["dep:tfhe_0_6", "dep:tfhe_0_7", "dep:tfhe-versionable_0_1", "dep:tfhe-versionable_0_2"]
generate = [
"dep:tfhe_0_6",
"dep:tfhe_0_7",
"dep:tfhe-versionable_0_1",
"dep:tfhe-versionable_0_2",
]
load = ["dep:semver"]

[workspace]
3 changes: 3 additions & 0 deletions data/0_7/high_level_api/client_key_with_compression.bcode
Git LFS file not shown
3 changes: 3 additions & 0 deletions data/0_7/high_level_api/client_key_with_compression.cbor
Git LFS file not shown
3 changes: 3 additions & 0 deletions data/0_7/high_level_api/server_key_with_compression.bcode
Git LFS file not shown
3 changes: 3 additions & 0 deletions data/0_7/high_level_api/server_key_with_compression.cbor
Git LFS file not shown
33 changes: 33 additions & 0 deletions data/high_level_api.ron
Original file line number Diff line number Diff line change
Expand Up @@ -347,4 +347,37 @@
],
)),
),
(
tfhe_version_min: "0.7",
tfhe_module: "high_level_api",
metadata: HlClientKey((
test_filename: "client_key_with_compression",
parameters: (
lwe_dimension: 761,
glwe_dimension: 1,
polynomial_size: 2048,
lwe_noise_gaussian_stddev: 0.00000636835566258815,
glwe_noise_gaussian_stddev: 0.00000000000000031529322391500584,
pbs_base_log: 23,
pbs_level: 1,
ks_base_log: 3,
ks_level: 5,
message_modulus: 4,
ciphertext_modulus: 18446744073709551616,
carry_modulus: 4,
max_noise_level: 5,
log2_p_fail: -40.05,
encryption_key_choice: "big",
),
)),
),
(
tfhe_version_min: "0.7",
tfhe_module: "high_level_api",
metadata: HlServerKey((
test_filename: "server_key_with_compression",
client_key_filename: "client_key_with_compression.cbor",
compressed: false,
)),
),
]
52 changes: 23 additions & 29 deletions src/data_0_6.rs
Original file line number Diff line number Diff line change
@@ -1,38 +1,32 @@
use std::{borrow::Cow, fs::create_dir_all};

use tfhe_0_6::{
boolean::engine::BooleanEngine,
core_crypto::commons::{
generators::DeterministicSeeder,
math::random::{ActivatedRandomGenerator, Seed},
},
generate_keys,
prelude::FheEncrypt,
set_server_key,
shortint::{
self,
engine::ShortintEngine,
parameters::{
DecompositionBaseLog, DecompositionLevelCount, DynamicDistribution, GlweDimension,
LweDimension, PolynomialSize, StandardDev, PARAM_MESSAGE_1_CARRY_1_PBS_KS,
},
CarryModulus, CiphertextModulus, ClassicPBSParameters, EncryptionKeyChoice, MaxNoiseLevel,
MessageModulus, PBSParameters,
},
ClientKey, CompactFheBool, CompactFheBoolList, CompactFheInt8, CompactFheInt8List,
CompactFheUint8, CompactFheUint8List, CompactPublicKey, CompressedCompactPublicKey,
CompressedFheBool, CompressedFheInt8, CompressedFheUint8, CompressedPublicKey,
CompressedServerKey, ConfigBuilder, FheBool, FheInt8, FheUint8, PublicKey,
};
use tfhe_versionable_0_1::Versionize;

use crate::generate::{save_cbor, store_versioned_test_01, TfhersVersion, VALID_TEST_PARAMS};
use crate::{
generate::{save_cbor, store_versioned_test_01, TfhersVersion, VALID_TEST_PARAMS},
HlBoolCiphertextListTest, HlBoolCiphertextTest, HlCiphertextListTest, HlCiphertextTest,
HlClientKeyTest, HlPublicKeyTest, HlServerKeyTest, HlSignedCiphertextListTest,
HlSignedCiphertextTest, ShortintCiphertextTest, ShortintClientKeyTest, TestMetadata,
TestParameterSet, HL_MODULE_NAME, SHORTINT_MODULE_NAME,
};
use std::borrow::Cow;
use std::fs::create_dir_all;
use tfhe_0_6::boolean::engine::BooleanEngine;
use tfhe_0_6::core_crypto::commons::generators::DeterministicSeeder;
use tfhe_0_6::core_crypto::commons::math::random::{ActivatedRandomGenerator, Seed};
use tfhe_0_6::prelude::FheEncrypt;
use tfhe_0_6::shortint::engine::ShortintEngine;
use tfhe_0_6::shortint::parameters::{
DecompositionBaseLog, DecompositionLevelCount, DynamicDistribution, GlweDimension,
LweDimension, PolynomialSize, StandardDev, PARAM_MESSAGE_1_CARRY_1_PBS_KS,
};
use tfhe_0_6::shortint::{
self, CarryModulus, CiphertextModulus, ClassicPBSParameters, EncryptionKeyChoice,
MaxNoiseLevel, MessageModulus, PBSParameters,
};
use tfhe_0_6::{
generate_keys, set_server_key, ClientKey, CompactFheBool, CompactFheBoolList, CompactFheInt8,
CompactFheInt8List, CompactFheUint8, CompactFheUint8List, CompactPublicKey,
CompressedCompactPublicKey, CompressedFheBool, CompressedFheInt8, CompressedFheUint8,
CompressedPublicKey, CompressedServerKey, ConfigBuilder, FheBool, FheInt8, FheUint8, PublicKey,
};
use tfhe_versionable_0_1::Versionize;

macro_rules! store_versioned_test {
($msg:expr, $dir:expr, $test_filename:expr $(,)? ) => {
Expand Down
76 changes: 49 additions & 27 deletions src/data_0_7.rs
Original file line number Diff line number Diff line change
@@ -1,31 +1,28 @@
use std::{borrow::Cow, fs::create_dir_all};

use tfhe_0_7::{
boolean::engine::BooleanEngine,
core_crypto::commons::{
generators::DeterministicSeeder, math::random::ActivatedRandomGenerator,
},
generate_keys,
prelude::FheEncrypt,
set_server_key,
shortint::{
engine::ShortintEngine,
parameters::{
DecompositionBaseLog, DecompositionLevelCount, DynamicDistribution, GlweDimension,
LweDimension, PolynomialSize, StandardDev, COMP_PARAM_MESSAGE_2_CARRY_2,
},
CarryModulus, CiphertextModulus, ClassicPBSParameters, EncryptionKeyChoice, MaxNoiseLevel,
MessageModulus, PBSParameters,
},
CompactCiphertextList, CompactPublicKey, CompressedCiphertextListBuilder, FheBool, FheInt8,
FheUint8, Seed,
use crate::generate::{
store_versioned_auxiliary_02, store_versioned_test_02, TfhersVersion, VALID_TEST_PARAMS,
};

use crate::{
generate::{
store_versioned_auxiliary_02, store_versioned_test_02, TfhersVersion, VALID_TEST_PARAMS,
},
DataKind, HlHeterogeneousCiphertextListTest, TestMetadata, TestParameterSet, HL_MODULE_NAME,
DataKind, HlClientKeyTest, HlHeterogeneousCiphertextListTest, HlServerKeyTest, TestMetadata,
TestParameterSet, HL_MODULE_NAME,
};
use std::borrow::Cow;
use std::fs::create_dir_all;
use tfhe_0_7::boolean::engine::BooleanEngine;
use tfhe_0_7::core_crypto::commons::generators::DeterministicSeeder;
use tfhe_0_7::core_crypto::commons::math::random::ActivatedRandomGenerator;
use tfhe_0_7::prelude::FheEncrypt;
use tfhe_0_7::shortint::engine::ShortintEngine;
use tfhe_0_7::shortint::parameters::{
DecompositionBaseLog, DecompositionLevelCount, DynamicDistribution, GlweDimension,
LweDimension, PolynomialSize, StandardDev, COMP_PARAM_MESSAGE_2_CARRY_2,
};
use tfhe_0_7::shortint::{
CarryModulus, CiphertextModulus, ClassicPBSParameters, EncryptionKeyChoice, MaxNoiseLevel,
MessageModulus, PBSParameters,
};
use tfhe_0_7::{
generate_keys, set_server_key, CompactCiphertextList, CompactPublicKey,
CompressedCiphertextListBuilder, FheBool, FheInt8, FheUint8, Seed,
};

macro_rules! store_versioned_test {
Expand Down Expand Up @@ -115,6 +112,17 @@ const HL_COMPRESSED_LIST_TEST: HlHeterogeneousCiphertextListTest =
compressed: true,
};

const HL_CLIENTKEY_WITH_COMPRESSION_TEST: HlClientKeyTest = HlClientKeyTest {
test_filename: Cow::Borrowed("client_key_with_compression"),
parameters: VALID_TEST_PARAMS,
};

const HL_SERVERKEY_WITH_COMPRESSION_TEST: HlServerKeyTest = HlServerKeyTest {
test_filename: Cow::Borrowed("server_key_with_compression"),
client_key_filename: Cow::Borrowed("client_key_with_compression.cbor"),
compressed: false,
};

pub struct V0_7;

impl TfhersVersion for V0_7 {
Expand Down Expand Up @@ -145,7 +153,7 @@ impl TfhersVersion for V0_7 {
.build();
let (hl_client_key, hl_server_key) = generate_keys(config);

set_server_key(hl_server_key);
set_server_key(hl_server_key.clone());

let compact_pub_key = CompactPublicKey::new(&hl_client_key);

Expand Down Expand Up @@ -195,10 +203,24 @@ impl TfhersVersion for V0_7 {
&HL_COMPRESSED_LIST_TEST.test_filename,
);

store_versioned_test!(
&hl_client_key,
&dir,
&HL_CLIENTKEY_WITH_COMPRESSION_TEST.test_filename,
);

store_versioned_test!(
&hl_server_key,
&dir,
&HL_SERVERKEY_WITH_COMPRESSION_TEST.test_filename,
);

vec![
TestMetadata::HlHeterogeneousCiphertextList(HL_PACKED_COMPACTLIST_TEST),
TestMetadata::HlHeterogeneousCiphertextList(HL_COMPACTLIST_TEST),
TestMetadata::HlHeterogeneousCiphertextList(HL_COMPRESSED_LIST_TEST),
TestMetadata::HlClientKey(HL_CLIENTKEY_WITH_COMPRESSION_TEST),
TestMetadata::HlServerKey(HL_SERVERKEY_WITH_COMPRESSION_TEST),
]
}
}