Palisade pke scheme headers

Palisade 是一个密码库,提供了基于BFVrns方案的公钥加密(PKE)和同态加密(HE)操作。BFVrns类包括LPCryptoParametersBFVrns(预计算参数)、LPAlgorithmParamsGenBFVrns(参数生成)、LPAlgorithmBFVrns(加密解密)、LPAlgorithmSHEBFVrns(同态计算)、LPAlgorithmPREBFVrns(PRE重加密)以及LPAlgorithmMultipartyBFVrns(多方计算)。所有这些组件一起构成了BFVrns的PKE方案。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Palisade pke scheme headers

\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() 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值