Palisade pke scheme headers

文章目录

  • Palisade pke scheme headers
  • \pke\include\scheme\rlwe.h
  • \pke\include\scheme\allscheme.h
  • \pke\include\scheme\bfvrns.h
    • LPCryptoParametersBFVrns 类
    • LPAlgorithmParamsGenBFVrns 类
    • LPAlgorithmBFVrns 类
    • LPAlgorithmSHEBFVrns 类
    • LPAlgorithmPREBFVrns 类
    • LPAlgorithmMultipartyBFVrns 类
    • LPPublicKeyEncryptionSchemeBFVrns 类

\pke\include\scheme\rlwe.h

继承自 LPCryptoParameters

#include <memory>
#include <string>#include "lattice/dcrtpoly.h"
#include "lattice/poly.h"
#include "lattice/stdlatticeparms.h"
#include "utils/serializable.h"namespace lbcrypto {// noise flooding distribution parameter
// for distributed decryption in
// threshold FHE
const double MP_SD = 1048576;/*** @brief Template for crypto parameters.* @tparam Element a ring element.*/
template <class Element>
class LPCryptoParametersRLWE : public LPCryptoParameters<Element> {public:/*** Default Constructor*/LPCryptoParametersRLWE() : LPCryptoParameters<Element>() {m_distributionParameter = 0.0f;m_assuranceMeasure = 0.0f;m_securityLevel = 0.0f;m_relinWindow = 1;m_dgg.SetStd(m_distributionParameter);m_depth = 0;m_maxDepth = 2;m_mode = RLWE;m_stdLevel = HEStd_NotSet;}/*** Copy constructor.**/LPCryptoParametersRLWE(const LPCryptoParametersRLWE &rhs): LPCryptoParameters<Element>(rhs.GetElementParams(),rhs.GetPlaintextModulus()) {m_distributionParameter = rhs.m_distributionParameter;m_assuranceMeasure = rhs.m_assuranceMeasure;m_securityLevel = rhs.m_securityLevel;m_relinWindow = rhs.m_relinWindow;m_dgg.SetStd(m_distributionParameter);m_depth = rhs.m_depth;m_maxDepth = rhs.m_maxDepth;m_mode = rhs.m_mode;m_stdLevel = rhs.m_stdLevel;}/*** Constructor that initializes values.** @param &params element parameters.* @param &encodingParams encoding-specific parameters* @param distributionParameter noise distribution parameter.* @param assuranceMeasure assurance level.* @param securityLevel security level.* @param relinWindow the size of the relinearization window.* @param depth is the depth of computation circuit supported for these* parameters (not used now; for future use).* @param maxDepth the maximum power of secret key for which the* relinearization key is generated* @param mode mode for secret polynomial, defaults to RLWE.*/LPCryptoParametersRLWE(shared_ptr<typename Element::Params> params,EncodingParams encodingParams,float distributionParameter, float assuranceMeasure,float securityLevel, usint relinWindow, int depth = 1,int maxDepth = 2, MODE mode = RLWE): LPCryptoParameters<Element>(params, encodingParams) {m_distributionParameter = distributionParameter;m_assuranceMeasure = assuranceMeasure;m_securityLevel = securityLevel;m_relinWindow = relinWindow;m_dgg.SetStd(m_distributionParameter);m_depth = depth;m_maxDepth = maxDepth;m_mode = mode;m_stdLevel = HEStd_NotSet;}/*** Constructor that initializes values - uses HomomorphicEncryption.org* standard security levels** @param &params element parameters.* @param &encodingParams encoding-specific parameters* @param distributionParameter noise distribution parameter.* @param assuranceMeasure assurance level.* @param securityLevel security level.* @param relinWindow the size of the relinearization window.* @param depth is the depth of computation circuit supported for these* parameters (not used now; for future use).* @param maxDepth the maximum power of secret key for which the* relinearization key is generated* @param mode mode for secret polynomial, defaults to RLWE.*/LPCryptoParametersRLWE(shared_ptr<typename Element::Params> params,EncodingParams encodingParams,float distributionParameter, float assuranceMeasure,SecurityLevel stdLevel, usint relinWindow,int depth = 1, int maxDepth = 2, MODE mode = RLWE): LPCryptoParameters<Element>(params, encodingParams) {m_distributionParameter = distributionParameter;m_assuranceMeasure = assuranceMeasure;m_securityLevel = 0;m_relinWindow = relinWindow;m_dgg.SetStd(m_distributionParameter);m_depth = depth;m_maxDepth = maxDepth;m_mode = mode;m_stdLevel = stdLevel;}/*** Destructor*/virtual ~LPCryptoParametersRLWE() {}/*** Returns the value of standard deviation r for discrete Gaussian* distribution** @return the standard deviation r.*/float GetDistributionParameter() const { return m_distributionParameter; }/*** Returns the values of assurance measure alpha** @return the assurance measure.*/float GetAssuranceMeasure() const { return m_assuranceMeasure; }/*** Returns the value of root Hermite factor security level /delta.** @return the root Hermite factor /delta.*/float GetSecurityLevel() const { return m_securityLevel; }/*** Returns the value of relinearization window.** @return the relinearization window.*/usint GetRelinWindow() const { return m_relinWindow; }/*** Returns the depth of computation circuit supported for these parameters* (not used now; for future use).** @return the computation depth supported d.*/int GetDepth() const { return m_depth; }/*** Returns the maximum homomorphic multiplication depth before performing* relinearization** @return the computation depth supported d.*/size_t GetMaxDepth() const { return m_maxDepth; }/*** Gets the mode setting: RLWE or OPTIMIZED.** @return the mode setting.*/MODE GetMode() const { return m_mode; }/*** Gets the standard security level** @return the security level.*/SecurityLevel GetStdLevel() const { return m_stdLevel; }/*** Returns reference to Discrete Gaussian Generator** @return reference to Discrete Gaussian Generaror.*/const typename Element::DggType &GetDiscreteGaussianGenerator() const {return m_dgg;}// @Set Properties/*** Sets the value of standard deviation r for discrete Gaussian distribution* @param distributionParameter*/void SetDistributionParameter(float distributionParameter) {m_distributionParameter = distributionParameter;m_dgg.SetStd(m_distributionParameter);}/*** Sets the values of assurance measure alpha* @param assuranceMeasure*/void SetAssuranceMeasure(float assuranceMeasure) {m_assuranceMeasure = assuranceMeasure;}/*** Sets the value of security level /delta* @param securityLevel*/void SetSecurityLevel(float securityLevel) {m_securityLevel = securityLevel;}/*** Sets the standard security level* @param standard security level*/void SetStdLevel(SecurityLevel securityLevel) { m_stdLevel = securityLevel; }/*** Sets the value of relinearization window* @param relinWindow*/void SetRelinWindow(usint relinWindow) { m_relinWindow = relinWindow; }/*** Sets the depth of computation circuit supported for these parameters (not* used now; for future use).* @param depth*/void SetDepth(int depth) { m_depth = depth; }/*** Sets the value of the maximum power of secret key for which the* relinearization key is generated* @param depth*/void SetMaxDepth(size_t maxDepth) { m_maxDepth = maxDepth; }/*** Configures the mode for generating the secret key polynomial* @param mode is RLWE or OPTIMIZED.*/void SetMode(MODE mode) { m_mode = mode; }/*** == operator to compare to this instance of LPCryptoParametersRLWE object.** @param &rhs LPCryptoParameters to check equality against.*/bool operator==(const LPCryptoParameters<Element> &rhs) const {const auto *el =dynamic_cast<const LPCryptoParametersRLWE<Element> *>(&rhs);if (el == nullptr) return false;return this->GetPlaintextModulus() == el->GetPlaintextModulus() &&*this->GetElementParams() == *el->GetElementParams() &&*this->GetEncodingParams() == *el->GetEncodingParams() &&m_distributionParameter == el->GetDistributionParameter() &&m_assuranceMeasure == el->GetAssuranceMeasure() &&m_securityLevel == el->GetSecurityLevel() &&m_relinWindow == el->GetRelinWindow() && m_mode == el->GetMode() &&m_stdLevel == el->GetStdLevel();}void PrintParameters(std::ostream &os) const {LPCryptoParameters<Element>::PrintParameters(os);os << "Distrib parm " << GetDistributionParameter()<< ", Assurance measure " << GetAssuranceMeasure() << ", Security level "<< GetSecurityLevel() << ", Relin window " << GetRelinWindow()<< ", Depth " << GetDepth() << ", Mode " << GetMode()<< ", Standard security level " << GetStdLevel() << std::endl;}template <class Archive>void save(Archive &ar, std::uint32_t const version) const {ar(::cereal::base_class<LPCryptoParameters<Element>>(this));ar(::cereal::make_nvp("dp", m_distributionParameter));ar(::cereal::make_nvp("am", m_assuranceMeasure));ar(::cereal::make_nvp("sl", m_securityLevel));ar(::cereal::make_nvp("rw", m_relinWindow));ar(::cereal::make_nvp("d", m_depth));ar(::cereal::make_nvp("md", m_maxDepth));ar(::cereal::make_nvp("mo", m_mode));ar(::cereal::make_nvp("slv", m_stdLevel));}template <class Archive>void load(Archive &ar, std::uint32_t const version) {ar(::cereal::base_class<LPCryptoParameters<Element>>(this));ar(::cereal::make_nvp("dp", m_distributionParameter));m_dgg.SetStd(m_distributionParameter);ar(::cereal::make_nvp("am", m_assuranceMeasure));ar(::cereal::make_nvp("sl", m_securityLevel));ar(::cereal::make_nvp("rw", m_relinWindow));ar(::cereal::make_nvp("d", m_depth));ar(::cereal::make_nvp("md", m_maxDepth));ar(::cereal::make_nvp("mo", m_mode));ar(::cereal::make_nvp("slv", m_stdLevel));}std::string SerializedObjectName() const { return "RLWESchemeParameters"; }protected:// standard deviation in Discrete Gaussian Distributionfloat m_distributionParameter;// assurance measure alphafloat m_assuranceMeasure;// root Hermite value /deltafloat m_securityLevel;// relinearization windowusint m_relinWindow;// depth of computations; used for FHEint m_depth;// maximum depth support of a ciphertext without keyswitching// corresponds to the highest power of secret key for which evaluation keys// are genererateduint32_t m_maxDepth;// specifies whether the secret polynomials are generated from discrete// Gaussian distribution or ternary distribution with the norm of unityMODE m_mode;// Security level according in the HomomorphicEncryption.org standardSecurityLevel m_stdLevel;typename Element::DggType m_dgg;
};
}  // namespace lbcrypto

\pke\include\scheme\allscheme.h

#include "scheme/rlwe.h"#include "scheme/bgvrns/bgvrns.h"#include "scheme/bfv/bfv.h"
#include "scheme/bfvrns/bfvrns.h"
#include "scheme/bfvrnsb/bfvrnsB.h"#include "scheme/ckks/ckks.h"
#include "scheme/null/nullscheme.h"

\pke\include\scheme\bfvrns.h

Operations for the HPS RNS variant of the BFV cryptoscheme.

/*** This code implements a RNS variant of the Brakerski-Fan-Vercauteren (BFV)*homomorphic encryption scheme.  This scheme is also referred to as the FV*scheme.** The BFV scheme is introduced in the following papers:*   - Zvika Brakerski (2012). Fully Homomorphic Encryption without Modulus*Switching from Classical GapSVP. Cryptology ePrint Archive, Report 2012/078.*(https://eprint.iacr.org/2012/078)*   - Junfeng Fan and Frederik Vercauteren (2012). Somewhat Practical Fully*Homomorphic Encryption.  Cryptology ePrint Archive, Report 2012/144.*(https://eprint.iacr.org/2012/144.pdf)** Our implementation builds from the designs here:*   - Halevi S., Polyakov Y., and Shoup V. An Improved RNS Variant of the BFV*Homomorphic Encryption Scheme. Cryptology ePrint Archive, Report 2018/117.*(https://eprint.iacr.org/2018/117)*   - Lepoint T., Naehrig M. (2014) A Comparison of the Homomorphic Encryption*Schemes FV and YASHE. In: Pointcheval D., Vergnaud D. (eds) Progress in*Cryptology – AFRICACRYPT 2014. AFRICACRYPT 2014. Lecture Notes in Computer*Science, vol 8469. Springer, Cham. (https://eprint.iacr.org/2014/062.pdf)*   - Jean-Claude Bajard and Julien Eynard and Anwar Hasan and Vincent*Zucca (2016). A Full RNS Variant of FV like Somewhat Homomorphic Encryption*Schemes. Cryptology ePrint Archive, Report 2016/510.*(https://eprint.iacr.org/2016/510)*   - Ahmad Al Badawi and Yuriy Polyakov and Khin Mi Mi Aung and Bharadwaj*Veeravalli and Kurt Rohloff (2018). Implementation and Performance Evaluation*of RNS Variants of the BFV Homomorphic Encryption Scheme. Cryptology ePrint*Archive, Report 2018/589. {https://eprint.iacr.org/2018/589}*/

LPCryptoParametersBFVrns 类

继承自 LPCryptoParametersRLWE<Element>
私有成员包含一些加密和同态计算中预计算的一些参数

#include <memory>
#include <string>
#include <vector>#include "palisade.h"
namespace lbcrypto {/*** @brief This is the parameters class for the BFVrns encryption scheme.  This* scheme is also referred to as the FVrns scheme.** @tparam Element a ring element type.*/
template <class Element>
class LPCryptoParametersBFVrns : public LPCryptoParametersRLWE<Element> {using IntType = typename Element::Integer;using ParmType = typename Element::Params;using DggType = typename Element::DggType;using DugType = typename Element::DugType;using TugType = typename Element::TugType;public:/*** Default constructor.*/LPCryptoParametersBFVrns();/*** Copy constructor.* @param rhs - source*/LPCryptoParametersBFVrns(const LPCryptoParametersBFVrns& rhs);/*** Constructor that initializes values.  Note that it is possible to set* parameters in a way that is overall infeasible for actual use.  There are* fewer degrees of freedom than parameters provided.  Typically one chooses* the basic noise, assurance and security parameters as the typical* community-accepted values, then chooses the plaintext modulus and depth as* needed.  The element parameters should then be choosen to provide* correctness and security.  In some cases we would need to operate over* already encrypted/provided ciphertext and the depth needs to be* pre-computed for initial settings.** @param &params Element parameters.  This will depend on the specific class* of element being used.* @param &plaintextModulus Plaintext modulus, typically denoted as p in most* publications.* @param distributionParameter Noise distribution parameter, typically* denoted as /sigma in most publications.  Community standards typically call* for a value of 3 to 6. Lower values provide more room for computation while* larger values provide more security.* @param assuranceMeasure Assurance level, typically denoted as w in most* applications.  This is oftern perceived as a fudge factor in the* literature, with a typical value of 9.* @param securityLevel Security level as Root Hermite Factor.  We use the* Root Hermite Factor representation of the security level to better conform* with US ITAR and EAR export regulations.  This is typically represented as* /delta in the literature.  Typically a Root Hermite Factor of 1.006 or less* provides reasonable security for RLWE crypto schemes.* @param relinWindow The size of the relinearization window.  This is* relevant when using this scheme for proxy re-encryption, and the value is* denoted as r in the literature.* @param mode optimization setting (RLWE vs OPTIMIZED)* @param depth is the depth of computation circuit supported for these* parameters (not used now; for future use).* @param maxDepth is the maximum homomorphic multiplication depth before* performing relinearization*/LPCryptoParametersBFVrns(shared_ptr<ParmType> params,const PlaintextModulus& plaintextModulus,float distributionParameter, float assuranceMeasure,float securityLevel, usint relinWindow,MODE mode = RLWE, int depth = 1, int maxDepth = 2);/*** Constructor that initializes values.** @param params element parameters.* @param encodingParams plaintext space parameters.* @param distributionParameter noise distribution parameter.* @param assuranceMeasure assurance level. = BigInteger::ZERO* @param securityLevel security level (root Hermite factor).* @param relinWindow the size of the relinearization window.* @param mode optimization setting (RLWE vs OPTIMIZED)* @param depth is the depth of computation circuit supported for these* parameters (not used now; for future use).* @param maxDepth is the maximum homomorphic multiplication depth before* performing relinearization*/LPCryptoParametersBFVrns(shared_ptr<ParmType> params,EncodingParams encodingParams,float distributionParameter, float assuranceMeasure,float securityLevel, usint relinWindow,MODE mode = RLWE, int depth = 1, int maxDepth = 2);/*** Constructor that initializes values.** @param &params element parameters.* @param &encodingParams plaintext space parameters.* @param distributionParameter noise distribution parameter.* @param assuranceMeasure assurance level. = BigInteger::ZERO* @param securityLevel standard security level* @param relinWindow the size of the relinearization window.* @param mode optimization setting (RLWE vs OPTIMIZED)* @param depth is the depth of computation circuit supported for these* parameters (not used now; for future use).* @param maxDepth is the maximum homomorphic multiplication depth before* performing relinearization*/LPCryptoParametersBFVrns(shared_ptr<ParmType> params,EncodingParams encodingParams,float distributionParameter, float assuranceMeasure,SecurityLevel securityLevel, usint relinWindow,MODE mode = RLWE, int depth = 1, int maxDepth = 2);/*** Destructor*/virtual ~LPCryptoParametersBFVrns() {}/*** Computes all tables needed for decryption, homomorphic multiplication, and* key switching* @return true on success*/bool PrecomputeCRTTables();/*** Gets the Auxiliary CRT basis {P} = {p_1,...,p_k}* used in homomorphic multiplication** @return the precomputed CRT params*/const shared_ptr<ILDCRTParams<BigInteger>> GetParamsP() const {return m_paramsP;}/*** Gets the Auxiliary expanded CRT basis {S} = {Q*P} =* {q_1,...,q_l,p_1,...,p_k} used in homomorphic multiplication** @return the precomputed CRT params*/const shared_ptr<ILDCRTParams<BigInteger>> GetParamsQP() const {return m_paramsQP;}/*** Gets the precomputed table of 1./q_i** @return the precomputed table*/std::vector<double> const& GetqInv() const { return m_qInv; }/*** Gets the precomputed table of 1./p_j** @return the precomputed table*/std::vector<double> const& GetpInv() const { return m_pInv; }/*** Gets the Barrett modulo reduction precomputation for q_i** @return the precomputed table*/std::vector<DoubleNativeInt> const& GetModqBarrettMu() const {return m_modqBarrettMu;}/*** Gets the Barrett modulo reduction precomputations for p_j** @return the precomputed table*/std::vector<DoubleNativeInt> const& GetModpBarrettMu() const {return m_modpBarrettMu;}/*** Gets the precomputed table of \frac{t*{Q/q_i}^{-1}/q_i}** @return the precomputed table*/const std::vector<double>& GettQHatInvModqDivqFrac() const {return m_tQHatInvModqDivqFrac;}/*** When log2(q_i) >= 45 bits, B = \floor[2^{\ceil{log2(q_i)/2}}* Gets the precomputed table of \frac{t*{Q/q_i}^{-1}*B/q_i}** @return the precomputed table*/const std::vector<double>& GettQHatInvModqBDivqFrac() const {return m_tQHatInvModqBDivqFrac;}/*** Gets the precomputed table of [\floor{t*{Q/q_i}^{-1}/q_i}]_t** @return the precomputed table*/const std::vector<NativeInteger>& GettQHatInvModqDivqModt() const {return m_tQHatInvModqDivqModt;}/*** Gets the NTL precomputations for [\floor{t*{Q/q_i}^{-1}/q_i}]_t** @return the precomputed table*/const std::vector<NativeInteger>& GettQHatInvModqDivqModtPrecon() const {return m_tQHatInvModqDivqModtPrecon;}/*** When log2(q_i) >= 45 bits, B = \floor[2^{\ceil{log2(q_i)/2}}* Gets the precomputed table of [\floor{t*{Q/q_i}^{-1}*B/q_i}]_t** @return the precomputed table*/const std::vector<NativeInteger>& GettQHatInvModqBDivqModt() const {return m_tQHatInvModqBDivqModt;}/*** When log2(q_i) >= 45 bits, B = \floor[2^{\ceil{log2(q_i)/2}}* Gets the NTL precomputations for [\floor{t*{Q/q_i}^{-1}*B/q_i}]_t** @return the precomputed table*/const std::vector<NativeInteger>& GettQHatInvModqBDivqModtPrecon() const {return m_tQHatInvModqBDivqModtPrecon;}/*** Gets the precomputed table of [\floor{Q/t}]_{q_i}** @return the precomputed table*/const std::vector<NativeInteger>& GetDelta() const { return m_QDivtModq; }/*** Gets the precomputed table of [(Q/q_i)^{-1}]_{q_i}** @return the precomputed table*/const std::vector<NativeInteger>& GetQHatInvModq() const {return m_QHatInvModq;}/*** Gets the NTL precomputations for [(Q/q_i)^{-1}]_{q_i}** @return the precomputed table*/const std::vector<NativeInteger>& GetQHatInvModqPrecon() const {return m_QHatInvModqPrecon;}/*** Gets the precomputed table of [Q/q_i]_{p_j}** @return the precomputed table*/const std::vector<std::vector<NativeInteger>>& GetQHatModp() const {return m_QHatModp;}/*** Gets the precomputed table of [\alpha*Q]_{p_j}** @return the precomputed table*/const std::vector<std::vector<NativeInteger>>& GetalphaQModp() const {return m_alphaQModp;}/*** For S = QP* Gets the precomputed table of \frac{[t*P*(S/s_k)^{-1}]_{s_k}/s_k}** @return the precomputed table*/const std::vector<double>& GettPSHatInvModsDivsFrac() const {return m_tPSHatInvModsDivsFrac;}/*** For S = QP* Gets the precomputed table of [\floor{t*P*(S/s_k)^{-1}/s_k}]_{p_j}** @return the precomputed table*/const std::vector<std::vector<NativeInteger>>& GettPSHatInvModsDivsModp()const {return m_tPSHatInvModsDivsModp;}/*** Gets the precomputed table of [(P/p_j)^{-1}]_{p_j}** @return the precomputed table*/const std::vector<NativeInteger>& GetPHatInvModp() const {return m_PHatInvModp;}/*** Gets the NTL precomputation for [(P/p_j)^{-1}]_{p_j}** @return the precomputed table*/const std::vector<NativeInteger>& GetPHatInvModpPrecon() const {return m_PHatInvModpPrecon;}/*** Gets the precomputed table of [P/p_j]_{q_i}** @return the precomputed table*/const std::vector<std::vector<NativeInteger>>& GetPHatModq() const {return m_PHatModq;}/*** Gets the precomputed table of [\alpha*P]_{q_i}** @return the precomputed table*/const std::vector<std::vector<NativeInteger>>& GetalphaPModq() const {return m_alphaPModq;}/*** == operator to compare to this instance of LPCryptoParametersBFVrns object.** @param &rhs LPCryptoParameters to check equality against.*/bool operator==(const LPCryptoParameters<Element>& rhs) const {const auto* el =dynamic_cast<const LPCryptoParametersBFVrns<Element>*>(&rhs);if (el == nullptr) return false;return LPCryptoParametersRLWE<Element>::operator==(rhs);}void PrintParameters(std::ostream& os) const {LPCryptoParametersRLWE<Element>::PrintParameters(os);}// NOTE that we do not serialize any of the members declared in this class.// they are all cached computations, and get recomputed in any implementation// that does a deserializationtemplate <class Archive>void save(Archive& ar, std::uint32_t const version) const {ar(::cereal::base_class<LPCryptoParametersRLWE<Element>>(this));}template <class Archive>void load(Archive& ar, std::uint32_t const version) {if (version > SerializedVersion()) {PALISADE_THROW(deserialize_error,"serialized object version " + std::to_string(version) +" is from a later version of the library");}ar(::cereal::base_class<LPCryptoParametersRLWE<Element>>(this));PrecomputeCRTTables();}std::string SerializedObjectName() const { return "BFVrnsSchemeParameters"; }static uint32_t SerializedVersion() { return 1; }private:// Auxiliary CRT basis {P} = {p_j}// used in homomorphic multiplicationshared_ptr<ILDCRTParams<BigInteger>> m_paramsP;// Auxiliary expanded CRT basis Q*P = {s_k}// used in homomorphic multiplicationshared_ptr<ILDCRTParams<BigInteger>> m_paramsQP;// Stores \frac{1/q_i}std::vector<double> m_qInv;// Stores \frac{1/p_j}std::vector<double> m_pInv;// Barrett modulo reduction precomputation for q_istd::vector<DoubleNativeInt> m_modqBarrettMu;// Barrett modulo reduction precomputation for p_jstd::vector<DoubleNativeInt> m_modpBarrettMu;// Stores \frac{t*{Q/q_i}^{-1}/q_i}std::vector<double> m_tQHatInvModqDivqFrac;// when log2(q_i) >= 45 bits, B = \floor[2^{\ceil{log2(q_i)/2}}// Stores \frac{t*{Q/q_i}^{-1}*B/q_i}std::vector<double> m_tQHatInvModqBDivqFrac;// Stores [\floor{t*{Q/q_i}^{-1}/q_i}]_tstd::vector<NativeInteger> m_tQHatInvModqDivqModt;// Stores NTL precomputations for [\floor{t*{Q/q_i}^{-1}/q_i}]_tstd::vector<NativeInteger> m_tQHatInvModqDivqModtPrecon;// when log2(q_i) >= 45 bits, B = \floor[2^{\ceil{log2(q_i)/2}}// Stores [\floor{t*{Q/q_i}^{-1}*B/q_i}]_tstd::vector<NativeInteger> m_tQHatInvModqBDivqModt;// when log2 q_i >= 45 bits, B = \floor[2^{\ceil{log2(q_i)/2}}// Stores NTL precomputations for [\floor{t*{Q/q_i}^{-1}*B/q_i}]_tstd::vector<NativeInteger> m_tQHatInvModqBDivqModtPrecon;// Stores [\floor{Q/t}]_{q_i}std::vector<NativeInteger> m_QDivtModq;// Stores [(Q/q_i)^{-1}]_{q_i}std::vector<NativeInteger> m_QHatInvModq;// Stores NTL precomputations for [(Q/q_i)^{-1}]_{q_i}std::vector<NativeInteger> m_QHatInvModqPrecon;// Stores [Q/q_i]_{p_j}std::vector<std::vector<NativeInteger>> m_QHatModp;// Stores [\alpha*Q]_{p_j} for 0 <= alpha <= sizeQstd::vector<std::vector<NativeInteger>> m_alphaQModp;// S = QP// Stores [\floor{t*P*(S/s_k)^{-1}/s_k}]_{p_j}std::vector<std::vector<NativeInteger>> m_tPSHatInvModsDivsModp;// S = QP// Stores \frac{[t*P*(S/s_k)^{-1}]_{s_k}/s_k}std::vector<double> m_tPSHatInvModsDivsFrac;// Stores [(P/p_j)^{-1}]_{p_j}std::vector<NativeInteger> m_PHatInvModp;// Stores NTL precomputations for [(P/p_j)^{-1}]_{p_j}std::vector<NativeInteger> m_PHatInvModpPrecon;// Stores [P/p_j]_{q_i}std::vector<std::vector<NativeInteger>> m_PHatModq;// Stores [\alpha*P]_{q_i} for 0 <= alpha <= sizePstd::vector<std::vector<NativeInteger>> m_alphaPModq;
};

LPAlgorithmParamsGenBFVrns 类

生成参数的类

/*** @brief Parameter generation for BFVrns.  This scheme is also referred to as* the FV scheme.** @tparam Element a ring element.*/
template <class Element>
class LPAlgorithmParamsGenBFVrns : public LPAlgorithmParamsGenBFV<Element> {using IntType = typename Element::Integer;using ParmType = typename Element::Params;using DggType = typename Element::DggType;using DugType = typename Element::DugType;using TugType = typename Element::TugType;public:/*** Default constructor*/LPAlgorithmParamsGenBFVrns() {}/*** Method for computing all derived parameters based on chosen primitive* parameters** @param cryptoParams the crypto parameters object to be populated with* parameters.* @param evalAddCount number of EvalAdds assuming no EvalMult and KeySwitch* operations are performed.* @param evalMultCount number of EvalMults assuming no EvalAdd and KeySwitch* operations are performed.* @param keySwitchCount number of KeySwitch operations assuming no EvalAdd* and EvalMult operations are performed.* @param dcrtBits number of bits in each CRT modulus* @param n ring dimension in case the user wants to use a custom ring* dimension*/bool ParamsGen(shared_ptr<LPCryptoParameters<Element>> cryptoParams,int32_t evalAddCount = 0, int32_t evalMultCount = 0,int32_t keySwitchCount = 0, size_t dcrBits = 60,uint32_t n = 0) const;
};

LPAlgorithmBFVrns 类

进行加解密

/*** @brief Encryption algorithm implementation for BFVrns for the basic public* key encrypt, decrypt and key generation methods for the BFVrns encryption* scheme.** @tparam Element a ring element.*/
template <class Element>
class LPAlgorithmBFVrns : public LPAlgorithmBFV<Element> {using IntType = typename Element::Integer;using ParmType = typename Element::Params;using DggType = typename Element::DggType;using DugType = typename Element::DugType;using TugType = typename Element::TugType;public:/*** Default constructor*/LPAlgorithmBFVrns() {}/*** Method for encrypting plaintext using BFVrns.** @param publicKey public key used for encryption.* @param plaintext the plaintext input.* @return ciphertext which results from encryption.*/Ciphertext<Element> Encrypt(const LPPublicKey<Element> publicKey,Element plaintext) const;/*** Method for encrypting plaintext with private key using BFVrns.** @param privateKey private key used for encryption.* @param plaintext the plaintext input.* @return ciphertext which results from encryption.*/Ciphertext<Element> Encrypt(const LPPrivateKey<Element> privateKey,Element plaintext) const;/*** Method for decrypting using BFVrns. See the class description for citations* on where the algorithms were taken from.** @param privateKey private key used for decryption.* @param ciphertext ciphertext to be decrypted.* @param *plaintext the plaintext output.* @return the decrypted plaintext returned.*/DecryptResult Decrypt(const LPPrivateKey<Element> privateKey,ConstCiphertext<Element> ciphertext,NativePoly* plaintext) const;
};

LPAlgorithmSHEBFVrns 类

进行同态计算的类

/*** @brief SHE algorithms implementation for BFVrns.** @tparam Element a ring element.*/
template <class Element>
class LPAlgorithmSHEBFVrns : public LPAlgorithmSHEBFV<Element> {using IntType = typename Element::Integer;using ParmType = typename Element::Params;using DggType = typename Element::DggType;using DugType = typename Element::DugType;using TugType = typename Element::TugType;public:/*** Default constructor*/LPAlgorithmSHEBFVrns() {}/*** Function for homomorphic addition of ciphertext and plaintext.** @param ct input ciphertext.* @param pt input plaintext.* @return new ciphertext.*/Ciphertext<Element> EvalAdd(ConstCiphertext<Element> ct,ConstPlaintext pt) const override;/*** Function for homomorphic subtraction of ciphertext ans plaintext.** @param ct input ciphertext.* @param pt input plaintext.* @return new ciphertext.*/Ciphertext<Element> EvalSub(ConstCiphertext<Element> ct1,ConstPlaintext pt) const override;/*** Function for homomorphic evaluation of ciphertexts.* The multiplication is supported for a fixed level without keyswitching* requirement (default level=2). If the total depth of the ciphertexts* exceeds the supported level, it throws an error.** @param ct1 first input ciphertext.* @param ct2 second input ciphertext.* @return resulting EvalMult ciphertext.*/Ciphertext<Element> EvalMult(ConstCiphertext<Element> ct1,ConstCiphertext<Element> ct2) const override;/*** Method for generating a KeySwitchHint using RLWE relinearization** @param oldKey Original private key used for encryption.* @param newKey New private key to generate the keyswitch hint.* @return resulting keySwitchHint.*/LPEvalKey<Element> KeySwitchGen(const LPPrivateKey<Element> oldKey,const LPPrivateKey<Element> newKey) const override;/*** Method for in-place key switching based on a KeySwitchHint using RLWE* relinearization** @param keySwitchHint Hint required to perform the ciphertext switching.* @param &cipherText Original ciphertext to perform in-place key switching* on.*/void KeySwitchInPlace(const LPEvalKey<Element> keySwitchHint,Ciphertext<Element>& ciphertext) const override;/*** Function for evaluating multiplication on ciphertext followed by* relinearization operation. Currently it assumes that the input arguments* have total depth smaller than the supported depth. Otherwise, it throws an* error.** @param ct1 first input ciphertext.* @param ct2 second input ciphertext.* @param &ek is the evaluation key to make the newCiphertext*  decryptable by the same secret key as that of ciphertext1 and ciphertext2.* @return new ciphertext*/Ciphertext<Element> EvalMultAndRelinearize(ConstCiphertext<Element> ct1, ConstCiphertext<Element> ct2,const vector<LPEvalKey<Element>>& ek) const override;
};

LPAlgorithmPREBFVrns 类

PRE 算法
重加密

/*** @brief PRE algorithms implementation for BFVrns.** @tparam Element a ring element.*/
template <class Element>
class LPAlgorithmPREBFVrns : public LPAlgorithmPREBFV<Element> {using IntType = typename Element::Integer;using ParmType = typename Element::Params;using DggType = typename Element::DggType;using DugType = typename Element::DugType;using TugType = typename Element::TugType;public:/*** Default constructor*/LPAlgorithmPREBFVrns() {}/*** The generation of re-encryption keys is based on the BG-PRE scheme* described in Polyakov, et. al., "Fast proxy re-encryption for* publish/subscribe systems".** The above scheme was found to have a weakness in Cohen, "What about Bob?* The inadequacy of CPA Security for proxy re-encryption". Section 5.1 shows* an attack where given an original ciphertext c=(c0,c1) and a re-encrypted* ciphertext c'=(c'0, c'1), the subscriber (Bob) can compute the secret key* of the publisher (Alice).** We fix this vulnerability by making re-encryption keys be encryptions of* the s*(2^{i*r}) terms, instead of simple addition as previously defined.* This makes retrieving the secret key using the above attack as hard as* breaking the RLWE assumption.** Our modification makes the scheme CPA-secure, but does not achieve* HRA-security as it was defined in the Cohen paper above. Please look at the* ReEncrypt method for an explanation of the two security definitions and how* to achieve each in Palisade.** @param newKey public key for the new private key.* @param oldKey original private key used for decryption.* @return evalKey the evaluation key for switching the ciphertext to be* decryptable by new private key.*/LPEvalKey<Element> ReKeyGen(const LPPublicKey<Element> newKey,const LPPrivateKey<Element> oldKey) const;/*** This method implements re-encryption using the evaluation key generated by* ReKeyGen.** The PRE scheme used can achieve two different levels of security, based on* the value supplied in the publicKey argument:** If publicKey is nullptr, the PRE scheme is CPA-secure. If the publicKey of* the recipient of the re-encrypted ciphertext is supplied, then the scheme* is HRA- secure. Please refer to Cohen, "What about Bob? The inadequacy of* CPA Security for proxy re-encryption", for more information on HRA* security.** The tradeoff of going for HRA is twofold: (1) performance is a little worst* because we add one additional encryption and homomorphic addition to the* result, and (2) more noise is added to the result because of the additional* operations - in particular, the extra encryption draws noise from a* distribution whose standard deviation is scaled by K, the number of digits* in the PRE decomposition.** @param ek the evaluation key.* @param ciphertext the input ciphertext.* @param publicKey the public key of the recipient of the re-encrypted* ciphertext.* @return resulting ciphertext after the re-encryption operation.*/Ciphertext<Element> ReEncrypt(const LPEvalKey<Element> ek, ConstCiphertext<Element> ciphertext,const LPPublicKey<Element> publicKey = nullptr) const;
};

LPAlgorithmMultipartyBFVrns 类

MultiParty 同态加密

/*** @brief Concrete class for the FHE Multiparty algorithms on BFVrns.    This* scheme is also referred to as the FV scheme.  A version of this multiparty* scheme built on the BGV scheme is seen here:*   - Asharov G., Jain A., López-Alt A., Tromer E., Vaikuntanathan V., Wichs* D. (2012) Multiparty Computation with Low Communication, Computation and* Interaction via Threshold FHE. In: Pointcheval D., Johansson T. (eds)* Advances in Cryptology – EUROCRYPT 2012. EUROCRYPT 2012. Lecture Notes in* Computer Science, vol 7237. Springer, Berlin, Heidelberg** During offline key generation, this multiparty scheme relies on the clients* coordinating their public key generation.  To do this, a single client* generates a public-secret key pair. This public key is shared with other keys* which use an element in the public key to generate their own public keys. The* clients generate a shared key pair using a scheme-specific approach, then* generate re-encryption keys.  Re-encryption keys are uploaded to the server.* Clients encrypt data with their public keys and send the encrypted data* server. The data is re-encrypted.  Computations are then run on the data. The* result is sent to each of the clients. One client runs a "Leader" multiparty* decryption operation with its own secret key.  All other clients run a* regular "Main" multiparty decryption with their own secret key. The resulting* partially decrypted ciphertext are then fully decrypted with the decryption* fusion algorithms.** @tparam Element a ring element.*/
template <class Element>
class LPAlgorithmMultipartyBFVrns : public LPAlgorithmMultipartyBFV<Element> {using IntType = typename Element::Integer;using ParmType = typename Element::Params;using DggType = typename Element::DggType;using DugType = typename Element::DugType;using TugType = typename Element::TugType;public:/*** Default constructor*/LPAlgorithmMultipartyBFVrns() {}/*** Threshold FHE: Method for combining the partially decrypted ciphertexts* and getting the final decryption in the clear as a NativePoly.** @param &ciphertextVec vector of "partial" decryptions.* @param *plaintext the plaintext output as a NativePoly.* @return the decoding result.*/DecryptResult MultipartyDecryptFusion(const vector<Ciphertext<Element>>& ciphertextVec,NativePoly* plaintext) const override;template <class Archive>void save(Archive& ar) const {ar(cereal::base_class<LPAlgorithmMultipartyBFV<Element>>(this));}template <class Archive>void load(Archive& ar) {ar(cereal::base_class<LPAlgorithmMultipartyBFV<Element>>(this));}/*** Threshold FHE: Generates a joined evaluation key* from the current secret share and a prior joined* evaluation key** @param oldKey secret key transformed from.* @param newKey secret key transformed to.* @param ek the prior joined evaluation key.* @return the new joined evaluation key.*/LPEvalKey<Element> MultiKeySwitchGen(const LPPrivateKey<Element> oldKey, const LPPrivateKey<Element> newKey,const LPEvalKey<Element> ek) const override;std::string SerializedObjectName() const { return "BFVrnsMultiparty"; }
};

LPPublicKeyEncryptionSchemeBFVrns 类

Main public key encryption scheme for BFVrns implementation

/*** @brief Main public key encryption scheme for BFVrns implementation,* @tparam Element a ring element.*/
template <class Element>
class LPPublicKeyEncryptionSchemeBFVrns: public LPPublicKeyEncryptionScheme<Element> {using IntType = typename Element::Integer;using ParmType = typename Element::Params;using DggType = typename Element::DggType;using DugType = typename Element::DugType;using TugType = typename Element::TugType;public:LPPublicKeyEncryptionSchemeBFVrns();bool operator==(const LPPublicKeyEncryptionScheme<Element>& sch) const override {return dynamic_cast<const LPPublicKeyEncryptionSchemeBFVrns<Element>*>(&sch) != nullptr;}void Enable(PKESchemeFeature feature) override;template <class Archive>void save(Archive& ar, std::uint32_t const version) const {ar(::cereal::base_class<LPPublicKeyEncryptionScheme<Element>>(this));}template <class Archive>void load(Archive& ar, std::uint32_t const version) {ar(::cereal::base_class<LPPublicKeyEncryptionScheme<Element>>(this));}std::string SerializedObjectName() const override { return "BFVrnsScheme"; }
};

只需要实现父类的某些函数

Palisade pke scheme headers相关推荐

  1. Python 使用pip命令提示WARNING: Ignoring invalid distribution

    目录 1.问题描述 2.问题表现 3.问题解决 1.问题描述 使用python pip命令提示警告worning 2.问题表现         2.1 pip list 查看已安装依赖包 C:\Use ...

  2. unittest参数化parameterized

    # pip install parameterized安装包 # 若报错"Value for scheme.headers does not match",重装pip # 若报错& ...

  3. HTTP headers(HTTP头)

    转自:http://hi.baidu.com/code100line/blog/item/5c8bb08a072394779f2fb4ee.html Requests Header   Descrip ...

  4. 格密码开源库PALISADE的使用

    格密码开源库PALISADE PALISADE是新泽西理工学院的一个格密码开源项目,也是现在少有的成熟稳定的格密码开源库,这篇文章主要介绍该库的使用与构建. 事实上该库的ReadMe文档介绍的十分详细 ...

  5. 在Linux上安装Scheme解释器

    在Linux上安装Scheme解释器 Sheme 是Lisp方言,详见与Scheme共舞 系统环境:Ubuntu 16.04 使用的软件及版本:racket-7.3 软件官网:https://rack ...

  6. urllib之urlopen和urlretrieve的headers传入以及parse、urlparse、urlsplit的使用

    urllib库是什么? urllib库python的一个最基本的网络请求库,不需要安装任何依赖库就可以导入使用.它可以模拟浏览器想目标服务器发起请求,并可以保存服务器返回的数据. urllib库的使用 ...

  7. 编码 data:text/html;c,关于 Data URI Scheme -- data:image/jpg;base64

    转载一篇大神的文章 大家可能注意到了,网页上有些图片的src或css背景图片的url后面跟了一大串字符,比如: data:image/jpeg;base64,/9j/4QAYRXhpZgAASUkqA ...

  8. 后端说:只是你不懂怎么用 headers!

    事情是这样的,上一个项目我们的后端提供的接口,一次性返回了所有数据给我,分页功能是前端自己完成的. 那么这次来的新项目,换了个后端,写了另外的接口,我做项目的时候,还是用的之前的前端分页组件,但是测试 ...

  9. 爬虫之requests模块在headers参数中携带cookie发送请求

    爬虫之requests模块在headers参数中携带cookie发送请求 网站经常利用请求头中的Cookie字段来做用户访问状态的保持,那么我们可以在headers参数中添加Cookie,模拟普通用户 ...

最新文章

  1. Python 精选笔试面试习题—类继承、方法对象、包管理、闭包、可变类型作为默认参数、列表引用、sort与sorted、 append 和 extend、深拷贝和浅拷贝
  2. javascript迭代器_JavaScript迭代器概述
  3. 使用TensorFlow进行机器学习即服务
  4. 用Eclipse进行远程Debug代码
  5. mysql的如何输入dateadd_mysql中date_add()函数的使用?
  6. Python 技术篇-操作oracle数据库执行SQL语句报错,提示ORA-00911: 无效字符解决方法
  7. 【C++】C++类的学习(一)——初识类
  8. Enterprise Library—缓存应用程序块
  9. WIN 10进入休眠、睡眠、关机的命令
  10. matlab实现输出的几种方式
  11. 软件测试的工作内容主要是干什么?
  12. 百度翻译vs谷歌翻译
  13. zabbix监控系统
  14. 一文读懂SDRAM内存模组与基本概念
  15. android如何获取进程占用的内存大小,Android获取cpu使用率,剩余内存和硬盘容量
  16. “值得”关注公司:我们应该向优衣库学习什么?
  17. ubuntu20.04中打开echo daytime服务
  18. php立方体相册源码,纯CSS实现3D的代码(正方体、动态立体图片册、平面的星空)...
  19. 曲面的渐近方向和共轭方向、主方向、曲率线网
  20. Chrome自动更新到78.0.3904.70后出现“Aw, Snap!”错误,所有页面不能打开。

热门文章

  1. PolyFit软件介绍
  2. 硬盘录像机nvr装硬盘操作
  3. DeepMind 如何控制机器人
  4. 阿里的千手观音,和影视剧里的职场女神们有什么不同?...
  5. 苹果OFFICE 2011MAC打开WORD字体乱码解决方法
  6. 聊天尬死名场面,你遇到过吗?教你一键获取斗图表情包,晋升聊天达人
  7. [转]MTK6515 android打版软件配置
  8. FLASK点击按钮实现中英文切换
  9. Android Studio 连接真机测试
  10. 360手机N6如何更新Android系统,360手机N6 Pro卡刷刷机教程_360手机N6 Pro升级更新官方包...