fix: divide and round to decode decrypted ct

Doing a right shift will ommit the bits that can be used to round to the
nearest integer
This commit is contained in:
youben11
2021-09-07 10:51:49 +01:00
committed by Quentin Bourgerie
parent 272a725e9a
commit 3893ad39bb
3 changed files with 129 additions and 107 deletions

View File

@@ -267,8 +267,10 @@ llvm::Error KeySet::decrypt_lwe(size_t argPos, LweCiphertext_u64 *ciphertext,
decrypt_lwe_u64(&err, std::get<2>(outputSk), ciphertext, &plaintext),
"cannot decrypt");
// Decode
output = plaintext._0 >>
(64 - (std::get<0>(outputSk).encryption->encoding.precision + 1));
double divisor = std::pow(
2, 64 - (std::get<0>(outputSk).encryption->encoding.precision + 1));
output = std::round(((double)plaintext._0) / divisor);
output %= (1 << (std::get<0>(outputSk).encryption->encoding.precision + 1));
return llvm::Error::success();
}