diff --git a/heu/library/algorithms/leichi_paillier/ciphertext.h b/heu/library/algorithms/leichi_paillier/ciphertext.h index 3044665a..01044f90 100644 --- a/heu/library/algorithms/leichi_paillier/ciphertext.h +++ b/heu/library/algorithms/leichi_paillier/ciphertext.h @@ -24,22 +24,15 @@ namespace heu::lib::algorithms::leichi_paillier { public: BIGNUM* bn_; public: - // Ciphertext() = default; Ciphertext() { bn_ = BN_new(); } ~Ciphertext(){ BN_free(bn_); - } //BN_free(bn_); - - // Ciphertext(BIGNUM* res) {bn_ = res;} - // Ciphertext(const Ciphertext& other){ - // bn_ = other.bn_; - // } + } Ciphertext(const Ciphertext& other) { bn_ = BN_dup(other.bn_); - // BN_copy(bn_, other.bn_); } Ciphertext& operator=(const Ciphertext& other) { @@ -49,7 +42,6 @@ namespace heu::lib::algorithms::leichi_paillier { return *this; } - // explicit Ciphertext(BIGNUM *bn) : bn_(bn){}; explicit Ciphertext(BIGNUM *bn){ bn_ = bn;}//BN_dup(bn);} std::string ToString() const; diff --git a/heu/library/algorithms/leichi_paillier/vector_encryptor.cc b/heu/library/algorithms/leichi_paillier/vector_encryptor.cc index 86bf130f..75656a11 100644 --- a/heu/library/algorithms/leichi_paillier/vector_encryptor.cc +++ b/heu/library/algorithms/leichi_paillier/vector_encryptor.cc @@ -22,6 +22,10 @@ namespace heu::lib::algorithms::leichi_paillier { pt_neg_zero.Set(0); std::vector m_flg; + for (int64_t i = 0;iGetEvaluator(); + auto ct = he_kit_->GetEncryptor()->EncryptZero(); for (auto _ : state) { - for (int i = 1; i < kTestSize; ++i) { - evaluator->AddInplace(&cts_[0], cts_[i]); + for (int i = 0; i < kTestSize; ++i) { + evaluator->AddInplace(&ct, cts_[i]); } } } @@ -92,9 +93,10 @@ class PheBenchmarks { void SubCipher(benchmark::State& state) { // sub (ciphertext - ciphertext) const auto& evaluator = he_kit_->GetEvaluator(); + auto ct = he_kit_->GetEncryptor()->EncryptZero(); for (auto _ : state) { - for (int i = 1; i < kTestSize; ++i) { - evaluator->SubInplace(&cts_[0], cts_[i]); + for (int i = 0; i < kTestSize; ++i) { + evaluator->SubInplace(&ct, cts_[i]); } } } @@ -104,7 +106,7 @@ class PheBenchmarks { const auto& evaluator = he_kit_->GetEvaluator(); auto edr = he_kit_->GetEncoder(1); for (auto _ : state) { - for (int i = 1; i < kTestSize; ++i) { + for (int i = 0; i < kTestSize; ++i) { evaluator->AddInplace(&cts_[i], edr.Encode(i)); } } @@ -115,7 +117,7 @@ class PheBenchmarks { const auto& evaluator = he_kit_->GetEvaluator(); auto edr = he_kit_->GetEncoder(1); for (auto _ : state) { - for (int i = 1; i < kTestSize; ++i) { + for (int i = 0; i < kTestSize; ++i) { evaluator->SubInplace(&cts_[i], edr.Encode(i)); } } @@ -125,9 +127,10 @@ class PheBenchmarks { // mul (ciphertext * plaintext) const auto& evaluator = he_kit_->GetEvaluator(); auto edr = he_kit_->GetEncoder(1); + auto ct = he_kit_->GetEncryptor()->Encrypt(edr.Encode(1)); for (auto _ : state) { for (int i = 1; i < kTestSize; ++i) { - evaluator->MulInplace(&cts_[i], edr.Encode(i)); + evaluator->MulInplace(&ct, edr.Encode(i)); } } }