From fef389e002004872d60e433bfbb38e2dfef15864 Mon Sep 17 00:00:00 2001 From: Arthur Meyre Date: Wed, 12 Apr 2023 15:05:55 +0200 Subject: [PATCH] chore(core): more reasonable LWE sub test - otherwise we are just checking that x.wrapping_sub(x) == 0 --- .../algorithms/test/lwe_linear_algebra.rs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/tfhe/src/core_crypto/algorithms/test/lwe_linear_algebra.rs b/tfhe/src/core_crypto/algorithms/test/lwe_linear_algebra.rs index 804536b10..0554593db 100644 --- a/tfhe/src/core_crypto/algorithms/test/lwe_linear_algebra.rs +++ b/tfhe/src/core_crypto/algorithms/test/lwe_linear_algebra.rs @@ -447,10 +447,13 @@ fn lwe_encrypt_sub_assign_decrypt_custom_mod(params: Test ciphertext_modulus, ); + let rhs_plaintext = + Plaintext(msg.wrapping_sub(Scalar::ONE).wrapping_rem(msg_modulus) * delta); + encrypt_lwe_ciphertext( &lwe_sk, &mut rhs, - plaintext, + rhs_plaintext, lwe_modular_std_dev, &mut rsc.encryption_random_generator, ); @@ -465,7 +468,7 @@ fn lwe_encrypt_sub_assign_decrypt_custom_mod(params: Test let decoded = round_decode(decrypted.0, delta) % msg_modulus; - assert_eq!(Scalar::ZERO, decoded); + assert_eq!(Scalar::ONE, decoded); } } } @@ -518,10 +521,13 @@ fn lwe_encrypt_sub_decrypt_custom_mod(params: TestParams< ciphertext_modulus, ); + let rhs_plaintext = + Plaintext(msg.wrapping_sub(Scalar::ONE).wrapping_rem(msg_modulus) * delta); + encrypt_lwe_ciphertext( &lwe_sk, &mut rhs, - plaintext, + rhs_plaintext, lwe_modular_std_dev, &mut rsc.encryption_random_generator, ); @@ -538,7 +544,7 @@ fn lwe_encrypt_sub_decrypt_custom_mod(params: TestParams< let decoded = round_decode(decrypted.0, delta) % msg_modulus; - assert_eq!(Scalar::ZERO, decoded); + assert_eq!(Scalar::ONE, decoded); } } }