From 8134254628ef40c163285b1d891fc636ce7b4eb2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pierre-Elis=C3=A9e=20Flory?= Date: Wed, 20 Jul 2022 15:35:55 +0200 Subject: [PATCH] Prevent panicking each time the computed sum is zero --- protocol/src/pjc/partner.rs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/protocol/src/pjc/partner.rs b/protocol/src/pjc/partner.rs index 49e2c3f..29b1a0e 100644 --- a/protocol/src/pjc/partner.rs +++ b/protocol/src/pjc/partner.rs @@ -8,6 +8,7 @@ use common::timer; use num_bigint::BigUint; use num_traits::One; +use num_traits::Zero; use std::path::Path; use std::sync::Arc; @@ -173,9 +174,13 @@ impl PartnerPJCProtocol for PartnerPjc { assert_eq!(encrypted_sum.len(), 1); let z = ((self.he_cipher.decrypt_vec(encrypted_sum))[0]).clone(); let sum = { - let v = (z % &max_val).to_u64_digits(); - assert_eq!(v.len(), 1); - v[0] + if z.is_zero() { + 0 + } else { + let v = (z % &max_val).to_u64_digits(); + assert_eq!(v.len(), 1); + v[0] + } }; info!("Feature: {}, Sum {}", feature_index, sum);