From 07d735e727c6c5c07eee02f0eec08327038d5b74 Mon Sep 17 00:00:00 2001 From: Nicolas Sarlin Date: Mon, 24 Jun 2024 15:35:32 +0200 Subject: [PATCH] feat: add 0.7 heterogenous compact list --- Cargo.lock | 90 +++++++++-- Cargo.toml | 3 +- data/0_7/high_level_api/client_key.cbor.bcode | 3 + data/0_7/high_level_api/client_key.cbor.cbor | 3 + .../hl_heterogeneous_list.bcode | 3 + .../high_level_api/hl_heterogeneous_list.cbor | 3 + .../hl_packed_heterogeneous_list.bcode | 3 + .../hl_packed_heterogeneous_list.cbor | 3 + data/high_level_api.ron | 2 +- src/data_0_7.rs | 145 ++++++++++++++++++ src/lib.rs | 33 ++++ src/main.rs | 4 +- 12 files changed, 283 insertions(+), 12 deletions(-) create mode 100644 data/0_7/high_level_api/client_key.cbor.bcode create mode 100644 data/0_7/high_level_api/client_key.cbor.cbor create mode 100644 data/0_7/high_level_api/hl_heterogeneous_list.bcode create mode 100644 data/0_7/high_level_api/hl_heterogeneous_list.cbor create mode 100644 data/0_7/high_level_api/hl_packed_heterogeneous_list.bcode create mode 100644 data/0_7/high_level_api/hl_packed_heterogeneous_list.cbor create mode 100644 src/data_0_7.rs diff --git a/Cargo.lock b/Cargo.lock index ce4a286..31e2881 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -52,11 +52,20 @@ dependencies = [ "serde", ] +[[package]] +name = "block-buffer" +version = "0.10.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71" +dependencies = [ + "generic-array", +] + [[package]] name = "bytemuck" -version = "1.16.0" +version = "1.16.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78834c15cb5d5efe3452d58b1e8ba890dd62d21907f867f383358198e56ebca5" +checksum = "b236fc92302c97ed75b38da1f4917b5cdda4984745740f153a5d3059e48d725e" [[package]] name = "cfg-if" @@ -126,6 +135,16 @@ dependencies = [ "serde", ] +[[package]] +name = "concrete-ntt" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b4f4643dbd5de069e099122ae6c2bbd3db70d69ffec348dfc228448d635f949e" +dependencies = [ + "aligned-vec", + "pulp", +] + [[package]] name = "cpufeatures" version = "0.2.12" @@ -176,6 +195,16 @@ dependencies = [ "typenum", ] +[[package]] +name = "digest" +version = "0.10.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" +dependencies = [ + "block-buffer", + "crypto-common", +] + [[package]] name = "dyn-stack" version = "0.9.1" @@ -247,6 +276,15 @@ dependencies = [ "either", ] +[[package]] +name = "keccak" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ecc2af9a1119c51f12a14607e783cb977bde58bc069ff0c3da1095e635d70654" +dependencies = [ + "cpufeatures", +] + [[package]] name = "libc" version = "0.2.155" @@ -287,9 +325,9 @@ checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a" [[package]] name = "proc-macro2" -version = "1.0.85" +version = "1.0.86" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "22244ce15aa966053a896d1accb3a6e68469b97c7f33f284b99f0d576879fc23" +checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77" dependencies = [ "unicode-ident", ] @@ -394,11 +432,21 @@ dependencies = [ "syn", ] +[[package]] +name = "sha3" +version = "0.10.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75872d278a8f37ef87fa0ddbda7802605cb18344497949862c0d4dcb291eba60" +dependencies = [ + "digest", + "keccak", +] + [[package]] name = "strum" -version = "0.26.2" +version = "0.26.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5d8cec3501a5194c432b2b7976db6b7d10ec95c253208b45f83f7136aa985e29" +checksum = "8fec0f0aef304996cf250b31b5a10dee7980c85da9d759361292b8bca5a18f06" dependencies = [ "strum_macros", ] @@ -418,9 +466,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.66" +version = "2.0.68" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c42f3f41a2de00b01c0aaad383c5a45241efc8b2d1eda5661812fda5f3cdcff5" +checksum = "901fa70d88b9d6c98022e23b4136f9f3e54e4662c3bc1bd1d84a42a9a0f0c1e9" dependencies = [ "proc-macro2", "quote", @@ -448,6 +496,29 @@ dependencies = [ "tfhe-versionable", ] +[[package]] +name = "tfhe" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dafa7eb0c9fadc8f2e26c83c2c2164e5b646e4a789952dc88d26daa53ae2b7d0" +dependencies = [ + "aligned-vec", + "bincode", + "bytemuck", + "concrete-csprng", + "concrete-fft", + "concrete-ntt", + "dyn-stack", + "itertools", + "paste", + "pulp", + "rand_core", + "rayon", + "serde", + "sha3", + "tfhe-versionable", +] + [[package]] name = "tfhe-backward-compat-data" version = "0.1.0" @@ -458,7 +529,8 @@ dependencies = [ "semver", "serde", "strum", - "tfhe", + "tfhe 0.6.4", + "tfhe 0.7.0", "tfhe-versionable", ] diff --git a/Cargo.toml b/Cargo.toml index 351c6dc..dced9ac 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,6 +10,7 @@ edition = "2021" # 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"], package = "tfhe", optional = true } +tfhe_0_7 = { version = "0.7", features = ["boolean", "integer", "shortint", "x86_64-unix"], package = "tfhe", optional = true } tfhe-versionable = { version = "0.1", optional = true } @@ -28,5 +29,5 @@ required-features = ["generate"] [features] default = ["generate"] -generate = ["dep:tfhe_0_6", "dep:tfhe-versionable"] +generate = ["dep:tfhe_0_6", "dep:tfhe_0_7", "dep:tfhe-versionable"] load = ["dep:semver"] diff --git a/data/0_7/high_level_api/client_key.cbor.bcode b/data/0_7/high_level_api/client_key.cbor.bcode new file mode 100644 index 0000000..4621873 --- /dev/null +++ b/data/0_7/high_level_api/client_key.cbor.bcode @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:0ebefafaff7add36d2df48083e77e2a8dc5f242f50ce6cfbab9bb19111cb88bf +size 22771 diff --git a/data/0_7/high_level_api/client_key.cbor.cbor b/data/0_7/high_level_api/client_key.cbor.cbor new file mode 100644 index 0000000..8ce1d1d --- /dev/null +++ b/data/0_7/high_level_api/client_key.cbor.cbor @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:23f58e48c01d0f965a1b4b0c19be82d50cb732c6fac6bb6dbfbabe60529ff4fc +size 3457 diff --git a/data/0_7/high_level_api/hl_heterogeneous_list.bcode b/data/0_7/high_level_api/hl_heterogeneous_list.bcode new file mode 100644 index 0000000..13e54d1 --- /dev/null +++ b/data/0_7/high_level_api/hl_heterogeneous_list.bcode @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e43e2385b0c6c05bf15280d9689eeab58b62258effead9f872db894715d03611 +size 16780 diff --git a/data/0_7/high_level_api/hl_heterogeneous_list.cbor b/data/0_7/high_level_api/hl_heterogeneous_list.cbor new file mode 100644 index 0000000..d569d09 --- /dev/null +++ b/data/0_7/high_level_api/hl_heterogeneous_list.cbor @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ccc6acc6e7492a4f9fd21af4fcd1984a76ede20d0156aa6ab181f077c98f2aba +size 18971 diff --git a/data/0_7/high_level_api/hl_packed_heterogeneous_list.bcode b/data/0_7/high_level_api/hl_packed_heterogeneous_list.bcode new file mode 100644 index 0000000..13e54d1 --- /dev/null +++ b/data/0_7/high_level_api/hl_packed_heterogeneous_list.bcode @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e43e2385b0c6c05bf15280d9689eeab58b62258effead9f872db894715d03611 +size 16780 diff --git a/data/0_7/high_level_api/hl_packed_heterogeneous_list.cbor b/data/0_7/high_level_api/hl_packed_heterogeneous_list.cbor new file mode 100644 index 0000000..d569d09 --- /dev/null +++ b/data/0_7/high_level_api/hl_packed_heterogeneous_list.cbor @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ccc6acc6e7492a4f9fd21af4fcd1984a76ede20d0156aa6ab181f077c98f2aba +size 18971 diff --git a/data/high_level_api.ron b/data/high_level_api.ron index 6202a39..15557ec 100644 --- a/data/high_level_api.ron +++ b/data/high_level_api.ron @@ -1 +1 @@ -[(tfhe_version_min:"0.6",tfhe_module:"high_level_api",metadata:HlClientKey((test_filename:"client_key",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.6",tfhe_module:"high_level_api",metadata:HlServerKey((test_filename:"server_key",client_key_filename:"client_key.cbor",compressed:false))),(tfhe_version_min:"0.6",tfhe_module:"high_level_api",metadata:HlPublicKey((test_filename:"public_key",client_key_filename:"client_key_for_pubkey.cbor",compressed:false,compact:false))),(tfhe_version_min:"0.6",tfhe_module:"high_level_api",metadata:HlPublicKey((test_filename:"compressed_public_key",client_key_filename:"client_key.cbor",compressed:true,compact:false))),(tfhe_version_min:"0.6",tfhe_module:"high_level_api",metadata:HlPublicKey((test_filename:"compact_public_key",client_key_filename:"client_key.cbor",compressed:false,compact:true))),(tfhe_version_min:"0.6",tfhe_module:"high_level_api",metadata:HlPublicKey((test_filename:"compressed_compact_public_key",client_key_filename:"client_key.cbor",compressed:true,compact:true))),(tfhe_version_min:"0.6",tfhe_module:"high_level_api",metadata:HlServerKey((test_filename:"compressed_server_key",client_key_filename:"client_key.cbor",compressed:true))),(tfhe_version_min:"0.6",tfhe_module:"high_level_api",metadata:HlCiphertext((test_filename:"ct1",key_filename:"client_key.cbor",compressed:false,compact:false,clear_value:0))),(tfhe_version_min:"0.6",tfhe_module:"high_level_api",metadata:HlCiphertext((test_filename:"ct2",key_filename:"client_key.cbor",compressed:false,compact:false,clear_value:255))),(tfhe_version_min:"0.6",tfhe_module:"high_level_api",metadata:HlCiphertext((test_filename:"ct_compressed_seeded",key_filename:"client_key.cbor",compressed:true,compact:false,clear_value:255))),(tfhe_version_min:"0.6",tfhe_module:"high_level_api",metadata:HlCiphertext((test_filename:"ct_compressed_modswitched",key_filename:"client_key.cbor",compressed:true,compact:false,clear_value:255))),(tfhe_version_min:"0.6",tfhe_module:"high_level_api",metadata:HlCiphertext((test_filename:"ct_compact",key_filename:"client_key.cbor",compressed:false,compact:true,clear_value:255))),(tfhe_version_min:"0.6",tfhe_module:"high_level_api",metadata:HlCiphertextList((test_filename:"ct_list",key_filename:"client_key.cbor",clear_values:[0,255]))),(tfhe_version_min:"0.6",tfhe_module:"high_level_api",metadata:HlSignedCiphertext((test_filename:"ct1_signed",key_filename:"client_key.cbor",compressed:false,compact:false,clear_value:0))),(tfhe_version_min:"0.6",tfhe_module:"high_level_api",metadata:HlSignedCiphertext((test_filename:"ct2_signed",key_filename:"client_key.cbor",compressed:false,compact:false,clear_value:-127))),(tfhe_version_min:"0.6",tfhe_module:"high_level_api",metadata:HlSignedCiphertext((test_filename:"ct_compressed_seeded_signed",key_filename:"client_key.cbor",compressed:true,compact:false,clear_value:255))),(tfhe_version_min:"0.6",tfhe_module:"high_level_api",metadata:HlSignedCiphertext((test_filename:"ct_compressed_modswitched_signed",key_filename:"client_key.cbor",compressed:true,compact:false,clear_value:255))),(tfhe_version_min:"0.6",tfhe_module:"high_level_api",metadata:HlSignedCiphertext((test_filename:"ct_compact_signed",key_filename:"client_key.cbor",compressed:false,compact:true,clear_value:255))),(tfhe_version_min:"0.6",tfhe_module:"high_level_api",metadata:HlSignedCiphertextList((test_filename:"ct_list_signed",key_filename:"client_key.cbor",clear_values:[-127,0,127]))),(tfhe_version_min:"0.6",tfhe_module:"high_level_api",metadata:HlBoolCiphertext((test_filename:"bool1",key_filename:"client_key.cbor",compressed:false,compact:false,clear_value:true))),(tfhe_version_min:"0.6",tfhe_module:"high_level_api",metadata:HlBoolCiphertext((test_filename:"bool2",key_filename:"client_key.cbor",compressed:false,compact:false,clear_value:false))),(tfhe_version_min:"0.6",tfhe_module:"high_level_api",metadata:HlBoolCiphertext((test_filename:"compressed_seeded_bool",key_filename:"client_key.cbor",compressed:true,compact:false,clear_value:true))),(tfhe_version_min:"0.6",tfhe_module:"high_level_api",metadata:HlBoolCiphertext((test_filename:"compressed_modswitched_bool",key_filename:"client_key.cbor",compressed:true,compact:false,clear_value:true))),(tfhe_version_min:"0.6",tfhe_module:"high_level_api",metadata:HlBoolCiphertext((test_filename:"compact_bool",key_filename:"client_key.cbor",compressed:false,compact:true,clear_value:true))),(tfhe_version_min:"0.6",tfhe_module:"high_level_api",metadata:HlBoolCiphertextList((test_filename:"bool_list",key_filename:"client_key.cbor",clear_values:[true,false,true])))] \ No newline at end of file +[(tfhe_version_min:"0.6",tfhe_module:"high_level_api",metadata:HlClientKey((test_filename:"client_key",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.6",tfhe_module:"high_level_api",metadata:HlServerKey((test_filename:"server_key",client_key_filename:"client_key.cbor",compressed:false))),(tfhe_version_min:"0.6",tfhe_module:"high_level_api",metadata:HlPublicKey((test_filename:"public_key",client_key_filename:"client_key_for_pubkey.cbor",compressed:false,compact:false))),(tfhe_version_min:"0.6",tfhe_module:"high_level_api",metadata:HlPublicKey((test_filename:"compressed_public_key",client_key_filename:"client_key.cbor",compressed:true,compact:false))),(tfhe_version_min:"0.6",tfhe_module:"high_level_api",metadata:HlPublicKey((test_filename:"compact_public_key",client_key_filename:"client_key.cbor",compressed:false,compact:true))),(tfhe_version_min:"0.6",tfhe_module:"high_level_api",metadata:HlPublicKey((test_filename:"compressed_compact_public_key",client_key_filename:"client_key.cbor",compressed:true,compact:true))),(tfhe_version_min:"0.6",tfhe_module:"high_level_api",metadata:HlServerKey((test_filename:"compressed_server_key",client_key_filename:"client_key.cbor",compressed:true))),(tfhe_version_min:"0.6",tfhe_module:"high_level_api",metadata:HlCiphertext((test_filename:"ct1",key_filename:"client_key.cbor",compressed:false,compact:false,clear_value:0))),(tfhe_version_min:"0.6",tfhe_module:"high_level_api",metadata:HlCiphertext((test_filename:"ct2",key_filename:"client_key.cbor",compressed:false,compact:false,clear_value:255))),(tfhe_version_min:"0.6",tfhe_module:"high_level_api",metadata:HlCiphertext((test_filename:"ct_compressed_seeded",key_filename:"client_key.cbor",compressed:true,compact:false,clear_value:255))),(tfhe_version_min:"0.6",tfhe_module:"high_level_api",metadata:HlCiphertext((test_filename:"ct_compressed_modswitched",key_filename:"client_key.cbor",compressed:true,compact:false,clear_value:255))),(tfhe_version_min:"0.6",tfhe_module:"high_level_api",metadata:HlCiphertext((test_filename:"ct_compact",key_filename:"client_key.cbor",compressed:false,compact:true,clear_value:255))),(tfhe_version_min:"0.6",tfhe_module:"high_level_api",metadata:HlCiphertextList((test_filename:"ct_list",key_filename:"client_key.cbor",clear_values:[0,255]))),(tfhe_version_min:"0.6",tfhe_module:"high_level_api",metadata:HlSignedCiphertext((test_filename:"ct1_signed",key_filename:"client_key.cbor",compressed:false,compact:false,clear_value:0))),(tfhe_version_min:"0.6",tfhe_module:"high_level_api",metadata:HlSignedCiphertext((test_filename:"ct2_signed",key_filename:"client_key.cbor",compressed:false,compact:false,clear_value:-127))),(tfhe_version_min:"0.6",tfhe_module:"high_level_api",metadata:HlSignedCiphertext((test_filename:"ct_compressed_seeded_signed",key_filename:"client_key.cbor",compressed:true,compact:false,clear_value:255))),(tfhe_version_min:"0.6",tfhe_module:"high_level_api",metadata:HlSignedCiphertext((test_filename:"ct_compressed_modswitched_signed",key_filename:"client_key.cbor",compressed:true,compact:false,clear_value:255))),(tfhe_version_min:"0.6",tfhe_module:"high_level_api",metadata:HlSignedCiphertext((test_filename:"ct_compact_signed",key_filename:"client_key.cbor",compressed:false,compact:true,clear_value:255))),(tfhe_version_min:"0.6",tfhe_module:"high_level_api",metadata:HlSignedCiphertextList((test_filename:"ct_list_signed",key_filename:"client_key.cbor",clear_values:[-127,0,127]))),(tfhe_version_min:"0.6",tfhe_module:"high_level_api",metadata:HlBoolCiphertext((test_filename:"bool1",key_filename:"client_key.cbor",compressed:false,compact:false,clear_value:true))),(tfhe_version_min:"0.6",tfhe_module:"high_level_api",metadata:HlBoolCiphertext((test_filename:"bool2",key_filename:"client_key.cbor",compressed:false,compact:false,clear_value:false))),(tfhe_version_min:"0.6",tfhe_module:"high_level_api",metadata:HlBoolCiphertext((test_filename:"compressed_seeded_bool",key_filename:"client_key.cbor",compressed:true,compact:false,clear_value:true))),(tfhe_version_min:"0.6",tfhe_module:"high_level_api",metadata:HlBoolCiphertext((test_filename:"compressed_modswitched_bool",key_filename:"client_key.cbor",compressed:true,compact:false,clear_value:true))),(tfhe_version_min:"0.6",tfhe_module:"high_level_api",metadata:HlBoolCiphertext((test_filename:"compact_bool",key_filename:"client_key.cbor",compressed:false,compact:true,clear_value:true))),(tfhe_version_min:"0.6",tfhe_module:"high_level_api",metadata:HlBoolCiphertextList((test_filename:"bool_list",key_filename:"client_key.cbor",clear_values:[true,false,true]))),(tfhe_version_min:"0.7",tfhe_module:"high_level_api",metadata:HlHeterogeneousCiphertextList((test_filename:"hl_heterogeneous_list",key_filename:"client_key.cbor",clear_values:[17,18446744073709551604,0,1],data_kinds:[Unsigned,Signed,Bool,Bool])))] \ No newline at end of file diff --git a/src/data_0_7.rs b/src/data_0_7.rs new file mode 100644 index 0000000..1b4ec2d --- /dev/null +++ b/src/data_0_7.rs @@ -0,0 +1,145 @@ +use std::{borrow::Cow, fs::create_dir_all}; + +use tfhe_0_7::{ + boolean::engine::BooleanEngine, + core_crypto::commons::{ + generators::DeterministicSeeder, math::random::ActivatedRandomGenerator, + }, + shortint::{ + engine::ShortintEngine, + parameters::{ + DecompositionBaseLog, DecompositionLevelCount, DynamicDistribution, GlweDimension, + LweDimension, PolynomialSize, StandardDev, + }, + CarryModulus, CiphertextModulus, ClassicPBSParameters, EncryptionKeyChoice, MaxNoiseLevel, + MessageModulus, PBSParameters, + }, + ClientKey, CompactCiphertextList, CompactPublicKey, Seed, +}; + +use crate::{ + generate::{store_versioned_test, TfhersVersion, VALID_TEST_PARAMS}, + DataKind, HlHeterogeneousCiphertextListTest, TestMetadata, TestParameterSet, HL_MODULE_NAME, +}; + +impl From for ClassicPBSParameters { + fn from(value: TestParameterSet) -> Self { + ClassicPBSParameters { + lwe_dimension: LweDimension(value.lwe_dimension), + glwe_dimension: GlweDimension(value.glwe_dimension), + polynomial_size: PolynomialSize(value.polynomial_size), + lwe_noise_distribution: DynamicDistribution::new_gaussian_from_std_dev(StandardDev( + value.lwe_noise_gaussian_stddev, + )), + glwe_noise_distribution: DynamicDistribution::new_gaussian_from_std_dev(StandardDev( + value.glwe_noise_gaussian_stddev, + )), + pbs_base_log: DecompositionBaseLog(value.pbs_base_log), + pbs_level: DecompositionLevelCount(value.pbs_level), + ks_base_log: DecompositionBaseLog(value.ks_base_log), + ks_level: DecompositionLevelCount(value.ks_level), + message_modulus: MessageModulus(value.message_modulus), + carry_modulus: CarryModulus(value.carry_modulus), + max_noise_level: MaxNoiseLevel::new(value.max_noise_level), + log2_p_fail: value.log2_p_fail, + ciphertext_modulus: CiphertextModulus::try_new(value.ciphertext_modulus).unwrap(), + encryption_key_choice: { + match &*value.encryption_key_choice { + "big" => EncryptionKeyChoice::Big, + "small" => EncryptionKeyChoice::Small, + _ => panic!("Invalid encryption key choice"), + } + }, + } + } +} + +impl From for PBSParameters { + fn from(value: TestParameterSet) -> Self { + let classic_pbs: ClassicPBSParameters = value.into(); + classic_pbs.into() + } +} + +const HL_PACKED_COMPACTLIST_TEST: HlHeterogeneousCiphertextListTest = + HlHeterogeneousCiphertextListTest { + test_filename: Cow::Borrowed("hl_packed_heterogeneous_list"), + key_filename: Cow::Borrowed("client_key.cbor"), + clear_values: Cow::Borrowed(&[17u8 as u64, -12i8 as u64, false as u64, true as u64]), + data_kinds: Cow::Borrowed(&[ + DataKind::Unsigned, + DataKind::Signed, + DataKind::Bool, + DataKind::Bool, + ]), + packed: true, + }; + +const HL_COMPACTLIST_TEST: HlHeterogeneousCiphertextListTest = HlHeterogeneousCiphertextListTest { + test_filename: Cow::Borrowed("hl_heterogeneous_list"), + key_filename: Cow::Borrowed("client_key.cbor"), + clear_values: Cow::Borrowed(&[17u8 as u64, -12i8 as u64, false as u64, true as u64]), + data_kinds: Cow::Borrowed(&[ + DataKind::Unsigned, + DataKind::Signed, + DataKind::Bool, + DataKind::Bool, + ]), + packed: false, +}; + +pub struct V0_7; + +impl TfhersVersion for V0_7 { + const VERSION_NUMBER: &'static str = "0.7"; + + fn seed_prng(seed: u128) { + let mut seeder = DeterministicSeeder::::new(Seed(seed)); + let shortint_engine = ShortintEngine::new_from_seeder(&mut seeder); + ShortintEngine::with_thread_local_mut(|local_engine| { + let _ = std::mem::replace(local_engine, shortint_engine); + }); + + let boolean_engine = BooleanEngine::new_from_seeder(&mut seeder); + BooleanEngine::replace_thread_local(boolean_engine); + } + + fn gen_shortint_data() -> Vec { + Vec::new() + } + + fn gen_hl_data() -> Vec { + let dir = Self::data_dir().join(HL_MODULE_NAME); + create_dir_all(&dir).unwrap(); + + // Generate a compact public key needed to create a compact list + let config = + tfhe_0_7::ConfigBuilder::with_custom_parameters(VALID_TEST_PARAMS, None).build(); + let hl_client_key = ClientKey::generate(config); + let compact_pub_key = CompactPublicKey::new(&hl_client_key); + + // Store the associated client key to be able to decrypt the ciphertexts in the list + store_versioned_test(&hl_client_key, &dir, &HL_COMPACTLIST_TEST.key_filename); + + let mut compact_builder = CompactCiphertextList::builder(&compact_pub_key); + compact_builder + .push(17u32) + .push(-1i64) + .push(false) + .push(true); + let compact_list_packed = compact_builder.build_packed(); + let compact_list = compact_builder.build(); + + store_versioned_test( + &compact_list_packed, + &dir, + &HL_PACKED_COMPACTLIST_TEST.test_filename, + ); + store_versioned_test(&compact_list, &dir, &HL_COMPACTLIST_TEST.test_filename); + + vec![ + TestMetadata::HlHeterogeneousCiphertextList(HL_PACKED_COMPACTLIST_TEST), + TestMetadata::HlHeterogeneousCiphertextList(HL_COMPACTLIST_TEST), + ] + } +} diff --git a/src/lib.rs b/src/lib.rs index 0c6ad87..7dfe9aa 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -15,6 +15,8 @@ use serde::{Deserialize, Serialize}; #[cfg(feature = "generate")] pub mod data_0_6; #[cfg(feature = "generate")] +pub mod data_0_7; +#[cfg(feature = "generate")] pub mod generate; #[cfg(feature = "load")] pub mod load; @@ -330,6 +332,36 @@ impl TestType for HlBoolCiphertextListTest { } } +#[derive(Serialize, Deserialize, Clone, Debug)] +pub enum DataKind { + Bool, + Signed, + Unsigned, +} + +#[derive(Serialize, Deserialize, Clone, Debug)] +pub struct HlHeterogeneousCiphertextListTest { + pub test_filename: Cow<'static, str>, + pub key_filename: Cow<'static, str>, + pub packed: bool, + pub clear_values: Cow<'static, [u64]>, + pub data_kinds: Cow<'static, [DataKind]>, +} + +impl TestType for HlHeterogeneousCiphertextListTest { + fn module(&self) -> String { + HL_MODULE_NAME.to_string() + } + + fn target_type(&self) -> String { + "CompactCiphertextList".to_string() + } + + fn test_filename(&self) -> String { + self.test_filename.to_string() + } +} + #[derive(Serialize, Deserialize, Clone, Debug, Display)] pub enum TestMetadata { // Shortint @@ -343,6 +375,7 @@ pub enum TestMetadata { HlCiphertextList(HlCiphertextListTest), HlSignedCiphertextList(HlSignedCiphertextListTest), HlBoolCiphertextList(HlBoolCiphertextListTest), + HlHeterogeneousCiphertextList(HlHeterogeneousCiphertextListTest), HlClientKey(HlClientKeyTest), HlServerKey(HlServerKeyTest), HlPublicKey(HlPublicKeyTest), diff --git a/src/main.rs b/src/main.rs index 1db33a1..b76c717 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,5 +1,6 @@ use tfhe_backward_compat_data::{ data_0_6::V0_6, + data_0_7::V0_7, data_dir, generate::{store_metadata, TfhersVersion}, Testcase, HL_MODULE_NAME, SHORTINT_MODULE_NAME, @@ -34,7 +35,8 @@ fn gen_all_data() -> Vec { fn main() { let root_dir = env!("CARGO_MANIFEST_DIR"); - let testcases = gen_all_data::(); // When we add more versions, extend the Vec with all the testcases + let mut testcases = gen_all_data::(); + testcases.extend(gen_all_data::()); let shortint_testcases: Vec = testcases .iter()