diff --git a/backends/concrete-cpu/implementation/Cargo.lock b/backends/concrete-cpu/implementation/Cargo.lock index 1c706f2716..dee61949b3 100644 --- a/backends/concrete-cpu/implementation/Cargo.lock +++ b/backends/concrete-cpu/implementation/Cargo.lock @@ -1,18 +1,27 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. -version = 3 +version = 4 [[package]] name = "aes" -version = "0.8.3" +version = "0.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac1f845298e95f983ff1944b728ae08b8cebab80d684f0a832ed0fc74dfa27e2" +checksum = "b169f7a6d4742236a0a00c541b845991d0ac43e546831af1249753ab4c3aa3a0" dependencies = [ "cfg-if", "cipher", "cpufeatures", ] +[[package]] +name = "aho-corasick" +version = "1.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916" +dependencies = [ + "memchr", +] + [[package]] name = "aligned-vec" version = "0.5.0" @@ -34,16 +43,16 @@ version = "0.2.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" dependencies = [ - "hermit-abi 0.1.19", + "hermit-abi", "libc", "winapi", ] [[package]] name = "autocfg" -version = "1.1.0" +version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" +checksum = "ace50bade8e6234aa140d9a2f552bbee1db4d353f69b8217bc503490fc1a9f26" [[package]] name = "bincode" @@ -60,6 +69,12 @@ version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" +[[package]] +name = "bitflags" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" + [[package]] name = "block-buffer" version = "0.10.4" @@ -71,15 +86,15 @@ dependencies = [ [[package]] name = "bumpalo" -version = "3.13.0" +version = "3.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a3e2c3daef883ecc1b5d58c15adae93470a91d425f3532ba1695849656af3fc1" +checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" [[package]] name = "bytemuck" -version = "1.16.1" +version = "1.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b236fc92302c97ed75b38da1f4917b5cdda4984745740f153a5d3059e48d725e" +checksum = "8334215b81e418a0a7bdb8ef0849474f40bb10c8b71f1c4ed315cff49f32494d" [[package]] name = "cast" @@ -106,12 +121,6 @@ dependencies = [ "toml", ] -[[package]] -name = "cc" -version = "1.0.79" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "50d30906286121d95be3d479533b458f87493b30a4b5f79a607db8f5d11aa91f" - [[package]] name = "cfg-if" version = "1.0.0" @@ -120,9 +129,9 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "ciborium" -version = "0.2.1" +version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "effd91f6c78e5a4ace8a5d3c0b6bfaec9e2baaef55f3efc00e45fb2e477ee926" +checksum = "42e69ffd6f0917f5c029256a24d0161db17cea3997d185db0d35926308770f0e" dependencies = [ "ciborium-io", "ciborium-ll", @@ -131,15 +140,15 @@ dependencies = [ [[package]] name = "ciborium-io" -version = "0.2.1" +version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cdf919175532b369853f5d5e20b26b43112613fd6fe7aee757e35f7a44642656" +checksum = "05afea1e0a06c9be33d539b876f1ce3692f4afea2cb41f740e7743225ed1c757" [[package]] name = "ciborium-ll" -version = "0.2.1" +version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "defaa24ecc093c77630e6c15e17c51f5e187bf35ee514f4e2d67baaa96dae22b" +checksum = "57663b653d948a338bfb3eeba9bb2fd5fcfaecb9e199e87e1eda4d9e8b240fd9" dependencies = [ "ciborium-io", "half", @@ -162,7 +171,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4ea181bf566f71cb9a5d17a59e1871af638180a18fb0035c92ae62b705207123" dependencies = [ "atty", - "bitflags", + "bitflags 1.3.2", "clap_lex", "indexmap", "strsim", @@ -214,8 +223,7 @@ dependencies = [ [[package]] name = "concrete-csprng" version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "90518357249582c16a6b64d7410243dfb3109d5bf0ad1665c058c9a59f2fc4cc" +source = "git+https://github.com/zama-ai/tfhe-rs.git?rev=483a4fe#483a4fecf1a6b2e2a7827251a04608d018c83002" dependencies = [ "aes", "libc", @@ -230,7 +238,7 @@ checksum = "3144f883422ee22c65d4f408c11b3406513eadc0d50b3d65bfadcb97852817e0" dependencies = [ "aligned-vec", "bytemuck", - "dyn-stack 0.9.0", + "dyn-stack 0.9.1", "num-complex", "pulp", ] @@ -266,9 +274,9 @@ version = "0.1.0" [[package]] name = "cpufeatures" -version = "0.2.8" +version = "0.2.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "03e69e28e9f7f77debdedbaafa2866e1de9ba56df55a8bd7cfc724c25a09987c" +checksum = "608697df725056feaccfa42cffdaeeec3fccc4ffc38358ecd19b243e716a78e0" dependencies = [ "libc", ] @@ -309,48 +317,36 @@ dependencies = [ "itertools 0.10.5", ] -[[package]] -name = "crossbeam-channel" -version = "0.5.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a33c2bf77f2df06183c3aa30d1e96c0695a313d4f9c453cc3762a6db39f99200" -dependencies = [ - "cfg-if", - "crossbeam-utils", -] - [[package]] name = "crossbeam-deque" -version = "0.8.3" +version = "0.8.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce6fd6f855243022dcecf8702fef0c297d4338e226845fe067f6341ad9fa0cef" +checksum = "613f8cc01fe9cf1a3eb3d7f488fd2fa8388403e97039e2f73692932e291a770d" dependencies = [ - "cfg-if", "crossbeam-epoch", "crossbeam-utils", ] [[package]] name = "crossbeam-epoch" -version = "0.9.15" +version = "0.9.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae211234986c545741a7dc064309f67ee1e5ad243d0e48335adc0484d960bcc7" +checksum = "5b82ac4a3c2ca9c3460964f020e1402edd5753411d7737aa39c3714ad1b5420e" dependencies = [ - "autocfg", - "cfg-if", "crossbeam-utils", - "memoffset", - "scopeguard", ] [[package]] name = "crossbeam-utils" -version = "0.8.16" +version = "0.8.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5a22b2d63d4d1dc0b7f1b6b2747dd0088008a9be28b6ddf0b1e7d335e3037294" -dependencies = [ - "cfg-if", -] +checksum = "22ec99545bb0ed0ea7bb9b8e1e9122ea386ff8a48c0922e43f36d45ab09e0e80" + +[[package]] +name = "crunchy" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7" [[package]] name = "crypto-common" @@ -374,9 +370,9 @@ dependencies = [ [[package]] name = "dyn-stack" -version = "0.9.0" +version = "0.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "24269739c7c175bc12130622ef1a60b9ab2d5b30c0b9ce5110cd406d7fd497bc" +checksum = "7fe7f8d7bcc523381d3c437b82cf74805de3931de0da69309ae0fe1bdf7a256e" dependencies = [ "bytemuck", "reborrow", @@ -394,39 +390,25 @@ dependencies = [ [[package]] name = "either" -version = "1.8.1" +version = "1.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7fcaabb2fef8c910e7f4c7ce9f67a1283a1715879a7c230ca9d6d1ae31f16d91" +checksum = "60b1af1c220855b6ceac025d3f6ecdd2b7c4894bfe9cd9bda4fbb4bc7c0d4cf0" [[package]] name = "errno" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4bcfec3a70f97c962c307b2d2c56e358cf1d00b558d74262b5f929ee8cc7e73a" -dependencies = [ - "errno-dragonfly", - "libc", - "windows-sys", -] - -[[package]] -name = "errno-dragonfly" -version = "0.1.2" +version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aa68f1b12764fab894d2755d2518754e71b4fd80ecfb822714a1206c2aab39bf" +checksum = "534c5cf6194dfab3db3242765c03bbe257cf92f22b38f6bc0c58d59108a820ba" dependencies = [ - "cc", "libc", + "windows-sys 0.52.0", ] [[package]] name = "fastrand" -version = "1.9.0" +version = "2.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e51093e27b0797c359783294ca4f0a911c270184cb10f85783b118614a1501be" -dependencies = [ - "instant", -] +checksum = "e8c02a5121d4ea3eb16a80748c74f5549a5665e4c21333c6098f283870fbdea6" [[package]] name = "generic-array" @@ -451,9 +433,13 @@ dependencies = [ [[package]] name = "half" -version = "1.8.2" +version = "2.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eabb4a44450da02c90444cf74558da904edde8fb4e9035a9a6a4e15445af0bd7" +checksum = "6dd08c532ae367adf81c312a4580bc67f1d0fe8bc9c460520283f4c0ff277888" +dependencies = [ + "cfg-if", + "crunchy", +] [[package]] name = "hashbrown" @@ -476,12 +462,6 @@ dependencies = [ "libc", ] -[[package]] -name = "hermit-abi" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fed44880c466736ef9a5c5b5facefb5ed0785676d0c02d612db14e54f0d84286" - [[package]] name = "indexmap" version = "1.9.3" @@ -501,26 +481,6 @@ dependencies = [ "generic-array", ] -[[package]] -name = "instant" -version = "0.1.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a5bbe824c507c5da5956355e86a746d82e0e1464f65d862cc5e71da70e94b2c" -dependencies = [ - "cfg-if", -] - -[[package]] -name = "io-lifetimes" -version = "1.0.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eae7b9aee968036d54dce06cebaefd919e4472e753296daccd6d344e3e2df0c2" -dependencies = [ - "hermit-abi 0.3.1", - "libc", - "windows-sys", -] - [[package]] name = "itertools" version = "0.10.5" @@ -541,15 +501,15 @@ dependencies = [ [[package]] name = "itoa" -version = "1.0.6" +version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "453ad9f582a441959e5f0d088b02ce04cfe8d51a8eaf077f12ac6d3e94164ca6" +checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" [[package]] name = "js-sys" -version = "0.3.64" +version = "0.3.72" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c5f195fe497f702db0f318b07fdd68edb16955aed830df8363d837542f8f935a" +checksum = "6a88f1bda2bd75b0452a14784937d796722fdebfe50df998aeb3f0b7603019a9" dependencies = [ "wasm-bindgen", ] @@ -565,15 +525,15 @@ dependencies = [ [[package]] name = "lazy_static" -version = "1.4.0" +version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" +checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" [[package]] name = "libc" -version = "0.2.155" +version = "0.2.159" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" +checksum = "561d97a539a36e26a9a5fad1ea11a3039a67714694aaa379433e580854bc3dc5" [[package]] name = "libm" @@ -583,30 +543,27 @@ checksum = "4ec2a862134d2a7d32d7983ddcdd1c4923530833c9f2ea1a44fc5fa473989058" [[package]] name = "linux-raw-sys" -version = "0.3.8" +version = "0.4.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ef53942eb7bf7ff43a617b3e2c1c4a5ecf5944a7c1bc12d7ee39bbb15e5c1519" +checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" [[package]] name = "log" -version = "0.4.19" +version = "0.4.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b06a4cde4c0f271a446782e3eff8de789548ce57dbc8eca9292c27f4a42004b4" +checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" [[package]] -name = "memoffset" -version = "0.9.0" +name = "memchr" +version = "2.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5a634b1c61a95585bd15607c6ab0c4e5b226e695ff2800ba0cdccddf208c406c" -dependencies = [ - "autocfg", -] +checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" [[package]] name = "num-complex" -version = "0.4.5" +version = "0.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "23c6602fda94a57c990fe0df199a035d83576b496aa29f4e634a8ac6004e68a6" +checksum = "73f88a1307638156682bada9d7604135552957b7818057dcef22705b4d509495" dependencies = [ "bytemuck", "num-traits", @@ -615,40 +572,30 @@ dependencies = [ [[package]] name = "num-traits" -version = "0.2.15" +version = "0.2.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "578ede34cf02f8924ab9447f50c28075b4d3e5b269972345e7e0372b38c6cdcd" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" dependencies = [ "autocfg", ] -[[package]] -name = "num_cpus" -version = "1.16.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" -dependencies = [ - "hermit-abi 0.3.1", - "libc", -] - [[package]] name = "once_cell" -version = "1.18.0" +version = "1.20.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d" +checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775" [[package]] name = "oorandom" -version = "11.1.3" +version = "11.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ab1bc2a289d34bd04a330323ac98a1b4bc82c9d9fcb1e66b63caa84da26b575" +checksum = "b410bbe7e14ab526a0e86877eb47c6996a2bd7746f027ba551028c925390e4e9" [[package]] name = "os_str_bytes" -version = "6.5.1" +version = "6.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4d5d9eb14b174ee9aa2ef96dc2b94637a2d4b6e7cb873c7e171f0c20c6cf3eac" +checksum = "e2355d85b9a3786f481747ced0e0ff2ba35213a1f9bd406ed906554d7af805a1" [[package]] name = "paste" @@ -658,9 +605,9 @@ checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a" [[package]] name = "plotters" -version = "0.3.5" +version = "0.3.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d2c224ba00d7cadd4d5c660deaf2098e5e80e07846537c51f9cfa4be50c1fd45" +checksum = "5aeb6f403d7a4911efb1e33402027fc44f29b5bf6def3effcc22d7bb75f2b747" dependencies = [ "num-traits", "plotters-backend", @@ -671,24 +618,24 @@ dependencies = [ [[package]] name = "plotters-backend" -version = "0.3.5" +version = "0.3.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9e76628b4d3a7581389a35d5b6e2139607ad7c75b17aed325f210aa91f4a9609" +checksum = "df42e13c12958a16b3f7f4386b9ab1f3e7933914ecea48da7139435263a4172a" [[package]] name = "plotters-svg" -version = "0.3.5" +version = "0.3.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38f6d39893cca0701371e3c27294f09797214b86f1fb951b89ade8ec04e2abab" +checksum = "51bae2ac328883f7acdfea3d66a7c35751187f870bc81f94563733a154d7a670" dependencies = [ "plotters-backend", ] [[package]] name = "proc-macro2" -version = "1.0.63" +version = "1.0.87" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b368fba921b0dce7e60f5e04ec15e565b3303972b42bcfde1d0713b881959eb" +checksum = "b3e4daa0dcf6feba26f985457cdf104d4b4256fc5a09547140f3631bb076b19a" dependencies = [ "unicode-ident", ] @@ -707,9 +654,9 @@ dependencies = [ [[package]] name = "quote" -version = "1.0.29" +version = "1.0.37" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "573015e8ab27661678357f27dc26460738fd2b6c86e46f386fde94cb5d913105" +checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af" dependencies = [ "proc-macro2", ] @@ -725,9 +672,9 @@ dependencies = [ [[package]] name = "rayon" -version = "1.7.0" +version = "1.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d2df5196e37bcc87abebc0053e20787d73847bb33134a69841207dd0a47f03b" +checksum = "b418a60154510ca1a002a752ca9714984e21e4241e804d32555251faf8b78ffa" dependencies = [ "either", "rayon-core", @@ -735,76 +682,78 @@ dependencies = [ [[package]] name = "rayon-core" -version = "1.11.0" +version = "1.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4b8f95bd6966f5c87776639160a66bd8ab9895d9d4ab01ddba9fc60661aebe8d" +checksum = "1465873a3dfdaa8ae7cb14b4383657caab0b3e8a0aa9ae8e04b044854c8dfce2" dependencies = [ - "crossbeam-channel", "crossbeam-deque", "crossbeam-utils", - "num_cpus", ] [[package]] name = "readonly" -version = "0.2.8" +version = "0.2.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eb656d27c22b5c47154452686cae5e096f12e124daacb36a0bfcb32dbebb39e3" +checksum = "a25d631e41bfb5fdcde1d4e2215f62f7f0afa3ff11e26563765bd6ea1d229aeb" dependencies = [ "proc-macro2", "quote", - "syn 2.0.22", + "syn 2.0.79", ] [[package]] name = "reborrow" -version = "0.5.4" +version = "0.5.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2962bf2e1f971c53ef59b2d7ca51d6a5e5c4a9d2be47eb1f661a321a4da85888" +checksum = "03251193000f4bd3b042892be858ee50e8b3719f2b08e5833ac4353724632430" [[package]] -name = "redox_syscall" -version = "0.3.5" +name = "regex" +version = "1.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "567664f262709473930a4bf9e51bf2ebf3348f2e748ccc50dea20646858f8f29" +checksum = "38200e5ee88914975b69f657f0801b6f6dccafd44fd9326302a4aaeecfacb1d8" dependencies = [ - "bitflags", + "aho-corasick", + "memchr", + "regex-automata", + "regex-syntax", ] [[package]] -name = "regex" -version = "1.8.4" +name = "regex-automata" +version = "0.4.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d0ab3ca65655bb1e41f2a8c8cd662eb4fb035e67c3f78da1d61dffe89d07300f" +checksum = "368758f23274712b504848e9d5a6f010445cc8b87a7cdb4d7cbee666c1288da3" dependencies = [ + "aho-corasick", + "memchr", "regex-syntax", ] [[package]] name = "regex-syntax" -version = "0.7.2" +version = "0.8.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "436b050e76ed2903236f032a59761c1eb99e1b0aead2c257922771dab1fc8c78" +checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c" [[package]] name = "rustix" -version = "0.37.27" +version = "0.38.37" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fea8ca367a3a01fe35e6943c400addf443c0f57670e6ec51196f71a4b8762dd2" +checksum = "8acb788b847c24f28525660c4d7758620a7210875711f79e7f663cc152726811" dependencies = [ - "bitflags", + "bitflags 2.6.0", "errno", - "io-lifetimes", "libc", "linux-raw-sys", - "windows-sys", + "windows-sys 0.52.0", ] [[package]] name = "ryu" -version = "1.0.13" +version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f91339c0467de62360649f8d3e185ca8de4224ff281f66000de5eb2a77a79041" +checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" [[package]] name = "same-file" @@ -815,39 +764,34 @@ dependencies = [ "winapi-util", ] -[[package]] -name = "scopeguard" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" - [[package]] name = "serde" -version = "1.0.164" +version = "1.0.210" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9e8c8cf938e98f769bc164923b06dce91cea1751522f46f8466461af04c9027d" +checksum = "c8e3592472072e6e22e0a54d5904d9febf8508f65fb8552499a1abc7d1078c3a" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.164" +version = "1.0.210" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d9735b638ccc51c28bf6914d90a2e9725b377144fc612c49a611fddd1b631d68" +checksum = "243902eda00fad750862fc144cea25caca5e20d615af0a81bee94ca738f1df1f" dependencies = [ "proc-macro2", "quote", - "syn 2.0.22", + "syn 2.0.79", ] [[package]] name = "serde_json" -version = "1.0.99" +version = "1.0.128" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "46266871c240a00b8f503b877622fe33430b3c7d963bdc0f2adc511e54a1eae3" +checksum = "6ff5456707a1de34e7e37f2a6fd3d3f808c318259cbd01ab6377795054b483d8" dependencies = [ "itoa", + "memchr", "ryu", "serde", ] @@ -881,9 +825,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.22" +version = "2.0.79" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2efbeae7acf4eabd6bcdcbd11c92f45231ddda7539edc7806bd1a04a03b24616" +checksum = "89132cd0bf050864e1d38dc3bbc07a0eb8e7530af26344d3d2bbbef83499f590" dependencies = [ "proc-macro2", "quote", @@ -892,38 +836,36 @@ dependencies = [ [[package]] name = "tempfile" -version = "3.6.0" +version = "3.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "31c0432476357e58790aaa47a8efb0c5138f137343f3b5f23bd36a27e3b0a6d6" +checksum = "f0f2c9fc62d0beef6951ccffd757e241266a2c833136efbe35af6cd2567dca5b" dependencies = [ - "autocfg", "cfg-if", "fastrand", - "redox_syscall", + "once_cell", "rustix", - "windows-sys", + "windows-sys 0.59.0", ] [[package]] name = "termcolor" -version = "1.2.0" +version = "1.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "be55cf8942feac5c765c2c993422806843c9a9a45d4d5c407ad6dd2ea95eb9b6" +checksum = "06794f8f6c5c898b3275aebefa6b8a1cb24cd2c6c79397ab15774837a0bc5755" dependencies = [ "winapi-util", ] [[package]] name = "textwrap" -version = "0.16.0" +version = "0.16.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "222a222a5bfe1bba4a77b45ec488a741b3cb8872e5e499451fd7d0129c9c7c3d" +checksum = "23d434d3f8967a09480fb04132ebe0a3e088c173e6d0ee7897abbdf4eab0f8b9" [[package]] name = "tfhe" version = "0.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81923c2433f461e35f3d0b933696335e4f03b874438c844c576eab99e302fe00" +source = "git+https://github.com/zama-ai/tfhe-rs.git?rev=483a4fe#483a4fecf1a6b2e2a7827251a04608d018c83002" dependencies = [ "aligned-vec", "bincode", @@ -944,9 +886,8 @@ dependencies = [ [[package]] name = "tfhe-versionable" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d09ede610a0eac494ab832533415d4cb4f103b716901a11da84ccfeb287d08bf" +version = "0.3.2" +source = "git+https://github.com/zama-ai/tfhe-rs.git?rev=483a4fe#483a4fecf1a6b2e2a7827251a04608d018c83002" dependencies = [ "aligned-vec", "num-complex", @@ -956,13 +897,12 @@ dependencies = [ [[package]] name = "tfhe-versionable-derive" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5d92c0fe0b3e42c45ac7ef98092e60c09db69aeaeb821429a1754aef28ea575c" +version = "0.3.2" +source = "git+https://github.com/zama-ai/tfhe-rs.git?rev=483a4fe#483a4fecf1a6b2e2a7827251a04608d018c83002" dependencies = [ "proc-macro2", "quote", - "syn 2.0.22", + "syn 2.0.79", ] [[package]] @@ -986,27 +926,27 @@ dependencies = [ [[package]] name = "typenum" -version = "1.16.0" +version = "1.17.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "497961ef93d974e23eb6f433eb5fe1b7930b659f06d12dec6fc44a8f554c0bba" +checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825" [[package]] name = "unicode-ident" -version = "1.0.9" +version = "1.0.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b15811caf2415fb889178633e7724bad2509101cde276048e013b9def5e51fa0" +checksum = "e91b56cd4cadaeb79bbf1a5645f6b4f8dc5bde8834ad5894a8db35fda9efa1fe" [[package]] name = "version_check" -version = "0.9.4" +version = "0.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" +checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" [[package]] name = "walkdir" -version = "2.3.3" +version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "36df944cda56c7d8d8b7496af378e6b16de9284591917d307c9b4d313c44e698" +checksum = "29790946404f91d9c5d06f9874efddea1dc06c5efe94541a7d6863108e3a5e4b" dependencies = [ "same-file", "winapi-util", @@ -1020,34 +960,35 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] name = "wasm-bindgen" -version = "0.2.87" +version = "0.2.95" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7706a72ab36d8cb1f80ffbf0e071533974a60d0a308d01a5d0375bf60499a342" +checksum = "128d1e363af62632b8eb57219c8fd7877144af57558fb2ef0368d0087bddeb2e" dependencies = [ "cfg-if", + "once_cell", "wasm-bindgen-macro", ] [[package]] name = "wasm-bindgen-backend" -version = "0.2.87" +version = "0.2.95" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5ef2b6d3c510e9625e5fe6f509ab07d66a760f0885d858736483c32ed7809abd" +checksum = "cb6dd4d3ca0ddffd1dd1c9c04f94b868c37ff5fac97c30b97cff2d74fce3a358" dependencies = [ "bumpalo", "log", "once_cell", "proc-macro2", "quote", - "syn 2.0.22", + "syn 2.0.79", "wasm-bindgen-shared", ] [[package]] name = "wasm-bindgen-macro" -version = "0.2.87" +version = "0.2.95" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dee495e55982a3bd48105a7b947fd2a9b4a8ae3010041b9e0faab3f9cd028f1d" +checksum = "e79384be7f8f5a9dd5d7167216f022090cf1f9ec128e6e6a482a2cb5c5422c56" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -1055,28 +996,28 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.87" +version = "0.2.95" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "54681b18a46765f095758388f2d0cf16eb8d4169b639ab575a8f5693af210c7b" +checksum = "26c6ab57572f7a24a4985830b120de1594465e5d500f24afe89e16b4e833ef68" dependencies = [ "proc-macro2", "quote", - "syn 2.0.22", + "syn 2.0.79", "wasm-bindgen-backend", "wasm-bindgen-shared", ] [[package]] name = "wasm-bindgen-shared" -version = "0.2.87" +version = "0.2.95" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ca6ad05a4870b2bf5fe995117d3728437bd27d7cd5f06f13c17443ef369775a1" +checksum = "65fc09f10666a9f147042251e0dda9c18f166ff7de300607007e96bdebc1068d" [[package]] name = "web-sys" -version = "0.3.64" +version = "0.3.72" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b85cbef8c220a6abc02aefd892dfc0fc23afb1c6a426316ec33253a3877249b" +checksum = "f6488b90108c040df0fe62fa815cbdee25124641df01814dd7282749234c6112" dependencies = [ "js-sys", "wasm-bindgen", @@ -1100,11 +1041,11 @@ checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" [[package]] name = "winapi-util" -version = "0.1.5" +version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" +checksum = "cf221c93e13a30d793f7645a0e7762c55d169dbb0a49671918a2319d289b10bb" dependencies = [ - "winapi", + "windows-sys 0.59.0", ] [[package]] @@ -1115,22 +1056,32 @@ checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" [[package]] name = "windows-sys" -version = "0.48.0" +version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-sys" +version = "0.59.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" dependencies = [ "windows-targets", ] [[package]] name = "windows-targets" -version = "0.48.1" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05d4b17490f70499f20b9e791dcf6a299785ce8af4d709018206dc5b4953e95f" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" dependencies = [ "windows_aarch64_gnullvm", "windows_aarch64_msvc", "windows_i686_gnu", + "windows_i686_gnullvm", "windows_i686_msvc", "windows_x86_64_gnu", "windows_x86_64_gnullvm", @@ -1139,42 +1090,48 @@ dependencies = [ [[package]] name = "windows_aarch64_gnullvm" -version = "0.48.0" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "91ae572e1b79dba883e0d315474df7305d12f569b400fcf90581b06062f7e1bc" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" [[package]] name = "windows_aarch64_msvc" -version = "0.48.0" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b2ef27e0d7bdfcfc7b868b317c1d32c641a6fe4629c171b8928c7b08d98d7cf3" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" [[package]] name = "windows_i686_gnu" -version = "0.48.0" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "622a1962a7db830d6fd0a69683c80a18fda201879f0f447f065a3b7467daa241" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" [[package]] name = "windows_i686_msvc" -version = "0.48.0" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4542c6e364ce21bf45d69fdd2a8e455fa38d316158cfd43b3ac1c5b1b19f8e00" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" [[package]] name = "windows_x86_64_gnu" -version = "0.48.0" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ca2b8a661f7628cbd23440e50b05d705db3686f894fc9580820623656af974b1" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" [[package]] name = "windows_x86_64_gnullvm" -version = "0.48.0" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7896dbc1f41e08872e9d5e8f8baa8fdd2677f29468c4e156210174edc7f7b953" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" [[package]] name = "windows_x86_64_msvc" -version = "0.48.0" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1a515f5799fe4961cb532f983ce2b23082366b898e52ffbce459c86f67c8378a" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" diff --git a/backends/concrete-cpu/implementation/Cargo.toml b/backends/concrete-cpu/implementation/Cargo.toml index 1ab9519fd8..686674dd65 100644 --- a/backends/concrete-cpu/implementation/Cargo.toml +++ b/backends/concrete-cpu/implementation/Cargo.toml @@ -10,7 +10,7 @@ crate-type = ["lib", "staticlib"] [dependencies] -concrete-csprng = { version = "0.4.1", optional = true, features = [ +concrete-csprng = { git = "https://github.com/zama-ai/tfhe-rs.git", rev = "483a4fe", optional = true, features = [ "generator_fallback", ] } concrete-cpu-noise-model = { path = "../noise-model/" } @@ -31,16 +31,16 @@ serde = "~1" rayon = { version = "1.6", optional = true } once_cell = { version = "1.16", optional = true } -tfhe = { version = "0.8", features = ["integer"] } +tfhe = { git = "https://github.com/zama-ai/tfhe-rs.git", rev = "483a4fe", features = ["integer"] } [target.x86_64-unknown-unix-gnu.dependencies] -tfhe = { version = "0.8", features = ["integer", "x86_64-unix"] } +tfhe = { git = "https://github.com/zama-ai/tfhe-rs.git", rev = "483a4fe", features = ["integer", "x86_64-unix"] } [target.aarch64-unknown-unix-gnu.dependencies] -tfhe = { version = "0.8", features = ["integer", "aarch64-unix"] } +tfhe = { git = "https://github.com/zama-ai/tfhe-rs.git", rev = "483a4fe", features = ["integer", "aarch64-unix"] } [target.x86_64-pc-windows-gnu.dependencies] -tfhe = { version = "0.8", features = ["integer", "x86_64"] } +tfhe = { git = "https://github.com/zama-ai/tfhe-rs.git", rev = "483a4fe", features = ["integer", "x86_64"] } [features] default = ["parallel", "std", "csprng"] diff --git a/backends/concrete-cpu/implementation/include/concrete-cpu.h b/backends/concrete-cpu/implementation/include/concrete-cpu.h index 600bf790ed..3c6ced4e8f 100644 --- a/backends/concrete-cpu/implementation/include/concrete-cpu.h +++ b/backends/concrete-cpu/implementation/include/concrete-cpu.h @@ -370,8 +370,8 @@ void concrete_cpu_keyswitch_lwe_ciphertext_u64(uint64_t *ct_out, size_t output_dimension); size_t concrete_cpu_lwe_array_to_tfhers_uint8(const uint64_t *lwe_vec_buffer, - uint8_t *fheuint_buffer, - size_t fheuint_buffer_size, + uint8_t *buffer, + size_t buffer_len, struct TfhersFheIntDescription fheuint_desc); size_t concrete_cpu_lwe_ciphertext_size_u64(size_t lwe_dimension); @@ -415,11 +415,8 @@ size_t concrete_cpu_serialize_lwe_secret_key_u64(const uint64_t *lwe_sk, size_t concrete_cpu_tfhers_fheint_buffer_size_u64(size_t lwe_size, size_t n_cts); -struct TfhersFheIntDescription concrete_cpu_tfhers_uint8_description(const uint8_t *serialized_data_ptr, - size_t serialized_data_len); - -int64_t concrete_cpu_tfhers_uint8_to_lwe_array(const uint8_t *serialized_data_ptr, - size_t serialized_data_len, +int64_t concrete_cpu_tfhers_uint8_to_lwe_array(const uint8_t *buffer, + size_t buffer_len, uint64_t *lwe_vec_buffer, struct TfhersFheIntDescription desc); diff --git a/backends/concrete-cpu/implementation/src/c_api.rs b/backends/concrete-cpu/implementation/src/c_api.rs index a42c00cdf5..b3c4248619 100644 --- a/backends/concrete-cpu/implementation/src/c_api.rs +++ b/backends/concrete-cpu/implementation/src/c_api.rs @@ -12,6 +12,12 @@ pub mod wop_pbs; pub mod wop_pbs_simulation; mod utils { + + use serde::de::DeserializeOwned; + use serde::Serialize; + use tfhe::named::Named; + use tfhe::{Unversionize, Versionize}; + #[inline] pub fn nounwind(f: impl FnOnce() -> R) -> R { struct AbortOnDrop; @@ -33,27 +39,70 @@ mod utils { let _: libc::size_t = 0_usize; }; - pub unsafe fn serialize(value: &T, out_buffer: *mut u8, out_buffer_len: usize) -> usize - where - T: serde::ser::Serialize, - { - let serialized_size: usize = match bincode::serialized_size(value) { + // Serialize a tfhe-rs versionable value into a buffer, returns 0 if any error + // TODO: Better error management + pub unsafe fn safe_serialize( + value: &T, + buffer: *mut u8, + buffer_len: usize, + ) -> usize { + let writer = core::slice::from_raw_parts_mut(buffer, buffer_len); + let size = match tfhe::safe_serialization::safe_serialized_size(value) { Ok(size) => { - if size > out_buffer_len as u64 { + if size > buffer_len as u64 { return 0; } size as usize } - Err(_) => return 0, + Err(_e) => return 0, }; - let write_buff: &mut [u8] = core::slice::from_raw_parts_mut(out_buffer, out_buffer_len); - match bincode::serialize_into(&mut write_buff[..], value) { + match tfhe::safe_serialization::safe_serialize(value, writer, buffer_len as u64) { + Ok(_) => size, + Err(_e) => 0, + } + } + + // Deserialize a tfhe-rs versionable value from a buffer, panic if any error + // TODO: Better error management + pub unsafe fn safe_deserialize( + buffer: *const u8, + buffer_len: usize, + ) -> T { + let reader = core::slice::from_raw_parts(buffer, buffer_len); + // TODO: Fix approximation when is fixed in TFHE-rs + tfhe::safe_serialization::safe_deserialize(reader, (buffer_len + 1000) as u64).unwrap() + } + + // Serialize a tfhe-rs NON-versionable value into a buffer, returns 0 if any error. + // TODO: Remove me when safe_serialization by thfe-rs is implemented for all object. + pub unsafe fn unsafe_serialize( + value: &T, + buffer: *mut u8, + buffer_len: usize, + ) -> usize { + let serialized_size: usize = match bincode::serialized_size(value) { + Ok(size) if size <= buffer_len as u64 => size as usize, + _ => return 0, + }; + + let writer: &mut [u8] = core::slice::from_raw_parts_mut(buffer, buffer_len); + match bincode::serialize_into(&mut writer[..], value) { Ok(_) => serialized_size, Err(_) => 0, } } + // Deserialize a tfhe-rs NON-versionable value into a buffer, panic if any error + // TODO: Remove me when safe_serialization by thfe-rs is implemented for all object. + pub unsafe fn unsafe_deserialize( + buffer: *const u8, + buffer_len: usize, + ) -> T { + let reader = core::slice::from_raw_parts(buffer, buffer_len); + bincode::deserialize_from(reader).unwrap() + } + #[cfg(test)] mod tests { use super::*; diff --git a/backends/concrete-cpu/implementation/src/c_api/fheint.rs b/backends/concrete-cpu/implementation/src/c_api/fheint.rs index d2bfe2fcdd..1364b62646 100644 --- a/backends/concrete-cpu/implementation/src/c_api/fheint.rs +++ b/backends/concrete-cpu/implementation/src/c_api/fheint.rs @@ -1,6 +1,5 @@ use super::utils::nounwind; use core::slice; -use std::io::Cursor; use tfhe::core_crypto::prelude::*; use tfhe::integer::ciphertext::Expandable; use tfhe::integer::IntegerCiphertext; @@ -128,49 +127,17 @@ pub fn tfhers_uint8_description(fheuint: FheUint8) -> TfhersFheIntDescription { } } -#[no_mangle] -pub unsafe extern "C" fn concrete_cpu_tfhers_uint8_description( - serialized_data_ptr: *const u8, - serialized_data_len: usize, -) -> TfhersFheIntDescription { - nounwind(|| { - // deserialize fheuint8 - let mut serialized_data = Cursor::new(slice::from_raw_parts( - serialized_data_ptr, - serialized_data_len, - )); - let fheuint: FheUint8 = match bincode::deserialize_from(&mut serialized_data) { - Ok(value) => value, - Err(_) => { - return TfhersFheIntDescription::zero(); - } - }; - tfhers_uint8_description(fheuint) - }) -} - #[no_mangle] pub unsafe extern "C" fn concrete_cpu_tfhers_uint8_to_lwe_array( - serialized_data_ptr: *const u8, - serialized_data_len: usize, + buffer: *const u8, + buffer_len: usize, lwe_vec_buffer: *mut u64, desc: TfhersFheIntDescription, ) -> i64 { nounwind(|| { - // deserialize fheuint8 - let mut serialized_data = Cursor::new(slice::from_raw_parts( - serialized_data_ptr, - serialized_data_len, - )); - // TODO: can we have a generic deserialize? - let fheuint: FheUint8 = match bincode::deserialize_from(&mut serialized_data) { - Ok(value) => value, - Err(_) => { - return 1; - } - }; + let fheuint: FheUint8 = super::utils::safe_deserialize(buffer, buffer_len); + // TODO - Use conformance check let fheuint_desc = tfhers_uint8_description(fheuint.clone()); - if !fheuint_desc.is_similar(&desc) { return 1; } @@ -199,19 +166,20 @@ pub extern "C" fn concrete_cpu_tfhers_fheint_buffer_size_u64( lwe_size: usize, n_cts: usize, ) -> usize { + // TODO - that is fragile // all FheUint should have the same size, but we use a big one to be safe let meta_fheuint = core::mem::size_of::(); let meta_ct = core::mem::size_of::(); - // FheUint[metadata, ciphertexts[ciphertext[metadata, lwe_buffer] * n_cts]] - meta_fheuint + (meta_ct + lwe_size * 8/*u64*/) * n_cts + // FheUint[metadata, ciphertexts[ciphertext[metadata, lwe_buffer] * n_cts]] + headers + (meta_fheuint + (meta_ct + lwe_size * 8/*u64*/) * n_cts) + 201 } #[no_mangle] pub unsafe extern "C" fn concrete_cpu_lwe_array_to_tfhers_uint8( lwe_vec_buffer: *const u64, - fheuint_buffer: *mut u8, - fheuint_buffer_size: usize, + buffer: *mut u8, + buffer_len: usize, fheuint_desc: TfhersFheIntDescription, ) -> usize { nounwind(|| { @@ -240,11 +208,10 @@ pub unsafe extern "C" fn concrete_cpu_lwe_array_to_tfhers_uint8( } let fheuint = match FheUint8::from_expanded_blocks(blocks, fheuint_desc.data_kind()) { Ok(value) => value, - Err(_) => { + Err(_e) => { return 0; } }; - - super::utils::serialize(&fheuint, fheuint_buffer, fheuint_buffer_size) + super::utils::safe_serialize(&fheuint, buffer, buffer_len) }) } diff --git a/backends/concrete-cpu/implementation/src/c_api/secret_key.rs b/backends/concrete-cpu/implementation/src/c_api/secret_key.rs index ecee624568..892eb21442 100644 --- a/backends/concrete-cpu/implementation/src/c_api/secret_key.rs +++ b/backends/concrete-cpu/implementation/src/c_api/secret_key.rs @@ -223,7 +223,7 @@ pub unsafe extern "C" fn concrete_cpu_serialize_lwe_secret_key_u64( concrete_cpu_lwe_secret_key_size_u64(lwe_dimension), )); - super::utils::serialize(&lwe_sk, out_buffer, out_buffer_len) + super::utils::unsafe_serialize(&lwe_sk, out_buffer, out_buffer_len) } #[no_mangle] @@ -233,8 +233,7 @@ pub unsafe extern "C" fn concrete_cpu_unserialize_lwe_secret_key_u64( lwe_sk: *mut u64, lwe_sk_size: usize, ) -> usize { - let serialized_data = slice::from_raw_parts(buffer, buffer_len); - let sk: LweSecretKey> = bincode::deserialize_from(serialized_data).unwrap(); + let sk: LweSecretKey> = super::utils::unsafe_deserialize(buffer, buffer_len); let container = sk.into_container(); assert!(container.len() <= lwe_sk_size); let lwe_sk_slice = slice::from_raw_parts_mut(lwe_sk, lwe_sk_size); @@ -258,7 +257,7 @@ pub unsafe extern "C" fn concrete_cpu_serialize_glwe_secret_key_u64( PolynomialSize(polynomial_size), ); - super::utils::serialize(&glwe_sk, out_buffer, out_buffer_len) + super::utils::unsafe_serialize(&glwe_sk, out_buffer, out_buffer_len) } #[no_mangle] @@ -268,8 +267,7 @@ pub unsafe extern "C" fn concrete_cpu_unserialize_glwe_secret_key_u64( glwe_sk: *mut u64, glwe_sk_size: usize, ) -> usize { - let serialized_data = slice::from_raw_parts(buffer, buffer_len); - let sk: GlweSecretKey> = bincode::deserialize_from(serialized_data).unwrap(); + let sk: GlweSecretKey> = super::utils::unsafe_deserialize(buffer, buffer_len); assert!(sk.glwe_dimension().0 == 1); let container = sk.into_container(); assert!(container.len() <= glwe_sk_size); diff --git a/compilers/concrete-compiler/compiler/include/concretelang/ClientLib/ClientLib.h b/compilers/concrete-compiler/compiler/include/concretelang/ClientLib/ClientLib.h index 56dba93763..bf0d65c430 100644 --- a/compilers/concrete-compiler/compiler/include/concretelang/ClientLib/ClientLib.h +++ b/compilers/concrete-compiler/compiler/include/concretelang/ClientLib/ClientLib.h @@ -40,8 +40,6 @@ importTfhersFheUint8(llvm::ArrayRef serializedFheUint8, double encryptionVariance); Result> exportTfhersFheUint8(TransportValue value, TfhersFheIntDescription info); -Result -getTfhersFheUint8Description(llvm::ArrayRef serializedFheUint8); class ClientCircuit { diff --git a/compilers/concrete-compiler/compiler/lib/Bindings/Python/CompilerAPIModule.cpp b/compilers/concrete-compiler/compiler/lib/Bindings/Python/CompilerAPIModule.cpp index a05c2a1196..54f1af4844 100644 --- a/compilers/concrete-compiler/compiler/lib/Bindings/Python/CompilerAPIModule.cpp +++ b/compilers/concrete-compiler/compiler/lib/Bindings/Python/CompilerAPIModule.cpp @@ -1905,17 +1905,4 @@ void mlir::concretelang::python::populateCompilerAPISubmodule( } return result.value(); }); - - m.def("get_tfhers_fheuint8_description", - [](const pybind11::bytes &serialized_fheuint) { - const std::string &buffer_str = serialized_fheuint; - std::vector buffer(buffer_str.begin(), buffer_str.end()); - auto arrayRef = llvm::ArrayRef(buffer); - auto info = - ::concretelang::clientlib::getTfhersFheUint8Description(arrayRef); - if (info.has_error()) { - throw std::runtime_error(info.error().mesg); - } - return info.value(); - }); } diff --git a/compilers/concrete-compiler/compiler/lib/Bindings/Python/concrete/compiler/tfhers_int.py b/compilers/concrete-compiler/compiler/lib/Bindings/Python/concrete/compiler/tfhers_int.py index 3a16cb379b..d4006b058d 100644 --- a/compilers/concrete-compiler/compiler/lib/Bindings/Python/concrete/compiler/tfhers_int.py +++ b/compilers/concrete-compiler/compiler/lib/Bindings/Python/concrete/compiler/tfhers_int.py @@ -5,7 +5,6 @@ from mlir._mlir_libs._concretelang._compiler import ( import_tfhers_fheuint8 as _import_tfhers_fheuint8, export_tfhers_fheuint8 as _export_tfhers_fheuint8, - get_tfhers_fheuint8_description as _get_tfhers_fheuint8_description, TfhersFheIntDescription as _TfhersFheIntDescription, TransportValue, ) @@ -178,23 +177,6 @@ def __str__(self) -> str: f"ks_first={self.ks_first}>" ) - @staticmethod - def from_serialized_fheuint8(buffer: bytes) -> "TfhersFheIntDescription": - """Get the description of a serialized TFHErs fheuint8. - - Args: - buffer (bytes): serialized fheuint8 - - Raises: - TypeError: buffer is not of type bytes - - Returns: - TfhersFheIntDescription: description of the serialized fheuint8 - """ - if not isinstance(buffer, bytes): - raise TypeError(f"buffer must be of type bytes, not {type(buffer)}") - return TfhersFheIntDescription.wrap(_get_tfhers_fheuint8_description(buffer)) - class TfhersExporter: """A helper class to import and export TFHErs big integers.""" diff --git a/compilers/concrete-compiler/compiler/lib/ClientLib/ClientLib.cpp b/compilers/concrete-compiler/compiler/lib/ClientLib/ClientLib.cpp index 77e823cce2..000ec4dd1f 100644 --- a/compilers/concrete-compiler/compiler/lib/ClientLib/ClientLib.cpp +++ b/compilers/concrete-compiler/compiler/lib/ClientLib/ClientLib.cpp @@ -187,15 +187,6 @@ Result ClientProgram::getClientCircuit(std::string circuitName) { "`"); } -Result -getTfhersFheUint8Description(llvm::ArrayRef serializedFheUint8) { - auto fheUintDesc = concrete_cpu_tfhers_uint8_description( - serializedFheUint8.data(), serializedFheUint8.size()); - if (fheUintDesc.width == 0) - return StringError("couldn't get fheuint info"); - return fheUintDesc; -} - Result importTfhersFheUint8(llvm::ArrayRef serializedFheUint8, TfhersFheIntDescription desc, uint32_t encryptionKeyId, @@ -211,7 +202,8 @@ importTfhersFheUint8(llvm::ArrayRef serializedFheUint8, serializedFheUint8.data(), serializedFheUint8.size(), outputTensor.values.data(), desc); if (err) { - return StringError("couldn't convert fheuint to lwe array"); + return StringError("couldn't convert fheuint to lwe array: err()") + << err << ")"; } auto value = Value{outputTensor}.intoRawTransportValue(); diff --git a/frontends/concrete-python/tests/tfhers-utils/Cargo.lock b/frontends/concrete-python/tests/tfhers-utils/Cargo.lock index d1f9c44a35..a0166f6d12 100644 --- a/frontends/concrete-python/tests/tfhers-utils/Cargo.lock +++ b/frontends/concrete-python/tests/tfhers-utils/Cargo.lock @@ -1,6 +1,6 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. -version = 3 +version = 4 [[package]] name = "aes" @@ -172,8 +172,7 @@ checksum = "d3fd119d74b830634cea2a0f58bbd0d54540518a14397557951e79340abc28c0" [[package]] name = "concrete-csprng" version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "90518357249582c16a6b64d7410243dfb3109d5bf0ad1665c058c9a59f2fc4cc" +source = "git+https://github.com/zama-ai/tfhe-rs.git?rev=483a4fe#483a4fecf1a6b2e2a7827251a04608d018c83002" dependencies = [ "aes", "libc", @@ -509,8 +508,7 @@ dependencies = [ [[package]] name = "tfhe" version = "0.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81923c2433f461e35f3d0b933696335e4f03b874438c844c576eab99e302fe00" +source = "git+https://github.com/zama-ai/tfhe-rs.git?rev=483a4fe#483a4fecf1a6b2e2a7827251a04608d018c83002" dependencies = [ "aligned-vec", "bincode", @@ -531,9 +529,8 @@ dependencies = [ [[package]] name = "tfhe-versionable" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d09ede610a0eac494ab832533415d4cb4f103b716901a11da84ccfeb287d08bf" +version = "0.3.2" +source = "git+https://github.com/zama-ai/tfhe-rs.git?rev=483a4fe#483a4fecf1a6b2e2a7827251a04608d018c83002" dependencies = [ "aligned-vec", "num-complex", @@ -543,9 +540,8 @@ dependencies = [ [[package]] name = "tfhe-versionable-derive" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5d92c0fe0b3e42c45ac7ef98092e60c09db69aeaeb821429a1754aef28ea575c" +version = "0.3.2" +source = "git+https://github.com/zama-ai/tfhe-rs.git?rev=483a4fe#483a4fecf1a6b2e2a7827251a04608d018c83002" dependencies = [ "proc-macro2", "quote", @@ -558,6 +554,7 @@ version = "0.1.0" dependencies = [ "bincode", "clap", + "serde", "tfhe", ] diff --git a/frontends/concrete-python/tests/tfhers-utils/Cargo.toml b/frontends/concrete-python/tests/tfhers-utils/Cargo.toml index df1c5ffd83..1fa2ae0a90 100644 --- a/frontends/concrete-python/tests/tfhers-utils/Cargo.toml +++ b/frontends/concrete-python/tests/tfhers-utils/Cargo.toml @@ -6,15 +6,17 @@ edition = "2021" [dependencies] bincode = "1.3.3" +serde = "1" + clap = { version = "4.5.16", features = ["derive"] } -tfhe = { version = "0.8.0", features = ["integer"] } +tfhe = { git = "https://github.com/zama-ai/tfhe-rs.git", rev = "483a4fe", features = ["integer"] } [target.x86_64-unknown-linux-gnu.dependencies] -tfhe = { version = "0.8.0", features = ["integer", "x86_64-unix"] } +tfhe = { git = "https://github.com/zama-ai/tfhe-rs.git", rev = "483a4fe", features = ["integer", "x86_64-unix"] } [target.aarch64-unknown-linux-gnu.dependencies] -tfhe = { version = "0.8.0", features = ["integer", "aarch64-unix"] } +tfhe = { git = "https://github.com/zama-ai/tfhe-rs.git", rev = "483a4fe", features = ["integer", "aarch64-unix"] } [target.x86_64-pc-windows-gnu.dependencies] -tfhe = { version = "0.8.0", features = ["integer", "x86_64"] } +tfhe = { git = "https://github.com/zama-ai/tfhe-rs.git", rev = "483a4fe", features = ["integer", "x86_64"] } diff --git a/frontends/concrete-python/tests/tfhers-utils/src/main.rs b/frontends/concrete-python/tests/tfhers-utils/src/main.rs index bc620a5492..5f363f1bd3 100644 --- a/frontends/concrete-python/tests/tfhers-utils/src/main.rs +++ b/frontends/concrete-python/tests/tfhers-utils/src/main.rs @@ -1,95 +1,84 @@ use clap::{Arg, ArgAction, Command}; use core::panic; +use serde::de::DeserializeOwned; use std::fs; -use std::io::Cursor; use std::path::Path; use tfhe::core_crypto::prelude::LweSecretKey; +use tfhe::{prelude::*}; use tfhe::shortint::{ClassicPBSParameters, EncryptionKeyChoice}; -use tfhe::{generate_keys, set_server_key, ClientKey, FheUint8, ServerKey}; -use tfhe::{prelude::*, ConfigBuilder}; +use tfhe::{generate_keys, set_server_key, ClientKey, ConfigBuilder, FheUint8, ServerKey}; + +use serde::Serialize; +use tfhe::named::Named; +use tfhe::{Unversionize, Versionize}; + +use tfhe::safe_serialization::{safe_deserialize, safe_serialize}; const BLOCK_PARAMS: ClassicPBSParameters = tfhe::shortint::prelude::PARAM_MESSAGE_2_CARRY_3_KS_PBS; +const SERIALIZE_SIZE_LIMIT: u64 = 1_000_000_000; -fn load_lwe_sk(lwe_sk_path: &String) -> LweSecretKey> { - let path_sk: &Path = Path::new(lwe_sk_path); - let serialized_sk = fs::read(path_sk).unwrap(); - let mut serialized_data = Cursor::new(serialized_sk); - bincode::deserialize_from(&mut serialized_data).unwrap() +// safe_save write to a path a value that implement the tfhe-rs safe serialization +fn safe_save(path: &String, value: &T) { + let file = fs::File::create(path).unwrap(); + safe_serialize(value, file, SERIALIZE_SIZE_LIMIT).unwrap() } -fn set_server_key_from_file(server_key_path: &String) { - let serialized_sk = fs::read(Path::new(server_key_path)).unwrap(); - let mut serialized_data = Cursor::new(serialized_sk); - let sk: ServerKey = bincode::deserialize_from(&mut serialized_data).unwrap(); - set_server_key(sk); +// safe_load read from a path a value that implement the tfhe-rs safe serialization +fn safe_load(path: &String) -> T { + let file = fs::File::open(path).unwrap(); + safe_deserialize(file, SERIALIZE_SIZE_LIMIT).unwrap() } -fn load_client_key(client_path: &String) -> ClientKey { - let path_key: &Path = Path::new(client_path); - let serialized_key = fs::read(path_key).unwrap(); - let mut serialized_data = Cursor::new(serialized_key); - let client_key: ClientKey = bincode::deserialize_from(&mut serialized_data).unwrap(); - client_key +// unsafe_save write to a path a value that NOT implement the tfhe-rs safe serialization +// TODO: Remove me when all object implemennt tfhe-rs safe serialization +fn unsafe_save(path: &String, value: &T) { + let file = fs::File::create(path).unwrap(); + bincode::serialize_into(file, value).unwrap() } -fn serialize_fheuint8(fheuint: FheUint8, ciphertext_path: &String) { - let mut serialized_ct = Vec::new(); - bincode::serialize_into(&mut serialized_ct, &fheuint).unwrap(); - let path_ct: &Path = Path::new(ciphertext_path); - fs::write(path_ct, serialized_ct).unwrap(); +// unsafe_load read from a path a value that NOT implement the tfhe-rs safe serialization +// TODO: Remove me when all object implemennt tfhe-rs safe serialization +fn unsafe_load(path: &String) -> T { + let file = fs::File::open(path).unwrap(); + bincode::deserialize_from(file).unwrap() } -fn encrypt_with_key( - value: u8, - client_key: ClientKey, - ciphertext_path: &String, -) -> Result<(), Box> { - let ct = FheUint8::encrypt(value, &client_key); - - serialize_fheuint8(ct, ciphertext_path); - - Ok(()) +fn set_server_key_from_file(path: &String) { + let sk: ServerKey = safe_load(path); + set_server_key(sk); } -fn deserialize_fheuint8(path: &String) -> FheUint8 { - let path_fheuint: &Path = Path::new(path); - let serialized_fheuint = fs::read(path_fheuint).unwrap(); - let mut serialized_data = Cursor::new(serialized_fheuint); - bincode::deserialize_from(&mut serialized_data).unwrap() +fn encrypt_with_key(value: u8, client_key: ClientKey, path: &String) { + let ct = FheUint8::encrypt(value, &client_key); + safe_save(path, &ct) } fn decrypt_with_key( client_key: ClientKey, ciphertext_path: &String, plaintext_path: Option<&String>, -) -> Result<(), Box> { - let fheuint = deserialize_fheuint8(ciphertext_path); - +) { + let fheuint: FheUint8 = safe_load(ciphertext_path); let result: u8 = fheuint.decrypt(&client_key); if let Some(path) = plaintext_path { let pt_path: &Path = Path::new(path); - fs::write(pt_path, result.to_string())?; + fs::write(pt_path, result.to_string()).unwrap(); } else { println!("result: {}", result); } - - Ok(()) } -fn sum(cts_paths: Vec<&String>, out_ct_path: &String) -> Result<(), Box> { +fn sum(cts_paths: Vec<&String>, out_ct_path: &String) { if cts_paths.is_empty() { panic!("can't call sum with 0 ciphertexts"); } - let mut acc = deserialize_fheuint8(cts_paths[0]); + let mut acc: FheUint8 = safe_load(cts_paths[0]); for ct_path in cts_paths[1..].iter() { - let fheuint = deserialize_fheuint8(ct_path); + let fheuint: FheUint8 = safe_load(ct_path); acc += fheuint; } - - serialize_fheuint8(acc, out_ct_path); - - Ok(()) + safe_save(out_ct_path, &acc) } fn write_keys( @@ -99,36 +88,25 @@ fn write_keys( client_key: Option, server_key: Option, lwe_secret_key: Option>>, -) -> Result<(), Box> { +) { if let Some(ck) = client_key { - let mut serialized_client_key = Vec::new(); - bincode::serialize_into(&mut serialized_client_key, &ck)?; - let path_client_key: &Path = Path::new(client_key_path); - fs::write(path_client_key, serialized_client_key).unwrap(); + safe_save(client_key_path, &ck) } if let Some(sk) = server_key { - let mut serialized_server_key = Vec::new(); - bincode::serialize_into(&mut serialized_server_key, &sk)?; - let path_server_key: &Path = Path::new(server_key_path); - fs::write(path_server_key, serialized_server_key).unwrap(); + safe_save(server_key_path, &sk) } if let Some(lwe_sk) = lwe_secret_key { - let mut serialized_lwe_key = Vec::new(); - bincode::serialize_into(&mut serialized_lwe_key, &lwe_sk)?; - let path_lwe_key: &Path = Path::new(output_lwe_path); - fs::write(path_lwe_key, serialized_lwe_key).unwrap(); + unsafe_save(output_lwe_path, &lwe_sk) } - - Ok(()) } fn keygen( client_key_path: &String, server_key_path: &String, output_lwe_path: &String, -) -> Result<(), Box> { +) { let config = ConfigBuilder::with_custom_parameters(BLOCK_PARAMS).build(); let (client_key, server_key) = generate_keys(config); @@ -145,19 +123,18 @@ fn keygen( Some(client_key), Some(server_key), Some(lwe_secret_key), - )?; - Ok(()) + ) } fn keygen_from_lwe(lwe_sk_path: &String) -> ClientKey { - let lwe_sk = load_lwe_sk(lwe_sk_path); + let lwe_sk = unsafe_load(lwe_sk_path); let shortint_key = tfhe::shortint::ClientKey::try_from_lwe_encryption_key(lwe_sk, BLOCK_PARAMS).unwrap(); ClientKey::from_raw_parts(shortint_key.into(), None, None, tfhe::Tag::default()) } -fn main() -> Result<(), Box> { +fn main() { let matches = Command::new("tfhers-utils") .about("TFHErs utilities") .subcommand_required(true) @@ -330,7 +307,7 @@ fn main() -> Result<(), Box> { if let Some(lwe_sk_path) = encrypt_matches.get_one::("lwe-sk") { client_key = keygen_from_lwe(lwe_sk_path); } else if let Some(client_key_path) = encrypt_matches.get_one::("client-key") { - client_key = load_client_key(client_key_path); + client_key = safe_load(client_key_path); } else { panic!("no key specified"); } @@ -345,7 +322,7 @@ fn main() -> Result<(), Box> { if let Some(lwe_sk_path) = decrypt_mtches.get_one::("lwe-sk") { client_key = keygen_from_lwe(lwe_sk_path); } else if let Some(client_key_path) = decrypt_mtches.get_one::("client-key") { - client_key = load_client_key(client_key_path); + client_key = safe_load(client_key_path); } else { panic!("no key specified"); } @@ -369,7 +346,7 @@ fn main() -> Result<(), Box> { if let Some(lwe_sk_path) = keygen_mtches.get_one::("lwe-sk") { let client_key = keygen_from_lwe(lwe_sk_path); let server_key = client_key.generate_server_key(); - let lwe_secret_key = load_lwe_sk(lwe_sk_path); + let lwe_secret_key = unsafe_load(lwe_sk_path); write_keys( client_key_path, server_key_path,