Program Listing for File base-fhe.h

Return to documentation for file (pke/include/schemebase/base-fhe.h)

//==================================================================================
// BSD 2-Clause License
//
// Copyright (c) 2014-2022, NJIT, Duality Technologies Inc. and other contributors
//
// All rights reserved.
//
// Author TPOC: contact@openfhe.org
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this
//    list of conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright notice,
//    this list of conditions and the following disclaimer in the documentation
//    and/or other materials provided with the distribution.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//==================================================================================

#ifndef LBCRYPTO_CRYPTO_BASE_FHE_H
#define LBCRYPTO_CRYPTO_BASE_FHE_H

#include "binfhecontext.h"
#include "ciphertext-fwd.h"
#include "cryptocontext-fwd.h"
#include "key/evalkey-fwd.h"
#include "key/keypair.h"
#include "key/privatekey-fwd.h"
#include "scheme/scheme-swch-params.h"
#include "utils/exception.h"

#include <map>
#include <memory>
#include <tuple>
#include <utility>
#include <vector>

namespace lbcrypto {

template <class Element>
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;

    virtual void EvalBootstrapSetup(const CryptoContextImpl<Element>& cc, std::vector<uint32_t> levelBudget,
                                    std::vector<uint32_t> dim1, uint32_t slots, uint32_t correctionFactor,
                                    bool precompute, bool BTSlotsEncoding) {
        OPENFHE_THROW(NOT_SUPPORTED_SIMPLE_ERROR);
    }

    virtual std::shared_ptr<std::map<uint32_t, EvalKey<Element>>> EvalBootstrapKeyGen(
        const PrivateKey<Element> privateKey, uint32_t slots) {
        OPENFHE_THROW(NOT_SUPPORTED_SIMPLE_ERROR);
    }

    virtual void EvalBootstrapPrecompute(const CryptoContextImpl<Element>& cc, uint32_t slots) {
        OPENFHE_THROW(NOT_SUPPORTED_SIMPLE_ERROR);
    }

    virtual Ciphertext<Element> EvalBootstrap(ConstCiphertext<Element>& ciphertext, uint32_t numIterations,
                                              uint32_t precision) const {
        OPENFHE_THROW(NOT_IMPLEMENTED_ERROR);
    }

    virtual Ciphertext<Element> EvalBootstrapStCFirst(ConstCiphertext<Element>& ciphertext, uint32_t numIterations,
                                                      uint32_t precision) const {
        OPENFHE_THROW(NOT_SUPPORTED_SIMPLE_ERROR);
    }

    virtual void EvalFBTSetup(const CryptoContextImpl<Element>& cc, const std::vector<std::complex<double>>& coeffs,
                              uint32_t numSlots, const BigInteger& PIn, const BigInteger& POut, const BigInteger& Bigq,
                              const PublicKey<DCRTPoly>& pubKey, const std::vector<uint32_t>& dim1,
                              const std::vector<uint32_t>& levelBudget, uint32_t lvlsAfterBoot = 0,
                              uint32_t depthLeveledComputation = 0, size_t order = 1) {
        OPENFHE_THROW(NOT_SUPPORTED_SIMPLE_ERROR);
    }
    virtual void EvalFBTSetup(const CryptoContextImpl<Element>& cc, const std::vector<int64_t>& coeffs,
                              uint32_t numSlots, const BigInteger& PIn, const BigInteger& POut, const BigInteger& Bigq,
                              const PublicKey<DCRTPoly>& pubKey, const std::vector<uint32_t>& dim1,
                              const std::vector<uint32_t>& levelBudget, uint32_t lvlsAfterBoot = 0,
                              uint32_t depthLeveledComputation = 0, size_t order = 1) {
        OPENFHE_THROW(NOT_SUPPORTED_SIMPLE_ERROR);
    }

    virtual Ciphertext<Element> EvalFBT(ConstCiphertext<DCRTPoly>& ciphertext,
                                        const std::vector<std::complex<double>>& coeffs, uint32_t digitBitSize,
                                        const BigInteger& initialScaling, uint64_t postScaling,
                                        uint32_t levelToReduce = 0, size_t order = 1) {
        OPENFHE_THROW(NOT_SUPPORTED_SIMPLE_ERROR);
    }
    virtual Ciphertext<Element> EvalFBT(ConstCiphertext<DCRTPoly>& ciphertext, const std::vector<int64_t>& coeffs,
                                        uint32_t digitBitSize, const BigInteger& initialScaling, uint64_t postScaling,
                                        uint32_t levelToReduce = 0, size_t order = 1) {
        OPENFHE_THROW(NOT_SUPPORTED_SIMPLE_ERROR);
    }

    virtual Ciphertext<Element> EvalFBTNoDecoding(ConstCiphertext<DCRTPoly>& ciphertext,
                                                  const std::vector<std::complex<double>>& coeffs,
                                                  uint32_t digitBitSize, const BigInteger& initialScaling,
                                                  size_t order = 1) {
        OPENFHE_THROW(NOT_SUPPORTED_SIMPLE_ERROR);
    }
    virtual Ciphertext<Element> EvalFBTNoDecoding(ConstCiphertext<DCRTPoly>& ciphertext,
                                                  const std::vector<int64_t>& coeffs, uint32_t digitBitSize,
                                                  const BigInteger& initialScaling, size_t order = 1) {
        OPENFHE_THROW(NOT_SUPPORTED_SIMPLE_ERROR);
    }

    virtual Ciphertext<Element> EvalHomDecoding(ConstCiphertext<DCRTPoly>& ciphertext, uint64_t postScaling,
                                                uint32_t levelToReduce = 0) {
        OPENFHE_THROW(NOT_SUPPORTED_SIMPLE_ERROR);
    }

    virtual std::shared_ptr<seriesPowers<DCRTPoly>> EvalMVBPrecompute(ConstCiphertext<DCRTPoly>& ciphertext,
                                                                      const std::vector<std::complex<double>>& coeffs,
                                                                      uint32_t digitBitSize,
                                                                      const BigInteger& initialScaling,
                                                                      size_t order = 1) {
        OPENFHE_THROW(NOT_SUPPORTED_SIMPLE_ERROR);
    }

    virtual std::shared_ptr<seriesPowers<DCRTPoly>> EvalMVBPrecompute(ConstCiphertext<DCRTPoly>& ciphertext,
                                                                      const std::vector<int64_t>& coeffs,
                                                                      uint32_t digitBitSize,
                                                                      const BigInteger& initialScaling,
                                                                      size_t order = 1) {
        OPENFHE_THROW(NOT_SUPPORTED_SIMPLE_ERROR);
    }

    virtual Ciphertext<Element> EvalMVB(const std::shared_ptr<seriesPowers<DCRTPoly>> ciphertexts,
                                        const std::vector<std::complex<double>>& coeffs, uint32_t digitBitSize,
                                        const uint64_t postScaling, uint32_t levelToReduce = 0, size_t order = 1) {
        OPENFHE_THROW(NOT_SUPPORTED_SIMPLE_ERROR);
    }
    virtual Ciphertext<Element> EvalMVB(const std::shared_ptr<seriesPowers<DCRTPoly>> ciphertexts,
                                        const std::vector<int64_t>& coeffs, uint32_t digitBitSize,
                                        const uint64_t postScaling, uint32_t levelToReduce = 0, size_t order = 1) {
        OPENFHE_THROW(NOT_SUPPORTED_SIMPLE_ERROR);
    }

    virtual Ciphertext<Element> EvalMVBNoDecoding(const std::shared_ptr<seriesPowers<DCRTPoly>> ciphertexts,
                                                  const std::vector<std::complex<double>>& coeffs,
                                                  uint32_t digitBitSize, size_t order = 1) {
        OPENFHE_THROW(NOT_SUPPORTED_SIMPLE_ERROR);
    }
    virtual Ciphertext<Element> EvalMVBNoDecoding(const std::shared_ptr<seriesPowers<DCRTPoly>> ciphertexts,
                                                  const std::vector<int64_t>& coeffs, uint32_t digitBitSize,
                                                  size_t order = 1) {
        OPENFHE_THROW(NOT_SUPPORTED_SIMPLE_ERROR);
    }

    virtual Ciphertext<DCRTPoly> EvalHermiteTrigSeries(ConstCiphertext<DCRTPoly>& ciphertext,
                                                       const std::vector<std::complex<double>>& coefficientsCheb,
                                                       double a, double b,
                                                       const std::vector<std::complex<double>>& coefficientsHerm,
                                                       size_t precomp = 0) {
        OPENFHE_THROW(NOT_SUPPORTED_SIMPLE_ERROR);
    }
    virtual Ciphertext<DCRTPoly> EvalHermiteTrigSeries(ConstCiphertext<DCRTPoly>& ciphertext,
                                                       const std::vector<std::complex<double>>& coefficientsCheb,
                                                       double a, double b, const std::vector<int64_t>& coefficientsHerm,
                                                       size_t precomp = 0) {
        OPENFHE_THROW(NOT_SUPPORTED_SIMPLE_ERROR);
    }

    virtual uint32_t GetCKKSBootCorrectionFactor() const {
        OPENFHE_THROW(NOT_SUPPORTED_SIMPLE_ERROR);
    }

    virtual void SetCKKSBootCorrectionFactor(uint32_t cf) {
        OPENFHE_THROW(NOT_SUPPORTED_SIMPLE_ERROR);
    }

    virtual LWEPrivateKey EvalCKKStoFHEWSetup(const SchSwchParams& params) {
        OPENFHE_THROW(NOT_SUPPORTED_ERROR);
    }

    virtual std::shared_ptr<std::map<uint32_t, EvalKey<Element>>> EvalCKKStoFHEWKeyGen(const KeyPair<Element>& keyPair,
                                                                                       ConstLWEPrivateKey& lwesk) {
        OPENFHE_THROW(NOT_SUPPORTED_ERROR);
    }

    virtual void EvalCKKStoFHEWPrecompute(const CryptoContextImpl<Element>& cc, double scale) {
        OPENFHE_THROW(NOT_SUPPORTED_ERROR);
    }

    virtual std::vector<std::shared_ptr<LWECiphertextImpl>> EvalCKKStoFHEW(ConstCiphertext<Element> ciphertext,
                                                                           uint32_t numCtxts) {
        OPENFHE_THROW(NOT_IMPLEMENTED_ERROR);
    }

    virtual void EvalFHEWtoCKKSSetup(const CryptoContextImpl<Element>& ccCKKS,
                                     const std::shared_ptr<BinFHEContext>& ccLWE, uint32_t numSlotsCKKS,
                                     uint32_t logQ) {
        OPENFHE_THROW(NOT_SUPPORTED_ERROR);
    }

    virtual std::shared_ptr<std::map<uint32_t, EvalKey<Element>>> EvalFHEWtoCKKSKeyGen(
        const KeyPair<Element>& keyPair, ConstLWEPrivateKey& lwesk, uint32_t numSlots = 0, uint32_t numCtxts = 0,
        uint32_t dim1 = 0, uint32_t L = 0) {
        OPENFHE_THROW(NOT_SUPPORTED_ERROR);
    }

    virtual void EvalCompareSwitchPrecompute(const CryptoContextImpl<Element>& ccCKKS, uint32_t pLWE, double scaleSign,
                                             bool unit) {
        OPENFHE_THROW(NOT_SUPPORTED_ERROR);
    }

    virtual Ciphertext<Element> EvalFHEWtoCKKS(std::vector<std::shared_ptr<LWECiphertextImpl>>& LWECiphertexts,
                                               uint32_t numCtxts, uint32_t numSlots, uint32_t p, double pmin,
                                               double pmax, uint32_t dim1) const {
        OPENFHE_THROW(NOT_IMPLEMENTED_ERROR);
    }

    virtual LWEPrivateKey EvalSchemeSwitchingSetup(const SchSwchParams& params) {
        OPENFHE_THROW(NOT_SUPPORTED_ERROR);
    }

    virtual std::shared_ptr<std::map<uint32_t, EvalKey<Element>>> EvalSchemeSwitchingKeyGen(
        const KeyPair<Element>& keyPair, ConstLWEPrivateKey& lwesk) {
        OPENFHE_THROW(NOT_SUPPORTED_ERROR);
    }

    virtual Ciphertext<Element> EvalCompareSchemeSwitching(ConstCiphertext<Element> ciphertext1,
                                                           ConstCiphertext<Element> ciphertext2, uint32_t numCtxts,
                                                           uint32_t numSlots, uint32_t pLWE, double scaleSign,
                                                           bool unit) {
        OPENFHE_THROW(NOT_SUPPORTED_ERROR);
    }

    virtual std::vector<Ciphertext<Element>> EvalMinSchemeSwitching(ConstCiphertext<Element> ciphertext,
                                                                    PublicKey<Element> publicKey, uint32_t numValues,
                                                                    uint32_t numSlots, uint32_t pLWE,
                                                                    double scaleSign) {
        OPENFHE_THROW(NOT_SUPPORTED_ERROR);
    }

    virtual std::vector<Ciphertext<Element>> EvalMinSchemeSwitchingAlt(ConstCiphertext<Element> ciphertext,
                                                                       PublicKey<Element> publicKey, uint32_t numValues,
                                                                       uint32_t numSlots, uint32_t pLWE,
                                                                       double scaleSign) {
        OPENFHE_THROW(NOT_SUPPORTED_ERROR);
    }

    virtual std::vector<Ciphertext<Element>> EvalMaxSchemeSwitching(ConstCiphertext<Element> ciphertext,
                                                                    PublicKey<Element> publicKey, uint32_t numValues,
                                                                    uint32_t numSlots, uint32_t pLWE,
                                                                    double scaleSign) {
        OPENFHE_THROW(NOT_SUPPORTED_ERROR);
    }

    virtual std::vector<Ciphertext<Element>> EvalMaxSchemeSwitchingAlt(ConstCiphertext<Element> ciphertext,
                                                                       PublicKey<Element> publicKey, uint32_t numValues,
                                                                       uint32_t numSlots, uint32_t pLWE,
                                                                       double scaleSign) {
        OPENFHE_THROW(NOT_SUPPORTED_ERROR);
    }

    virtual std::shared_ptr<lbcrypto::BinFHEContext> GetBinCCForSchemeSwitch() {
        OPENFHE_THROW(NOT_SUPPORTED_ERROR);
    }
    virtual void SetBinCCForSchemeSwitch(std::shared_ptr<lbcrypto::BinFHEContext> ccLWE) {
        OPENFHE_THROW(NOT_SUPPORTED_ERROR);
    }

    virtual Ciphertext<Element> GetSwkFC() {
        OPENFHE_THROW(NOT_SUPPORTED_ERROR);
    }
    virtual void SetSwkFC(Ciphertext<Element> FHEWtoCKKSswk) {
        OPENFHE_THROW(NOT_SUPPORTED_ERROR);
    }

    // SERIALIZATION

    template <class Archive>
    void save(Archive& ar) const {}

    template <class Archive>
    void load(Archive& ar) {}
};

}  // namespace lbcrypto

#endif