diff --git a/Cargo.lock b/Cargo.lock index 31e2881..2354d6f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -45,9 +45,9 @@ dependencies = [ [[package]] name = "bitflags" -version = "2.5.0" +version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1" +checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" dependencies = [ "serde", ] @@ -113,8 +113,18 @@ dependencies = [ [[package]] name = "concrete-csprng" version = "0.4.0" +source = "git+https://github.com/zama-ai/tfhe-rs?branch=release/0.7.x#10ff0ad968a040658eb0520d42c697a948747fd9" +dependencies = [ + "aes", + "libc", + "rayon", +] + +[[package]] +name = "concrete-csprng" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1c7080e711c39c3dda834604f7c31f4634a38b8dddeb9f24db5d7801751415ad" +checksum = "90518357249582c16a6b64d7410243dfb3109d5bf0ad1665c058c9a59f2fc4cc" dependencies = [ "aes", "libc", @@ -217,9 +227,9 @@ dependencies = [ [[package]] name = "either" -version = "1.12.0" +version = "1.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3dca9240753cf90908d7e4aac30f630662b02aebaa1b58a3cadabdb23385b58b" +checksum = "60b1af1c220855b6ceac025d3f6ecdd2b7c4894bfe9cd9bda4fbb4bc7c0d4cf0" [[package]] name = "generic-array" @@ -414,18 +424,18 @@ checksum = "61697e0a1c7e512e84a621326239844a24d8207b4669b41bc18b32ea5cbf988b" [[package]] name = "serde" -version = "1.0.203" +version = "1.0.204" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7253ab4de971e72fb7be983802300c30b5a7f0c2e56fab8abfc6a214307c0094" +checksum = "bc76f558e0cbb2a839d37354c575f1dc3fdc6546b5be373ba43d95f231bf7c12" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.203" +version = "1.0.204" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "500cbc0ebeb6f46627f50f3f5811ccf6bf00643be300b4c3eabc0ef55dc5b5ba" +checksum = "e0cd7e117be63d3c3678776753929474f3b04a43a080c744d6b0ae2a8c28e222" dependencies = [ "proc-macro2", "quote", @@ -466,9 +476,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.68" +version = "2.0.71" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "901fa70d88b9d6c98022e23b4136f9f3e54e4662c3bc1bd1d84a42a9a0f0c1e9" +checksum = "b146dcf730474b4bcd16c311627b31ede9ab149045db4d6088b3becaea046462" dependencies = [ "proc-macro2", "quote", @@ -484,7 +494,7 @@ dependencies = [ "aligned-vec", "bincode", "bytemuck", - "concrete-csprng", + "concrete-csprng 0.4.1", "concrete-fft", "dyn-stack", "itertools", @@ -493,19 +503,18 @@ dependencies = [ "rand_core", "rayon", "serde", - "tfhe-versionable", + "tfhe-versionable 0.1.0", ] [[package]] name = "tfhe" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dafa7eb0c9fadc8f2e26c83c2c2164e5b646e4a789952dc88d26daa53ae2b7d0" +version = "0.7.1" +source = "git+https://github.com/zama-ai/tfhe-rs?branch=release/0.7.x#10ff0ad968a040658eb0520d42c697a948747fd9" dependencies = [ "aligned-vec", "bincode", "bytemuck", - "concrete-csprng", + "concrete-csprng 0.4.0", "concrete-fft", "concrete-ntt", "dyn-stack", @@ -516,7 +525,7 @@ dependencies = [ "rayon", "serde", "sha3", - "tfhe-versionable", + "tfhe-versionable 0.2.0", ] [[package]] @@ -530,8 +539,9 @@ dependencies = [ "serde", "strum", "tfhe 0.6.4", - "tfhe 0.7.0", - "tfhe-versionable", + "tfhe 0.7.1", + "tfhe-versionable 0.1.0", + "tfhe-versionable 0.2.0", ] [[package]] @@ -543,7 +553,18 @@ dependencies = [ "aligned-vec", "num-complex", "serde", - "tfhe-versionable-derive", + "tfhe-versionable-derive 0.1.0", +] + +[[package]] +name = "tfhe-versionable" +version = "0.2.0" +source = "git+https://github.com/zama-ai/tfhe-rs?branch=release/0.7.x#10ff0ad968a040658eb0520d42c697a948747fd9" +dependencies = [ + "aligned-vec", + "num-complex", + "serde", + "tfhe-versionable-derive 0.2.0", ] [[package]] @@ -557,6 +578,16 @@ dependencies = [ "syn", ] +[[package]] +name = "tfhe-versionable-derive" +version = "0.2.0" +source = "git+https://github.com/zama-ai/tfhe-rs?branch=release/0.7.x#10ff0ad968a040658eb0520d42c697a948747fd9" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "typenum" version = "1.17.0" diff --git a/Cargo.toml b/Cargo.toml index e908759..da155d6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,7 +12,8 @@ edition = "2021" 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 = { version = "0.1", 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" } # other deps serde = { version = "1.0", features = ["derive"] } @@ -22,6 +23,10 @@ ron = { version = "0.8", features = ["integer128"] } ciborium = "0.2" bincode = "1.3" +[patch.crates-io] +tfhe_0_7 = { git = "https://github.com/zama-ai/tfhe-rs", branch = "release/0.7.x", package = "tfhe"} +tfhe_versionable_0_2 = { git = "https://github.com/zama-ai/tfhe-rs", branch = "release/0.7.x", package = "tfhe-versionable" } + [[bin]] name = "tfhe-backward-compat-data" required-features = ["generate"] @@ -29,5 +34,5 @@ required-features = ["generate"] [features] default = ["generate"] -generate = ["dep:tfhe_0_6", "dep:tfhe_0_7", "dep:tfhe-versionable"] +generate = ["dep:tfhe_0_6", "dep:tfhe_0_7", "dep:tfhe-versionable_0_1", "dep:tfhe-versionable_0_2"] load = ["dep:semver"] diff --git a/README.md b/README.md index 7fb2e71..8693469 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ Any commits to `main` should be backported to the latest version branch. To re-generate the data, run the binary target for this project: `cargo run --release`. The prng is seeded with a fixed seed, so the data should be identical. # Adding a test for an existing type -To add a new test for a type that is already tested, you need to create a const global variable with the metadata for that test. The type of metadata depends on the type being tested (for example, the metadata for a test of the `ClientKey' from the `high_level_api' is `HlClientKEy'). Then go to the `data_vvv.rs` file (where "vvv" is the TFHE-rs version of the tested data) and update the `gen_xxx_data` method (where "xxx" is the API layer of your test (hl, shortint, integer,...)). In this method, create the object you want to test and serialize it using the `store_versioned_test` method. Add the metadata of your test to the vector returned by this method. +To add a new test for a type that is already tested, you need to create a const global variable with the metadata for that test. The type of metadata depends on the type being tested (for example, the metadata for a test of the `ClientKey' from the `high_level_api' is `HlClientKEy'). Then go to the `data_vvv.rs` file (where "vvv" is the TFHE-rs version of the tested data) and update the `gen_xxx_data` method (where "xxx" is the API layer of your test (hl, shortint, integer,...)). In this method, create the object you want to test and serialize it using the `store_versioned_test` macro. Add the metadata of your test to the vector returned by this method. The test will be automatically selected when you run TFHE-rs `make test_backward_compatibility`. @@ -55,7 +55,7 @@ impl TfhersVersion for V0_6 { let ct1 = fheint8::encrypt(HL_CT1_TEST.clear_value, &hl_client_key); // 3. Store it - store_versioned_test(&ct1, &dir, &HL_CT1_TEST.test_filename); + store_versioned_test!(&ct1, &dir, &HL_CT1_TEST.test_filename); // 4. Return the metadata vec![ diff --git a/data/0_7/high_level_api/client_key.cbor b/data/0_7/high_level_api/client_key.cbor new file mode 100644 index 0000000..5db721a --- /dev/null +++ b/data/0_7/high_level_api/client_key.cbor @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:fa27dc2ea178bc9a55d7f6c5b3a6140c13aa85eece2049d6798d4f4bd0aa9dc5 +size 5075 diff --git a/data/0_7/high_level_api/client_key.cbor.bcode b/data/0_7/high_level_api/client_key.cbor.bcode deleted file mode 100644 index 4621873..0000000 --- a/data/0_7/high_level_api/client_key.cbor.bcode +++ /dev/null @@ -1,3 +0,0 @@ -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 deleted file mode 100644 index 8ce1d1d..0000000 --- a/data/0_7/high_level_api/client_key.cbor.cbor +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:23f58e48c01d0f965a1b4b0c19be82d50cb732c6fac6bb6dbfbabe60529ff4fc -size 3457 diff --git a/data/0_7/high_level_api/hl_compressed_heterogeneous_list.bcode b/data/0_7/high_level_api/hl_compressed_heterogeneous_list.bcode new file mode 100644 index 0000000..3fb20cd --- /dev/null +++ b/data/0_7/high_level_api/hl_compressed_heterogeneous_list.bcode @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:204374b0c6089ce675d8bb82d515967cb46f744c6cc0ea07d93d59055c848096 +size 2036 diff --git a/data/0_7/high_level_api/hl_compressed_heterogeneous_list.cbor b/data/0_7/high_level_api/hl_compressed_heterogeneous_list.cbor new file mode 100644 index 0000000..24a6772 --- /dev/null +++ b/data/0_7/high_level_api/hl_compressed_heterogeneous_list.cbor @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:6f4fe672202e7c8eb6ab4c1d1225ac8d889372497e60b94b9dc2e06aa5d3663c +size 2469 diff --git a/data/0_7/high_level_api/hl_heterogeneous_list.bcode b/data/0_7/high_level_api/hl_heterogeneous_list.bcode index 084ff4f..68e8a2e 100644 --- a/data/0_7/high_level_api/hl_heterogeneous_list.bcode +++ b/data/0_7/high_level_api/hl_heterogeneous_list.bcode @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:78db6b0a593adebb219ec1da31238f38d61425e9a5392aeea7a5143f5ab7f0bc -size 16980 +oid sha256:920f31bb4ca2f16e401f703adec2d4a5650b3697df52168e3b712c2e605b7949 +size 16660 diff --git a/data/0_7/high_level_api/hl_heterogeneous_list.cbor b/data/0_7/high_level_api/hl_heterogeneous_list.cbor index 8e5ac34..e490089 100644 --- a/data/0_7/high_level_api/hl_heterogeneous_list.cbor +++ b/data/0_7/high_level_api/hl_heterogeneous_list.cbor @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:0f12c274869b4091cfea079bc236cdc0915560f34972d4492cee2d3a1b501f91 -size 19196 +oid sha256:a7efa99b9dce9ac342b262ea0f326b3a569d0f52f5e043994273978a3d93cc3a +size 18834 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 index 13e54d1..8b059f1 100644 --- a/data/0_7/high_level_api/hl_packed_heterogeneous_list.bcode +++ b/data/0_7/high_level_api/hl_packed_heterogeneous_list.bcode @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:e43e2385b0c6c05bf15280d9689eeab58b62258effead9f872db894715d03611 -size 16780 +oid sha256:980a4290692f930e32bc06f75cebd0fc803576d3acb7ed2ea2895dc529489dea +size 16620 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 index d569d09..f05dd60 100644 --- a/data/0_7/high_level_api/hl_packed_heterogeneous_list.cbor +++ b/data/0_7/high_level_api/hl_packed_heterogeneous_list.cbor @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:ccc6acc6e7492a4f9fd21af4fcd1984a76ede20d0156aa6ab181f077c98f2aba -size 18971 +oid sha256:8b766419926ce71ba93df10883971f8a5fe926e595e2833f622027632e84a2ab +size 18789 diff --git a/data/high_level_api.ron b/data/high_level_api.ron index b779307..e13237c 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]))),(tfhe_version_min:"0.7",tfhe_module:"high_level_api",metadata:HlHeterogeneousCiphertextList((test_filename:"hl_packed_heterogeneous_list",key_filename:"client_key.cbor",packed:true,clear_values:[17,18446744073709551604,0,1],data_kinds:[Unsigned,Signed,Bool,Bool]))),(tfhe_version_min:"0.7",tfhe_module:"high_level_api",metadata:HlHeterogeneousCiphertextList((test_filename:"hl_heterogeneous_list",key_filename:"client_key.cbor",packed:false,clear_values:[17,18446744073709551604,0,1],data_kinds:[Unsigned,Signed,Bool,Bool])))] \ 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_packed_heterogeneous_list",key_filename:"client_key.cbor",compressed:false,clear_values:[17,18446744073709551604,0,1],data_kinds:[Unsigned,Signed,Bool,Bool]))),(tfhe_version_min:"0.7",tfhe_module:"high_level_api",metadata:HlHeterogeneousCiphertextList((test_filename:"hl_heterogeneous_list",key_filename:"client_key.cbor",compressed:false,clear_values:[17,18446744073709551604,0,1],data_kinds:[Unsigned,Signed,Bool,Bool]))),(tfhe_version_min:"0.7",tfhe_module:"high_level_api",metadata:HlHeterogeneousCiphertextList((test_filename:"hl_compressed_heterogeneous_list",key_filename:"client_key.cbor",compressed:true,clear_values:[17,18446744073709551604,0,1],data_kinds:[Unsigned,Signed,Bool,Bool])))] \ No newline at end of file diff --git a/src/data_0_6.rs b/src/data_0_6.rs index fe61ba1..6d0b28d 100644 --- a/src/data_0_6.rs +++ b/src/data_0_6.rs @@ -24,16 +24,22 @@ use tfhe_0_6::{ CompressedFheBool, CompressedFheInt8, CompressedFheUint8, CompressedPublicKey, CompressedServerKey, ConfigBuilder, FheBool, FheInt8, FheUint8, PublicKey, }; -use tfhe_versionable::Versionize; +use tfhe_versionable_0_1::Versionize; use crate::{ - generate::{save_cbor, store_versioned_test, TfhersVersion, VALID_TEST_PARAMS}, + 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, }; +macro_rules! store_versioned_test { + ($msg:expr, $dir:expr, $test_filename:expr $(,)? ) => { + store_versioned_test_01($msg, $dir, $test_filename) + }; +} + impl From for ClassicPBSParameters { fn from(value: TestParameterSet) -> Self { ClassicPBSParameters { @@ -295,7 +301,7 @@ impl TfhersVersion for V0_6 { // generate a client key let shortint_client_key = shortint::ClientKey::new(SHORTINT_CLIENTKEY_TEST.parameters); - store_versioned_test( + store_versioned_test!( &shortint_client_key, &dir, &SHORTINT_CLIENTKEY_TEST.test_filename, @@ -306,8 +312,8 @@ impl TfhersVersion for V0_6 { let ct2 = shortint_client_key.encrypt(SHORTINT_CT2_TEST.clear_value); // Serialize them - store_versioned_test(&ct1, &dir, &SHORTINT_CT1_TEST.test_filename); - store_versioned_test(&ct2, &dir, &SHORTINT_CT2_TEST.test_filename); + store_versioned_test!(&ct1, &dir, &SHORTINT_CT1_TEST.test_filename); + store_versioned_test!(&ct2, &dir, &SHORTINT_CT2_TEST.test_filename); vec![ TestMetadata::ShortintClientKey(SHORTINT_CLIENTKEY_TEST), @@ -339,31 +345,31 @@ impl TfhersVersion for V0_6 { let compact_pub_key = CompactPublicKey::new(&hl_client_key); let compressed_compact_pub_key = CompressedCompactPublicKey::new(&hl_client_key); - store_versioned_test(&hl_client_key, &dir, &HL_CLIENTKEY_TEST.test_filename); + store_versioned_test!(&hl_client_key, &dir, &HL_CLIENTKEY_TEST.test_filename); - store_versioned_test(&hl_server_key, &dir, &HL_SERVERKEY_TEST.test_filename); - store_versioned_test( + store_versioned_test!(&hl_server_key, &dir, &HL_SERVERKEY_TEST.test_filename); + store_versioned_test!( &compressed_server_key, &dir, &HL_COMPRESSED_SERVERKEY_TEST.test_filename, ); - store_versioned_test(&pub_key, &dir, &HL_PUBKEY_TEST.test_filename); + store_versioned_test!(&pub_key, &dir, &HL_PUBKEY_TEST.test_filename); save_cbor( &client_key_for_pk.versionize(), dir.join(&*HL_PUBKEY_TEST.client_key_filename), ); - store_versioned_test( + store_versioned_test!( &compressed_pub_key, &dir, &HL_COMPRESSED_PUBKEY_TEST.test_filename, ); - store_versioned_test( + store_versioned_test!( &compact_pub_key, &dir, &HL_COMPACT_PUBKEY_TEST.test_filename, ); - store_versioned_test( + store_versioned_test!( &compressed_compact_pub_key, &dir, &HL_COMPRESSED_COMPACT_PUBKEY_TEST.test_filename, @@ -422,54 +428,54 @@ impl TfhersVersion for V0_6 { CompactFheBoolList::encrypt(&HL_BOOL_LIST_TEST.clear_values, &compact_pub_key); // Serialize them - store_versioned_test(&ct1, &dir, &HL_CT1_TEST.test_filename); - store_versioned_test(&ct2, &dir, &HL_CT2_TEST.test_filename); - store_versioned_test( + store_versioned_test!(&ct1, &dir, &HL_CT1_TEST.test_filename); + store_versioned_test!(&ct2, &dir, &HL_CT2_TEST.test_filename); + store_versioned_test!( &compressed_ct1, &dir, &HL_COMPRESSED_SEEDED_CT_TEST.test_filename, ); - store_versioned_test( + store_versioned_test!( &compressed_ct2, &dir, &HL_COMPRESSED_CT_MODSWITCHED_TEST.test_filename, ); - store_versioned_test(&compact_ct, &dir, &HL_COMPACT_CT_TEST.test_filename); - store_versioned_test(&ct_list, &dir, &HL_CT_LIST_TEST.test_filename); + store_versioned_test!(&compact_ct, &dir, &HL_COMPACT_CT_TEST.test_filename); + store_versioned_test!(&ct_list, &dir, &HL_CT_LIST_TEST.test_filename); - store_versioned_test(&ct1_signed, &dir, &HL_SIGNED_CT1_TEST.test_filename); - store_versioned_test(&ct2_signed, &dir, &HL_SIGNED_CT2_TEST.test_filename); - store_versioned_test( + store_versioned_test!(&ct1_signed, &dir, &HL_SIGNED_CT1_TEST.test_filename); + store_versioned_test!(&ct2_signed, &dir, &HL_SIGNED_CT2_TEST.test_filename); + store_versioned_test!( &compressed_ct1_signed, &dir, &HL_SIGNED_COMPRESSED_SEEDED_CT_TEST.test_filename, ); - store_versioned_test( + store_versioned_test!( &compressed_ct2_signed, &dir, &HL_SIGNED_COMPRESSED_CT_MODSWITCHED_TEST.test_filename, ); - store_versioned_test( + store_versioned_test!( &compact_ct_signed, &dir, &HL_SIGNED_COMPACT_CT_TEST.test_filename, ); - store_versioned_test(&ct_list_signed, &dir, &HL_SIGNED_CT_LIST_TEST.test_filename); + store_versioned_test!(&ct_list_signed, &dir, &HL_SIGNED_CT_LIST_TEST.test_filename); - store_versioned_test(&bool1, &dir, &HL_BOOL1_TEST.test_filename); - store_versioned_test(&bool2, &dir, &HL_BOOL2_TEST.test_filename); - store_versioned_test( + store_versioned_test!(&bool1, &dir, &HL_BOOL1_TEST.test_filename); + store_versioned_test!(&bool2, &dir, &HL_BOOL2_TEST.test_filename); + store_versioned_test!( &compressed_bool1, &dir, &HL_COMPRESSED_BOOL_SEEDED_TEST.test_filename, ); - store_versioned_test( + store_versioned_test!( &compressed_bool2, &dir, &HL_COMPRESSED_BOOL_MODSWITCHED_TEST.test_filename, ); - store_versioned_test(&compact_bool, &dir, &HL_COMPACT_BOOL_TEST.test_filename); - store_versioned_test(&bool_list, &dir, &HL_BOOL_LIST_TEST.test_filename); + store_versioned_test!(&compact_bool, &dir, &HL_COMPACT_BOOL_TEST.test_filename); + store_versioned_test!(&bool_list, &dir, &HL_BOOL_LIST_TEST.test_filename); vec![ TestMetadata::HlClientKey(HL_CLIENTKEY_TEST), diff --git a/src/data_0_7.rs b/src/data_0_7.rs index 1b4ec2d..5b450cb 100644 --- a/src/data_0_7.rs +++ b/src/data_0_7.rs @@ -5,23 +5,41 @@ use tfhe_0_7::{ 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, + LweDimension, PolynomialSize, StandardDev, COMP_PARAM_MESSAGE_2_CARRY_2, }, CarryModulus, CiphertextModulus, ClassicPBSParameters, EncryptionKeyChoice, MaxNoiseLevel, MessageModulus, PBSParameters, }, - ClientKey, CompactCiphertextList, CompactPublicKey, Seed, + CompactCiphertextList, CompactPublicKey, CompressedCiphertextListBuilder, FheBool, FheInt8, + FheUint8, Seed, }; use crate::{ - generate::{store_versioned_test, TfhersVersion, VALID_TEST_PARAMS}, + generate::{ + store_versioned_auxiliary_02, store_versioned_test_02, TfhersVersion, VALID_TEST_PARAMS, + }, DataKind, HlHeterogeneousCiphertextListTest, TestMetadata, TestParameterSet, HL_MODULE_NAME, }; +macro_rules! store_versioned_test { + ($msg:expr, $dir:expr, $test_filename:expr $(,)? ) => { + store_versioned_test_02($msg, $dir, $test_filename) + }; +} + +macro_rules! store_versioned_auxiliary { + ($msg:expr, $dir:expr, $test_filename:expr $(,)? ) => { + store_versioned_auxiliary_02($msg, $dir, $test_filename) + }; +} + impl From for ClassicPBSParameters { fn from(value: TestParameterSet) -> Self { ClassicPBSParameters { @@ -61,10 +79,32 @@ impl From for PBSParameters { } } +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, + ]), + compressed: false, +}; + const HL_PACKED_COMPACTLIST_TEST: HlHeterogeneousCiphertextListTest = HlHeterogeneousCiphertextListTest { test_filename: Cow::Borrowed("hl_packed_heterogeneous_list"), key_filename: Cow::Borrowed("client_key.cbor"), + clear_values: HL_COMPACTLIST_TEST.clear_values, + data_kinds: HL_COMPACTLIST_TEST.data_kinds, + compressed: false, + }; + +const HL_COMPRESSED_LIST_TEST: HlHeterogeneousCiphertextListTest = + HlHeterogeneousCiphertextListTest { + test_filename: Cow::Borrowed("hl_compressed_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, @@ -72,22 +112,9 @@ const HL_PACKED_COMPACTLIST_TEST: HlHeterogeneousCiphertextListTest = DataKind::Bool, DataKind::Bool, ]), - packed: true, + compressed: 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 { @@ -113,33 +140,65 @@ impl TfhersVersion for V0_7 { 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 config = tfhe_0_7::ConfigBuilder::with_custom_parameters(VALID_TEST_PARAMS, None) + .enable_compression(COMP_PARAM_MESSAGE_2_CARRY_2) + .build(); + let (hl_client_key, hl_server_key) = generate_keys(config); + + set_server_key(hl_server_key); + 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); + store_versioned_auxiliary!(&hl_client_key, &dir, &HL_COMPACTLIST_TEST.key_filename); + // Generate heterogeneous list data let mut compact_builder = CompactCiphertextList::builder(&compact_pub_key); compact_builder - .push(17u32) - .push(-1i64) - .push(false) - .push(true); + .push(HL_COMPACTLIST_TEST.clear_values[0] as u8) + .push(HL_COMPACTLIST_TEST.clear_values[1] as i8) + .push(HL_COMPACTLIST_TEST.clear_values[2] == 0) + .push(HL_COMPACTLIST_TEST.clear_values[3] == 0); + let compact_list_packed = compact_builder.build_packed(); let compact_list = compact_builder.build(); - store_versioned_test( + let mut compressed_builder = CompressedCiphertextListBuilder::new(); + compressed_builder + .push(FheUint8::encrypt( + HL_COMPRESSED_LIST_TEST.clear_values[0] as u8, + &hl_client_key, + )) + .push(FheInt8::encrypt( + HL_COMPRESSED_LIST_TEST.clear_values[1] as i8, + &hl_client_key, + )) + .push(FheBool::encrypt( + HL_COMPRESSED_LIST_TEST.clear_values[2] == 0, + &hl_client_key, + )) + .push(FheBool::encrypt( + HL_COMPRESSED_LIST_TEST.clear_values[3] == 0, + &hl_client_key, + )); + let compressed_list = compressed_builder.build().unwrap(); + + store_versioned_test!( &compact_list_packed, &dir, &HL_PACKED_COMPACTLIST_TEST.test_filename, ); - store_versioned_test(&compact_list, &dir, &HL_COMPACTLIST_TEST.test_filename); + store_versioned_test!(&compact_list, &dir, &HL_COMPACTLIST_TEST.test_filename); + store_versioned_test!( + &compressed_list, + &dir, + &HL_COMPRESSED_LIST_TEST.test_filename, + ); vec![ TestMetadata::HlHeterogeneousCiphertextList(HL_PACKED_COMPACTLIST_TEST), TestMetadata::HlHeterogeneousCiphertextList(HL_COMPACTLIST_TEST), + TestMetadata::HlHeterogeneousCiphertextList(HL_COMPRESSED_LIST_TEST), ] } } diff --git a/src/generate.rs b/src/generate.rs index a0a7d91..74a472a 100644 --- a/src/generate.rs +++ b/src/generate.rs @@ -6,7 +6,8 @@ use std::{ use bincode::Options; use serde::Serialize; -use tfhe_versionable::Versionize; +use tfhe_versionable_0_1::Versionize as Versionize01; +use tfhe_versionable_0_2::Versionize as Versionize02; use crate::{data_dir, dir_for_version, TestMetadata, TestParameterSet}; @@ -59,22 +60,47 @@ pub fn save_bcode>(msg: &Data, path: P) { options.serialize_into(&mut file, msg).unwrap(); } -/// Stores the test data in `dir`, encoded in both cbor and bincode -pub fn store_versioned_test>( - msg: &Data, - dir: P, - test_filename: &str, -) { - let versioned = msg.versionize(); - - // Store in cbor - let filename_cbor = format!("{}.cbor", test_filename); - save_cbor(&versioned, dir.as_ref().join(filename_cbor)); - - // Store in bincode - let filename_bincode = format!("{}.bcode", test_filename); - save_bcode(&versioned, dir.as_ref().join(filename_bincode)); +/// Stores the test data in `dir`, encoded in both cbor and bincode, using the right tfhe-versionable version +macro_rules! define_store_versioned_test_fn { + ($fn_name:ident, $versionize_trait:ident) => { + pub fn $fn_name>( + msg: &Data, + dir: P, + test_filename: &str, + ) { + let versioned = msg.versionize(); + + // Store in cbor + let filename_cbor = format!("{}.cbor", test_filename); + save_cbor(&versioned, dir.as_ref().join(filename_cbor)); + + // Store in bincode + let filename_bincode = format!("{}.bcode", test_filename); + save_bcode(&versioned, dir.as_ref().join(filename_bincode)); + } + }; +} +define_store_versioned_test_fn!(store_versioned_test_01, Versionize01); +define_store_versioned_test_fn!(store_versioned_test_02, Versionize02); + +/// Stores the auxiliary data in `dir`, encoded in cbor, using the right tfhe-versionable version +macro_rules! define_store_versioned_auxiliary_fn { + ($fn_name:ident, $versionize_trait:ident) => { + pub fn $fn_name>( + msg: &Data, + dir: P, + test_filename: &str, + ) { + let versioned = msg.versionize(); + + // Store in cbor + let filename_cbor = format!("{}", test_filename); + save_cbor(&versioned, dir.as_ref().join(filename_cbor)); + } + }; } +define_store_versioned_auxiliary_fn!(store_versioned_auxiliary_01, Versionize01); +define_store_versioned_auxiliary_fn!(store_versioned_auxiliary_02, Versionize02); pub fn store_metadata>(value: &Meta, path: P) { let serialized = ron::to_string(value).unwrap(); diff --git a/src/lib.rs b/src/lib.rs index 7dfe9aa..c259638 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -269,6 +269,7 @@ impl TestType for HlBoolCiphertextTest { } } +/// Legacy compact unsigned ciphertext lists (deprected in 0.7) #[derive(Serialize, Deserialize, Clone, Debug)] pub struct HlCiphertextListTest { pub test_filename: Cow<'static, str>, @@ -290,6 +291,7 @@ impl TestType for HlCiphertextListTest { } } +/// Legacy compact signed ciphertext lists (deprected in 0.7) #[derive(Serialize, Deserialize, Clone, Debug)] pub struct HlSignedCiphertextListTest { pub test_filename: Cow<'static, str>, @@ -311,6 +313,7 @@ impl TestType for HlSignedCiphertextListTest { } } +/// Legacy compact bool ciphertext lists (deprected in 0.7) #[derive(Serialize, Deserialize, Clone, Debug)] pub struct HlBoolCiphertextListTest { pub test_filename: Cow<'static, str>, @@ -332,7 +335,7 @@ impl TestType for HlBoolCiphertextListTest { } } -#[derive(Serialize, Deserialize, Clone, Debug)] +#[derive(Serialize, Deserialize, Clone, Copy, Debug)] pub enum DataKind { Bool, Signed, @@ -343,7 +346,7 @@ pub enum DataKind { pub struct HlHeterogeneousCiphertextListTest { pub test_filename: Cow<'static, str>, pub key_filename: Cow<'static, str>, - pub packed: bool, + pub compressed: bool, pub clear_values: Cow<'static, [u64]>, pub data_kinds: Cow<'static, [DataKind]>, }