Skip to content

Commit

Permalink
Corrected the precompute logic to work the same way as it used to wor…
Browse files Browse the repository at this point in the history
…k in palisade
  • Loading branch information
dsuponitskiy-duality committed Aug 25, 2023
1 parent cd0b586 commit 44482bb
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 25 deletions.
17 changes: 11 additions & 6 deletions src/pke/include/scheme/bfvrns/bfvrns-cryptoparameters.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#define LBCRYPTO_CRYPTO_BFVRNS_CRYPTOPARAMETERS_H

#include "schemerns/rns-cryptoparameters.h"
#include "globals.h"

#include <memory>
#include <string>
Expand Down Expand Up @@ -66,12 +67,14 @@ class CryptoParametersBFVRNS : public CryptoParametersRNS {
SecretKeyDist secretKeyDist, int maxRelinSkDeg = 2, KeySwitchTechnique ksTech = BV,
ScalingTechnique scalTech = FIXEDMANUAL, EncryptionTechnique encTech = STANDARD,
MultiplicationTechnique multTech = HPS, ProxyReEncryptionMode PREMode = NOT_SET,
MultipartyMode multipartyMode = FIXED_NOISE_MULTIPARTY, ExecutionMode executionMode = EXEC_EVALUATION,
DecryptionNoiseMode decryptionNoiseMode = FIXED_NOISE_DECRYPT, PlaintextModulus noiseScale = 1,
uint32_t statisticalSecurity = 30, uint32_t numAdversarialQueries = 1, uint32_t thresholdNumOfParties = 1)
MultipartyMode multipartyMode = FIXED_NOISE_MULTIPARTY,
ExecutionMode executionMode = EXEC_EVALUATION,
DecryptionNoiseMode decryptionNoiseMode = FIXED_NOISE_DECRYPT,
PlaintextModulus noiseScale = 1, uint32_t statisticalSecurity = 30,
uint32_t numAdversarialQueries = 1, uint32_t thresholdNumOfParties = 1)
: CryptoParametersRNS(params, encodingParams, distributionParameter, assuranceMeasure, securityLevel, digitSize,
secretKeyDist, maxRelinSkDeg, ksTech, scalTech, encTech, multTech, PREMode,
multipartyMode, executionMode, decryptionNoiseMode, noiseScale, statisticalSecurity,
multipartyMode, executionMode, decryptionNoiseMode, noiseScale, statisticalSecurity,
numAdversarialQueries, thresholdNumOfParties) {}

virtual ~CryptoParametersBFVRNS() {}
Expand Down Expand Up @@ -101,8 +104,10 @@ class CryptoParametersBFVRNS : public CryptoParametersRNS {

ar(cereal::base_class<CryptoParametersRNS>(this));

PrecomputeCRTTables(m_ksTechnique, m_scalTechnique, m_encTechnique, m_multTechnique, m_numPartQ, m_auxBits,
m_extraBits);
if (PrecomputeCRTTablesAfterDeserializaton()) {
PrecomputeCRTTables(m_ksTechnique, m_scalTechnique, m_encTechnique, m_multTechnique, m_numPartQ, m_auxBits,
m_extraBits);
}
}

std::string SerializedObjectName() const override {
Expand Down
7 changes: 5 additions & 2 deletions src/pke/include/scheme/bgvrns/bgvrns-cryptoparameters.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#define LBCRYPTO_CRYPTO_BGVRNS_CRYPTOPARAMETERS_H

#include "schemerns/rns-cryptoparameters.h"
#include "globals.h"

#include <string>
#include <memory>
Expand Down Expand Up @@ -102,8 +103,10 @@ class CryptoParametersBGVRNS : public CryptoParametersRNS {
}
ar(cereal::base_class<CryptoParametersRNS>(this));

PrecomputeCRTTables(m_ksTechnique, m_scalTechnique, m_encTechnique, m_multTechnique, m_numPartQ, m_auxBits,
m_extraBits);
if (PrecomputeCRTTablesAfterDeserializaton()) {
PrecomputeCRTTables(m_ksTechnique, m_scalTechnique, m_encTechnique, m_multTechnique, m_numPartQ, m_auxBits,
m_extraBits);
}
}

std::string SerializedObjectName() const override {
Expand Down
7 changes: 5 additions & 2 deletions src/pke/include/scheme/ckksrns/ckksrns-cryptoparameters.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#define LBCRYPTO_CRYPTO_CKKSRNS_CRYPTOPARAMETERS_H

#include "schemerns/rns-cryptoparameters.h"
#include "globals.h"

#include <memory>
#include <string>
Expand Down Expand Up @@ -108,8 +109,10 @@ class CryptoParametersCKKSRNS : public CryptoParametersRNS {
}
ar(cereal::base_class<CryptoParametersRNS>(this));

PrecomputeCRTTables(m_ksTechnique, m_scalTechnique, m_encTechnique, m_multTechnique, m_numPartQ, m_auxBits,
m_extraBits);
if (PrecomputeCRTTablesAfterDeserializaton()) {
PrecomputeCRTTables(m_ksTechnique, m_scalTechnique, m_encTechnique, m_multTechnique, m_numPartQ, m_auxBits,
m_extraBits);
}
}

std::string SerializedObjectName() const override {
Expand Down
5 changes: 0 additions & 5 deletions src/pke/lib/scheme/bfvrns/bfvrns-cryptoparameters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ BFV implementation. See https://eprint.iacr.org/2021/204 for details.

#include "cryptocontext.h"
#include "scheme/bfvrns/bfvrns-cryptoparameters.h"
#include "globals.h"

namespace lbcrypto {

Expand All @@ -46,10 +45,6 @@ namespace lbcrypto {
void CryptoParametersBFVRNS::PrecomputeCRTTables(KeySwitchTechnique ksTech, ScalingTechnique scalTech,
EncryptionTechnique encTech, MultiplicationTechnique multTech,
uint32_t numPartQ, uint32_t auxBits, uint32_t extraBits) {
// Don't run the function if it is not required
if (!PrecomputeCRTTablesAfterDeserializaton())
return;

CryptoParametersRNS::PrecomputeCRTTables(ksTech, scalTech, encTech, multTech, numPartQ, auxBits, extraBits);

size_t sizeQ = GetElementParams()->GetParams().size();
Expand Down
5 changes: 0 additions & 5 deletions src/pke/lib/scheme/bgvrns/bgvrns-cryptoparameters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ BGV implementation. See https://eprint.iacr.org/2021/204 for details.

#include "cryptocontext.h"
#include "scheme/bgvrns/bgvrns-cryptoparameters.h"
#include "globals.h"

namespace lbcrypto {

Expand All @@ -46,10 +45,6 @@ namespace lbcrypto {
void CryptoParametersBGVRNS::PrecomputeCRTTables(KeySwitchTechnique ksTech, ScalingTechnique scalTech,
EncryptionTechnique encTech, MultiplicationTechnique multTech,
uint32_t numPartQ, uint32_t auxBits, uint32_t extraBits) {
// Don't run the function if it is not required
if (!PrecomputeCRTTablesAfterDeserializaton())
return;

CryptoParametersRNS::PrecomputeCRTTables(ksTech, scalTech, encTech, multTech, numPartQ, auxBits, extraBits);

size_t sizeQ = GetElementParams()->GetParams().size();
Expand Down
5 changes: 0 additions & 5 deletions src/pke/lib/scheme/ckksrns/ckksrns-cryptoparameters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ CKKS implementation. See https://eprint.iacr.org/2020/1118 for details.

#include "cryptocontext.h"
#include "scheme/ckksrns/ckksrns-cryptoparameters.h"
#include "globals.h"

namespace lbcrypto {

Expand All @@ -46,10 +45,6 @@ namespace lbcrypto {
void CryptoParametersCKKSRNS::PrecomputeCRTTables(KeySwitchTechnique ksTech, ScalingTechnique scalTech,
EncryptionTechnique encTech, MultiplicationTechnique multTech,
uint32_t numPartQ, uint32_t auxBits, uint32_t extraBits) {
// Don't run the function if it is not required
if (!PrecomputeCRTTablesAfterDeserializaton())
return;

CryptoParametersRNS::PrecomputeCRTTables(ksTech, scalTech, encTech, multTech, numPartQ, auxBits, extraBits);

size_t sizeQ = GetElementParams()->GetParams().size();
Expand Down
3 changes: 3 additions & 0 deletions src/pke/lib/schemebase/base-pke.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ KeyPair<Element> PKEBase<Element>::KeyGenInternal(CryptoContext<Element> cc, boo

const std::shared_ptr<ParmType> elementParams = cryptoParams->GetElementParams();
const std::shared_ptr<ParmType> paramsPK = cryptoParams->GetParamsPK();
if (!paramsPK) {
OPENFHE_THROW(config_error, "PrecomputeCRTTables() must be called before using precomputed params.");
}

const auto ns = cryptoParams->GetNoiseScale();
const DggType& dgg = cryptoParams->GetDiscreteGaussianGenerator();
Expand Down

0 comments on commit 44482bb

Please sign in to comment.