Program Listing for File base-advancedshe.h
↰ Return to documentation for file (pke/include/schemebase/base-advancedshe.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_ADVANCEDSHE_H
#define LBCRYPTO_CRYPTO_BASE_ADVANCEDSHE_H
#include "ciphertext-fwd.h"
#include "encoding/plaintext-fwd.h"
#include "key/evalkey-fwd.h"
#include "key/privatekey-fwd.h"
#include "key/publickey-fwd.h"
#include "utils/exception.h"
#include "utils/inttypes.h"
#include <complex>
#include <map>
#include <memory>
#include <set>
#include <string>
#include <vector>
namespace lbcrypto {
template <class Element>
class AdvancedSHEBase {
using ParmType = typename Element::Params;
using IntType = typename Element::Integer;
using DugType = typename Element::DugType;
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;
virtual Ciphertext<Element> EvalAddMany(const std::vector<Ciphertext<Element>>& ciphertextVec) const;
virtual Ciphertext<Element> EvalAddManyInPlace(std::vector<Ciphertext<Element>>& ciphertextVec) const;
virtual Ciphertext<Element> EvalMultMany(const std::vector<Ciphertext<Element>>& ciphertextVec,
const std::vector<EvalKey<Element>>& evalKeyVec) const;
//------------------------------------------------------------------------------
// LINEAR WEIGHTED SUM
//------------------------------------------------------------------------------
virtual Ciphertext<Element> EvalLinearWSum(std::vector<ReadOnlyCiphertext<Element>>& ciphertextVec,
const std::vector<int64_t>& weights) const {
OPENFHE_THROW(NOT_IMPLEMENTED_ERROR);
}
virtual Ciphertext<Element> EvalLinearWSum(std::vector<ReadOnlyCiphertext<Element>>& ciphertextVec,
const std::vector<double>& weights) const {
OPENFHE_THROW(NOT_IMPLEMENTED_ERROR);
}
virtual Ciphertext<Element> EvalLinearWSum(std::vector<ReadOnlyCiphertext<Element>>& ciphertextVec,
const std::vector<std::complex<double>>& weights) const {
OPENFHE_THROW(NOT_IMPLEMENTED_ERROR);
}
virtual Ciphertext<Element> EvalLinearWSumMutable(std::vector<Ciphertext<Element>>& ciphertextVec,
const std::vector<int64_t>& weights) const {
OPENFHE_THROW(NOT_IMPLEMENTED_ERROR);
}
virtual Ciphertext<Element> EvalLinearWSumMutable(std::vector<Ciphertext<Element>>& ciphertextVec,
const std::vector<double>& weights) const {
OPENFHE_THROW(NOT_IMPLEMENTED_ERROR);
}
virtual Ciphertext<Element> EvalLinearWSumMutable(std::vector<Ciphertext<Element>>& ciphertextVec,
const std::vector<std::complex<double>>& weights) const {
OPENFHE_THROW(NOT_IMPLEMENTED_ERROR);
}
//------------------------------------------------------------------------------
// EVAL POLYNOMIAL
//------------------------------------------------------------------------------
virtual std::shared_ptr<seriesPowers<Element>> EvalPowers(ConstCiphertext<Element>& ciphertext,
const std::vector<int64_t>& coefficients) const {
OPENFHE_THROW(NOT_IMPLEMENTED_ERROR);
}
virtual std::shared_ptr<seriesPowers<Element>> EvalPowers(ConstCiphertext<Element>& ciphertext,
const std::vector<double>& coefficients) const {
OPENFHE_THROW(NOT_IMPLEMENTED_ERROR);
}
virtual std::shared_ptr<seriesPowers<Element>> EvalPowers(
ConstCiphertext<Element>& ciphertext, const std::vector<std::complex<double>>& coefficients) const {
OPENFHE_THROW(NOT_IMPLEMENTED_ERROR);
}
virtual Ciphertext<Element> EvalPoly(ConstCiphertext<Element>& ciphertext,
const std::vector<int64_t>& coefficients) const {
OPENFHE_THROW(NOT_IMPLEMENTED_ERROR);
}
virtual Ciphertext<Element> EvalPoly(ConstCiphertext<Element>& ciphertext,
const std::vector<double>& coefficients) const {
OPENFHE_THROW(NOT_IMPLEMENTED_ERROR);
}
virtual Ciphertext<Element> EvalPoly(ConstCiphertext<Element>& ciphertext,
const std::vector<std::complex<double>>& coefficients) const {
OPENFHE_THROW(NOT_IMPLEMENTED_ERROR);
}
virtual Ciphertext<Element> EvalPolyWithPrecomp(std::shared_ptr<seriesPowers<Element>> powers,
const std::vector<int64_t>& coefficients) const {
OPENFHE_THROW(NOT_IMPLEMENTED_ERROR);
}
virtual Ciphertext<Element> EvalPolyWithPrecomp(std::shared_ptr<seriesPowers<Element>> powers,
const std::vector<double>& coefficients) const {
OPENFHE_THROW(NOT_IMPLEMENTED_ERROR);
}
virtual Ciphertext<Element> EvalPolyWithPrecomp(std::shared_ptr<seriesPowers<Element>> powers,
const std::vector<std::complex<double>>& coefficients) const {
OPENFHE_THROW(NOT_IMPLEMENTED_ERROR);
}
virtual Ciphertext<Element> EvalPolyLinear(ConstCiphertext<Element>& ciphertext,
const std::vector<int64_t>& coefficients) const {
OPENFHE_THROW(NOT_IMPLEMENTED_ERROR);
}
virtual Ciphertext<Element> EvalPolyLinear(ConstCiphertext<Element>& ciphertext,
const std::vector<double>& coefficients) const {
OPENFHE_THROW(NOT_IMPLEMENTED_ERROR);
}
virtual Ciphertext<Element> EvalPolyLinear(ConstCiphertext<Element>& ciphertext,
const std::vector<std::complex<double>>& coefficients) const {
OPENFHE_THROW(NOT_IMPLEMENTED_ERROR);
}
virtual Ciphertext<Element> EvalPolyPS(ConstCiphertext<Element>& x,
const std::vector<int64_t>& coefficients) const {
OPENFHE_THROW(NOT_IMPLEMENTED_ERROR);
}
virtual Ciphertext<Element> EvalPolyPS(ConstCiphertext<Element>& x, const std::vector<double>& coefficients) const {
OPENFHE_THROW(NOT_IMPLEMENTED_ERROR);
}
virtual Ciphertext<Element> EvalPolyPS(ConstCiphertext<Element>& x,
const std::vector<std::complex<double>>& coefficients) const {
OPENFHE_THROW(NOT_IMPLEMENTED_ERROR);
}
//------------------------------------------------------------------------------
// EVAL CHEBYSHEV SERIES
//------------------------------------------------------------------------------
virtual std::shared_ptr<seriesPowers<Element>> EvalChebyPolys(ConstCiphertext<Element>& ciphertext,
const std::vector<int64_t>& coefficients, double a,
double b) const {
OPENFHE_THROW(NOT_IMPLEMENTED_ERROR);
}
virtual std::shared_ptr<seriesPowers<Element>> EvalChebyPolys(ConstCiphertext<Element>& ciphertext,
const std::vector<double>& coefficients, double a,
double b) const {
OPENFHE_THROW(NOT_IMPLEMENTED_ERROR);
}
virtual std::shared_ptr<seriesPowers<Element>> EvalChebyPolys(ConstCiphertext<Element>& ciphertext,
const std::vector<std::complex<double>>& coefficients,
double a, double b) const {
OPENFHE_THROW(NOT_IMPLEMENTED_ERROR);
}
virtual Ciphertext<Element> EvalChebyshevSeries(ConstCiphertext<Element>& ciphertext,
const std::vector<int64_t>& coefficients, double a,
double b) const {
OPENFHE_THROW(NOT_IMPLEMENTED_ERROR);
}
virtual Ciphertext<Element> EvalChebyshevSeries(ConstCiphertext<Element>& ciphertext,
const std::vector<double>& coefficients, double a, double b) const {
OPENFHE_THROW(NOT_IMPLEMENTED_ERROR);
}
virtual Ciphertext<Element> EvalChebyshevSeries(ConstCiphertext<Element>& ciphertext,
const std::vector<std::complex<double>>& coefficients, double a,
double b) const {
OPENFHE_THROW(NOT_IMPLEMENTED_ERROR);
}
virtual Ciphertext<Element> EvalChebyshevSeriesWithPrecomp(std::shared_ptr<seriesPowers<Element>> polys,
const std::vector<int64_t>& coefficients) const {
OPENFHE_THROW(NOT_IMPLEMENTED_ERROR);
}
virtual Ciphertext<Element> EvalChebyshevSeriesWithPrecomp(std::shared_ptr<seriesPowers<Element>> polys,
const std::vector<double>& coefficients) const {
OPENFHE_THROW(NOT_IMPLEMENTED_ERROR);
}
virtual Ciphertext<Element> EvalChebyshevSeriesWithPrecomp(
std::shared_ptr<seriesPowers<Element>> polys, const std::vector<std::complex<double>>& coefficients) const {
OPENFHE_THROW(NOT_IMPLEMENTED_ERROR);
}
virtual Ciphertext<Element> EvalChebyshevSeriesLinear(ConstCiphertext<Element>& ciphertext,
const std::vector<int64_t>& coefficients, double a,
double b) const {
OPENFHE_THROW(NOT_IMPLEMENTED_ERROR);
}
virtual Ciphertext<Element> EvalChebyshevSeriesLinear(ConstCiphertext<Element>& ciphertext,
const std::vector<double>& coefficients, double a,
double b) const {
OPENFHE_THROW(NOT_IMPLEMENTED_ERROR);
}
virtual Ciphertext<Element> EvalChebyshevSeriesLinear(ConstCiphertext<Element>& ciphertext,
const std::vector<std::complex<double>>& coefficients,
double a, double b) const {
OPENFHE_THROW(NOT_IMPLEMENTED_ERROR);
}
virtual Ciphertext<Element> EvalChebyshevSeriesPS(ConstCiphertext<Element>& ciphertext,
const std::vector<int64_t>& coefficients, double a,
double b) const {
OPENFHE_THROW(NOT_IMPLEMENTED_ERROR);
}
virtual Ciphertext<Element> EvalChebyshevSeriesPS(ConstCiphertext<Element>& ciphertext,
const std::vector<double>& coefficients, double a,
double b) const {
OPENFHE_THROW(NOT_IMPLEMENTED_ERROR);
}
virtual Ciphertext<Element> EvalChebyshevSeriesPS(ConstCiphertext<Element>& ciphertext,
const std::vector<std::complex<double>>& coefficients, double a,
double b) const {
OPENFHE_THROW(NOT_IMPLEMENTED_ERROR);
}
//------------------------------------------------------------------------------
// Advanced SHE EVAL SUM
//------------------------------------------------------------------------------
virtual std::shared_ptr<std::map<uint32_t, EvalKey<Element>>> EvalSumKeyGen(
const PrivateKey<Element> privateKey) const;
virtual std::shared_ptr<std::map<uint32_t, EvalKey<Element>>> EvalSumRowsKeyGen(
const PrivateKey<Element> privateKey, uint32_t rowSize, uint32_t subringDim,
std::vector<uint32_t>& indices) const;
virtual std::shared_ptr<std::map<uint32_t, EvalKey<Element>>> EvalSumColsKeyGen(
const PrivateKey<Element> privateKey, std::vector<uint32_t>& indices) const;
virtual Ciphertext<Element> EvalSum(ConstCiphertext<Element> ciphertext, uint32_t batchSize,
const std::map<uint32_t, EvalKey<Element>>& evalSumKeyMap) const;
virtual Ciphertext<Element> EvalSumRows(ConstCiphertext<Element> ciphertext, uint32_t numRows,
const std::map<uint32_t, EvalKey<Element>>& evalSumKeys,
uint32_t subringDim) const;
virtual Ciphertext<Element> EvalSumCols(ConstCiphertext<Element> ciphertext, uint32_t numCols,
const std::map<uint32_t, EvalKey<Element>>& evalSumKeys,
const std::map<uint32_t, EvalKey<Element>>& rightEvalKeys) const;
//------------------------------------------------------------------------------
// Advanced SHE EVAL INNER PRODUCT
//------------------------------------------------------------------------------
virtual Ciphertext<Element> EvalInnerProduct(ConstCiphertext<Element> ciphertext1,
ConstCiphertext<Element> ciphertext2, uint32_t batchSize,
const std::map<uint32_t, EvalKey<Element>>& evalKeyMap,
const EvalKey<Element> evalMultKey) const;
virtual Ciphertext<Element> EvalInnerProduct(ConstCiphertext<Element> ciphertext, ConstPlaintext plaintext,
uint32_t batchSize,
const std::map<uint32_t, EvalKey<Element>>& evalKeyMap) const;
virtual Ciphertext<Element> AddRandomNoise(ConstCiphertext<Element> ciphertext) const;
virtual Ciphertext<Element> EvalMerge(const std::vector<Ciphertext<Element>>& ciphertextVector,
const std::map<uint32_t, EvalKey<Element>>& evalKeyMap) const;
//------------------------------------------------------------------------------
// LINEAR TRANSFORMATION
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
// Other Methods for Bootstrap
//------------------------------------------------------------------------------
protected:
std::set<uint32_t> GenerateIndices_2n(uint32_t batchSize, uint32_t m) const;
std::set<uint32_t> GenerateIndices2nComplex(uint32_t batchSize, uint32_t m) const;
std::set<uint32_t> GenerateIndices2nComplexRows(uint32_t rowSize, uint32_t m) const;
std::set<uint32_t> GenerateIndices2nComplexCols(uint32_t batchSize, uint32_t m) const;
std::set<uint32_t> GenerateIndexListForEvalSum(const PrivateKey<Element>& privateKey) const;
Ciphertext<Element> EvalSum_2n(ConstCiphertext<Element> ciphertext, uint32_t batchSize, uint32_t m,
const std::map<uint32_t, EvalKey<Element>>& evalKeyMap) const;
Ciphertext<Element> EvalSum2nComplex(ConstCiphertext<Element> ciphertext, uint32_t batchSize, uint32_t m,
const std::map<uint32_t, EvalKey<Element>>& evalKeyMap) const;
Ciphertext<Element> EvalSum2nComplexRows(ConstCiphertext<Element> ciphertext, uint32_t rowSize, uint32_t m,
const std::map<uint32_t, EvalKey<Element>>& evalKeyMap) const;
Ciphertext<Element> EvalSum2nComplexCols(ConstCiphertext<Element> ciphertext, uint32_t batchSize, uint32_t m,
const std::map<uint32_t, EvalKey<Element>>& evalKeyMap) const;
};
} // namespace lbcrypto
#endif