Skip to content

Commit

Permalink
modified the EncryptZero fuction
Browse files Browse the repository at this point in the history
  • Loading branch information
baluluyakalulu committed Jul 26, 2023
1 parent ac1133f commit 59930c2
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 16 deletions.
10 changes: 1 addition & 9 deletions heu/library/algorithms/leichi_paillier/ciphertext.h
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions heu/library/algorithms/leichi_paillier/vector_encryptor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ namespace heu::lib::algorithms::leichi_paillier {
pt_neg_zero.Set(0);

std::vector<uint8_t> m_flg;
for (int64_t i = 0;i<size;i++)
{
m_flg.push_back(0);
}
for (int64_t i = 0;i<size;i++) {
BN_bn2binpad(Plaintext::generateRandom(pk_.n_).bn_,r_bytes+r_offset,BYTECOUNT(pk_.n_.numBits()));
r_offset += BYTECOUNT(pk_.n_.numBits());
Expand Down
17 changes: 10 additions & 7 deletions heu/library/benchmark/phe_bench.cc
Original file line number Diff line number Diff line change
Expand Up @@ -82,19 +82,21 @@ class PheBenchmarks {
void AddCipher(benchmark::State& state) {
// add (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->AddInplace(&cts_[0], cts_[i]);
for (int i = 0; i < kTestSize; ++i) {
evaluator->AddInplace(&ct, cts_[i]);
}
}
}

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]);
}
}
}
Expand All @@ -104,7 +106,7 @@ class PheBenchmarks {
const auto& evaluator = he_kit_->GetEvaluator();
auto edr = he_kit_->GetEncoder<phe::PlainEncoder>(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));
}
}
Expand All @@ -115,7 +117,7 @@ class PheBenchmarks {
const auto& evaluator = he_kit_->GetEvaluator();
auto edr = he_kit_->GetEncoder<phe::PlainEncoder>(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));
}
}
Expand All @@ -125,9 +127,10 @@ class PheBenchmarks {
// mul (ciphertext * plaintext)
const auto& evaluator = he_kit_->GetEvaluator();
auto edr = he_kit_->GetEncoder<phe::PlainEncoder>(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));
}
}
}
Expand Down

0 comments on commit 59930c2

Please sign in to comment.