Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed a bug with parameter selection #893

Merged
merged 2 commits into from
Oct 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/pke/lib/scheme/bgvrns/bgvrns-parametergeneration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,9 @@ bool ParameterGenerationBGVRNS::ParamsGenBGVRNS(std::shared_ptr<CryptoParameters
qBound += cryptoParamsBGVRNS->EstimateMultipartyFloodingLogQ();

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

uint32_t auxTowers = 0;
if (ksTech == HYBRID) {
Expand Down Expand Up @@ -482,7 +484,7 @@ bool ParameterGenerationBGVRNS::ParamsGenBGVRNS(std::shared_ptr<CryptoParameters
numPartQ, std::log2(moduliQ[0].ConvertToDouble()),
(moduliQ.size() > 1) ? std::log2(moduliQ[1].ConvertToDouble()) : 0,
(scalTech == FLEXIBLEAUTOEXT) ? std::log2(moduliQ[moduliQ.size() - 1].ConvertToDouble()) : 0,
(scalTech == FLEXIBLEAUTOEXT) ? moduliQ.size() - 1 : moduliQ.size(), auxBits, true);
(scalTech == FLEXIBLEAUTOEXT) ? moduliQ.size() - 1 : moduliQ.size(), auxBits, false);
newQBound += std::get<0>(hybridKSInfo);
}
} while (qBound < newQBound);
Expand Down
4 changes: 3 additions & 1 deletion src/pke/lib/scheme/ckksrns/ckksrns-parametergeneration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,9 @@ bool ParameterGenerationCKKSRNS::ParamsGenCKKSRNS(std::shared_ptr<CryptoParamete
uint32_t qBound = firstModSize + (numPrimes - 1) * scalingModSize + extraModSize;

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

// Estimate ciphertext modulus Q*P bound (in case of HYBRID P*Q)
if (ksTech == HYBRID) {
Expand Down
11 changes: 6 additions & 5 deletions src/pke/lib/schemerns/rns-cryptoparameters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -415,23 +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 for the special moduli selection logic in BGV and CKKS
if (addOne)
// 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 != 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
Loading