Skip to content

Commit

Permalink
Update secret_key.cc
Browse files Browse the repository at this point in the history
  • Loading branch information
shaojian-ant authored Oct 14, 2024
1 parent 954d50b commit be751d3
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions heu/library/algorithms/paillier_zahlen/secret_key.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,20 @@
#include "heu/library/algorithms/paillier_zahlen/secret_key.h"

namespace heu::lib::algorithms::paillier_z {

void SecretKey::Init() {
p_square_ = p_ * p_; // p^2
q_square_ = q_ * q_; // q^2
p_square_ = p_ * p_; // p^2
q_square_ = q_ * q_; // q^2
n_square_ = p_square_ * q_square_;
MPInt q_square_inv;
MPInt::InvertMod(q_square_, p_square_, &q_square_inv);
q_square_inv_mul_q_square_ =
q_square_inv * q_square_; // [(q^2)^{-1} mod p^2] * q^2
q_square_inv * q_square_; // [(q^2)^{-1} mod p^2] * q^2
MPInt::InvertMod(p_, q_, &p_inv_mod_q_); // p^{-1} mod q
phi_p_square_ = p_ * (p_ - MPInt::_1_); // p(p-1)
phi_q_square_ = q_ * (q_ - MPInt::_1_); // q(q-1)
phi_p_ = p_ - 1_mp; // p-1
phi_q_ = q_ - 1_mp; // q-1
phi_p_square_ = p_ * (p_ - MPInt::_1_); // p(p-1)
phi_q_square_ = q_ * (q_ - MPInt::_1_); // q(q-1)
phi_p_ = p_ - 1_mp; // p-1
phi_q_ = q_ - 1_mp; // q-1

// Precompute hp
MPInt n = p_ * q_;
Expand Down Expand Up @@ -65,9 +66,8 @@ MPInt SecretKey::PowModNSquareCrt(const MPInt &base, const MPInt &exp) const {

std::string SecretKey::ToString() const {
return fmt::format("Z-paillier SK: p={}[{}bits], q={}[{}bits]",
p_.ToHexString(),
p_.BitCount(),
q_.ToHexString(),
p_.ToHexString(), p_.BitCount(), q_.ToHexString(),
q_.BitCount());
}
} // namespace heu::lib::algorithms::paillier_z

} // namespace heu::lib::algorithms::paillier_z

0 comments on commit be751d3

Please sign in to comment.