diff --git a/src/binfhe/include/rgsw-acc.h b/src/binfhe/include/rgsw-acc.h index 1f9d8ec81..742675e39 100644 --- a/src/binfhe/include/rgsw-acc.h +++ b/src/binfhe/include/rgsw-acc.h @@ -59,7 +59,7 @@ class RingGSWAccumulator { */ virtual RingGSWACCKey KeyGenAcc(const std::shared_ptr& params, const NativePoly& skNTT, ConstLWEPrivateKey& LWEsk) const { - OPENFHE_THROW("KeyGenACC operation not supported"); + OPENFHE_THROW("Operation not supported"); } /** @@ -72,7 +72,7 @@ class RingGSWAccumulator { */ virtual void EvalAcc(const std::shared_ptr& params, ConstRingGSWACCKey& ek, RLWECiphertext& acc, const NativeVector& a) const { - OPENFHE_THROW("ACC operation not supported"); + OPENFHE_THROW("Operation not supported"); } /** diff --git a/src/binfhe/lib/binfhe-base-scheme.cpp b/src/binfhe/lib/binfhe-base-scheme.cpp index 706e901cd..912ad33c1 100644 --- a/src/binfhe/lib/binfhe-base-scheme.cpp +++ b/src/binfhe/lib/binfhe-base-scheme.cpp @@ -262,9 +262,7 @@ LWECiphertext BinFHEScheme::EvalFunc(const std::shared_ptr& const auto& LWEParams = params->GetLWEParams(); uint32_t N{LWEParams->GetN()}; if (q.ConvertToInt() > N) { // need q to be at most = N for arbitary function - std::string errMsg = - "ERROR: ciphertext modulus q needs to be <= ring dimension for arbitrary function evaluation"; - OPENFHE_THROW(errMsg); + OPENFHE_THROW("Ciphertext modulus q needs to be <= ring dimension for arbitrary function evaluation"); } // TODO: figure out a way to not do this :( @@ -390,7 +388,7 @@ LWECiphertext BinFHEScheme::EvalSign(const std::shared_ptr& auto q{LWEParams->Getq()}; if (mod <= q) { std::string errMsg = - "ERROR: EvalSign is only for large precision. For small precision, please use bootstrapping directly"; + "This function is only for large precision. For small precision, please use bootstrapping directly"; OPENFHE_THROW(errMsg); } @@ -398,8 +396,7 @@ LWECiphertext BinFHEScheme::EvalSign(const std::shared_ptr& const auto curBase = RGSWParams->GetBaseG(); auto search = EKs.find(curBase); if (search == EKs.end()) { - std::string errMsg("ERROR: No key [" + std::to_string(curBase) + "] found in the map"); - OPENFHE_THROW(errMsg); + OPENFHE_THROW("No key [" + std::to_string(curBase) + "] found in the map"); } RingGSWBTKey curEK(search->second); @@ -426,8 +423,7 @@ LWECiphertext BinFHEScheme::EvalSign(const std::shared_ptr& auto search = EKs.find(base); if (search == EKs.end()) { - std::string errMsg("ERROR: No key [" + std::to_string(curBase) + "] found in the map"); - OPENFHE_THROW(errMsg); + OPENFHE_THROW("No key [" + std::to_string(curBase) + "] found in the map"); } curEK = search->second; } @@ -470,15 +466,14 @@ std::vector BinFHEScheme::EvalDecomp(const std::shared_ptrGetq(); if (mod <= q) { std::string errMsg = - "ERROR: EvalDecomp is only for large precision. For small precision, please use bootstrapping directly"; + "This function is only for large precision. For small precision, please use bootstrapping directly"; OPENFHE_THROW(errMsg); } const auto curBase = RGSWParams->GetBaseG(); auto search = EKs.find(curBase); if (search == EKs.end()) { - std::string errMsg("ERROR: No key [" + std::to_string(curBase) + "] found in the map"); - OPENFHE_THROW(errMsg); + OPENFHE_THROW("No key [" + std::to_string(curBase) + "] found in the map"); } RingGSWBTKey curEK(search->second); @@ -508,8 +503,7 @@ std::vector BinFHEScheme::EvalDecomp(const std::shared_ptrsecond; } diff --git a/src/binfhe/lib/lwe-pke.cpp b/src/binfhe/lib/lwe-pke.cpp index cf356d298..746c11fa2 100644 --- a/src/binfhe/lib/lwe-pke.cpp +++ b/src/binfhe/lib/lwe-pke.cpp @@ -103,8 +103,7 @@ LWEPublicKey LWEEncryptionScheme::PubKeyGen(const std::shared_ptr& params, ConstLWEPrivateKey& sk, LWEPlaintext m, LWEPlaintextModulus p, NativeInteger mod) const { if (mod % p != 0 && mod.ConvertToInt() & (1 == 0)) { - std::string errMsg = "ERROR: ciphertext modulus q needs to be divisible by plaintext modulus p."; - OPENFHE_THROW(errMsg); + OPENFHE_THROW("Ciphertext modulus q needs to be divisible by plaintext modulus p."); } NativeVector s = sk->GetElement(); @@ -133,8 +132,7 @@ LWECiphertext LWEEncryptionScheme::Encrypt(const std::shared_ptr& params, ConstLWEPublicKey& pk, LWEPlaintext m, LWEPlaintextModulus p, NativeInteger mod) const { if (mod % p != 0 && mod.ConvertToInt() & (1 == 0)) { - std::string errMsg = "ERROR: ciphertext modulus q needs to be divisible by plaintext modulus p."; - OPENFHE_THROW(errMsg); + OPENFHE_THROW("Ciphertext modulus q needs to be divisible by plaintext modulus p."); } auto bp = pk->Getv(); @@ -187,8 +185,7 @@ void LWEEncryptionScheme::Decrypt(const std::shared_ptr& params // Create local variables to speed up the computations const auto& mod = ct->GetModulus(); if (mod % (p * 2) != 0 && mod.ConvertToInt() & (1 == 0)) { - std::string errMsg = "ERROR: ciphertext modulus q needs to be divisible by plaintext modulus p*2."; - OPENFHE_THROW(errMsg); + OPENFHE_THROW("Ciphertext modulus q needs to be divisible by plaintext modulus p*2."); } const auto& a = ct->GetA(); diff --git a/src/core/include/lattice/field2n-impl.h b/src/core/include/lattice/field2n-impl.h index 64ef76843..4212ffa4e 100644 --- a/src/core/include/lattice/field2n-impl.h +++ b/src/core/include/lattice/field2n-impl.h @@ -145,9 +145,7 @@ Field2n Field2n::Plus(const Field2n& rhs) const { // Scalar addition operation for field elements Field2n Field2n::Plus(double scalar) const { if (format != Format::COEFFICIENT) - OPENFHE_THROW( - "Field2n scalar addition is currently supported only for " - "Format::COEFFICIENT representation"); + OPENFHE_THROW("Field2n scalar addition is currently supported only for Format::COEFFICIENT representation"); Field2n sum(*this); sum.at(0) += scalar; return sum; @@ -166,9 +164,7 @@ Field2n Field2n::Minus(const Field2n& rhs) const { // Multiplication operation for field elements Field2n Field2n::Times(const Field2n& rhs) const { if (format != Format::EVALUATION && rhs.GetFormat() != Format::EVALUATION) - OPENFHE_THROW( - "At least one of the polynomials is not in " - "Format::EVALUATION representation"); + OPENFHE_THROW("At least one of the polynomials is not in Format::EVALUATION representation"); Field2n result(*this); for (size_t i = 0; i < rhs.size(); ++i) result[i] *= rhs[i]; @@ -191,9 +187,7 @@ Field2n Field2n::ShiftRight() { // Performs an automorphism transform operation and returns the result. Field2n Field2n::AutomorphismTransform(size_t i) const { if (format != Format::EVALUATION) - OPENFHE_THROW( - "Field2n Automorphism is only implemented for " - "Format::EVALUATION format"); + OPENFHE_THROW("Field2n Automorphism is only implemented for Format::EVALUATION format"); if (i % 2 == 0) OPENFHE_THROW("automorphism index should be odd\n"); Field2n result(*this); diff --git a/src/core/include/lattice/hal/dcrtpoly-interface.h b/src/core/include/lattice/hal/dcrtpoly-interface.h index 36f945855..e374b9c83 100644 --- a/src/core/include/lattice/hal/dcrtpoly-interface.h +++ b/src/core/include/lattice/hal/dcrtpoly-interface.h @@ -83,6 +83,8 @@ namespace lbcrypto { template typename RNSContainerType> class DCRTPolyInterface : public ILElement { + constexpr static std::string_view NOT_IMPLEMENTED_ERROR = "This function is not implemented for DCRTPoly"; + public: using BigIntType = typename BigVecType::Integer; using Params = ILDCRTParams; @@ -259,10 +261,10 @@ class DCRTPolyInterface : public ILElement { * @return interpolated value at index i. */ BigIntType& at(usint i) final { - OPENFHE_THROW("at() not implemented for DCRTPoly"); + OPENFHE_THROW(NOT_IMPLEMENTED_ERROR); } const BigIntType& at(usint i) const final { - OPENFHE_THROW("const at() not implemented for DCRTPoly"); + OPENFHE_THROW(NOT_IMPLEMENTED_ERROR); } /** @@ -271,10 +273,10 @@ class DCRTPolyInterface : public ILElement { * @return interpolated value at index i. */ BigIntType& operator[](usint i) final { - OPENFHE_THROW("operator[] not implemented for DCRTPoly"); + OPENFHE_THROW(NOT_IMPLEMENTED_ERROR); } const BigIntType& operator[](usint i) const final { - OPENFHE_THROW("const operator[] not implemented for DCRTPoly"); + OPENFHE_THROW(NOT_IMPLEMENTED_ERROR); } /** @@ -656,7 +658,7 @@ class DCRTPolyInterface : public ILElement { * @warning Will remove, this is only inplace because of BFV */ DerivedType MultiplyAndRound(const BigIntType& p, const BigIntType& q) const final { - OPENFHE_THROW("MultiplyAndRound not implemented for DCRTPoly"); + OPENFHE_THROW(NOT_IMPLEMENTED_ERROR); } /** @@ -669,7 +671,7 @@ class DCRTPolyInterface : public ILElement { * @warning Will remove, this is only inplace because of BFV */ DerivedType DivideAndRound(const BigIntType& q) const final { - OPENFHE_THROW("DivideAndRound not implemented for DCRTPoly"); + OPENFHE_THROW(NOT_IMPLEMENTED_ERROR); } /** @@ -725,7 +727,7 @@ class DCRTPolyInterface : public ILElement { * @warning Doesn't make sense for DCRT */ DerivedType ModByTwo() const final { - OPENFHE_THROW("Mod of a BigIntType not implemented for DCRTPoly"); + OPENFHE_THROW(NOT_IMPLEMENTED_ERROR); } /** @@ -738,7 +740,7 @@ class DCRTPolyInterface : public ILElement { * @warning Doesn't make sense for DCRT */ DerivedType Mod(const BigIntType& modulus) const final { - OPENFHE_THROW("Mod of a BigIntType not implemented for DCRTPoly"); + OPENFHE_THROW(NOT_IMPLEMENTED_ERROR); } /** @@ -749,7 +751,7 @@ class DCRTPolyInterface : public ILElement { * @warning Doesn't make sense for DCRT */ const BigVecType& GetValues() const final { - OPENFHE_THROW("GetValues not implemented for DCRTPoly"); + OPENFHE_THROW(NOT_IMPLEMENTED_ERROR); } /** @@ -761,7 +763,7 @@ class DCRTPolyInterface : public ILElement { * @warning Doesn't make sense for DCRT */ void SetValues(const BigVecType& values, Format format) { - OPENFHE_THROW("SetValues not implemented for DCRTPoly"); + OPENFHE_THROW(NOT_IMPLEMENTED_ERROR); } /** @@ -786,7 +788,7 @@ class DCRTPolyInterface : public ILElement { * @warning Doesn't make sense for DCRT */ DerivedType AddRandomNoise(const BigIntType& modulus) const { - OPENFHE_THROW("AddRandomNoise is not currently implemented for DCRTPoly"); + OPENFHE_THROW(NOT_IMPLEMENTED_ERROR); } /** @@ -798,7 +800,7 @@ class DCRTPolyInterface : public ILElement { * @warning Only used by RingSwitching, which is no longer supported. Will be removed in future. */ void MakeSparse(uint32_t wFactor) final { - OPENFHE_THROW("MakeSparse is not currently implemented for DCRTPoly"); + OPENFHE_THROW(NOT_IMPLEMENTED_ERROR); } /** @@ -1392,7 +1394,7 @@ class DCRTPolyInterface : public ILElement { */ void SwitchModulus(const BigIntType& modulus, const BigIntType& rootOfUnity, const BigIntType& modulusArb, const BigIntType& rootOfUnityArb) final { - OPENFHE_THROW("SwitchModulus not implemented for DCRTPoly"); + OPENFHE_THROW(NOT_IMPLEMENTED_ERROR); } /** diff --git a/src/core/include/lattice/hal/default/dcrtpoly-impl.h b/src/core/include/lattice/hal/default/dcrtpoly-impl.h index 0fec66253..9e023010c 100644 --- a/src/core/include/lattice/hal/default/dcrtpoly-impl.h +++ b/src/core/include/lattice/hal/default/dcrtpoly-impl.h @@ -652,9 +652,9 @@ template void DCRTPolyImpl::SetValuesModSwitch(const DCRTPolyImpl& element, const NativeInteger& modulus) { size_t N(m_params->GetRingDimension()); if (N != element.GetRingDimension()) - OPENFHE_THROW(std::string(__func__) + ": Ring dimension mismatch."); + OPENFHE_THROW("Ring dimension mismatch."); if (element.m_vectors.size() != 1 || m_vectors.size() != 1) - OPENFHE_THROW(std::string(__func__) + ": Only implemented for DCRTPoly with one tower."); + OPENFHE_THROW("Only implemented for DCRTPoly with one tower."); auto input{element.m_vectors[0]}; input.SetFormat(Format::COEFFICIENT); @@ -671,7 +671,7 @@ void DCRTPolyImpl::SetValuesModSwitch(const DCRTPolyImpl& element, cons template void DCRTPolyImpl::AddILElementOne() { if (m_format != Format::EVALUATION) - OPENFHE_THROW(std::string(__func__) + ": only available in COEFFICIENT format."); + OPENFHE_THROW("Only available in COEFFICIENT format."); size_t size{m_vectors.size()}; #pragma omp parallel for num_threads(OpenFHEParallelControls.GetThreadLimit(size)) for (size_t i = 0; i < size; ++i) @@ -690,9 +690,9 @@ bool DCRTPolyImpl::IsEmpty() const { template void DCRTPolyImpl::DropLastElement() { if (m_vectors.size() == 0) - OPENFHE_THROW(std::string(__func__) + ": Input has no elements to drop."); + OPENFHE_THROW("Input has no elements to drop."); if (m_vectors.size() == 1) - OPENFHE_THROW(std::string(__func__) + ": Removing last element of DCRTPoly renders it invalid."); + OPENFHE_THROW("Removing last element of DCRTPoly renders it invalid."); m_vectors.resize(m_vectors.size() - 1); DCRTPolyImpl::Params* newP = new DCRTPolyImpl::Params(*m_params); newP->PopLastParam(); @@ -702,7 +702,7 @@ void DCRTPolyImpl::DropLastElement() { template void DCRTPolyImpl::DropLastElements(size_t i) { if (m_vectors.size() <= i) - OPENFHE_THROW(std::string(__func__) + ": Too few towers in input."); + OPENFHE_THROW("Too few towers in input."); m_vectors.resize(m_vectors.size() - i); DCRTPolyImpl::Params* newP = new DCRTPolyImpl::Params(*m_params); for (size_t j = 0; j < i; ++j) @@ -788,7 +788,7 @@ void DCRTPolyImpl::ModReduce(const NativeInteger& t, const std::vector< template typename DCRTPolyImpl::PolyLargeType DCRTPolyImpl::CRTInterpolate() const { if (m_format != Format::COEFFICIENT) - OPENFHE_THROW(std::string(__func__) + ": Only available in COEFFICIENT format."); + OPENFHE_THROW("Only available in COEFFICIENT format."); const uint32_t t(m_vectors.size()); const uint32_t r{m_params->GetRingDimension()}; @@ -826,7 +826,7 @@ typename DCRTPolyImpl::PolyLargeType DCRTPolyImpl::CRTInterpol template typename DCRTPolyImpl::PolyLargeType DCRTPolyImpl::CRTInterpolateIndex(uint32_t i) const { if (m_format != Format::COEFFICIENT) - OPENFHE_THROW(std::string(__func__) + ": Only available in COEFFICIENT format."); + OPENFHE_THROW("Only available in COEFFICIENT format."); uint32_t r{m_params->GetRingDimension()}; const Integer qt{m_params->GetModulus()}; diff --git a/src/core/include/lattice/hal/default/dcrtpoly.h b/src/core/include/lattice/hal/default/dcrtpoly.h index 2cf18e26b..6fd38ea03 100644 --- a/src/core/include/lattice/hal/default/dcrtpoly.h +++ b/src/core/include/lattice/hal/default/dcrtpoly.h @@ -152,14 +152,14 @@ class DCRTPolyImpl final : public DCRTPolyInterface, VecTy DCRTPolyType Plus(const std::vector& rhs) const; DCRTPolyType Plus(const DCRTPolyType& rhs) const override { if (m_params->GetRingDimension() != rhs.m_params->GetRingDimension()) - OPENFHE_THROW("RingDimension missmatch"); + OPENFHE_THROW("RingDimension mismatch"); if (m_format != rhs.m_format) - OPENFHE_THROW("Format missmatch"); + OPENFHE_THROW("Format mismatch"); size_t size{m_vectors.size()}; if (size != rhs.m_vectors.size()) OPENFHE_THROW("tower size mismatch; cannot add"); if (m_vectors[0].GetModulus() != rhs.m_vectors[0].GetModulus()) - OPENFHE_THROW("Modulus missmatch"); + OPENFHE_THROW("Modulus mismatch"); DCRTPolyType tmp(m_params, m_format); #pragma omp parallel for num_threads(OpenFHEParallelControls.GetThreadLimit(size)) for (size_t i = 0; i < size; ++i) @@ -173,14 +173,14 @@ class DCRTPolyImpl final : public DCRTPolyInterface, VecTy DCRTPolyType Times(const DCRTPolyType& rhs) const override { if (m_params->GetRingDimension() != rhs.m_params->GetRingDimension()) - OPENFHE_THROW("RingDimension missmatch"); + OPENFHE_THROW("RingDimension mismatch"); if (m_format != Format::EVALUATION || rhs.m_format != Format::EVALUATION) OPENFHE_THROW("operator* for DCRTPolyImpl supported only in Format::EVALUATION"); size_t size{m_vectors.size()}; if (size != rhs.m_vectors.size()) OPENFHE_THROW("tower size mismatch; cannot multiply"); if (m_vectors[0].GetModulus() != rhs.m_vectors[0].GetModulus()) - OPENFHE_THROW("Modulus missmatch"); + OPENFHE_THROW("Modulus mismatch"); DCRTPolyType tmp(m_params, m_format); #pragma omp parallel for num_threads(OpenFHEParallelControls.GetThreadLimit(size)) for (size_t i = 0; i < size; ++i) diff --git a/src/core/include/lattice/hal/default/poly.h b/src/core/include/lattice/hal/default/poly.h index 547cd992f..ba83a6e66 100644 --- a/src/core/include/lattice/hal/default/poly.h +++ b/src/core/include/lattice/hal/default/poly.h @@ -221,11 +221,11 @@ class PolyImpl final : public PolyInterface, VecType, PolyImpl PolyImpl Plus(const PolyImpl& rhs) const override { if (m_params->GetRingDimension() != rhs.m_params->GetRingDimension()) - OPENFHE_THROW("RingDimension missmatch"); + OPENFHE_THROW("RingDimension mismatch"); if (m_params->GetModulus() != rhs.m_params->GetModulus()) - OPENFHE_THROW("Modulus missmatch"); + OPENFHE_THROW("Modulus mismatch"); if (m_format != rhs.m_format) - OPENFHE_THROW("Format missmatch"); + OPENFHE_THROW("Format mismatch"); auto tmp(*this); tmp.m_values->ModAddNoCheckEq(*rhs.m_values); return tmp; @@ -253,9 +253,9 @@ class PolyImpl final : public PolyInterface, VecType, PolyImpl PolyImpl Times(const PolyImpl& rhs) const override { if (m_params->GetRingDimension() != rhs.m_params->GetRingDimension()) - OPENFHE_THROW("RingDimension missmatch"); + OPENFHE_THROW("RingDimension mismatch"); if (m_params->GetModulus() != rhs.m_params->GetModulus()) - OPENFHE_THROW("Modulus missmatch"); + OPENFHE_THROW("Modulus mismatch"); if (m_format != Format::EVALUATION || rhs.m_format != Format::EVALUATION) OPENFHE_THROW("operator* for PolyImpl supported only in Format::EVALUATION"); auto tmp(*this); @@ -269,9 +269,9 @@ class PolyImpl final : public PolyInterface, VecType, PolyImpl } PolyImpl& operator*=(const PolyImpl& rhs) override { if (m_params->GetRingDimension() != rhs.m_params->GetRingDimension()) - OPENFHE_THROW("RingDimension missmatch"); + OPENFHE_THROW("RingDimension mismatch"); if (m_params->GetModulus() != rhs.m_params->GetModulus()) - OPENFHE_THROW("Modulus missmatch"); + OPENFHE_THROW("Modulus mismatch"); if (m_format != Format::EVALUATION || rhs.m_format != Format::EVALUATION) OPENFHE_THROW("operator* for PolyImpl supported only in Format::EVALUATION"); if (m_values) { diff --git a/src/core/include/lattice/hal/poly-interface.h b/src/core/include/lattice/hal/poly-interface.h index 332eaa5a5..bc9d2a017 100644 --- a/src/core/include/lattice/hal/poly-interface.h +++ b/src/core/include/lattice/hal/poly-interface.h @@ -440,8 +440,7 @@ class PolyInterface : public ILElement { inline DerivedType Transpose() const final { if (this->GetDerived().GetFormat() == Format::COEFFICIENT) { OPENFHE_THROW( - "PolyInterface element transposition is currently " - "implemented only in the Evaluation representation."); + "PolyInterface element transposition is currently implemented only in the Evaluation representation."); } return this->GetDerived().AutomorphismTransform(this->GetDerived().GetCyclotomicOrder() - 1); } diff --git a/src/core/include/math/nbtheory-impl.h b/src/core/include/math/nbtheory-impl.h index 86d52fbef..42f25b30d 100644 --- a/src/core/include/math/nbtheory-impl.h +++ b/src/core/include/math/nbtheory-impl.h @@ -329,7 +329,7 @@ template IntType FirstPrime(uint32_t nBits, uint64_t m) { if constexpr (std::is_same_v) { if (nBits > MAX_MODULUS_SIZE) - OPENFHE_THROW(std::string(__func__) + ": Requested bit length " + std::to_string(nBits) + + OPENFHE_THROW("Requested bit length " + std::to_string(nBits) + " exceeds maximum allowed length " + std::to_string(MAX_MODULUS_SIZE)); } @@ -341,7 +341,7 @@ IntType FirstPrime(uint32_t nBits, uint64_t m) { qNew += M; while (!MillerRabinPrimalityTest(qNew)) { if ((qNew += M) < q) - OPENFHE_THROW(std::string(__func__) + ": overflow growing candidate"); + OPENFHE_THROW("Overflow growing candidate"); } return qNew; } @@ -350,7 +350,7 @@ template IntType LastPrime(uint32_t nBits, uint64_t m) { if constexpr (std::is_same_v) { if (nBits > MAX_MODULUS_SIZE) - OPENFHE_THROW(std::string(__func__) + ": Requested bit length " + std::to_string(nBits) + + OPENFHE_THROW("Requested bit length " + std::to_string(nBits) + " exceeds maximum allowed length " + std::to_string(MAX_MODULUS_SIZE)); } @@ -362,11 +362,11 @@ IntType LastPrime(uint32_t nBits, uint64_t m) { qNew -= M; while (!MillerRabinPrimalityTest(qNew)) { if ((qNew -= M) > q) - OPENFHE_THROW(std::string(__func__) + ": overflow shrinking candidate"); + OPENFHE_THROW("overflow shrinking candidate"); } if (qNew.GetMSB() != nBits) - OPENFHE_THROW(std::string(__func__) + ": Requested " + std::to_string(nBits) + " bits, but returned " + + OPENFHE_THROW("Requested " + std::to_string(nBits) + " bits, but returned " + std::to_string(qNew.GetMSB()) + ". Please adjust parameters."); return qNew; @@ -377,7 +377,7 @@ IntType NextPrime(const IntType& q, uint64_t m) { IntType M(m), qNew(q + M); while (!MillerRabinPrimalityTest(qNew)) { if ((qNew += M) < q) - OPENFHE_THROW(std::string(__func__) + ": overflow growing candidate"); + OPENFHE_THROW("Overflow growing candidate"); } return qNew; } @@ -387,7 +387,7 @@ IntType PreviousPrime(const IntType& q, uint64_t m) { IntType M(m), qNew(q - M); while (!MillerRabinPrimalityTest(qNew)) { if ((qNew -= M) > q) - OPENFHE_THROW(std::string(__func__) + ": overflow shrinking candidate"); + OPENFHE_THROW("Overflow shrinking candidate"); } return qNew; } diff --git a/src/core/include/utils/exception.h b/src/core/include/utils/exception.h index a9c31557d..17f5994f5 100644 --- a/src/core/include/utils/exception.h +++ b/src/core/include/utils/exception.h @@ -41,6 +41,7 @@ #include #include #include +#include #include namespace lbcrypto { @@ -100,96 +101,41 @@ class ThreadException { // } // e.Rethrow(); -class __attribute__((deprecated("OpenFHEException is the only exception class to be used in OpenFHE now."))) -openfhe_error : public std::runtime_error { - std::string filename; - int linenum; - std::string message; - -public: - openfhe_error(const std::string& file, int line, const std::string& what) - : std::runtime_error(what), filename(file), linenum(line) { - message = filename + ":" + std::to_string(linenum) + " " + what; - } - - const char* what() const throw() { - return message.c_str(); - } - - const std::string& GetFilename() const { - return filename; - } - int GetLinenum() const { - return linenum; - } -}; - -class __attribute__((deprecated("OpenFHEException is the only exception class to be used in OpenFHE now."))) -config_error : public openfhe_error { -public: - config_error(const std::string& file, int line, const std::string& what) : openfhe_error(file, line, what) {} -}; - -class __attribute__((deprecated("OpenFHEException is the only exception class to be used in OpenFHE now."))) math_error - : public openfhe_error { -public: - math_error(const std::string& file, int line, const std::string& what) : openfhe_error(file, line, what) {} -}; - -class __attribute__((deprecated("OpenFHEException is the only exception class to be used in OpenFHE now."))) -not_implemented_error : public openfhe_error { -public: - not_implemented_error(const std::string& file, int line, const std::string& what) - : openfhe_error(file, line, what) {} -}; - -class __attribute__((deprecated("OpenFHEException is the only exception class to be used in OpenFHE now."))) -not_available_error : public openfhe_error { -public: - not_available_error(const std::string& file, int line, const std::string& what) : openfhe_error(file, line, what) {} -}; - -class __attribute__((deprecated("OpenFHEException is the only exception class to be used in OpenFHE now."))) type_error - : public openfhe_error { -public: - type_error(const std::string& file, int line, const std::string& what) : openfhe_error(file, line, what) {} -}; - -// use this error when serializing openfhe objects -class __attribute__((deprecated("OpenFHEException is the only exception class to be used in OpenFHE now."))) -serialize_error : public openfhe_error { -public: - serialize_error(const std::string& file, int line, const std::string& what) : openfhe_error(file, line, what) {} -}; - -// use this error when deserializing openfhe objects -class __attribute__((deprecated("OpenFHEException is the only exception class to be used in OpenFHE now."))) -deserialize_error : public openfhe_error { -public: - deserialize_error(const std::string& file, int line, const std::string& what) : openfhe_error(file, line, what) {} -}; - class OpenFHEException : public std::exception { +// clang-format off std::string m_errorDescription; std::string m_fileName; std::string m_funcName; - size_t m_lineNumber; + size_t m_lineNumber{0}; std::string m_errorMessage; std::vector m_callStack; -public: - OpenFHEException(const std::string errorDescription, const std::string fileName = __builtin_FILE(), - const std::string funcName = __builtin_FUNCTION(), size_t lineNumber = __builtin_LINE()) - : m_errorDescription(errorDescription), m_fileName(fileName), m_funcName(funcName), m_lineNumber(lineNumber) { - m_errorMessage = - m_fileName + ":l." + std::to_string(m_lineNumber) + ":" + m_funcName + "(): " + m_errorDescription; - m_callStack = get_call_stack(); + static std::string buildErrorMessage(const std::string& file, + const std::string& func, + std::size_t line, + const std::string& desc) { + return file + ":l." + std::to_string(line) + ":" + func + "(): " + desc; } - OpenFHEException(const OpenFHEException& ex) = default; - - const char* what() const noexcept { +public: + explicit OpenFHEException(const std::string_view errorDescription, + const std::string fileName, + const std::string funcName, + size_t lineNumber) + : m_errorDescription(errorDescription), + m_fileName(fileName), + m_funcName(funcName), + m_lineNumber(lineNumber), + m_errorMessage(buildErrorMessage(m_fileName, m_funcName, m_lineNumber, m_errorDescription)), + m_callStack(get_call_stack()) {} +// clang-format on + + ~OpenFHEException() override = default; + OpenFHEException(const OpenFHEException&) = default; + OpenFHEException& operator=(const OpenFHEException&) = default; + + const char* what() const noexcept override { return m_errorMessage.c_str(); } @@ -200,20 +146,21 @@ class OpenFHEException : public std::exception { // getCallStackAsString() was added to be used by JSON logger. the implementtion will follow std::string getCallStackAsString() const { return std::string(); + + // if (m_callStack.empty()) + // return {}; + + // std::string ret = m_callStack.front(); + // for (std::size_t i = 1; i < m_callStack.size(); ++i) { + // ret += '\n'; + // ret += m_callStack[i]; + // } + // return ret; } }; -// ATTN: -// 1. OPENFHE_THROW is to be overloaded for the period of transition to OpenFHEException only. -// 2. After that openfhe_error, all classes derived from it and OPENFHE_THROW_OLD must be removed -// 3. All the macros below should be removed except OPENFHE_THROW_NEW. OPENFHE_THROW_NEW should -// be renamed to OPENFHE_THROW -// #define OPENFHE_THROW(expr) throw lbcrypto::OpenFHEException(expr) -#define OPENFHE_THROW_OLD(exc, expr) throw exc(__FILE__, __LINE__, (expr)) -#define OPENFHE_THROW_NEW(expr) throw lbcrypto::OpenFHEException(expr) - -#define GET_CORRECT_MACRO(_1, _2, NAME, ...) NAME -#define OPENFHE_THROW(...) GET_CORRECT_MACRO(__VA_ARGS__, OPENFHE_THROW_OLD, OPENFHE_THROW_NEW)(__VA_ARGS__) + +#define OPENFHE_THROW(desc) throw lbcrypto::OpenFHEException((desc), __FILE__, __func__, __LINE__) } // namespace lbcrypto diff --git a/src/core/lib/math/hal/bigintntl/mubintvecntl.cpp b/src/core/lib/math/hal/bigintntl/mubintvecntl.cpp index 33aaaf0d5..4f0789df9 100644 --- a/src/core/lib/math/hal/bigintntl/mubintvecntl.cpp +++ b/src/core/lib/math/hal/bigintntl/mubintvecntl.cpp @@ -436,8 +436,7 @@ myVecP& myVecP::ModEq(const myT& modulus) { template myVecP myVecP::ModAddAtIndex(size_t i, const myT& b) const { if (i > this->GetLength() - 1) { - std::string errMsg = "myVecP::ModAddAtIndex. Index is out of range. i = " + std::to_string(i); - OPENFHE_THROW(errMsg); + OPENFHE_THROW("Index is out of range. i = " + std::to_string(i)); } myVecP ans(*this); // copy vector ModulusCheck("myVecP::ModAddAtIndex"); @@ -448,8 +447,7 @@ myVecP myVecP::ModAddAtIndex(size_t i, const myT& b) const { template myVecP& myVecP::ModAddAtIndexEq(size_t i, const myT& b) { if (i > this->GetLength() - 1) { - std::string errMsg = "myVecP::ModAddAtIndex. Index is out of range. i = " + std::to_string(i); - OPENFHE_THROW(errMsg); + OPENFHE_THROW("Index is out of range. i = " + std::to_string(i)); } ModulusCheck("myVecP::ModAddAtIndex"); (*this)[i] = (*this)[i].ModAdd(b, this->m_modulus); diff --git a/src/core/lib/math/hal/bigintntl/ubintntl.cpp b/src/core/lib/math/hal/bigintntl/ubintntl.cpp index a6767ce31..683d5def5 100644 --- a/src/core/lib/math/hal/bigintntl/ubintntl.cpp +++ b/src/core/lib/math/hal/bigintntl/ubintntl.cpp @@ -127,7 +127,7 @@ myZZ& myZZ::MultiplyAndRoundEq(const myZZ& p, const myZZ& q) { myZZ myZZ::DivideAndRound(const myZZ& q) const { if (q == myZZ(0)) { - OPENFHE_THROW("DivideAndRound() Divisor is zero"); + OPENFHE_THROW("Divisor is zero"); } myZZ halfQ(q >> 1); if (*this < q) { @@ -151,7 +151,7 @@ myZZ myZZ::DivideAndRound(const myZZ& q) const { myZZ& myZZ::DivideAndRoundEq(const myZZ& q) { if (q == myZZ(0)) { - OPENFHE_THROW("DivideAndRound() Divisor is zero"); + OPENFHE_THROW("Divisor is zero"); } myZZ halfQ(q >> 1); if (*this < q) { diff --git a/src/core/lib/math/hal/intnat/mubintvecnat.cpp b/src/core/lib/math/hal/intnat/mubintvecnat.cpp index 1ad8e03a3..d6e0b4acb 100644 --- a/src/core/lib/math/hal/intnat/mubintvecnat.cpp +++ b/src/core/lib/math/hal/intnat/mubintvecnat.cpp @@ -217,7 +217,7 @@ NativeVectorT& NativeVectorT::ModAddAtIndexEq(size_t i template NativeVectorT NativeVectorT::ModAdd(const NativeVectorT& b) const { if (m_modulus != b.m_modulus || m_data.size() != b.m_data.size()) - OPENFHE_THROW("ModAdd called on NativeVectorT's with different parameters."); + OPENFHE_THROW("Called on NativeVectorT's with different parameters."); auto mv{m_modulus}; auto ans(*this); for (size_t i = 0; i < ans.m_data.size(); ++i) @@ -228,7 +228,7 @@ NativeVectorT NativeVectorT::ModAdd(const NativeVector template NativeVectorT& NativeVectorT::ModAddEq(const NativeVectorT& b) { if (m_data.size() != b.m_data.size() || m_modulus != b.m_modulus) - OPENFHE_THROW("ModAddEq called on NativeVectorT's with different parameters."); + OPENFHE_THROW("Called on NativeVectorT's with different parameters."); auto mv{m_modulus}; for (size_t i = 0; i < m_data.size(); ++i) m_data[i].ModAddFastEq(b[i], mv); @@ -261,7 +261,7 @@ NativeVectorT& NativeVectorT::ModSubEq(const IntegerTy template NativeVectorT NativeVectorT::ModSub(const NativeVectorT& b) const { if (m_data.size() != b.m_data.size() || m_modulus != b.m_modulus) - OPENFHE_THROW("ModSub called on NativeVectorT's with different parameters."); + OPENFHE_THROW("Called on NativeVectorT's with different parameters."); auto mv{m_modulus}; auto ans(*this); for (size_t i = 0; i < ans.m_data.size(); ++i) @@ -272,7 +272,7 @@ NativeVectorT NativeVectorT::ModSub(const NativeVector template NativeVectorT& NativeVectorT::ModSubEq(const NativeVectorT& b) { if (m_data.size() != b.m_data.size() || m_modulus != b.m_modulus) - OPENFHE_THROW("ModSubEq called on NativeVectorT's with different parameters."); + OPENFHE_THROW("Called on NativeVectorT's with different parameters."); for (size_t i = 0; i < m_data.size(); ++i) m_data[i].ModSubFastEq(b[i], m_modulus); return *this; @@ -306,7 +306,7 @@ NativeVectorT& NativeVectorT::ModMulEq(const IntegerTy template NativeVectorT NativeVectorT::ModMul(const NativeVectorT& b) const { if (m_data.size() != b.m_data.size() || m_modulus != b.m_modulus) - OPENFHE_THROW("ModMul called on NativeVectorT's with different parameters."); + OPENFHE_THROW("Called on NativeVectorT's with different parameters."); auto ans(*this); uint32_t size(m_data.size()); auto mv{m_modulus}; @@ -324,7 +324,7 @@ NativeVectorT NativeVectorT::ModMul(const NativeVector template NativeVectorT& NativeVectorT::ModMulEq(const NativeVectorT& b) { if (m_data.size() != b.m_data.size() || m_modulus != b.m_modulus) - OPENFHE_THROW("ModMulEq called on NativeVectorT's with different parameters."); + OPENFHE_THROW("Called on NativeVectorT's with different parameters."); auto mv{m_modulus}; size_t size{m_data.size()}; #ifdef NATIVEINT_BARRET_MOD @@ -381,7 +381,7 @@ NativeVectorT& NativeVectorT::ModExpEq(const IntegerTy template NativeVectorT NativeVectorT::MultWithOutMod(const NativeVectorT& b) const { if (m_data.size() != b.m_data.size() || m_modulus != b.m_modulus) - OPENFHE_THROW("ModMul called on NativeVectorT's with different parameters."); + OPENFHE_THROW("Called on NativeVectorT's with different parameters."); auto ans(*this); for (size_t i = 0; i < ans.m_data.size(); ++i) ans[i].m_value = ans[i].m_value * b[i].m_value; diff --git a/src/pke/include/ciphertext.h b/src/pke/include/ciphertext.h index 0933a8dd4..4fb195bc5 100644 --- a/src/pke/include/ciphertext.h +++ b/src/pke/include/ciphertext.h @@ -145,9 +145,7 @@ class CiphertextImpl : public CryptoObject { const Element& GetElement() const { if (m_elements.size() == 1) return m_elements[0]; - OPENFHE_THROW( - "GetElement should only be used in cases with a " - "Ciphertext with a single element"); + OPENFHE_THROW("Can be called on a Ciphertext with a single element ONLY"); } /** @@ -159,9 +157,7 @@ class CiphertextImpl : public CryptoObject { Element& GetElement() { if (m_elements.size() == 1) return m_elements[0]; - OPENFHE_THROW( - "GetElement should only be used in cases with a " - "Ciphertext with a single element"); + OPENFHE_THROW("Can be called on a Ciphertext with a single element ONLY"); } /** @@ -196,9 +192,7 @@ class CiphertextImpl : public CryptoObject { else if (m_elements.size() == 1) m_elements[0] = element; else - OPENFHE_THROW( - "SetElement should only be used in cases with a " - "Ciphertext with a single element"); + OPENFHE_THROW("Can be called on a Ciphertext with a single element ONLY"); } /** diff --git a/src/pke/include/encoding/plaintext.h b/src/pke/include/encoding/plaintext.h index 9548bb02f..19d327714 100644 --- a/src/pke/include/encoding/plaintext.h +++ b/src/pke/include/encoding/plaintext.h @@ -258,12 +258,12 @@ class PlaintextImpl { */ template Element& GetElement() { - OPENFHE_THROW("Generic GetElement() is not implemented"); + OPENFHE_THROW("Not implemented"); } template const Element& GetElement() const { - OPENFHE_THROW("Generic GetElement() is not implemented"); + OPENFHE_THROW("Not implemented"); } /** diff --git a/src/pke/include/key/evalkey.h b/src/pke/include/key/evalkey.h index 1494d9414..c2ff1b17c 100644 --- a/src/pke/include/key/evalkey.h +++ b/src/pke/include/key/evalkey.h @@ -51,6 +51,8 @@ namespace lbcrypto { */ template class EvalKeyImpl : public Key { + constexpr static std::string_view NOT_SUPPORTED_ERROR = "This function is not supported"; + public: /** * Basic constructor for setting crypto params @@ -71,7 +73,7 @@ class EvalKeyImpl : public Key { */ virtual void SetAVector(const std::vector& a) { - OPENFHE_THROW("SetAVector copy operation not supported"); + OPENFHE_THROW(NOT_SUPPORTED_ERROR); } /** @@ -82,7 +84,7 @@ class EvalKeyImpl : public Key { */ virtual void SetAVector(std::vector&& a) { - OPENFHE_THROW("SetAVector move operation not supported"); + OPENFHE_THROW(NOT_SUPPORTED_ERROR); } /** @@ -93,7 +95,7 @@ class EvalKeyImpl : public Key { */ virtual const std::vector& GetAVector() const { - OPENFHE_THROW("GetAVector operation not supported"); + OPENFHE_THROW(NOT_SUPPORTED_ERROR); } /** @@ -104,7 +106,7 @@ class EvalKeyImpl : public Key { */ virtual void SetBVector(const std::vector& b) { - OPENFHE_THROW("SetBVector copy operation not supported"); + OPENFHE_THROW(NOT_SUPPORTED_ERROR); } /** @@ -115,7 +117,7 @@ class EvalKeyImpl : public Key { */ virtual void SetBVector(std::vector&& b) { - OPENFHE_THROW("SetBVector move operation not supported"); + OPENFHE_THROW(NOT_SUPPORTED_ERROR); } /** @@ -126,11 +128,11 @@ class EvalKeyImpl : public Key { */ virtual const std::vector& GetBVector() const { - OPENFHE_THROW("GetBVector operation not supported"); + OPENFHE_THROW(NOT_SUPPORTED_ERROR); } virtual void ClearKeys() { - OPENFHE_THROW("ClearKeys operation is not supported"); + OPENFHE_THROW(NOT_SUPPORTED_ERROR); } friend bool operator==(const EvalKeyImpl& a, const EvalKeyImpl& b) { diff --git a/src/pke/include/keyswitch/keyswitch-base.h b/src/pke/include/keyswitch/keyswitch-base.h index f54f58c75..9196a198b 100644 --- a/src/pke/include/keyswitch/keyswitch-base.h +++ b/src/pke/include/keyswitch/keyswitch-base.h @@ -61,6 +61,8 @@ template class KeySwitchBase { using ParmType = typename Element::Params; + constexpr static std::string_view NOT_SUPPORTED_ERROR = "This function is not supported"; + public: KeySwitchBase() = default; @@ -76,36 +78,36 @@ class KeySwitchBase { */ virtual EvalKey KeySwitchGenInternal(const PrivateKey oldPrivateKey, const PrivateKey newPrivateKey) const { - OPENFHE_THROW(std::string(__func__) + " is not supported"); + OPENFHE_THROW(NOT_SUPPORTED_ERROR); } virtual EvalKey KeySwitchGenInternal(const PrivateKey oldPrivateKey, const PrivateKey newPrivateKey, const EvalKey evalKey) const { - OPENFHE_THROW(std::string(__func__) + " is not supported"); + OPENFHE_THROW(NOT_SUPPORTED_ERROR); } virtual EvalKey KeySwitchGenInternal(const PrivateKey oldPrivateKey, const PublicKey newPublicKey) const { - OPENFHE_THROW(std::string(__func__) + " is not supported"); + OPENFHE_THROW(NOT_SUPPORTED_ERROR); } virtual Ciphertext KeySwitch(ConstCiphertext ciphertext, const EvalKey evalKey) const; virtual void KeySwitchInPlace(Ciphertext& ciphertext, const EvalKey evalKey) const { - OPENFHE_THROW("KeySwitch is not supported"); + OPENFHE_THROW(NOT_SUPPORTED_ERROR); } virtual Ciphertext KeySwitchExt(ConstCiphertext ciphertext, bool addFirst) const { - OPENFHE_THROW("KeySwitchExt is not supported"); + OPENFHE_THROW(NOT_SUPPORTED_ERROR); } virtual Ciphertext KeySwitchDown(ConstCiphertext ciphertext) const { - OPENFHE_THROW("KeySwitchDown is not supported"); + OPENFHE_THROW(NOT_SUPPORTED_ERROR); } virtual Element KeySwitchDownFirstElement(ConstCiphertext ciphertext) const { - OPENFHE_THROW("KeySwitchDownFirstElement is not supported"); + OPENFHE_THROW(NOT_SUPPORTED_ERROR); } ///////////////////////////////////////// // CORE OPERATIONS @@ -113,24 +115,24 @@ class KeySwitchBase { virtual std::shared_ptr> KeySwitchCore(const Element& a, const EvalKey evalKey) const { - OPENFHE_THROW("KeySwitchCore is not supported"); + OPENFHE_THROW(NOT_SUPPORTED_ERROR); } virtual std::shared_ptr> EvalKeySwitchPrecomputeCore( const Element& c, std::shared_ptr> cryptoParamsBase) const { - OPENFHE_THROW("EvalKeySwitchPrecomputeCore is not supported"); + OPENFHE_THROW(NOT_SUPPORTED_ERROR); } virtual std::shared_ptr> EvalFastKeySwitchCore( const std::shared_ptr> digits, const EvalKey evalKey, const std::shared_ptr paramsQl) const { - OPENFHE_THROW("EvalFastKeySwitchCore is not supported"); + OPENFHE_THROW(NOT_SUPPORTED_ERROR); } virtual std::shared_ptr> EvalFastKeySwitchCoreExt( const std::shared_ptr> digits, const EvalKey evalKey, const std::shared_ptr paramsQl) const { - OPENFHE_THROW("EvalFastKeySwitchCoreExt is not supported"); + OPENFHE_THROW(NOT_SUPPORTED_ERROR); } }; diff --git a/src/pke/include/schemebase/base-advancedshe.h b/src/pke/include/schemebase/base-advancedshe.h index de6293c82..579fcb932 100644 --- a/src/pke/include/schemebase/base-advancedshe.h +++ b/src/pke/include/schemebase/base-advancedshe.h @@ -65,6 +65,7 @@ class AdvancedSHEBase { using DggType = typename Element::DggType; using TugType = typename Element::TugType; + constexpr static std::string_view NOT_IMPLEMENTED_ERROR = "Not implemented for this scheme"; public: virtual ~AdvancedSHEBase() = default; @@ -111,15 +112,15 @@ class AdvancedSHEBase { */ virtual Ciphertext EvalLinearWSum(std::vector>& ciphertextVec, const std::vector& weights) const { - OPENFHE_THROW("Not implemented for this scheme"); + OPENFHE_THROW(NOT_IMPLEMENTED_ERROR); } virtual Ciphertext EvalLinearWSum(std::vector>& ciphertextVec, const std::vector& weights) const { - OPENFHE_THROW("Not implemented for this scheme"); + OPENFHE_THROW(NOT_IMPLEMENTED_ERROR); } virtual Ciphertext EvalLinearWSum(std::vector>& ciphertextVec, const std::vector>& weights) const { - OPENFHE_THROW("Not implemented for this scheme"); + OPENFHE_THROW(NOT_IMPLEMENTED_ERROR); } /** @@ -133,15 +134,15 @@ class AdvancedSHEBase { */ virtual Ciphertext EvalLinearWSumMutable(std::vector>& ciphertextVec, const std::vector& weights) const { - OPENFHE_THROW("Not implemented for this scheme"); + OPENFHE_THROW(NOT_IMPLEMENTED_ERROR); } virtual Ciphertext EvalLinearWSumMutable(std::vector>& ciphertextVec, const std::vector& weights) const { - OPENFHE_THROW("Not implemented for this scheme"); + OPENFHE_THROW(NOT_IMPLEMENTED_ERROR); } virtual Ciphertext EvalLinearWSumMutable(std::vector>& ciphertextVec, const std::vector>& weights) const { - OPENFHE_THROW("Not implemented for this scheme"); + OPENFHE_THROW(NOT_IMPLEMENTED_ERROR); } //------------------------------------------------------------------------------ @@ -160,15 +161,15 @@ class AdvancedSHEBase { */ virtual std::shared_ptr> EvalPowers(ConstCiphertext& ciphertext, const std::vector& coefficients) const { - OPENFHE_THROW("Not implemented for this scheme"); + OPENFHE_THROW(NOT_IMPLEMENTED_ERROR); } virtual std::shared_ptr> EvalPowers(ConstCiphertext& ciphertext, const std::vector& coefficients) const { - OPENFHE_THROW("Not implemented for this scheme"); + OPENFHE_THROW(NOT_IMPLEMENTED_ERROR); } virtual std::shared_ptr> EvalPowers( ConstCiphertext& ciphertext, const std::vector>& coefficients) const { - OPENFHE_THROW("Not implemented for this scheme"); + OPENFHE_THROW(NOT_IMPLEMENTED_ERROR); } /** @@ -182,28 +183,28 @@ class AdvancedSHEBase { */ virtual Ciphertext EvalPoly(ConstCiphertext& ciphertext, const std::vector& coefficients) const { - OPENFHE_THROW("Not implemented for this scheme"); + OPENFHE_THROW(NOT_IMPLEMENTED_ERROR); } virtual Ciphertext EvalPoly(ConstCiphertext& ciphertext, const std::vector& coefficients) const { - OPENFHE_THROW("Not implemented for this scheme"); + OPENFHE_THROW(NOT_IMPLEMENTED_ERROR); } virtual Ciphertext EvalPoly(ConstCiphertext& ciphertext, const std::vector>& coefficients) const { - OPENFHE_THROW("Not implemented for this scheme"); + OPENFHE_THROW(NOT_IMPLEMENTED_ERROR); } virtual Ciphertext EvalPolyWithPrecomp(std::shared_ptr> powers, const std::vector& coefficients) const { - OPENFHE_THROW("Not implemented for this scheme"); + OPENFHE_THROW(NOT_IMPLEMENTED_ERROR); } virtual Ciphertext EvalPolyWithPrecomp(std::shared_ptr> powers, const std::vector& coefficients) const { - OPENFHE_THROW("Not implemented for this scheme"); + OPENFHE_THROW(NOT_IMPLEMENTED_ERROR); } virtual Ciphertext EvalPolyWithPrecomp(std::shared_ptr> powers, const std::vector>& coefficients) const { - OPENFHE_THROW("Not implemented for this scheme"); + OPENFHE_THROW(NOT_IMPLEMENTED_ERROR); } /** @@ -218,15 +219,15 @@ class AdvancedSHEBase { */ virtual Ciphertext EvalPolyLinear(ConstCiphertext& ciphertext, const std::vector& coefficients) const { - OPENFHE_THROW("Not implemented for this scheme"); + OPENFHE_THROW(NOT_IMPLEMENTED_ERROR); } virtual Ciphertext EvalPolyLinear(ConstCiphertext& ciphertext, const std::vector& coefficients) const { - OPENFHE_THROW("Not implemented for this scheme"); + OPENFHE_THROW(NOT_IMPLEMENTED_ERROR); } virtual Ciphertext EvalPolyLinear(ConstCiphertext& ciphertext, const std::vector>& coefficients) const { - OPENFHE_THROW("Not implemented for this scheme"); + OPENFHE_THROW(NOT_IMPLEMENTED_ERROR); } /** @@ -240,14 +241,14 @@ class AdvancedSHEBase { */ virtual Ciphertext EvalPolyPS(ConstCiphertext& x, const std::vector& coefficients) const { - OPENFHE_THROW("Not implemented for this scheme"); + OPENFHE_THROW(NOT_IMPLEMENTED_ERROR); } virtual Ciphertext EvalPolyPS(ConstCiphertext& x, const std::vector& coefficients) const { - OPENFHE_THROW("Not implemented for this scheme"); + OPENFHE_THROW(NOT_IMPLEMENTED_ERROR); } virtual Ciphertext EvalPolyPS(ConstCiphertext& x, const std::vector>& coefficients) const { - OPENFHE_THROW("Not implemented for this scheme"); + OPENFHE_THROW(NOT_IMPLEMENTED_ERROR); } //------------------------------------------------------------------------------ @@ -268,17 +269,17 @@ class AdvancedSHEBase { virtual std::shared_ptr> EvalChebyPolys(ConstCiphertext& ciphertext, const std::vector& coefficients, double a, double b) const { - OPENFHE_THROW("Not implemented for this scheme"); + OPENFHE_THROW(NOT_IMPLEMENTED_ERROR); } virtual std::shared_ptr> EvalChebyPolys(ConstCiphertext& ciphertext, const std::vector& coefficients, double a, double b) const { - OPENFHE_THROW("Not implemented for this scheme"); + OPENFHE_THROW(NOT_IMPLEMENTED_ERROR); } virtual std::shared_ptr> EvalChebyPolys(ConstCiphertext& ciphertext, const std::vector>& coefficients, double a, double b) const { - OPENFHE_THROW("Not implemented for this scheme"); + OPENFHE_THROW(NOT_IMPLEMENTED_ERROR); } /** @@ -296,61 +297,61 @@ class AdvancedSHEBase { virtual Ciphertext EvalChebyshevSeries(ConstCiphertext& ciphertext, const std::vector& coefficients, double a, double b) const { - OPENFHE_THROW("Not implemented for this scheme"); + OPENFHE_THROW(NOT_IMPLEMENTED_ERROR); } virtual Ciphertext EvalChebyshevSeries(ConstCiphertext& ciphertext, const std::vector& coefficients, double a, double b) const { - OPENFHE_THROW("Not implemented for this scheme"); + OPENFHE_THROW(NOT_IMPLEMENTED_ERROR); } virtual Ciphertext EvalChebyshevSeries(ConstCiphertext& ciphertext, const std::vector>& coefficients, double a, double b) const { - OPENFHE_THROW("Not implemented for this scheme"); + OPENFHE_THROW(NOT_IMPLEMENTED_ERROR); } virtual Ciphertext EvalChebyshevSeriesWithPrecomp(std::shared_ptr> polys, const std::vector& coefficients) const { - OPENFHE_THROW("Not implemented for this scheme"); + OPENFHE_THROW(NOT_IMPLEMENTED_ERROR); } virtual Ciphertext EvalChebyshevSeriesWithPrecomp(std::shared_ptr> polys, const std::vector& coefficients) const { - OPENFHE_THROW("Not implemented for this scheme"); + OPENFHE_THROW(NOT_IMPLEMENTED_ERROR); } virtual Ciphertext EvalChebyshevSeriesWithPrecomp( std::shared_ptr> polys, const std::vector>& coefficients) const { - OPENFHE_THROW("Not implemented for this scheme"); + OPENFHE_THROW(NOT_IMPLEMENTED_ERROR); } virtual Ciphertext EvalChebyshevSeriesLinear(ConstCiphertext& ciphertext, const std::vector& coefficients, double a, double b) const { - OPENFHE_THROW("Not implemented for this scheme"); + OPENFHE_THROW(NOT_IMPLEMENTED_ERROR); } virtual Ciphertext EvalChebyshevSeriesLinear(ConstCiphertext& ciphertext, const std::vector& coefficients, double a, double b) const { - OPENFHE_THROW("Not implemented for this scheme"); + OPENFHE_THROW(NOT_IMPLEMENTED_ERROR); } virtual Ciphertext EvalChebyshevSeriesLinear(ConstCiphertext& ciphertext, const std::vector>& coefficients, double a, double b) const { - OPENFHE_THROW("Not implemented for this scheme"); + OPENFHE_THROW(NOT_IMPLEMENTED_ERROR); } virtual Ciphertext EvalChebyshevSeriesPS(ConstCiphertext& ciphertext, const std::vector& coefficients, double a, double b) const { - OPENFHE_THROW("Not implemented for this scheme"); + OPENFHE_THROW(NOT_IMPLEMENTED_ERROR); } virtual Ciphertext EvalChebyshevSeriesPS(ConstCiphertext& ciphertext, const std::vector& coefficients, double a, double b) const { - OPENFHE_THROW("Not implemented for this scheme"); + OPENFHE_THROW(NOT_IMPLEMENTED_ERROR); } virtual Ciphertext EvalChebyshevSeriesPS(ConstCiphertext& ciphertext, const std::vector>& coefficients, double a, double b) const { - OPENFHE_THROW("Not implemented for this scheme"); + OPENFHE_THROW(NOT_IMPLEMENTED_ERROR); } //------------------------------------------------------------------------------ diff --git a/src/pke/include/schemebase/base-fhe.h b/src/pke/include/schemebase/base-fhe.h index ab267e52e..6aa6a64f1 100644 --- a/src/pke/include/schemebase/base-fhe.h +++ b/src/pke/include/schemebase/base-fhe.h @@ -59,6 +59,12 @@ namespace lbcrypto { */ template class FHEBase { + // TODO: should we use just one error message instead of a few (see below) + constexpr static std::string_view NOT_IMPLEMENTED_ERROR = "Not implemented for this scheme"; + constexpr static std::string_view NOT_SUPPORTED_ERROR = "Not supported for this scheme"; + constexpr static std::string_view NOT_SUPPORTED_SIMPLE_ERROR = "Not supported"; + + public: virtual ~FHEBase() = default; @@ -85,7 +91,7 @@ class FHEBase { virtual void EvalBootstrapSetup(const CryptoContextImpl& cc, std::vector levelBudget, std::vector dim1, uint32_t slots, uint32_t correctionFactor, bool precompute) { - OPENFHE_THROW("Not supported"); + OPENFHE_THROW(NOT_SUPPORTED_SIMPLE_ERROR); } /** @@ -98,7 +104,7 @@ class FHEBase { */ virtual std::shared_ptr>> EvalBootstrapKeyGen( const PrivateKey privateKey, uint32_t slots) { - OPENFHE_THROW("Not supported"); + OPENFHE_THROW(NOT_SUPPORTED_SIMPLE_ERROR); } /** @@ -107,7 +113,7 @@ class FHEBase { * @param slots - number of slots to be bootstrapped */ virtual void EvalBootstrapPrecompute(const CryptoContextImpl& cc, uint32_t slots) { - OPENFHE_THROW("Not supported"); + OPENFHE_THROW(NOT_SUPPORTED_SIMPLE_ERROR); } /** @@ -127,7 +133,7 @@ class FHEBase { */ virtual Ciphertext EvalBootstrap(ConstCiphertext& ciphertext, uint32_t numIterations, uint32_t precision) const { - OPENFHE_THROW("EvalBootstrap is not implemented for this scheme"); + OPENFHE_THROW(NOT_IMPLEMENTED_ERROR); } virtual void EvalFBTSetup(const CryptoContextImpl& cc, const std::vector>& coeffs, @@ -135,43 +141,43 @@ class FHEBase { const PublicKey& pubKey, const std::vector& dim1, const std::vector& levelBudget, uint32_t lvlsAfterBoot = 0, uint32_t depthLeveledComputation = 0, size_t order = 1) { - OPENFHE_THROW("Not supported"); + OPENFHE_THROW(NOT_SUPPORTED_SIMPLE_ERROR); } virtual void EvalFBTSetup(const CryptoContextImpl& cc, const std::vector& coeffs, uint32_t numSlots, const BigInteger& PIn, const BigInteger& POut, const BigInteger& Bigq, const PublicKey& pubKey, const std::vector& dim1, const std::vector& levelBudget, uint32_t lvlsAfterBoot = 0, uint32_t depthLeveledComputation = 0, size_t order = 1) { - OPENFHE_THROW("Not supported"); + OPENFHE_THROW(NOT_SUPPORTED_SIMPLE_ERROR); } virtual Ciphertext EvalFBT(ConstCiphertext& ciphertext, const std::vector>& coeffs, uint32_t digitBitSize, const BigInteger& initialScaling, uint64_t postScaling, uint32_t levelToReduce = 0, size_t order = 1) { - OPENFHE_THROW("Not supported"); + OPENFHE_THROW(NOT_SUPPORTED_SIMPLE_ERROR); } virtual Ciphertext EvalFBT(ConstCiphertext& ciphertext, const std::vector& coeffs, uint32_t digitBitSize, const BigInteger& initialScaling, uint64_t postScaling, uint32_t levelToReduce = 0, size_t order = 1) { - OPENFHE_THROW("Not supported"); + OPENFHE_THROW(NOT_SUPPORTED_SIMPLE_ERROR); } virtual Ciphertext EvalFBTNoDecoding(ConstCiphertext& ciphertext, const std::vector>& coeffs, uint32_t digitBitSize, const BigInteger& initialScaling, size_t order = 1) { - OPENFHE_THROW("Not supported"); + OPENFHE_THROW(NOT_SUPPORTED_SIMPLE_ERROR); } virtual Ciphertext EvalFBTNoDecoding(ConstCiphertext& ciphertext, const std::vector& coeffs, uint32_t digitBitSize, const BigInteger& initialScaling, size_t order = 1) { - OPENFHE_THROW("Not supported"); + OPENFHE_THROW(NOT_SUPPORTED_SIMPLE_ERROR); } virtual Ciphertext EvalHomDecoding(ConstCiphertext& ciphertext, uint64_t postScaling, uint32_t levelToReduce = 0) { - OPENFHE_THROW("Not supported"); + OPENFHE_THROW(NOT_SUPPORTED_SIMPLE_ERROR); } virtual std::shared_ptr> EvalMVBPrecompute(ConstCiphertext& ciphertext, @@ -179,7 +185,7 @@ class FHEBase { uint32_t digitBitSize, const BigInteger& initialScaling, size_t order = 1) { - OPENFHE_THROW("Not supported"); + OPENFHE_THROW(NOT_SUPPORTED_SIMPLE_ERROR); } virtual std::shared_ptr> EvalMVBPrecompute(ConstCiphertext& ciphertext, @@ -187,29 +193,29 @@ class FHEBase { uint32_t digitBitSize, const BigInteger& initialScaling, size_t order = 1) { - OPENFHE_THROW("Not supported"); + OPENFHE_THROW(NOT_SUPPORTED_SIMPLE_ERROR); } virtual Ciphertext EvalMVB(const std::shared_ptr> ciphertexts, const std::vector>& coeffs, uint32_t digitBitSize, const uint64_t postScaling, uint32_t levelToReduce = 0, size_t order = 1) { - OPENFHE_THROW("Not supported"); + OPENFHE_THROW(NOT_SUPPORTED_SIMPLE_ERROR); } virtual Ciphertext EvalMVB(const std::shared_ptr> ciphertexts, const std::vector& coeffs, uint32_t digitBitSize, const uint64_t postScaling, uint32_t levelToReduce = 0, size_t order = 1) { - OPENFHE_THROW("Not supported"); + OPENFHE_THROW(NOT_SUPPORTED_SIMPLE_ERROR); } virtual Ciphertext EvalMVBNoDecoding(const std::shared_ptr> ciphertexts, const std::vector>& coeffs, uint32_t digitBitSize, size_t order = 1) { - OPENFHE_THROW("Not supported"); + OPENFHE_THROW(NOT_SUPPORTED_SIMPLE_ERROR); } virtual Ciphertext EvalMVBNoDecoding(const std::shared_ptr> ciphertexts, const std::vector& coeffs, uint32_t digitBitSize, size_t order = 1) { - OPENFHE_THROW("Not supported"); + OPENFHE_THROW(NOT_SUPPORTED_SIMPLE_ERROR); } virtual Ciphertext EvalHermiteTrigSeries(ConstCiphertext& ciphertext, @@ -217,13 +223,13 @@ class FHEBase { double a, double b, const std::vector>& coefficientsHerm, size_t precomp = 0) { - OPENFHE_THROW("Not supported"); + OPENFHE_THROW(NOT_SUPPORTED_SIMPLE_ERROR); } virtual Ciphertext EvalHermiteTrigSeries(ConstCiphertext& ciphertext, const std::vector>& coefficientsCheb, double a, double b, const std::vector& coefficientsHerm, size_t precomp = 0) { - OPENFHE_THROW("Not supported"); + OPENFHE_THROW(NOT_SUPPORTED_SIMPLE_ERROR); } /** @@ -233,7 +239,7 @@ class FHEBase { * @return the FHEW secret key */ virtual LWEPrivateKey EvalCKKStoFHEWSetup(const SchSwchParams& params) { - OPENFHE_THROW("EvalCKKStoFHEWSetup is not supported for this scheme"); + OPENFHE_THROW(NOT_SUPPORTED_ERROR); } /** @@ -245,7 +251,7 @@ class FHEBase { */ virtual std::shared_ptr>> EvalCKKStoFHEWKeyGen(const KeyPair& keyPair, ConstLWEPrivateKey& lwesk) { - OPENFHE_THROW("EvalCKKStoFHEWKeyGen is not supported for this scheme"); + OPENFHE_THROW(NOT_SUPPORTED_ERROR); } /** @@ -258,7 +264,7 @@ class FHEBase { * @param L level on which the hom. decoding matrix should be. We want the hom. decoded ciphertext to be on the last level */ virtual void EvalCKKStoFHEWPrecompute(const CryptoContextImpl& cc, double scale) { - OPENFHE_THROW("EvalCKKStoFHEWPrecompute is not supported for this scheme"); + OPENFHE_THROW(NOT_SUPPORTED_ERROR); } /** @@ -269,7 +275,7 @@ class FHEBase { */ virtual std::vector> EvalCKKStoFHEW(ConstCiphertext ciphertext, uint32_t numCtxts) { - OPENFHE_THROW("EvalCKKStoFHEW is not implemented for this scheme"); + OPENFHE_THROW(NOT_IMPLEMENTED_ERROR); } /** @@ -284,7 +290,7 @@ class FHEBase { virtual void EvalFHEWtoCKKSSetup(const CryptoContextImpl& ccCKKS, const std::shared_ptr& ccLWE, uint32_t numSlotsCKKS, uint32_t logQ) { - OPENFHE_THROW("EvalFHEWtoCKKSSetup is not supported for this scheme"); + OPENFHE_THROW(NOT_SUPPORTED_ERROR); } /** @@ -301,7 +307,7 @@ class FHEBase { virtual std::shared_ptr>> EvalFHEWtoCKKSKeyGen( const KeyPair& keyPair, ConstLWEPrivateKey& lwesk, uint32_t numSlots = 0, uint32_t numCtxts = 0, uint32_t dim1 = 0, uint32_t L = 0) { - OPENFHE_THROW("EvalFHEWtoCKKSKeyGen is not supported for this scheme"); + OPENFHE_THROW(NOT_SUPPORTED_ERROR); } /** @@ -316,7 +322,7 @@ class FHEBase { */ virtual void EvalCompareSwitchPrecompute(const CryptoContextImpl& ccCKKS, uint32_t pLWE, double scaleSign, bool unit) { - OPENFHE_THROW("EvalCompareSwitchPrecompute is not supported for this scheme"); + OPENFHE_THROW(NOT_SUPPORTED_ERROR); } /** @@ -334,7 +340,7 @@ class FHEBase { virtual Ciphertext EvalFHEWtoCKKS(std::vector>& LWECiphertexts, uint32_t numCtxts, uint32_t numSlots, uint32_t p, double pmin, double pmax, uint32_t dim1) const { - OPENFHE_THROW("EvalFHEWtoCKKS is not implemented for this scheme"); + OPENFHE_THROW(NOT_IMPLEMENTED_ERROR); } /** @@ -345,7 +351,7 @@ class FHEBase { * TODO: add an overload for when BinFHEContext is already generated and fed as a parameter */ virtual LWEPrivateKey EvalSchemeSwitchingSetup(const SchSwchParams& params) { - OPENFHE_THROW("EvalSchemeSwitchingSetup is not supported for this scheme"); + OPENFHE_THROW(NOT_SUPPORTED_ERROR); } /** @@ -358,7 +364,7 @@ class FHEBase { */ virtual std::shared_ptr>> EvalSchemeSwitchingKeyGen( const KeyPair& keyPair, ConstLWEPrivateKey& lwesk) { - OPENFHE_THROW("EvalSchemeSwitchingKeyGen is not supported for this scheme"); + OPENFHE_THROW(NOT_SUPPORTED_ERROR); } /** @@ -379,7 +385,7 @@ class FHEBase { ConstCiphertext ciphertext2, uint32_t numCtxts, uint32_t numSlots, uint32_t pLWE, double scaleSign, bool unit) { - OPENFHE_THROW("EvalCompareSchemeSwitching is not supported for this scheme"); + OPENFHE_THROW(NOT_SUPPORTED_ERROR); } /** @@ -402,7 +408,7 @@ class FHEBase { PublicKey publicKey, uint32_t numValues, uint32_t numSlots, uint32_t pLWE, double scaleSign) { - OPENFHE_THROW("EvalMinSchemeSwitching is not supported for this scheme"); + OPENFHE_THROW(NOT_SUPPORTED_ERROR); } /** @@ -412,7 +418,7 @@ class FHEBase { PublicKey publicKey, uint32_t numValues, uint32_t numSlots, uint32_t pLWE, double scaleSign) { - OPENFHE_THROW("EvalMinSchemeSwitchingAlt is not supported for this scheme"); + OPENFHE_THROW(NOT_SUPPORTED_ERROR); } /** @@ -435,7 +441,7 @@ class FHEBase { PublicKey publicKey, uint32_t numValues, uint32_t numSlots, uint32_t pLWE, double scaleSign) { - OPENFHE_THROW("EvalMaxSchemeSwitching is not supported for this scheme"); + OPENFHE_THROW(NOT_SUPPORTED_ERROR); } /** @@ -445,27 +451,27 @@ class FHEBase { PublicKey publicKey, uint32_t numValues, uint32_t numSlots, uint32_t pLWE, double scaleSign) { - OPENFHE_THROW("EvalMaxSchemeSwitchingAlt is not supported for this scheme"); + OPENFHE_THROW(NOT_SUPPORTED_ERROR); } /** * Getter and setter for the binFHE cryptocontext used in scheme switching */ virtual std::shared_ptr GetBinCCForSchemeSwitch() { - OPENFHE_THROW("GetBinCCForSchemeSwitch is not supported for this scheme"); + OPENFHE_THROW(NOT_SUPPORTED_ERROR); } virtual void SetBinCCForSchemeSwitch(std::shared_ptr ccLWE) { - OPENFHE_THROW("SetBinCCForSchemeSwitch is not supported for this scheme"); + OPENFHE_THROW(NOT_SUPPORTED_ERROR); } /** * Getter and setter for the switching key between FHEW to CKKS */ virtual Ciphertext GetSwkFC() { - OPENFHE_THROW("GetSwkFC is not supported for this scheme"); + OPENFHE_THROW(NOT_SUPPORTED_ERROR); } virtual void SetSwkFC(Ciphertext FHEWtoCKKSswk) { - OPENFHE_THROW("SetSwkFC is not supported for this scheme"); + OPENFHE_THROW(NOT_SUPPORTED_ERROR); } ///////////////////////////////////// diff --git a/src/pke/include/schemebase/base-leveledshe.h b/src/pke/include/schemebase/base-leveledshe.h index 5f01c7fc5..1aebea1b7 100644 --- a/src/pke/include/schemebase/base-leveledshe.h +++ b/src/pke/include/schemebase/base-leveledshe.h @@ -64,6 +64,10 @@ class LeveledSHEBase { using DggType = typename Element::DggType; using TugType = typename Element::TugType; + // TODO: should we use just one error message instead of two (see below) + constexpr static std::string_view NOT_IMPLEMENTED_ERROR = "Not implemented for this scheme"; + constexpr static std::string_view NOT_SUPPORTED_ERROR = "Not supported for this scheme"; + public: virtual ~LeveledSHEBase() = default; @@ -124,11 +128,11 @@ class LeveledSHEBase { */ virtual Ciphertext EvalAddMutable(Ciphertext& ciphertext1, Ciphertext& ciphertext2) const { - OPENFHE_THROW("EvalAddMutable is not implemented for this scheme"); + OPENFHE_THROW(NOT_IMPLEMENTED_ERROR); } virtual void EvalAddMutableInPlace(Ciphertext& ciphertext1, Ciphertext& ciphertext2) const { - OPENFHE_THROW("EvalAddMutable is not implemented for this scheme"); + OPENFHE_THROW(NOT_IMPLEMENTED_ERROR); } /** @@ -160,7 +164,7 @@ class LeveledSHEBase { * @return the new ciphertext. */ virtual Ciphertext EvalAddMutable(Ciphertext& ciphertext, Plaintext& plaintext) const { - OPENFHE_THROW("EvalAddMutable is not implemented for this scheme"); + OPENFHE_THROW(NOT_IMPLEMENTED_ERROR); } /** @@ -173,31 +177,31 @@ class LeveledSHEBase { * @return the new ciphertext. */ virtual void EvalAddMutableInPlace(Ciphertext& ciphertext, Plaintext& plaintext) const { - OPENFHE_THROW("EvalAddMutable is not implemented for this scheme"); + OPENFHE_THROW(NOT_IMPLEMENTED_ERROR); } virtual Ciphertext EvalAdd(ConstCiphertext& ciphertext, NativeInteger scalar) const { - OPENFHE_THROW("integer scalar addition is not implemented for this scheme"); + OPENFHE_THROW(NOT_IMPLEMENTED_ERROR); } virtual void EvalAddInPlace(Ciphertext& ciphertext, NativeInteger scalar) const { - OPENFHE_THROW("integer scalar addition is not implemented for this scheme"); + OPENFHE_THROW(NOT_IMPLEMENTED_ERROR); } virtual Ciphertext EvalAdd(ConstCiphertext& ciphertext, double scalar) const { - OPENFHE_THROW("double scalar addition is not implemented for this scheme"); + OPENFHE_THROW(NOT_IMPLEMENTED_ERROR); } virtual void EvalAddInPlace(Ciphertext& ciphertext, double scalar) const { - OPENFHE_THROW("double scalar addition is not implemented for this scheme"); + OPENFHE_THROW(NOT_IMPLEMENTED_ERROR); } virtual Ciphertext EvalAdd(ConstCiphertext& ciphertext, std::complex scalar) const { - OPENFHE_THROW("complex scalar addition is not implemented for this scheme"); + OPENFHE_THROW(NOT_IMPLEMENTED_ERROR); } virtual void EvalAddInPlace(Ciphertext& ciphertext, std::complex scalar) const { - OPENFHE_THROW("complex scalar addition is not implemented for this scheme"); + OPENFHE_THROW(NOT_IMPLEMENTED_ERROR); } ///////////////////////////////////////// @@ -235,7 +239,7 @@ class LeveledSHEBase { */ virtual Ciphertext EvalSubMutable(Ciphertext& ciphertext1, Ciphertext& ciphertext2) const { - OPENFHE_THROW("EvalSubMutable is not implemented for this scheme"); + OPENFHE_THROW(NOT_IMPLEMENTED_ERROR); } /** @@ -248,7 +252,7 @@ class LeveledSHEBase { * @return the new ciphertext. */ virtual void EvalSubMutableInPlace(Ciphertext& ciphertext1, Ciphertext& ciphertext2) const { - OPENFHE_THROW("EvalSubMutable is not implemented for this scheme"); + OPENFHE_THROW(NOT_IMPLEMENTED_ERROR); } /** @@ -273,27 +277,27 @@ class LeveledSHEBase { * @return the new ciphertext. */ virtual Ciphertext EvalSubMutable(Ciphertext& ciphertext, Plaintext& plaintext) const { - OPENFHE_THROW("EvalSubMutable is not implemented for this scheme"); + OPENFHE_THROW(NOT_IMPLEMENTED_ERROR); } virtual void EvalSubMutableInPlace(Ciphertext& ciphertext, Plaintext& plaintext) const { - OPENFHE_THROW("EvalSubMutable is not implemented for this scheme"); + OPENFHE_THROW(NOT_IMPLEMENTED_ERROR); } virtual Ciphertext EvalSub(ConstCiphertext& ciphertext, NativeInteger scalar) const { - OPENFHE_THROW("integer scalar subtraction is not implemented for this scheme"); + OPENFHE_THROW(NOT_IMPLEMENTED_ERROR); } virtual void EvalSubInPlace(Ciphertext& ciphertext, NativeInteger scalar) const { - OPENFHE_THROW("integer scalar subtraction is not implemented for this scheme"); + OPENFHE_THROW(NOT_IMPLEMENTED_ERROR); } virtual Ciphertext EvalSub(ConstCiphertext& ciphertext, double scalar) const { - OPENFHE_THROW("double scalar subtraction is not implemented for this scheme"); + OPENFHE_THROW(NOT_IMPLEMENTED_ERROR); } virtual void EvalSubInPlace(Ciphertext& ciphertext, double scalar) const { - OPENFHE_THROW("double scalar subtraction is not implemented for this scheme"); + OPENFHE_THROW(NOT_IMPLEMENTED_ERROR); } //------------------------------------------------------------------------------ @@ -335,7 +339,7 @@ class LeveledSHEBase { */ virtual Ciphertext EvalMult(ConstCiphertext& ciphertext1, ConstCiphertext& ciphertext2) const { - OPENFHE_THROW("EvalMult is not implemented for this scheme"); + OPENFHE_THROW(NOT_IMPLEMENTED_ERROR); } /** @@ -349,7 +353,7 @@ class LeveledSHEBase { */ virtual Ciphertext EvalMultMutable(Ciphertext& ciphertext1, Ciphertext& ciphertext2) const { - OPENFHE_THROW("EvalMultMutable is not implemented for this scheme"); + OPENFHE_THROW(NOT_IMPLEMENTED_ERROR); } /** @@ -361,7 +365,7 @@ class LeveledSHEBase { * @return the new ciphertext. */ virtual Ciphertext EvalSquare(ConstCiphertext& ciphertext1) const { - OPENFHE_THROW("EvalSquare is not implemented for this scheme"); + OPENFHE_THROW(NOT_IMPLEMENTED_ERROR); } /** @@ -374,7 +378,7 @@ class LeveledSHEBase { * @return the new ciphertext. */ virtual Ciphertext EvalSquareMutable(Ciphertext& ciphertext1) const { - OPENFHE_THROW("EvalSquareMutable is not implemented for this scheme"); + OPENFHE_THROW(NOT_IMPLEMENTED_ERROR); } //------------------------------------------------------------------------------ @@ -403,7 +407,7 @@ class LeveledSHEBase { * @return the new ciphertext. */ virtual Ciphertext EvalMultMutable(Ciphertext& ciphertext, Plaintext& plaintext) const { - OPENFHE_THROW("EvalMultMutable C,P is not implemented for this scheme"); + OPENFHE_THROW(NOT_IMPLEMENTED_ERROR); } /** @@ -416,47 +420,47 @@ class LeveledSHEBase { * @return the new ciphertext. */ virtual void EvalMultMutableInPlace(Ciphertext& ciphertext, Plaintext& plaintext) const { - OPENFHE_THROW("EvalMultMutableInPlace C P is not implemented for this scheme"); + OPENFHE_THROW(NOT_IMPLEMENTED_ERROR); } virtual Ciphertext MultByMonomial(ConstCiphertext& ciphertext, uint32_t power) const { - OPENFHE_THROW("MultByMonomial is not implemented for this scheme"); + OPENFHE_THROW(NOT_IMPLEMENTED_ERROR); } virtual void MultByMonomialInPlace(Ciphertext& ciphertext, uint32_t power) const { - OPENFHE_THROW("MultByMonomialInPlace is not implemented for this scheme"); + OPENFHE_THROW(NOT_IMPLEMENTED_ERROR); } virtual Ciphertext EvalMult(ConstCiphertext& ciphertext, NativeInteger scalar) const { - OPENFHE_THROW("integer scalar multiplication is not implemented for this scheme"); + OPENFHE_THROW(NOT_IMPLEMENTED_ERROR); } virtual void EvalMultInPlace(Ciphertext& ciphertext, NativeInteger scalar) const { - OPENFHE_THROW("integer scalar multiplication is not implemented for this scheme"); + OPENFHE_THROW(NOT_IMPLEMENTED_ERROR); } virtual Ciphertext EvalMult(ConstCiphertext& ciphertext, double scalar) const { - OPENFHE_THROW("double scalar multiplication is not implemented for this scheme"); + OPENFHE_THROW(NOT_IMPLEMENTED_ERROR); } virtual void EvalMultInPlace(Ciphertext& ciphertext, double scalar) const { - OPENFHE_THROW("double scalar multiplication is not implemented for this scheme"); + OPENFHE_THROW(NOT_IMPLEMENTED_ERROR); } virtual Ciphertext EvalMult(ConstCiphertext& ciphertext, std::complex scalar) const { - OPENFHE_THROW("complex scalar multiplication is not implemented for this scheme"); + OPENFHE_THROW(NOT_IMPLEMENTED_ERROR); } virtual void EvalMultInPlace(Ciphertext& ciphertext, std::complex scalar) const { - OPENFHE_THROW("complex scalar multiplication is not implemented for this scheme"); + OPENFHE_THROW(NOT_IMPLEMENTED_ERROR); } virtual Ciphertext MultByInteger(ConstCiphertext& ciphertext, uint64_t integer) const { - OPENFHE_THROW("MultByInteger is not implemented for this scheme"); + OPENFHE_THROW(NOT_IMPLEMENTED_ERROR); } virtual void MultByIntegerInPlace(Ciphertext& ciphertext, uint64_t integer) const { - OPENFHE_THROW("MultByIntegerInPlace is not implemented for this scheme"); + OPENFHE_THROW(NOT_IMPLEMENTED_ERROR); } /** @@ -576,8 +580,7 @@ class LeveledSHEBase { virtual std::shared_ptr>> EvalAutomorphismKeyGen( const PublicKey publicKey, const PrivateKey privateKey, const std::vector& indexList) const { - std::string errMsg = "EvalAutomorphismKeyGen is not implemented for this scheme."; - OPENFHE_THROW(errMsg); + OPENFHE_THROW(NOT_IMPLEMENTED_ERROR); } /** @@ -621,7 +624,7 @@ class LeveledSHEBase { const std::shared_ptr> expandedCiphertext, bool addFirst, const std::map>& evalKeys) const { - OPENFHE_THROW("EvalFastRotationExt is not implemented for this scheme."); + OPENFHE_THROW(NOT_IMPLEMENTED_ERROR); } /** @@ -650,7 +653,7 @@ class LeveledSHEBase { const std::map>& evalKeyMap) const; virtual uint32_t FindAutomorphismIndex(uint32_t index, uint32_t m) const { - OPENFHE_THROW("FindAutomorphismIndex is not supported for this scheme"); + OPENFHE_THROW(NOT_SUPPORTED_ERROR); } ///////////////////////////////////////// @@ -664,7 +667,7 @@ class LeveledSHEBase { * @param levels the number of towers to drop. */ virtual Ciphertext ModReduce(ConstCiphertext& ciphertext, size_t levels) const { - OPENFHE_THROW("ModReduce is not supported for this scheme"); + OPENFHE_THROW(NOT_SUPPORTED_ERROR); } /** @@ -674,7 +677,7 @@ class LeveledSHEBase { * @param levels the number of towers to drop. */ virtual void ModReduceInPlace(Ciphertext& ciphertext, size_t levels) const { - OPENFHE_THROW("ModReduce is not supported for this scheme"); + OPENFHE_THROW(NOT_SUPPORTED_ERROR); } /** @@ -718,12 +721,12 @@ class LeveledSHEBase { */ virtual void LevelReduceInPlace(Ciphertext& ciphertext1, const EvalKey evalKey, size_t levels) const { - OPENFHE_THROW("LevelReduceInPlace is not supported for this scheme"); + OPENFHE_THROW(NOT_SUPPORTED_ERROR); } virtual Ciphertext Compress(ConstCiphertext& ciphertext, size_t towersLeft, size_t noiseScaleDeg) const { - OPENFHE_THROW("Compress is not supported for this scheme"); + OPENFHE_THROW(NOT_SUPPORTED_ERROR); } /** @@ -734,7 +737,7 @@ class LeveledSHEBase { * @return ciphertext after the modulus reduction performed. */ virtual Ciphertext ModReduceInternal(ConstCiphertext& ciphertext, size_t levels) const { - OPENFHE_THROW("ModReduce is not supported for this scheme"); + OPENFHE_THROW(NOT_SUPPORTED_ERROR); } /** @@ -745,7 +748,7 @@ class LeveledSHEBase { * @details \p cipherText will have modulus reduction performed in-place. */ virtual void ModReduceInternalInPlace(Ciphertext& ciphertext, size_t levels) const { - OPENFHE_THROW("ModReduce is not supported for this scheme"); + OPENFHE_THROW(NOT_SUPPORTED_ERROR); } /** @@ -758,7 +761,7 @@ class LeveledSHEBase { * @return resulting ciphertext. */ virtual Ciphertext LevelReduceInternal(ConstCiphertext& ciphertext, size_t levels) const { - OPENFHE_THROW("LevelReduce is not supported for this scheme"); + OPENFHE_THROW(NOT_SUPPORTED_ERROR); } /** @@ -770,29 +773,29 @@ class LeveledSHEBase { * @param levels the number of towers to drop. */ virtual void LevelReduceInternalInPlace(Ciphertext& ciphertext, size_t levels) const { - OPENFHE_THROW("LevelReduce is not supported for this scheme"); + OPENFHE_THROW(NOT_SUPPORTED_ERROR); } virtual void AdjustLevelsInPlace(Ciphertext& ciphertext1, Ciphertext& ciphertext2) const { - OPENFHE_THROW("Leveled Operations are not supported for this scheme"); + OPENFHE_THROW(NOT_SUPPORTED_ERROR); } virtual void AdjustLevelsAndDepthInPlace(Ciphertext& ciphertext1, Ciphertext& ciphertext2) const { - OPENFHE_THROW("Mutable Operations are not supported for this scheme"); + OPENFHE_THROW(NOT_SUPPORTED_ERROR); } virtual void AdjustLevelsAndDepthToOneInPlace(Ciphertext& ciphertext1, Ciphertext& ciphertext2) const { - OPENFHE_THROW("Mutable Operations are not supported for this scheme"); + OPENFHE_THROW(NOT_SUPPORTED_ERROR); } // TODO (Andrey) : Move these functions to protected or to rns? virtual void AdjustForAddOrSubInPlace(Ciphertext& ciphertext1, Ciphertext& ciphertext2) const { - OPENFHE_THROW("Mutable Operations are not supported for this scheme"); + OPENFHE_THROW(NOT_SUPPORTED_ERROR); } virtual void AdjustForMultInPlace(Ciphertext& ciphertext1, Ciphertext& ciphertext2) const { - OPENFHE_THROW("Mutable Operations are not supported for this scheme"); + OPENFHE_THROW(NOT_SUPPORTED_ERROR); } virtual Ciphertext MorphPlaintext(ConstPlaintext& plaintext, ConstCiphertext& ciphertext) const; diff --git a/src/pke/include/schemebase/base-multiparty.h b/src/pke/include/schemebase/base-multiparty.h index 415d6661c..1d7be01ee 100644 --- a/src/pke/include/schemebase/base-multiparty.h +++ b/src/pke/include/schemebase/base-multiparty.h @@ -86,6 +86,8 @@ class MultipartyBase { using DggType = typename Element::DggType; using TugType = typename Element::TugType; + constexpr static std::string_view NOT_SUPPORTED_ERROR = "This function is not supported"; + public: virtual ~MultipartyBase() = default; @@ -218,7 +220,7 @@ class MultipartyBase { */ virtual DecryptResult MultipartyDecryptFusion(const std::vector>& ciphertextVec, Poly* plaintext) const { - OPENFHE_THROW("Decryption to Poly is not supported"); + OPENFHE_THROW(NOT_SUPPORTED_ERROR); } /** @@ -297,7 +299,7 @@ class MultipartyBase { * @return: Resulting Ciphertext */ virtual Ciphertext IntBootAdjustScale(ConstCiphertext ciphertext) const { - OPENFHE_THROW("The function is not supported"); + OPENFHE_THROW(NOT_SUPPORTED_ERROR); } /** @@ -313,7 +315,7 @@ class MultipartyBase { */ virtual Ciphertext IntBootDecrypt(const PrivateKey privateKey, ConstCiphertext ciphertext) const { - OPENFHE_THROW("The function is not supported"); + OPENFHE_THROW(NOT_SUPPORTED_ERROR); } /** @@ -328,7 +330,7 @@ class MultipartyBase { */ virtual Ciphertext IntBootEncrypt(const PublicKey publicKey, ConstCiphertext ciphertext) const { - OPENFHE_THROW("The function is not supported"); + OPENFHE_THROW(NOT_SUPPORTED_ERROR); } /** @@ -342,7 +344,7 @@ class MultipartyBase { */ virtual Ciphertext IntBootAdd(ConstCiphertext ciphertext1, ConstCiphertext ciphertext2) const { - OPENFHE_THROW("The function is not supported"); + OPENFHE_THROW(NOT_SUPPORTED_ERROR); } /** @@ -352,7 +354,7 @@ class MultipartyBase { * @return: Resulting Ciphertext */ virtual Ciphertext IntMPBootAdjustScale(ConstCiphertext ciphertext) const { - OPENFHE_THROW("The function is not supported"); + OPENFHE_THROW(NOT_SUPPORTED_ERROR); } /** @@ -363,7 +365,7 @@ class MultipartyBase { */ virtual Ciphertext IntMPBootRandomElementGen(std::shared_ptr params, const PublicKey publicKey) const { - OPENFHE_THROW("The function is not supported"); + OPENFHE_THROW(NOT_SUPPORTED_ERROR); } /** @@ -378,7 +380,7 @@ class MultipartyBase { virtual std::vector> IntMPBootDecrypt(const PrivateKey privateKey, ConstCiphertext ciphertext, ConstCiphertext a) const { - OPENFHE_THROW("The function is not supported"); + OPENFHE_THROW(NOT_SUPPORTED_ERROR); } /** @@ -391,7 +393,7 @@ class MultipartyBase { */ virtual std::vector> IntMPBootAdd( std::vector>>& sharesPairVec) const { - OPENFHE_THROW("The function is not supported"); + OPENFHE_THROW(NOT_SUPPORTED_ERROR); } /** @@ -411,7 +413,7 @@ class MultipartyBase { const std::vector>& sharesPair, ConstCiphertext a, ConstCiphertext ciphertext) const { - OPENFHE_THROW("The function is not supported"); + OPENFHE_THROW(NOT_SUPPORTED_ERROR); } template diff --git a/src/pke/include/schemebase/base-parametergeneration.h b/src/pke/include/schemebase/base-parametergeneration.h index 60694430e..754390052 100644 --- a/src/pke/include/schemebase/base-parametergeneration.h +++ b/src/pke/include/schemebase/base-parametergeneration.h @@ -80,7 +80,7 @@ class ParameterGenerationBase { virtual bool ParamsGenBFVRNSInternal(std::shared_ptr> cryptoParams, uint32_t evalAddCount, uint32_t multiplicativeDepth, uint32_t keySwitchCount, size_t dcrtBits, uint32_t n, uint32_t numPartQ) const { - OPENFHE_THROW("This signature for ParamsGen is not supported for this scheme."); + OPENFHE_THROW("Not supported for this scheme."); } /** @@ -99,7 +99,7 @@ class ParameterGenerationBase { uint32_t cyclOrder, uint32_t numPrimes, uint32_t scalingModSize, uint32_t firstModSize, uint32_t numPartQ, COMPRESSION_LEVEL mPIntBootCiphertextCompressionLevel) const { - OPENFHE_THROW("This signature for ParamsGen is not supported for this scheme."); + OPENFHE_THROW("Not supported for this scheme."); } /** @@ -120,7 +120,7 @@ class ParameterGenerationBase { uint32_t evalAddCount, uint32_t keySwitchCount, uint32_t cyclOrder, uint32_t numPrimes, uint32_t firstModSize, uint32_t dcrtBits, uint32_t numPartQ, uint32_t PRENumHops) const { - OPENFHE_THROW("This signature for ParamsGen is not supported for this scheme."); + OPENFHE_THROW("Not supported for this scheme."); } template diff --git a/src/pke/include/schemebase/base-pke.h b/src/pke/include/schemebase/base-pke.h index 8069b0fb2..8b8391c62 100644 --- a/src/pke/include/schemebase/base-pke.h +++ b/src/pke/include/schemebase/base-pke.h @@ -112,7 +112,7 @@ class PKEBase { */ virtual DecryptResult Decrypt(ConstCiphertext ciphertext, const PrivateKey privateKey, NativePoly* plaintext) const { - OPENFHE_THROW("Decryption to NativePoly is not supported"); + OPENFHE_THROW("Not supported for NativePoly"); } /** @@ -125,7 +125,7 @@ class PKEBase { */ virtual DecryptResult Decrypt(ConstCiphertext ciphertext, const PrivateKey privateKey, Poly* plaintext) const { - OPENFHE_THROW("Decryption to Poly is not supported"); + OPENFHE_THROW("Not supported for Poly"); } ///////////////////////////////////////// diff --git a/src/pke/include/schemerns/rns-cryptoparameters.h b/src/pke/include/schemerns/rns-cryptoparameters.h index 948ba1a1f..7d59c6c37 100644 --- a/src/pke/include/schemerns/rns-cryptoparameters.h +++ b/src/pke/include/schemerns/rns-cryptoparameters.h @@ -448,9 +448,7 @@ class CryptoParametersRNS : public CryptoParametersRLWE { if (part < m_PartQlHatInvModq.size() && sublvl < m_PartQlHatInvModq[part].size()) return m_PartQlHatInvModq[part][sublvl]; - OPENFHE_THROW( - "CryptoParametersCKKS::GetPartitionQHatInvModQTable - " - "index out of bounds."); + OPENFHE_THROW("Index out of bounds."); } /** @@ -463,10 +461,7 @@ class CryptoParametersRNS : public CryptoParametersRLWE { if (part < m_PartQlHatInvModqPrecon.size() && sublvl < m_PartQlHatInvModqPrecon[part].size()) return m_PartQlHatInvModqPrecon[part][sublvl]; - OPENFHE_THROW( - "CryptoParametersCKKS::" - "GetPartitionQHatInvModQPreconTable - index " - "out of bounds."); + OPENFHE_THROW("Index out of bounds."); } /** @@ -479,9 +474,7 @@ class CryptoParametersRNS : public CryptoParametersRLWE { if (lvl < m_PartQlHatModp.size() && part < m_PartQlHatModp[lvl].size()) return m_PartQlHatModp[lvl][part]; - OPENFHE_THROW( - "CryptoParametersCKKS::GetPartitionQHatModPTable - " - "index out of bounds."); + OPENFHE_THROW("Index out of bounds."); } /** @@ -494,9 +487,7 @@ class CryptoParametersRNS : public CryptoParametersRLWE { if (lvl < m_modComplPartqBarrettMu.size() && part < m_modComplPartqBarrettMu[lvl].size()) return m_modComplPartqBarrettMu[lvl][part]; - OPENFHE_THROW( - "CryptoParametersCKKS::GetPartitionPrecon - index out " - "of bounds."); + OPENFHE_THROW("Index out of bounds."); } /** diff --git a/src/pke/include/schemerns/rns-leveledshe.h b/src/pke/include/schemerns/rns-leveledshe.h index 5e6a5b810..82a21f63d 100644 --- a/src/pke/include/schemerns/rns-leveledshe.h +++ b/src/pke/include/schemerns/rns-leveledshe.h @@ -323,7 +323,7 @@ class LeveledSHERNS : public LeveledSHEBase { * @details \p cipherText will have modulus reduction performed in-place. */ void ModReduceInternalInPlace(Ciphertext& ciphertext, size_t levels) const override { - OPENFHE_THROW("ModReduceInternalInPlace is not supported for this scheme"); + OPENFHE_THROW("Not supported for this scheme"); } /** @@ -347,7 +347,7 @@ class LeveledSHERNS : public LeveledSHEBase { * @param levels the number of towers to drop. */ void LevelReduceInternalInPlace(Ciphertext& ciphertext, size_t levels) const override { - OPENFHE_THROW("LevelReduceInternalInPlace is not supported for this scheme"); + OPENFHE_THROW("Not supported for this scheme"); } void AdjustLevelsInPlace(Ciphertext& ciphertext1, Ciphertext& ciphertext2) const override; diff --git a/src/pke/lib/scheme/ckksrns/ckksrns-multiparty.cpp b/src/pke/lib/scheme/ckksrns/ckksrns-multiparty.cpp index 3f3910e18..5ceff37b1 100644 --- a/src/pke/lib/scheme/ckksrns/ckksrns-multiparty.cpp +++ b/src/pke/lib/scheme/ckksrns/ckksrns-multiparty.cpp @@ -118,8 +118,7 @@ DecryptResult MultipartyCKKSRNS::MultipartyDecryptFusion(const std::vector MultipartyCKKSRNS::IntMPBootAdjustScale(ConstCiphertext ciphertext) const { if (ciphertext->NumberCiphertextElements() == 0) { - std::string msg = "IntMPBootAdjustScale: no polynomials in the input ciphertext."; - OPENFHE_THROW(msg); + OPENFHE_THROW("No polynomials in the input ciphertext."); } auto cc = ciphertext->GetCryptoContext(); @@ -135,8 +134,7 @@ Ciphertext MultipartyCKKSRNS::IntMPBootAdjustScale(ConstCiphertextGetElements()[0].GetNumOfElements() < numTowersToKeep) { - std::string msg = std::string(__func__) + ": not enough towers in the input polynomial."; - OPENFHE_THROW(msg); + OPENFHE_THROW("Not enough towers in the input polynomial."); } if (cryptoParams->GetScalingTechnique() == ScalingTechnique::FLEXIBLEAUTO || cryptoParams->GetScalingTechnique() == FLEXIBLEAUTOEXT) { @@ -267,8 +265,7 @@ void PrecomputeRNSExtensionTables(CryptoContext& cc, usint from, usint // noise will not be added if IsZeroNoise is set to true (as in computing h_0,i) DCRTPoly ComputeNoisyMult(CryptoContext& cc, const DCRTPoly& sk, const DCRTPoly& poly, bool IsZeroNoise) { if (sk.GetNumOfElements() != poly.GetNumOfElements()) { - std::string errMsg = "ERROR: Number of towers in input polys does not match!"; - OPENFHE_THROW(errMsg); + OPENFHE_THROW("Number of towers in input polys does not match!"); } DCRTPoly res = sk * poly; @@ -389,8 +386,7 @@ std::vector> MultipartyCKKSRNS::IntMPBootDecrypt(const Priv std::vector> MultipartyCKKSRNS::IntMPBootAdd( std::vector>>& sharesPairVec) const { if (sharesPairVec.size() == 0) { - std::string msg = "IntMPBootAdd: no polynomials in input share(s)."; - OPENFHE_THROW(msg); + OPENFHE_THROW("No polynomials in input share(s)."); } std::vector> result = sharesPairVec[0]; @@ -409,8 +405,7 @@ Ciphertext MultipartyCKKSRNS::IntMPBootEncrypt(const PublicKey a, ConstCiphertext ciphertext) const { if (ciphertext->NumberCiphertextElements() == 0) { - std::string msg = "IntMPBootEncrypt: no polynomials in the input ciphertext."; - OPENFHE_THROW(msg); + OPENFHE_THROW("No polynomials in the input ciphertext."); } auto cc = ciphertext->GetCryptoContext(); diff --git a/src/pke/lib/scheme/ckksrns/ckksrns-pke.cpp b/src/pke/lib/scheme/ckksrns/ckksrns-pke.cpp index cd011803c..7d01ee5f6 100644 --- a/src/pke/lib/scheme/ckksrns/ckksrns-pke.cpp +++ b/src/pke/lib/scheme/ckksrns/ckksrns-pke.cpp @@ -83,7 +83,7 @@ DecryptResult PKECKKSRNS::Decrypt(ConstCiphertext ciphertext, const Pr const size_t sizeQl = b.GetParams()->GetParams().size(); if (sizeQl == 0) - OPENFHE_THROW("Decryption failure: No towers left; consider increasing the depth."); + OPENFHE_THROW("No towers left; consider increasing the depth."); if (sizeQl == 1) { *plaintext = Poly(b.GetElementAtIndex(0), Format::COEFFICIENT); diff --git a/src/pke/lib/schemebase/base-advancedshe.cpp b/src/pke/lib/schemebase/base-advancedshe.cpp index 78a7ca5ae..c69763948 100644 --- a/src/pke/lib/schemebase/base-advancedshe.cpp +++ b/src/pke/lib/schemebase/base-advancedshe.cpp @@ -245,7 +245,7 @@ Ciphertext AdvancedSHEBase::EvalSum(ConstCiphertext c if ((encodingParams->GetBatchSize() == 0)) OPENFHE_THROW( - "EvalSum: Packed encoding parameters 'batch size' is not set; " + "Packed encoding parameters 'batch size' is not set; " "Please check the EncodingParams passed to the crypto context."); usint m = cryptoParams->GetElementParams()->GetCyclotomicOrder(); @@ -261,7 +261,7 @@ Ciphertext AdvancedSHEBase::EvalSum(ConstCiphertext c else { // Arbitrary cyclotomics if (encodingParams->GetPlaintextGenerator() == 0) { OPENFHE_THROW( - "EvalSum: Packed encoding parameters 'plaintext " + "Packed encoding parameters 'plaintext " "generator' is not set; Please check the " "EncodingParams passed to the crypto context."); } diff --git a/src/pke/lib/schemerns/rns-leveledshe.cpp b/src/pke/lib/schemerns/rns-leveledshe.cpp index ddcc1a9ee..51d13290b 100644 --- a/src/pke/lib/schemerns/rns-leveledshe.cpp +++ b/src/pke/lib/schemerns/rns-leveledshe.cpp @@ -337,7 +337,7 @@ void LeveledSHERNS::LevelReduceInPlace(Ciphertext& ciphertext, const E size_t levels) const { auto st = std::dynamic_pointer_cast(ciphertext->GetCryptoParameters())->GetScalingTechnique(); if (st == NORESCALE) - OPENFHE_THROW("LevelReduceInPlace is not implemented for NORESCALE rescaling technique"); + OPENFHE_THROW("Not implemented for NORESCALE rescaling technique"); if (st == FIXEDMANUAL && levels > 0) LevelReduceInternalInPlace(ciphertext, levels); } diff --git a/src/pke/unittest/utckksrns/UnitTestBootstrap.cpp b/src/pke/unittest/utckksrns/UnitTestBootstrap.cpp index 2abb3e305..8cc3f611a 100644 --- a/src/pke/unittest/utckksrns/UnitTestBootstrap.cpp +++ b/src/pke/unittest/utckksrns/UnitTestBootstrap.cpp @@ -813,7 +813,7 @@ class UTCKKSRNS_BOOT : public ::testing::TestWithParam result->SetLength(8); checkEquality(ptxt->GetCKKSPackedValue(), result->GetCKKSPackedValue(), eps, - failmsg + " input/output missmatch"); + failmsg + " input/output mismatch"); } catch (std::exception& e) { std::cerr << "Exception thrown from " << __func__ << "(): " << e.what() << std::endl;