From f69c8dfaba9b8b304e648ddce021cc3c35fcda22 Mon Sep 17 00:00:00 2001 From: Quentin Bourgerie Date: Thu, 18 Aug 2022 14:14:32 +0200 Subject: [PATCH] fix: Fix decoding of encrypted integer above 30 bits --- compiler/lib/ClientLib/KeySet.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/compiler/lib/ClientLib/KeySet.cpp b/compiler/lib/ClientLib/KeySet.cpp index e4e19af3b..412de824f 100644 --- a/compiler/lib/ClientLib/KeySet.cpp +++ b/compiler/lib/ClientLib/KeySet.cpp @@ -280,10 +280,12 @@ KeySet::decrypt_lwe(size_t argPos, uint64_t *ciphertext, uint64_t &output) { // Simple TFHE integers - 1 blocks with one padding bits uint64_t plaintext = ::decrypt_lwe_u64(engine, lweSecretKey, ciphertext); // Decode - size_t precision = encryption->encoding.precision; + uint64_t precision = encryption->encoding.precision; output = plaintext >> (64 - precision - 2); - size_t carry = output % 2; - output = ((output >> 1) + carry) % (1 << (precision + 1)); + auto carry = output % 2; + uint64_t mod = (((uint64_t)1) << (precision + 1)); + output = ((output >> 1) + carry) % mod; + return outcome::success(); }