diff --git a/tfhe/benches/shortint/bench.rs b/tfhe/benches/shortint/bench.rs index 3846f25009..a6a2764379 100644 --- a/tfhe/benches/shortint/bench.rs +++ b/tfhe/benches/shortint/bench.rs @@ -363,7 +363,7 @@ fn server_key_from_compressed_key(c: &mut Criterion) { b.iter_batched( clone_compressed_key, |sks_cloned| { - let _ = ServerKey::from(sks_cloned); + let _ = sks_cloned.decompress(); }, criterion::BatchSize::PerIteration, ) diff --git a/tfhe/src/boolean/ciphertext/mod.rs b/tfhe/src/boolean/ciphertext/mod.rs index 5984d43dff..fdfea30c58 100644 --- a/tfhe/src/boolean/ciphertext/mod.rs +++ b/tfhe/src/boolean/ciphertext/mod.rs @@ -22,13 +22,11 @@ pub struct CompressedCiphertext { pub(crate) ciphertext: SeededLweCiphertext, } -impl From for Ciphertext { - fn from(value: CompressedCiphertext) -> Self { - Self::Encrypted(value.ciphertext.decompress_into_lwe_ciphertext()) +impl CompressedCiphertext { + pub fn decompress(&self) -> Ciphertext { + Ciphertext::Encrypted(self.ciphertext.decompress_into_lwe_ciphertext()) } -} -impl CompressedCiphertext { /// Deconstruct a [`CompressedCiphertext`] into its constituents. pub fn into_raw_parts(self) -> SeededLweCiphertext { self.ciphertext diff --git a/tfhe/src/boolean/engine/bootstrapping.rs b/tfhe/src/boolean/engine/bootstrapping.rs index 5527d53883..7d3ca82c73 100644 --- a/tfhe/src/boolean/engine/bootstrapping.rs +++ b/tfhe/src/boolean/engine/bootstrapping.rs @@ -600,9 +600,3 @@ impl ServerKey { output } } - -impl From for ServerKey { - fn from(compressed_server_key: CompressedServerKey) -> Self { - compressed_server_key.decompress() - } -} diff --git a/tfhe/src/boolean/public_key/standard.rs b/tfhe/src/boolean/public_key/standard.rs index c7966fdef8..4f7a69a811 100644 --- a/tfhe/src/boolean/public_key/standard.rs +++ b/tfhe/src/boolean/public_key/standard.rs @@ -113,15 +113,16 @@ impl PublicKey { } } -impl From for PublicKey { - fn from(compressed_public_key: CompressedPublicKey) -> Self { - let parameters = compressed_public_key.parameters; +impl CompressedPublicKey { + pub fn decompress(&self) -> PublicKey { + let parameters = self.parameters; - let decompressed_public_key = compressed_public_key + let decompressed_public_key = self .compressed_lwe_public_key + .as_view() .par_decompress_into_lwe_public_key(); - Self { + PublicKey { lwe_public_key: decompressed_public_key, parameters, } @@ -194,7 +195,7 @@ mod tests { let keys = KEY_CACHE.get_from_param(parameters); let (cks, sks) = (keys.client_key(), keys.server_key()); let cpks = CompressedPublicKey::new(cks); - let pks = PublicKey::from(cpks); + let pks = cpks.decompress(); for _ in 0..NB_TESTS { let b1 = random_boolean(); diff --git a/tfhe/src/c_api/boolean/ciphertext.rs b/tfhe/src/c_api/boolean/ciphertext.rs index 32c15b5d98..e92de53d8a 100644 --- a/tfhe/src/c_api/boolean/ciphertext.rs +++ b/tfhe/src/c_api/boolean/ciphertext.rs @@ -60,7 +60,7 @@ pub unsafe extern "C" fn boolean_decompress_ciphertext( let compressed_ciphertext = get_mut_checked(compressed_ciphertext).unwrap(); - let ciphertext = compressed_ciphertext.0.clone().into(); + let ciphertext = compressed_ciphertext.0.decompress(); let heap_allocated_ciphertext = Box::new(BooleanCiphertext(ciphertext)); diff --git a/tfhe/src/c_api/boolean/server_key.rs b/tfhe/src/c_api/boolean/server_key.rs index 31fcd72e23..0de17e8997 100644 --- a/tfhe/src/c_api/boolean/server_key.rs +++ b/tfhe/src/c_api/boolean/server_key.rs @@ -677,9 +677,8 @@ pub unsafe extern "C" fn boolean_decompress_server_key( let compressed_server_key = get_ref_checked(compressed_server_key).unwrap(); - let heap_allocated_public_key = Box::new(BooleanServerKey( - boolean::server_key::ServerKey::from(compressed_server_key.0.clone()), - )); + let heap_allocated_public_key = + Box::new(BooleanServerKey(compressed_server_key.0.decompress())); *result = Box::into_raw(heap_allocated_public_key); }) diff --git a/tfhe/src/c_api/high_level_api/integers.rs b/tfhe/src/c_api/high_level_api/integers.rs index d8904928f1..fb3f4fc342 100644 --- a/tfhe/src/c_api/high_level_api/integers.rs +++ b/tfhe/src/c_api/high_level_api/integers.rs @@ -336,7 +336,7 @@ macro_rules! create_integer_wrapper_type { $crate::c_api::utils::catch_panic(|| { let compressed = $crate::c_api::utils::get_ref_checked(sself).unwrap(); - let decompressed_inner = compressed.0.clone().into(); + let decompressed_inner = compressed.0.decompress(); *result = Box::into_raw(Box::new($name(decompressed_inner))); }) } diff --git a/tfhe/src/c_api/shortint/ciphertext.rs b/tfhe/src/c_api/shortint/ciphertext.rs index bacad31c15..1596849bfa 100644 --- a/tfhe/src/c_api/shortint/ciphertext.rs +++ b/tfhe/src/c_api/shortint/ciphertext.rs @@ -87,7 +87,7 @@ pub unsafe extern "C" fn shortint_decompress_ciphertext( let compressed_ciphertext = get_ref_checked(compressed_ciphertext).unwrap(); - let ciphertext = compressed_ciphertext.0.clone().into(); + let ciphertext = compressed_ciphertext.0.decompress(); let heap_allocated_ciphertext = Box::new(ShortintCiphertext(ciphertext)); diff --git a/tfhe/src/c_api/shortint/public_key.rs b/tfhe/src/c_api/shortint/public_key.rs index 9eb3622c04..817b06f32f 100644 --- a/tfhe/src/c_api/shortint/public_key.rs +++ b/tfhe/src/c_api/shortint/public_key.rs @@ -185,7 +185,7 @@ pub unsafe extern "C" fn shortint_decompress_public_key( let compressed_public_key = get_ref_checked(compressed_public_key).unwrap(); let heap_allocated_public_key = - Box::new(ShortintPublicKey(compressed_public_key.0.clone().into())); + Box::new(ShortintPublicKey(compressed_public_key.0.decompress())); *result = Box::into_raw(heap_allocated_public_key); }) diff --git a/tfhe/src/c_api/shortint/server_key/mod.rs b/tfhe/src/c_api/shortint/server_key/mod.rs index 41f6431565..b78321ac80 100644 --- a/tfhe/src/c_api/shortint/server_key/mod.rs +++ b/tfhe/src/c_api/shortint/server_key/mod.rs @@ -173,9 +173,8 @@ pub unsafe extern "C" fn shortint_decompress_server_key( let compressed_server_key = get_ref_checked(compressed_server_key).unwrap(); - let heap_allocated_public_key = Box::new(ShortintServerKey( - shortint::server_key::ServerKey::from(compressed_server_key.0.clone()), - )); + let heap_allocated_public_key = + Box::new(ShortintServerKey(compressed_server_key.0.decompress())); *result = Box::into_raw(heap_allocated_public_key); }) diff --git a/tfhe/src/core_crypto/entities/seeded_lwe_ciphertext.rs b/tfhe/src/core_crypto/entities/seeded_lwe_ciphertext.rs index bbb27befa2..8eab9aab33 100644 --- a/tfhe/src/core_crypto/entities/seeded_lwe_ciphertext.rs +++ b/tfhe/src/core_crypto/entities/seeded_lwe_ciphertext.rs @@ -9,7 +9,7 @@ use crate::core_crypto::entities::*; use crate::core_crypto::prelude::misc::check_encrypted_content_respects_mod; /// A [`seeded GLWE ciphertext`](`SeededLweCiphertext`). -#[derive(Clone, Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize)] +#[derive(Copy, Clone, Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize)] pub struct SeededLweCiphertext { data: Scalar, lwe_size: LweSize, diff --git a/tfhe/src/high_level_api/booleans/base.rs b/tfhe/src/high_level_api/booleans/base.rs index 82f4a86040..28ce9d10a4 100644 --- a/tfhe/src/high_level_api/booleans/base.rs +++ b/tfhe/src/high_level_api/booleans/base.rs @@ -1,6 +1,5 @@ use super::inner::InnerBoolean; use crate::conformance::ParameterSetConformant; -use crate::high_level_api::booleans::compressed::CompressedFheBool; use crate::high_level_api::global_state; #[cfg(feature = "gpu")] use crate::high_level_api::global_state::with_thread_local_cuda_stream; @@ -11,7 +10,7 @@ use crate::integer::parameters::RadixCiphertextConformanceParams; use crate::integer::BooleanBlock; use crate::named::Named; use crate::shortint::ciphertext::NotTrivialCiphertextError; -use crate::{CompactFheBool, Device}; +use crate::Device; use serde::{Deserialize, Serialize}; use std::borrow::Borrow; use std::ops::{BitAnd, BitAndAssign, BitOr, BitOrAssign, BitXor, BitXorAssign}; @@ -59,18 +58,6 @@ impl ParameterSetConformant for FheBool { } } -impl From for FheBool { - fn from(value: CompressedFheBool) -> Self { - value.decompress() - } -} - -impl From for FheBool { - fn from(value: CompactFheBool) -> Self { - value.expand() - } -} - impl FheBool { pub(in crate::high_level_api) fn new>(ciphertext: T) -> Self { Self { diff --git a/tfhe/src/high_level_api/booleans/tests.rs b/tfhe/src/high_level_api/booleans/tests.rs index cbf9f6ad49..cea7cbb9bb 100644 --- a/tfhe/src/high_level_api/booleans/tests.rs +++ b/tfhe/src/high_level_api/booleans/tests.rs @@ -303,8 +303,8 @@ fn compressed_bool_test_case(setup_fn: impl FnOnce() -> (ClientKey, Device)) { let cttrue = CompressedFheBool::encrypt(true, &cks); let cffalse = CompressedFheBool::encrypt(false, &cks); - let a = FheBool::from(cttrue); - let b = FheBool::from(cffalse); + let a = cttrue.decompress(); + let b = cffalse.decompress(); assert_degree_is_ok(&a); assert_degree_is_ok(&b); diff --git a/tfhe/src/high_level_api/integers/signed/base.rs b/tfhe/src/high_level_api/integers/signed/base.rs index a86b1dc0a6..d247d4a002 100644 --- a/tfhe/src/high_level_api/integers/signed/base.rs +++ b/tfhe/src/high_level_api/integers/signed/base.rs @@ -8,7 +8,7 @@ use crate::integer::SignedRadixCiphertext; use crate::named::Named; use crate::prelude::CastFrom; use crate::shortint::ciphertext::NotTrivialCiphertextError; -use crate::{CompactFheInt, CompressedFheInt, FheBool}; +use crate::FheBool; pub trait FheIntId: IntegerId {} @@ -32,24 +32,6 @@ pub struct FheInt { pub(in crate::high_level_api::integers) id: Id, } -impl From> for FheInt -where - Id: FheIntId, -{ - fn from(value: CompressedFheInt) -> Self { - value.decompress() - } -} - -impl From> for FheInt -where - Id: FheIntId, -{ - fn from(value: CompactFheInt) -> Self { - value.expand() - } -} - impl ParameterSetConformant for FheInt { type ParameterSet = RadixCiphertextConformanceParams; fn is_conformant(&self, params: &RadixCiphertextConformanceParams) -> bool { diff --git a/tfhe/src/high_level_api/integers/signed/compressed.rs b/tfhe/src/high_level_api/integers/signed/compressed.rs index e27bc6867d..ddc81d3449 100644 --- a/tfhe/src/high_level_api/integers/signed/compressed.rs +++ b/tfhe/src/high_level_api/integers/signed/compressed.rs @@ -68,8 +68,8 @@ where /// Decompress to a [FheInt] /// /// See [CompressedFheInt] example. - pub fn decompress(self) -> FheInt { - let inner = self.ciphertext.into(); + pub fn decompress(&self) -> FheInt { + let inner = self.ciphertext.decompress(); FheInt::new(inner) } } diff --git a/tfhe/src/high_level_api/integers/signed/tests.rs b/tfhe/src/high_level_api/integers/signed/tests.rs index f3658a63af..ee55ceb6c8 100644 --- a/tfhe/src/high_level_api/integers/signed/tests.rs +++ b/tfhe/src/high_level_api/integers/signed/tests.rs @@ -14,7 +14,7 @@ fn test_signed_integer_compressed() { let clear = -1234i16; let compressed = CompressedFheInt16::try_encrypt(clear, &client_key).unwrap(); - let decompressed = FheInt16::from(compressed); + let decompressed = compressed.decompress(); let clear_decompressed: i16 = decompressed.decrypt(&client_key); assert_eq!(clear_decompressed, clear); } @@ -28,7 +28,7 @@ fn test_integer_compressed_small() { let clear = rng.gen::(); let compressed = CompressedFheInt16::try_encrypt(clear, &client_key).unwrap(); - let decompressed = FheInt16::from(compressed); + let decompressed = compressed.decompress(); let clear_decompressed: i16 = decompressed.decrypt(&client_key); assert_eq!(clear_decompressed, clear); } diff --git a/tfhe/src/high_level_api/integers/unsigned/base.rs b/tfhe/src/high_level_api/integers/unsigned/base.rs index d84be660f6..de765e95b3 100644 --- a/tfhe/src/high_level_api/integers/unsigned/base.rs +++ b/tfhe/src/high_level_api/integers/unsigned/base.rs @@ -9,7 +9,7 @@ use crate::integer::block_decomposition::RecomposableFrom; use crate::integer::parameters::RadixCiphertextConformanceParams; use crate::named::Named; use crate::shortint::ciphertext::NotTrivialCiphertextError; -use crate::{CompactFheUint, CompressedFheUint, FheBool}; +use crate::FheBool; #[derive(Debug)] pub enum GenericIntegerBlockError { @@ -70,24 +70,6 @@ pub struct FheUint { pub(in crate::high_level_api::integers) id: Id, } -impl From> for FheUint -where - Id: FheUintId, -{ - fn from(value: CompressedFheUint) -> Self { - value.decompress() - } -} - -impl From> for FheUint -where - Id: FheUintId, -{ - fn from(value: CompactFheUint) -> Self { - value.expand() - } -} - impl ParameterSetConformant for FheUint { type ParameterSet = RadixCiphertextConformanceParams; fn is_conformant(&self, params: &RadixCiphertextConformanceParams) -> bool { diff --git a/tfhe/src/high_level_api/integers/unsigned/compressed.rs b/tfhe/src/high_level_api/integers/unsigned/compressed.rs index a917ae8b23..0e541cc33a 100644 --- a/tfhe/src/high_level_api/integers/unsigned/compressed.rs +++ b/tfhe/src/high_level_api/integers/unsigned/compressed.rs @@ -67,8 +67,8 @@ where /// Decompress to a [FheUint] /// /// See [CompressedFheUint] example. - pub fn decompress(self) -> FheUint { - let inner: crate::integer::RadixCiphertext = self.ciphertext.into(); + pub fn decompress(&self) -> FheUint { + let inner: crate::integer::RadixCiphertext = self.ciphertext.decompress(); let mut ciphertext = FheUint::new(inner); ciphertext.move_to_device_of_server_key_if_set(); ciphertext diff --git a/tfhe/src/high_level_api/integers/unsigned/tests/cpu.rs b/tfhe/src/high_level_api/integers/unsigned/tests/cpu.rs index eb309e250a..687b9e6a97 100644 --- a/tfhe/src/high_level_api/integers/unsigned/tests/cpu.rs +++ b/tfhe/src/high_level_api/integers/unsigned/tests/cpu.rs @@ -40,7 +40,7 @@ fn test_integer_compressed_can_be_serialized() { let bytes = bincode::serialize(&compressed).unwrap(); let deserialized: CompressedFheUint256 = bincode::deserialize_from(bytes.as_slice()).unwrap(); - let decompressed = FheUint256::from(deserialized); + let decompressed = FheUint256::from(deserialized.decompress()); let clear_decompressed: U256 = decompressed.decrypt(&client_key); assert_eq!(clear_decompressed, clear); } @@ -52,7 +52,7 @@ fn test_integer_compressed() { let clear = 12_837u16; let compressed = CompressedFheUint16::try_encrypt(clear, &client_key).unwrap(); - let decompressed = FheUint16::from(compressed); + let decompressed = FheUint16::from(compressed.decompress()); let clear_decompressed: u16 = decompressed.decrypt(&client_key); assert_eq!(clear_decompressed, clear); } @@ -64,7 +64,7 @@ fn test_integer_compressed_small() { let clear = 12_837u16; let compressed = CompressedFheUint16::try_encrypt(clear, &client_key).unwrap(); - let decompressed = FheUint16::from(compressed); + let decompressed = FheUint16::from(compressed.decompress()); let clear_decompressed: u16 = decompressed.decrypt(&client_key); assert_eq!(clear_decompressed, clear); } diff --git a/tfhe/src/high_level_api/keys/public.rs b/tfhe/src/high_level_api/keys/public.rs index ef83bd9de6..0447004d16 100644 --- a/tfhe/src/high_level_api/keys/public.rs +++ b/tfhe/src/high_level_api/keys/public.rs @@ -70,9 +70,9 @@ impl CompressedPublicKey { Self { key } } - pub fn decompress(self) -> PublicKey { + pub fn decompress(&self) -> PublicKey { PublicKey { - key: crate::integer::PublicKey::from(self.key), + key: self.key.decompress(), } } diff --git a/tfhe/src/high_level_api/keys/server.rs b/tfhe/src/high_level_api/keys/server.rs index fc1ee7f116..d2fc384cbb 100644 --- a/tfhe/src/high_level_api/keys/server.rs +++ b/tfhe/src/high_level_api/keys/server.rs @@ -145,12 +145,6 @@ impl CompressedServerKey { } } -impl From for ServerKey { - fn from(value: CompressedServerKey) -> Self { - value.decompress() - } -} - #[cfg(feature = "gpu")] #[derive(Clone)] pub struct CudaServerKey { diff --git a/tfhe/src/integer/ciphertext/compressed.rs b/tfhe/src/integer/ciphertext/compressed.rs index 1db848ec5f..c1aa778855 100644 --- a/tfhe/src/integer/ciphertext/compressed.rs +++ b/tfhe/src/integer/ciphertext/compressed.rs @@ -21,13 +21,12 @@ impl ParameterSetConformant for CompressedRadixCiphertext { } } -impl From for RadixCiphertext { - fn from(compressed: CompressedRadixCiphertext) -> Self { - Self::from( - compressed - .blocks - .into_iter() - .map(From::from) +impl CompressedRadixCiphertext { + pub fn decompress(&self) -> RadixCiphertext { + RadixCiphertext::from( + self.blocks + .iter() + .map(CompressedCiphertext::decompress) .collect::>(), ) } @@ -49,13 +48,12 @@ impl ParameterSetConformant for CompressedSignedRadixCiphertext { } } -impl From for SignedRadixCiphertext { - fn from(compressed: CompressedSignedRadixCiphertext) -> Self { - Self::from( - compressed - .blocks - .into_iter() - .map(From::from) +impl CompressedSignedRadixCiphertext { + pub fn decompress(&self) -> SignedRadixCiphertext { + SignedRadixCiphertext::from( + self.blocks + .iter() + .map(CompressedCiphertext::decompress) .collect::>(), ) } @@ -64,14 +62,14 @@ impl From for SignedRadixCiphertext { /// Structure containing a **compressed** ciphertext in CRT decomposition. pub type CompressedCrtCiphertext = BaseCrtCiphertext; -impl From for CrtCiphertext { - fn from(compressed: CompressedCrtCiphertext) -> Self { - let blocks = compressed +impl CompressedCrtCiphertext { + pub fn decompress(&self) -> CrtCiphertext { + let blocks = self .blocks - .into_iter() - .map(From::from) + .iter() + .map(CompressedCiphertext::decompress) .collect::>(); - let moduli = compressed.moduli; - Self::from((blocks, moduli)) + let moduli = self.moduli.clone(); + CrtCiphertext::from((blocks, moduli)) } } diff --git a/tfhe/src/integer/public_key/compact.rs b/tfhe/src/integer/public_key/compact.rs index 5472c68e0d..f498e1d899 100644 --- a/tfhe/src/integer/public_key/compact.rs +++ b/tfhe/src/integer/public_key/compact.rs @@ -168,9 +168,3 @@ impl CompressedCompactPublicKey { } } } - -impl From for CompactPublicKey { - fn from(value: CompressedCompactPublicKey) -> Self { - value.decompress() - } -} diff --git a/tfhe/src/integer/public_key/standard.rs b/tfhe/src/integer/public_key/standard.rs index 3ef1f02dae..6e0c068b0e 100644 --- a/tfhe/src/integer/public_key/standard.rs +++ b/tfhe/src/integer/public_key/standard.rs @@ -99,10 +99,10 @@ impl PublicKey { } } -impl From for PublicKey { - fn from(value: CompressedPublicKey) -> Self { - Self { - key: value.key.into(), +impl CompressedPublicKey { + pub fn decompress(&self) -> PublicKey { + PublicKey { + key: self.key.decompress(), } } } @@ -122,7 +122,7 @@ mod tests { let (cks, sks) = KEY_CACHE.get_from_params(param, IntegerKeyKind::Radix); let compressed_pk = crate::integer::CompressedPublicKey::new(&cks); - let pk = crate::integer::PublicKey::from(compressed_pk); + let pk = compressed_pk.decompress(); let a = pk.encrypt_radix(255u64, 4); let b = pk.encrypt_radix(1u64, 4); diff --git a/tfhe/src/integer/server_key/mod.rs b/tfhe/src/integer/server_key/mod.rs index e773098b68..157e937698 100644 --- a/tfhe/src/integer/server_key/mod.rs +++ b/tfhe/src/integer/server_key/mod.rs @@ -255,12 +255,6 @@ impl CompressedServerKey { } } -impl From for ServerKey { - fn from(compressed: CompressedServerKey) -> Self { - compressed.decompress() - } -} - #[cfg(test)] mod test { use super::*; @@ -283,7 +277,7 @@ mod test { let csks = CompressedServerKey::new_radix_compressed_server_key(&cks); assert_eq!(csks.key.max_degree, expected_radix_max_degree); - let decompressed_sks: ServerKey = csks.into(); + let decompressed_sks: ServerKey = csks.decompress(); assert_eq!(decompressed_sks.key.max_degree, expected_radix_max_degree); } @@ -298,7 +292,7 @@ mod test { let csks = CompressedServerKey::new_crt_compressed_server_key(&cks); assert_eq!(csks.key.max_degree, expected_crt_max_degree); - let decompressed_sks: ServerKey = csks.into(); + let decompressed_sks: ServerKey = csks.decompress(); assert_eq!(decompressed_sks.key.max_degree, expected_crt_max_degree); } @@ -307,7 +301,7 @@ mod test { let client_key = RadixClientKey::new(PARAM_MESSAGE_2_CARRY_2, 14); let compressed_eval_key = CompressedServerKey::new_radix_compressed_server_key(client_key.as_ref()); - let evaluation_key = ServerKey::from(compressed_eval_key); + let evaluation_key = compressed_eval_key.decompress(); let modulus = (client_key.parameters().message_modulus().0 as u128) .pow(client_key.num_blocks() as u32); diff --git a/tfhe/src/js_on_wasm_api/boolean.rs b/tfhe/src/js_on_wasm_api/boolean.rs index bf3e1f4649..3ab3d49d26 100644 --- a/tfhe/src/js_on_wasm_api/boolean.rs +++ b/tfhe/src/js_on_wasm_api/boolean.rs @@ -200,7 +200,7 @@ impl Boolean { compressed_ciphertext: &BooleanCompressedCiphertext, ) -> BooleanCiphertext { set_hook(Box::new(console_error_panic_hook::hook)); - BooleanCiphertext(compressed_ciphertext.0.clone().into()) + BooleanCiphertext(compressed_ciphertext.0.decompress()) } #[wasm_bindgen] diff --git a/tfhe/src/js_on_wasm_api/shortint.rs b/tfhe/src/js_on_wasm_api/shortint.rs index 4f051974e2..89fb69ffe7 100644 --- a/tfhe/src/js_on_wasm_api/shortint.rs +++ b/tfhe/src/js_on_wasm_api/shortint.rs @@ -431,7 +431,7 @@ impl Shortint { compressed_ciphertext: &ShortintCompressedCiphertext, ) -> ShortintCiphertext { set_hook(Box::new(console_error_panic_hook::hook)); - ShortintCiphertext(compressed_ciphertext.0.clone().into()) + ShortintCiphertext(compressed_ciphertext.0.decompress()) } #[wasm_bindgen] diff --git a/tfhe/src/shortint/ciphertext/compressed.rs b/tfhe/src/shortint/ciphertext/compressed.rs index 5f1f2e4a0a..bab0ab8e2a 100644 --- a/tfhe/src/shortint/ciphertext/compressed.rs +++ b/tfhe/src/shortint/ciphertext/compressed.rs @@ -34,7 +34,7 @@ impl ParameterSetConformant for CompressedCiphertext { } impl CompressedCiphertext { - pub fn decompress(self) -> Ciphertext { + pub fn decompress(&self) -> Ciphertext { let Self { ct, degree, @@ -46,11 +46,11 @@ impl CompressedCiphertext { Ciphertext { ct: ct.decompress_into_lwe_ciphertext(), - degree, - message_modulus, - carry_modulus, - pbs_order, - noise_level, + degree: *degree, + message_modulus: *message_modulus, + carry_modulus: *carry_modulus, + pbs_order: *pbs_order, + noise_level: *noise_level, } } @@ -103,9 +103,3 @@ impl CompressedCiphertext { } } } - -impl From for Ciphertext { - fn from(value: CompressedCiphertext) -> Self { - value.decompress() - } -} diff --git a/tfhe/src/shortint/public_key/compact.rs b/tfhe/src/shortint/public_key/compact.rs index e19f8976f0..a4b0bd2270 100644 --- a/tfhe/src/shortint/public_key/compact.rs +++ b/tfhe/src/shortint/public_key/compact.rs @@ -387,9 +387,3 @@ impl CompressedCompactPublicKey { } } } - -impl From for CompactPublicKey { - fn from(value: CompressedCompactPublicKey) -> Self { - value.decompress() - } -} diff --git a/tfhe/src/shortint/public_key/standard.rs b/tfhe/src/shortint/public_key/standard.rs index 786531cfdb..1940072437 100644 --- a/tfhe/src/shortint/public_key/standard.rs +++ b/tfhe/src/shortint/public_key/standard.rs @@ -252,24 +252,26 @@ impl PublicKey { } } -impl From for PublicKey { - fn from(compressed_public_key: CompressedPublicKey) -> Self { - let parameters = compressed_public_key.parameters; +impl CompressedPublicKey { + pub fn decompress(&self) -> PublicKey { + let parameters = self.parameters; #[cfg(any(not(feature = "__wasm_api"), feature = "parallel-wasm-api"))] - let decompressed_public_key = compressed_public_key + let decompressed_public_key = self .lwe_public_key + .as_view() .par_decompress_into_lwe_public_key(); #[cfg(all(feature = "__wasm_api", not(feature = "parallel-wasm-api")))] - let decompressed_public_key = compressed_public_key + let decompressed_public_key = self .lwe_public_key + .as_view() .decompress_into_lwe_public_key(); - Self { + PublicKey { lwe_public_key: decompressed_public_key, parameters, - pbs_order: compressed_public_key.pbs_order, + pbs_order: self.pbs_order, } } } diff --git a/tfhe/src/shortint/server_key/mod.rs b/tfhe/src/shortint/server_key/mod.rs index 1232d7a39d..fb11bc83d8 100644 --- a/tfhe/src/shortint/server_key/mod.rs +++ b/tfhe/src/shortint/server_key/mod.rs @@ -1327,12 +1327,6 @@ impl ServerKey { } } -impl From for ServerKey { - fn from(compressed_server_key: CompressedServerKey) -> Self { - compressed_server_key.decompress() - } -} - #[derive(Copy, Clone)] pub struct CiphertextNoiseDegree { pub noise_level: NoiseLevel,