Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/binfhe/include/rgsw-acc.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class RingGSWAccumulator {
*/
virtual RingGSWACCKey KeyGenAcc(const std::shared_ptr<RingGSWCryptoParams>& params, const NativePoly& skNTT,
ConstLWEPrivateKey& LWEsk) const {
OPENFHE_THROW("KeyGenACC operation not supported");
OPENFHE_THROW("Operation not supported");
}

/**
Expand All @@ -72,7 +72,7 @@ class RingGSWAccumulator {
*/
virtual void EvalAcc(const std::shared_ptr<RingGSWCryptoParams>& params, ConstRingGSWACCKey& ek,
RLWECiphertext& acc, const NativeVector& a) const {
OPENFHE_THROW("ACC operation not supported");
OPENFHE_THROW("Operation not supported");
}

/**
Expand Down
20 changes: 7 additions & 13 deletions src/binfhe/lib/binfhe-base-scheme.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -262,9 +262,7 @@ LWECiphertext BinFHEScheme::EvalFunc(const std::shared_ptr<BinFHECryptoParams>&
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 :(
Expand Down Expand Up @@ -390,16 +388,15 @@ LWECiphertext BinFHEScheme::EvalSign(const std::shared_ptr<BinFHECryptoParams>&
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);
}

const auto& RGSWParams = params->GetRingGSWParams();
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);

Expand All @@ -426,8 +423,7 @@ LWECiphertext BinFHEScheme::EvalSign(const std::shared_ptr<BinFHECryptoParams>&

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;
}
Expand Down Expand Up @@ -470,15 +466,14 @@ std::vector<LWECiphertext> BinFHEScheme::EvalDecomp(const std::shared_ptr<BinFHE
NativeInteger q = LWEParams->Getq();
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);

Expand Down Expand Up @@ -508,8 +503,7 @@ std::vector<LWECiphertext> BinFHEScheme::EvalDecomp(const std::shared_ptr<BinFHE

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;
}
Expand Down
9 changes: 3 additions & 6 deletions src/binfhe/lib/lwe-pke.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,7 @@ LWEPublicKey LWEEncryptionScheme::PubKeyGen(const std::shared_ptr<LWECryptoParam
LWECiphertext LWEEncryptionScheme::Encrypt(const std::shared_ptr<LWECryptoParams>& 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();
Expand Down Expand Up @@ -133,8 +132,7 @@ LWECiphertext LWEEncryptionScheme::Encrypt(const std::shared_ptr<LWECryptoParams
LWECiphertext LWEEncryptionScheme::EncryptN(const std::shared_ptr<LWECryptoParams>& 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();
Expand Down Expand Up @@ -187,8 +185,7 @@ void LWEEncryptionScheme::Decrypt(const std::shared_ptr<LWECryptoParams>& 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();
Expand Down
12 changes: 3 additions & 9 deletions src/core/include/lattice/field2n-impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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];
Expand All @@ -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);
Expand Down
28 changes: 15 additions & 13 deletions src/core/include/lattice/hal/dcrtpoly-interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ namespace lbcrypto {
template <typename DerivedType, typename BigVecType, typename LilVecType,
template <typename LVT> typename RNSContainerType>
class DCRTPolyInterface : public ILElement<DerivedType, BigVecType> {
constexpr static std::string_view NOT_IMPLEMENTED_ERROR = "This function is not implemented for DCRTPoly";

public:
using BigIntType = typename BigVecType::Integer;
using Params = ILDCRTParams<BigIntType>;
Expand Down Expand Up @@ -259,10 +261,10 @@ class DCRTPolyInterface : public ILElement<DerivedType, BigVecType> {
* @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);
}

/**
Expand All @@ -271,10 +273,10 @@ class DCRTPolyInterface : public ILElement<DerivedType, BigVecType> {
* @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);
}

/**
Expand Down Expand Up @@ -656,7 +658,7 @@ class DCRTPolyInterface : public ILElement<DerivedType, BigVecType> {
* @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);
}

/**
Expand All @@ -669,7 +671,7 @@ class DCRTPolyInterface : public ILElement<DerivedType, BigVecType> {
* @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);
}

/**
Expand Down Expand Up @@ -725,7 +727,7 @@ class DCRTPolyInterface : public ILElement<DerivedType, BigVecType> {
* @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);
}

/**
Expand All @@ -738,7 +740,7 @@ class DCRTPolyInterface : public ILElement<DerivedType, BigVecType> {
* @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);
}

/**
Expand All @@ -749,7 +751,7 @@ class DCRTPolyInterface : public ILElement<DerivedType, BigVecType> {
* @warning Doesn't make sense for DCRT
*/
const BigVecType& GetValues() const final {
OPENFHE_THROW("GetValues not implemented for DCRTPoly");
OPENFHE_THROW(NOT_IMPLEMENTED_ERROR);
}

/**
Expand All @@ -761,7 +763,7 @@ class DCRTPolyInterface : public ILElement<DerivedType, BigVecType> {
* @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);
}

/**
Expand All @@ -786,7 +788,7 @@ class DCRTPolyInterface : public ILElement<DerivedType, BigVecType> {
* @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);
}

/**
Expand All @@ -798,7 +800,7 @@ class DCRTPolyInterface : public ILElement<DerivedType, BigVecType> {
* @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);
}

/**
Expand Down Expand Up @@ -1392,7 +1394,7 @@ class DCRTPolyInterface : public ILElement<DerivedType, BigVecType> {
*/
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);
}

/**
Expand Down
16 changes: 8 additions & 8 deletions src/core/include/lattice/hal/default/dcrtpoly-impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -652,9 +652,9 @@ template <typename VecType>
void DCRTPolyImpl<VecType>::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);
Expand All @@ -671,7 +671,7 @@ void DCRTPolyImpl<VecType>::SetValuesModSwitch(const DCRTPolyImpl& element, cons
template <typename VecType>
void DCRTPolyImpl<VecType>::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)
Expand All @@ -690,9 +690,9 @@ bool DCRTPolyImpl<VecType>::IsEmpty() const {
template <typename VecType>
void DCRTPolyImpl<VecType>::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();
Expand All @@ -702,7 +702,7 @@ void DCRTPolyImpl<VecType>::DropLastElement() {
template <typename VecType>
void DCRTPolyImpl<VecType>::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)
Expand Down Expand Up @@ -788,7 +788,7 @@ void DCRTPolyImpl<VecType>::ModReduce(const NativeInteger& t, const std::vector<
template <typename VecType>
typename DCRTPolyImpl<VecType>::PolyLargeType DCRTPolyImpl<VecType>::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()};
Expand Down Expand Up @@ -826,7 +826,7 @@ typename DCRTPolyImpl<VecType>::PolyLargeType DCRTPolyImpl<VecType>::CRTInterpol
template <typename VecType>
typename DCRTPolyImpl<VecType>::PolyLargeType DCRTPolyImpl<VecType>::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()};
Expand Down
10 changes: 5 additions & 5 deletions src/core/include/lattice/hal/default/dcrtpoly.h
Original file line number Diff line number Diff line change
Expand Up @@ -152,14 +152,14 @@ class DCRTPolyImpl final : public DCRTPolyInterface<DCRTPolyImpl<VecType>, VecTy
DCRTPolyType Plus(const std::vector<Integer>& 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)
Expand All @@ -173,14 +173,14 @@ class DCRTPolyImpl final : public DCRTPolyInterface<DCRTPolyImpl<VecType>, 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)
Expand Down
14 changes: 7 additions & 7 deletions src/core/include/lattice/hal/default/poly.h
Original file line number Diff line number Diff line change
Expand Up @@ -221,11 +221,11 @@ class PolyImpl final : public PolyInterface<PolyImpl<VecType>, 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;
Expand Down Expand Up @@ -253,9 +253,9 @@ class PolyImpl final : public PolyInterface<PolyImpl<VecType>, 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);
Expand All @@ -269,9 +269,9 @@ class PolyImpl final : public PolyInterface<PolyImpl<VecType>, 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) {
Expand Down
Loading