Skip to content

Commit

Permalink
Addressed review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
dsuponitskiy-duality committed Oct 28, 2024
1 parent fe4680e commit 6ae3aca
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/pke/lib/scheme/bgvrns/bgvrns-parametergeneration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ bool ParameterGenerationBGVRNS::ParamsGenBGVRNS(std::shared_ptr<CryptoParameters

// we add an extra bit to account for the special logic of selecting the RNS moduli in BGV
// ignore the case when there is only one max size modulus
if (qBound != static_cast<double>(auxBits))
if (qBound != auxBits)
qBound++;

uint32_t auxTowers = 0;
Expand Down
2 changes: 1 addition & 1 deletion src/pke/lib/scheme/ckksrns/ckksrns-parametergeneration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ bool ParameterGenerationCKKSRNS::ParamsGenCKKSRNS(std::shared_ptr<CryptoParamete

// we add an extra bit to account for the alternating logic of selecting the RNS moduli in CKKS
// ignore the case when there is only one max size modulus
if (qBound != static_cast<double>(auxBits))
if (qBound != auxBits)
qBound++;

// Estimate ciphertext modulus Q*P bound (in case of HYBRID P*Q)
Expand Down
8 changes: 4 additions & 4 deletions src/pke/lib/schemerns/rns-cryptoparameters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -415,24 +415,24 @@ std::pair<double, uint32_t> CryptoParametersRNS::EstimateLogP(uint32_t numPartQ,
qi[sizeQ - 1] = extraModulusSize;

// Compute partitions of Q into numPartQ digits
double maxBits = 0;
uint32_t maxBits = 0;
for (size_t j = 0; j < numPartQ; ++j) {
size_t startTower = j * numPerPartQ;
size_t endTower = ((j + 1) * numPerPartQ - 1 < sizeQ) ? (j + 1) * numPerPartQ - 1 : sizeQ - 1;

// sum qi elements qi[startTower] + ... + qi[endTower] inclusive. the end element should be qi.begin()+(endTower+1)
double bits = std::accumulate(qi.begin() + startTower, qi.begin() + (endTower + 1), 0.0);
uint32_t bits = static_cast<uint32_t>(std::accumulate(qi.begin() + startTower, qi.begin() + (endTower + 1), 0.0));
if (bits > maxBits)
maxBits = bits;
}

// we add an extra bit to account for the special moduli selection logic in BGV and CKKS
// ignore the case when there is only one max size modulus
if ((addOne) && (maxBits != static_cast<double>(auxBits)))
if (addOne && (maxBits != auxBits))
maxBits++;

// Select number of primes in auxiliary CRT basis
auto sizeP = static_cast<uint32_t>(std::ceil(maxBits / auxBits));
auto sizeP = static_cast<uint32_t>(std::ceil(static_cast<double>(maxBits) / auxBits));

return std::make_pair(sizeP * auxBits, sizeP);
}
Expand Down

0 comments on commit 6ae3aca

Please sign in to comment.