Skip to content

Commit

Permalink
Update public_key.cc
Browse files Browse the repository at this point in the history
  • Loading branch information
shaojian-ant authored Oct 14, 2024
1 parent f0e5106 commit f260897
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions heu/library/algorithms/paillier_zahlen/public_key.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,25 @@
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#include "heu/library/algorithms/paillier_zahlen/public_key.h"

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

namespace {
size_t kExpUnitBits = 10;
} // namespace

void SetCacheTableDensity(size_t density) {
YACL_ENFORCE(density > 0, "density must > 0");
kExpUnitBits = density;
}

void PublicKey::Init() {
n_square_ = n_ * n_;
n_half_ = n_ / MPInt::_2_;
key_size_ = n_.BitCount();

m_space_ = std::make_shared<MontgomerySpace>(n_square_);
hs_table_ = std::make_shared<BaseTable>();
m_space_->MakeBaseTable(
Expand All @@ -32,10 +38,12 @@ void PublicKey::Init() {
(key_size_ / 2 + MP_DIGIT_BIT - 1) / MP_DIGIT_BIT * MP_DIGIT_BIT,
hs_table_.get());
}

std::string PublicKey::ToString() const {
return fmt::format(
"Z-paillier PK: n={}[{}bits], h_s={}, max_plaintext={}[~{}bits]",
n_.ToHexString(), n_.BitCount(), h_s_.ToHexString(),
PlaintextBound().ToHexString(), PlaintextBound().BitCount());
}

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

0 comments on commit f260897

Please sign in to comment.