Skip to content

Commit

Permalink
fixed a bug in BGV parameter estimation logic
Browse files Browse the repository at this point in the history
  • Loading branch information
Yuriy Polyakov committed Jun 11, 2024
1 parent cb714a0 commit 0cd4df6
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/pke/lib/scheme/bgvrns/bgvrns-parametergeneration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -455,12 +455,15 @@ bool ParameterGenerationBGVRNS::ParamsGenBGVRNS(std::shared_ptr<CryptoParameters
auxTowers = std::get<1>(hybridKSInfo);
}

// when the scaling technique is not FIXED_MANUAL, set a small value so that the rest of the logic could go through
// when the scaling technique is not FIXEDMANUAL (and not FLEXIBLEAUTOEXT),
// set a small value so that the rest of the logic could go through (this is a workaround)
// TODO we should uncouple the logic of FIXEDMANUAL and all FLEXIBLE MODES; some of the code above should be moved
// to the branch for FIXEDMANUAL
if (qBound == 0)
qBound = 20;

// HE Standards compliance logic/check
uint32_t n = computeRingDimension(cryptoParams, qBound, cyclOrder);
// End HE Standards compliance logic/check

uint32_t vecSize = (scalTech != FLEXIBLEAUTOEXT) ? numPrimes : numPrimes + 1;
std::vector<NativeInteger> moduliQ(vecSize);
Expand All @@ -471,7 +474,10 @@ bool ParameterGenerationBGVRNS::ParamsGenBGVRNS(std::shared_ptr<CryptoParameters
auto moduliInfo = computeModuli(cryptoParams, n, evalAddCount, keySwitchCount, auxTowers, numPrimes);
moduliQ = std::get<0>(moduliInfo);
uint32_t newQBound = std::get<1>(moduliInfo);
while (qBound < newQBound) {

// the counter makes sure the first iteration of the while loop is always run
uint32_t counter = 0;
while ((counter == 0) || (qBound < newQBound)) {
qBound = newQBound;
n = computeRingDimension(cryptoParams, newQBound, cyclOrder);
auto moduliInfo = computeModuli(cryptoParams, n, evalAddCount, keySwitchCount, auxTowers, numPrimes);
Expand All @@ -487,6 +493,7 @@ bool ParameterGenerationBGVRNS::ParamsGenBGVRNS(std::shared_ptr<CryptoParameters
(scalTech == FLEXIBLEAUTOEXT) ? moduliQ.size() - 1 : moduliQ.size(), auxBits);
newQBound += std::get<0>(hybridKSInfo);
}
counter++;
}
cyclOrder = 2 * n;
modulusOrder = getCyclicOrder(n, ptm, scalTech);
Expand All @@ -496,6 +503,7 @@ bool ParameterGenerationBGVRNS::ParamsGenBGVRNS(std::shared_ptr<CryptoParameters
}
}
else {
// FIXEDMANUAL mode
cyclOrder = 2 * n;
// For ModulusSwitching to work we need the moduli to be also congruent to 1 modulo ptm
usint plaintextModulus = ptm;
Expand Down

0 comments on commit 0cd4df6

Please sign in to comment.