diff --git a/sunscreen_tfhe/src/ops/encryption/lwe_encryption.rs b/sunscreen_tfhe/src/ops/encryption/lwe_encryption.rs index 5c1829c5d..7e9bda3e0 100644 --- a/sunscreen_tfhe/src/ops/encryption/lwe_encryption.rs +++ b/sunscreen_tfhe/src/ops/encryption/lwe_encryption.rs @@ -44,6 +44,7 @@ where params.assert_valid(); let (a, b) = ct.a_b_mut(params); + *b = Torus::zero(); for (a_i, d_i) in a.iter_mut().zip(sk.as_slice().iter()) { *a_i = uniform_torus::(); @@ -76,7 +77,7 @@ where #[cfg(test)] mod tests { - use crate::{high_level::*, PlaintextBits}; + use crate::{high_level::*, ops::encryption::encode_and_encrypt_lwe_ciphertext, PlaintextBits}; #[test] fn can_encrypt_decrypt() { @@ -91,6 +92,26 @@ mod tests { assert_eq!(pt, 4); } + #[test] + fn can_reuse_lwe_ciphertext() { + let params = TEST_LWE_DEF_1; + let bits = PlaintextBits(4); + + let sk = keygen::generate_binary_lwe_sk(¶ms); + + for _ in 0..10 { + let mut ct = encryption::encrypt_lwe_secret(4, &sk, ¶ms, bits); + let pt = encryption::decrypt_lwe(&ct, &sk, ¶ms, bits); + + assert_eq!(pt, 4); + + encode_and_encrypt_lwe_ciphertext(&mut ct, &sk, 3, ¶ms, bits); + + assert_eq!(encryption::decrypt_lwe(&ct, &sk, ¶ms, bits), 3); + + } + } + #[test] fn can_encrypt_decrypt_uniform() { let params = TEST_LWE_DEF_1;