Palisade math headers

Palisade源码01

今天开始正式记录一下palisade开源库源代码。

\core\include\encoding\encodingparams.h

这个头文件定义了类 EncodingParamsImpl

#include "math/backend.h"
class EncodingParamsImpl : public lbcrypto::Serializable 

定义别名

typedef std::shared_ptr<EncodingParamsImpl> EncodingParams;
typedef uint64_t PlaintextModulus;

私有成员

private:
  std::ostream &doprint(std::ostream &out) const {
   
    out << "[p=" << m_plaintextModulus << " rootP =" << m_plaintextRootOfUnity
        << " bigP =" << m_plaintextBigModulus
        << " rootBigP =" << m_plaintextBigRootOfUnity
        << " g=" << m_plaintextGenerator << " L=" << m_batchSize << "]";
    return out;
  }

  // plaintext modulus that is used by all schemes	明文模数
  PlaintextModulus m_plaintextModulus;
  // root of unity for plaintext modulus	明文模数的生成元
  NativeInteger m_plaintextRootOfUnity;
  // big plaintext modulus that is used for arbitrary cyclotomics 任意分圆多项式的模数
  NativeInteger m_plaintextBigModulus;
  // root of unity for big plaintext modulus		上面模数的生成元
  NativeInteger m_plaintextBigRootOfUnity;
  // plaintext generator is used for packed encoding (to find the correct
  // automorphism index)	暂时没懂
  uint32_t m_plaintextGenerator;
  // maximum batch size used by EvalSumKeyGen for packed encoding   暂时没懂
  uint32_t m_batchSize;

public成员
一堆getter和setter函数

/**
   * Main constructor. Supports (1) default constructor, (2) regular encoding
   * with plaintext modulus set, (3) packed encoding with at least first two
   * parameters set. All of the private members not explicitly included as
   * arguments will be initialized to zero.
   *
   * @param plaintextModulus plainext modulus (used by all encodings)
   * @param plaintextGenerator (used by packed encoding for plaintext slot
   * rotation)
   * @param batchSize sets the maximum batch size (as a power of 2) needed for
   * EvalSum
   */

三个构造函数,赋值构造,默认参数都是0,copy constructor,move constructor

EncodingParamsImpl(PlaintextModulus plaintextModulus = 0,
                     uint32_t batchSize = 0, uint32_t plaintextGenerator = 0,
                     NativeInteger plaintextRootOfUnity = 0,
                     NativeInteger plaintextBigModulus = 0,
                     NativeInteger plaintextBigRootOfUnity = 0) {
   
    m_plaintextModulus = plaintextModulus;
    m_plaintextRootOfUnity = plaintextRootOfUnity;
    m_plaintextBigModulus = plaintextBigModulus;
    m_plaintextBigRootOfUnity = plaintextBigRootOfUnity;
    m_batchSize = batchSize;
    m_plaintextGenerator = plaintextGenerator;
  }

  /**
   * Copy constructor.
   *
   * @param &rhs the input set of parameters which is copied.
   */
  EncodingParamsImpl(const EncodingParamsImpl &rhs) {
   
    m_plaintextModulus = rhs.m_plaintextModulus;
    m_plaintextRootOfUnity = rhs.m_plaintextRootOfUnity;
    m_plaintextBigModulus = rhs.m_plaintextBigModulus;
    m_plaintextBigRootOfUnity = rhs.m_plaintextBigRootOfUnity;
    m_plaintextGenerator = rhs.m_plaintextGenerator;
    m_batchSize = rhs.m_batchSize;
  }

  /**
   * Move constructor.
   *
   * @param &rhs the input set of parameters which is copied.
   */
  EncodingParamsImpl(const EncodingParamsImpl &&rhs) {
   
    m_plaintextModulus = std::move(rhs.m_plaintextModulus);
    m_plaintextRootOfUnity = std::move(rhs.m_plaintextRootOfUnity);
    m_plaintextBigModulus = std::move(rhs.m_plaintextBigModulus);
    m_plaintextBigRootOfUnity = std::move(rhs.m_plaintextBigRootOfUnity);
    m_plaintextGenerator = std::move(rhs.m_plaintextGenerator);
    m_batchSize = rhs.m_batchSize;
  }

一个析构函数

virtual ~EncodingParamsImpl() {
   }

赋值操作

/**
   * Assignment Operator.
   *
   * @param &rhs the EncodingParamsImpl to be copied.
   * @return the resulting EncodingParamsImpl.
   */
  const EncodingParamsImpl &operator=(const EncodingParamsImpl &rhs) {
   
    m_plaintextModulus = rhs.m_plaintextModulus;
    m_plaintextRootOfUnity = rhs.m_plaintextRootOfUnity;
    m_plaintextBigModulus = rhs.m_plaintextBigModulus;
    m_plaintextBigRootOfUnity = rhs.m_plaintextBigRootOfUnity;
    m_plaintextGenerator = rhs.m_plaintextGenerator;
    m_batchSize = rhs.m_batchSize;
    return *this;
  }

一些比较运算和输出运算

// Operators
  /**
   * @brief output stream operator.
   * @param out the output stream to output.
   * @param item the following object to output.
   * @return the string output.
   */
  friend std::ostream &operator<<(std::ostream &out,
                                  const EncodingParamsImpl &item) {
   
    return item.doprint(out);
  }
  /**
   * @brief Equality operator for the parameters.  Tests that all the parameters
   * are equal.
   * @param other the other parameter set to compare to.
   * @return true if values of all data are equal.
   */
  bool operator==(const EncodingParamsImpl &other) const {
   
    return m_plaintextModulus == other.m_plaintextModulus &&
           m_plaintextRootOfUnity == other.m_plaintextRootOfUnity &&
           m_plaintextBigModulus == other.m_plaintextBigModulus &&
           m_plaintextBigRootOfUnity == other.m_plaintextBigRootOfUnity &&
           m_plaintextGenerator == other.m_plaintextGenerator &&
           m_batchSize == other.m_batchSize;
  }
  /**
   * @brief Inequality operator for the parameters.  Tests that all the
   * parameters are not equal.
   * @param other the other parameter set to compare to.
   * @return true if values of any data is not equal.
   */
  bool operator!=(const EncodingParamsImpl &other) const {
   
    return !(*this == other);
  }

save和load函数

  template <class Archive>
  void save(Archive &ar, std::uint32_t const version) const {
   
    ar(::cereal::make_nvp("m", m_plaintextModulus));
    ar(::cereal::make_nvp("ru", m_plaintextRootOfUnity));
    ar(::cereal::make_nvp("bm", m_plaintextBigModulus));
    ar(::cereal::make_nvp("bru", m_plaintextBigRootOfUnity));
    ar(::cereal::make_nvp("g", m_plaintextGenerator));
    ar(::cereal::make_nvp("bs", m_batchSize));
  }

  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::make_nvp("m", m_plaintextModulus));
    ar(::cereal::make_nvp("ru", m_plaintextRootOfUnity));
    ar(::cereal::make_nvp("bm", m_plaintextBigModulus));
    ar(::cereal::make_nvp("bru", m_plaintextBigRootOfUnity));
    ar(::cereal::make_nvp("g", m_plaintextGenerator));
    ar(::cereal::make_nvp("bs", m_batchSize));
  }

定义在类外的函数

inline std::ostream &operator<<(std::ostream &out,
                                std::shared_ptr<EncodingParamsImpl> o) {
   
  if (o) out << *o;
  return out;
}
inline bool operator==(std::shared_ptr<EncodingParamsImpl> o1,
                       std::shared_ptr<EncodingParamsImpl> o2) {
   
  if (o1 && o2) return *o1 == *o2;
  if (!o1 && !o2) return true;
  return false;
}

\core\include\math\backend.h

定义了一些数据类型的长度

#include "config_core.h"
#include "version.h"

#include "interface.h"
#include "utils/debug.h"
#include "utils/exception.h"
#include "utils/inttypes.h"
#include "utils/memory.h"
#include "utils/palisadebase64.h"
#include "utils/parallel.h"
#include "utils/serializable.h"

namespace不同

namespace bigintnat {
   

template <typename I>
class NativeIntegerT;

#if NATIVEINT == 128
#define MAX_MODULUS_SIZE 121
using BasicInteger = unsigned __int128;	// 128个比特的无符号整型
typedef NativeIntegerT<unsigned __int128> NativeInteger;
typedef NativeIntegerT<unsigned __int128> NativeInteger128;
#elif NATIVEINT == 64 && !defined(HAVE_INT128)
#define MAX_MODULUS_SIZE 58
using BasicInteger = uint64_t;
typedef NativeIntegerT<uint64_t> NativeInteger;
typedef NativeIntegerT<uint64_t> NativeInteger64;
#elif NATIVEINT == 64 && defined(HAVE_INT128)
#define MAX_MODULUS_SIZE 60
using BasicInteger = uint64_t;
typedef NativeIntegerT<uint64_t> NativeInteger;
typedef NativeIntegerT<uint64_t> NativeInteger64;
#elif NATIVEINT == 32  // NOLINT
#define MAX_MODULUS_SIZE 28
using BasicInteger = uint32_t;
typedef NativeIntegerT<uint32_t> NativeInteger;
typedef NativeIntegerT<uint32_t> NativeInteger32;
#endif

}  // namespace bigintnat

默认设置MATHBACKEND=2,要修改成其他值只需要解注释。

/*! Define the underlying default math implementation being used by defining
 * MATHBACKEND */

// Each math backend is defined in its own namespace, and can be used at any
// time by referencing the objects in its namespace

// Selecting a math backend by defining MATHBACKEND means defining which
// underlying implementation is the default BigInteger and BigVector

// note that we #define how many bits the underlying integer can store as a
// guide for users of the backends

// MATHBACKEND 2
//    Uses bigintfxd:: definition as default
//    Implemented as a vector of integers
//    Configurable maximum bit length and type of underlying integer

// MATHBACKEND 4
//     This uses bigintdyn:: definition as default
//     This backend supports arbitrary bitwidths; no memory pool is
// used; can grow up to RAM limitation
//    Configurable type of underlying integer (either 32 or 64 bit)

// passes all tests with UBINTDYN_32
// fails tests with UBINTDYN_64
// there is a bug in the way modulus is computed. do not use.

// MATHBACKEND 6
//     This uses bigintntl:: definition as default
//     GMP 6.1.2 / NTL 10.3.0 backend

// To select backend, please UNCOMMENT the appropriate line rather than changing
// the number on the uncommented line (and breaking the documentation of the
// line)

#ifndef MATHBACKEND
#define MATHBACKEND 2
// #define MATHBACKEND 4
// #define MATHBACKEND 6
#endif

#if MATHBACKEND != 2 && MATHBACKEND != 4 && MATHBACKEND != 6
#error "MATHBACKEND value is not valid"
#endif

定义别名

// bigintfxd code
typedef uint32_t integral_dtype;

大整数比特长度

/** Define the mapping for BigInteger
    3500 is the maximum bit width supported by BigIntegers, large enough for
most use cases The bitwidth can be decreased to the least value still supporting
BigInteger operations for a specific application - to achieve smaller runtimes
**/
#ifndef BigIntegerBitLength
#if (NATIVEINT < 128)
#define BigIntegerBitLength 3500  // for 32-bit and 64-bit native backend
#else
#define BigIntegerBitLength 8000  // for 128-bit native backend
#endif
#endif

#if BigIntegerBitLength < 600
#error "BigIntegerBitLength is too small"
#endif
#include "bigintfxd/mubintvecfxd.h"
#include "bigintfxd/ubintfxd.h"
static_assert(bigintfxd::DataTypeChecker<integral_dtype>::value,
              "Data type provided is not supported in BigInteger");

// for bigintdyn, decide if you want 32 bit or 64 bit underlying
/// integers in the implementation
#define UBINT_32
// #define UBINT_64

#ifdef UBINT_32
#define MATH_UBBITS 32
typedef uint32_t expdtype;
#undef UBINT_64  // cant have both accidentally
#endif

#ifdef UBINT_64
#define MATH_UBBITS 64
typedef uint64_t expdtype;
#undef UBINT_32  // cant have both accidentally
#endif
#include "bigintdyn/mubintvecdyn.h"  // rings of ubints
#include "bigintdyn/ubintdyn.h"  // dynamically sized unsigned big integers or ubints

namespace bigintdyn {
   
/** Define the mapping for ExpBigInteger (experimental) */
typedef ubint<expdtype> xubint;

/** Define the mapping for modulo Big Integer Vector */
typedef mubintvec<xubint> xmubintvec;
}  // namespace bigintdyn
#ifdef WITH_NTL

#include "bigintntl/mubintvecntl.h"  // rings of such
#include "bigintntl/ubintntl.h"      // experimental gmp unsigned big ints

namespace bigintntl {
   
typedef NTL::myZZ ubint;
}

using M6Integer = NTL::myZZ;
using M6Vector = NTL::myVecP<M6Integer>;

#endif
// typedefs for the known math backends
using M2Integer = bigintfxd::BigInteger<integral_dtype, BigIntegerBitLength>;
using M2Vector = bigintfxd::BigVectorImpl<M2Integer>;
using M4Integer = bigintdyn::xubint;
using M4Vector = bigintdyn::xmubintvec;
/**
 * @namespace lbcrypto
 * The namespace of lbcrypto
 */
namespace lbcrypto {
   

#if NATIVEINT == 128
typedef unsigned __int128 DoubleNativeInt;
typedef unsigned __int128 uint128_t;
typedef __int128 int128_t;
#elif NATIVEINT == 64 && defined(HAVE_INT128)
typedef unsigned __int128 DoubleNativeInt;
typedef unsigned __int128 uint128_t;
typedef __int128 int128_t;
#elif NATIVEINT == 64 && !defined(HAVE_INT128)
typedef uint64_t DoubleNativeInt;
typedef uint64_t uint128_t;
typedef int64_t int128_t;
#elif NATIVEINT == 32
typedef uint64_t DoubleNativeInt;
#endif

#if MATHBACKEND == 2

using BigInteger = M2Integer;
using BigVector = M2Vector;

#endif

#if MATHBACKEND == 4

#ifdef UBINT_64
#error MATHBACKEND 4 with UBINT_64 currently does not work do not use.
#endif

using BigInteger = M4Integer;
using BigVector = M4Vector;

#endif

#if MATHBACKEND == 6

using BigInteger = M6Integer;
using BigVector = M6Vector;

#endif

}  // namespace lbcrypto
// definitions for native integer and native vector
#include <initializer_list>
#include "bigintnat/mubintvecnat.h"
#include "bigintnat/ubintnat.h"

#if NATIVEINT == 128
typedef bigintnat::NativeIntegerT<unsigned __int128> NativeInteger128;
typedef bigintnat::NativeVector<NativeInteger128> NativeVector128;
#elif NATIVEINT == 64
typedef bigintnat::NativeIntegerT<uint64_t> NativeInteger64;
typedef bigintnat::NativeVector<NativeInteger64> NativeVector64;
#elif NATIVEINT == 32
typedef bigintnat::NativeIntegerT<uint32_t> NativeInteger32;
typedef bigintnat::NativeVector<NativeInteger32> NativeVector32;
#endif

#if NATIVEINT == 128
typedef NativeInteger128 NativeInteger;
typedef NativeVector128 NativeVector;
#elif NATIVEINT == 64
typedef NativeInteger64 NativeInteger;
typedef NativeVector64 NativeVector;
#elif NATIVEINT == 32  // NOLINT
typedef NativeInteger32 NativeInteger;
typedef NativeVector32 NativeVector;
#endif

#endif

NATIVEINT在哪里被定义?
利用 cmake 自动添加宏定义
有文件 config_core.in:

#cmakedefine WITH_BE2
#cmakedefine WITH_BE4
#cmakedefine WITH_NTL
#cmakedefine WITH_TCM

#cmakedefine HAVE_INT128 @HAVE_INT128@
#cmakedefine HAVE_INT64 @HAVE_INT64@
#cmakedefine NATIVEINT @NATIVEINT@
#cmakedefine CKKS_M_FACTOR @CKKS_M_FACTOR@

编译之后会出现 /usr/local/include/palisade/core/config_core.h:

#define WITH_BE2
#define WITH_BE4
/* #undef WITH_NTL */
/* #undef WITH_TCM */

#define HAVE_INT128 TRUE
#define HAVE_INT64 TRUE
#define NATIVEINT 64
#define CKKS_M_FACTOR 1

我猜测可能是根据 cmake 时候用户的选项来的
整个Palisade库的CMakeLists.txt中有这样一段代码:

### build configure_core.h to make options available
configure_file(./configure/config_core.in src/core/config_core.h)
install(FILES ${
   CMAKE_BINARY_DIR}/src/core/config_core.h DESTINATION include/palisade/core)

\core\include\math\interface.h

This file contains the interfaces for math data types.也就是说提供了数据类型的一些接口。

#include <string>
#include "utils/inttypes.h"

namespace lbcrypto {
   

friend友元

BigIntegerInterface类:定义了加减乘除,乘以p/q然后舍入,除以p然后舍入,取模运算,Barrett取模运算(快速算法),模加,模减,模乘,模幂,模逆,移位操作,比较运算,转换数据类型操作,还有一些其他的计算函数。

template <typename T>
class BigIntegerInterface {
   
 public:
  // CONSTRUCTORS

  // Constructors must be implemented in the derived classes
  // There are no base class constructors that need to be called

  // The derived classes should implement constructors from uint64_t,
  // NativeInteger, and strings There should be copy and move constructors, as
  // well as copy and move assignment

  // ASSIGNMENT OPERATORS

  // ACCESSORS

  /**
   * Set from a string
   *
   * @param str is the string representation of the value
   */
  void SetValue(const std::string& str);

【注】操作符重载的时候返回值是常量引用。
函数返回值三种方式

// ARITHMETIC OPERATIONS

  /**
   * Addition operation.
   *
   * @param &b is the value to add.
   * @return result of the addition operation.
   */
  T Add(const T& b) const;
  const T& AddEq(const T& b);

  /// inline operators for the addition operation.
  inline friend T operator+(const T& a, const T& b) {
    return a.Add(b); }
  inline friend const T& operator+=(T& a, const T& b) {
    return a.AddEq(b); }

  /**
   * Subtraction operation.
   *
   * @param &b is the value to subtract.
   * @return is the result of the subtraction operation.
   */
  T Sub(const T& b) const;
  const T& SubEq(const T& b);

  /// inline operators for the subtraction operation.
  inline friend T operator-(const T& a, const T& b) {
    return a.Sub(b); }
  inline friend const T& operator-=(T& a, const T& b) {
    return a.SubEq(b); }

  /**
   * Multiplication operation.
   *
   * @param &b is the value to multiply with.
   * @return is the result of the multiplication operation.
   */
  T Mul(const T& b) const;

  /**
   * Multiplication operation. In-place variant.
   *
   * @param &b is the value to multiply with.
   * @return is the result of the multiplication operation.
   */
  const T& MulEq(const T& b);

  /// inline operators for the multiplication operation.
  inline friend T operator*(const T& a, const T& b) {
    return a.Mul(b); }
  inline friend const T& operator*=(T& a, const T& b) {
    return a.MulEq(b); }

  /**
   * Division operation.
   *
   * @param &b is the value to divide by.
   * @return is the result of the division operation.
   */
  T DividedBy(const T& b) const;

  /**
   * Division operation. In-place variant.
   *
   * @param &b is the value to divide by.
   * @return is the result of the division operation.
   */
  const T& DividedByEq(const T& b);

  /// inline operators for the division operation.
  inline friend T operator/(const T& a, const T& b) {
    return a.DividedBy(b); }
  inline friend const T& operator/=(T& a, const T& b) {
   
    return a.DividedByEq(b);
  }

  /**
   * Multiply and Rounding operation. Returns [x*p/q] where [] is the rounding
   * operation.
   *
   * @param &p is the numerator to be multiplied.
   * @param &q is the denominator to be divided.
   * @return is the result of multiply and round operation.
   */
  T MultiplyAndRound(const T& p, const T& q) const;

  /**
   * Multiply and Rounding operation. Returns [x*p/q] where [] is the rounding
   * operation. In-place variant.
   *
   * @param &p is the numerator to be multiplied.
   * @param &q is the denominator to be divided.
   * @return is the result of multiply and round operation.
   */
  const T& MultiplyAndRoundEq(const T& p, const T& q);

  /**
   * Divide and Rounding operation. Returns [x/q] where [] is the rounding
   * operation.
   *
   * @param &q is the denominator to be divided.
   * @return is the result of divide and round operation.
   */
  T DivideAndRound(const T& q) const;

  /**
   * Divide and Rounding operation. Returns [x/q] where [] is the rounding
   * operation. In-place variant.
   *
   * @param &q is the denominator to be divided.
   * @return is the result of divide and round operation.
   */
  const T& DivideAndRoundEq(const T& q);

  // MODULAR ARITHMETIC OPERATIONS

  /**
   * Naive modulus operation.
   *
   * @param &modulus is the modulus to perform.
   * @return is the result of the modulus operation.
   */
  T Mod(const T& modulus) const;

  /**
   * Naive modulus operation. In-place variant.
   *
   * @param &modulus is the modulus to perform.
   * @return is the result of the modulus operation.
   */
  const T& ModEq(const T& modulus);

  // inline operators for the modulus operation.
  inline friend T operator%(const T& a, const T& b) {
    return a.Mod(b); }
  inline friend const T& operator%=(T& a, const T& b) {
    return a.ModEq(b); }

  /**
   * Precomputes a parameter mu for Barrett modular reduction.
   *
   * @return the precomputed parameter mu.
   */
  T ComputeMu() const;

  /**
   * Barrett modulus operation.
   * Implements generalized Barrett modular reduction algorithm. Uses one
   * precomputed value of mu.
   *
   * @param &modulus is the modulus to perform.
   * @param &mu is the Barrett value.
   * @return is the result of the modulus operation.
   */
  T Mod(const T& modulus, const T& mu) const;

  /**
   * Barrett modulus operation. In-place variant.
   * Implements generalized Barrett modular reduction algorithm. Uses one
   * precomputed value of mu.
   *
   * @param &modulus is the modulus to perform.
   * @param &mu is the Barrett value.
   * @return is the result of the modulus operation.
   */
  const T& ModEq(const T& modulus, const T& mu);

  /**
   * Modulus addition operation.
   *
   * @param &b is the scalar to add.
   * @param &modulus is the modulus to perform operations with.
   * @return is the result of the modulus addition operation.
   */
  T ModAdd(const T& b, const T& modulus) const;

  /**
   * Modulus addition operation. In-place variant.
   *
   * @param &b is the scalar to add.
   * @param &modulus is the modulus to perform operations with.
   * @return is the result of the modulus addition operation.
   */
  const T& ModAddEq(const T& b, const T& modulus);

  /**
   * Modulus addition where operands are < modulus.
   *
   * @param &b is the scalar to add.
   * @param &modulus is the modulus to perform operations with.
   * @return is the result of the modulus addition operation.
   */
  T ModAddFast(const T& b, const T& modulus) const;

  /**
   * Modulus addition where operands are < modulus. In-place variant.
   *
   * @param &b is the scalar to add.
   * @param &modulus is the modulus to perform operations with.
   * @return is the result of the modulus addition operation.
   */
  const T& ModAddFastEq(const T& b, const T& modulus);

  /**
   * Barrett modulus addition operation.
   *
   * @param &b is the scalar to add.
   * @param &modulus is the modulus to perform operations with.
   * @param &mu is the Barrett value.
   * @return is the result of the modulus addition operation.
   */
  T ModAdd(const T& b, const T& modulus, const T& mu) const;

  /**
   * Barrett modulus addition operation. In-place variant.
   *
   * @param &b is the scalar to add.
   * @param &modulus is the modulus to perform operations with.
   * @param &mu is the Barrett value.
   * @return is the result of the modulus addition operation.
   */
  const T& ModAddEq(const T& b, const T& modulus, const T& mu);

  /**
   * Modulus subtraction operation.
   *
   * @param &b is the scalar to subtract.
   * @param &modulus is the modulus to perform operations with.
   * @return is the result of the modulus subtraction operation.
   */
  T ModSub(const T& b, const T& modulus) const;

  /**
   * Modulus subtraction operation. In-place variant.
   *
   * @param &b is the scalar to subtract.
   * @param &modulus is the modulus to perform operations with.
   * @return is the result of the modulus subtraction operation.
   */
  const T& ModSubEq(const T& b, const T& modulus);

  /**
   * Modulus subtraction where operands are < modulus.
   *
   * @param &b is the scalar to subtract.
   * @param &modulus is the modulus to perform operations with.
   * @return is the result of the modulus subtraction operation.
   */
  T ModSubFast(const T& b, const T& modulus) const;

  /**
   * Modulus subtraction where operands are < modulus. In-place variant.
   *
   * @param &b is the scalar to subtract.
   * @param &modulus is the modulus to perform operations with.
   * @return is the result of the modulus subtraction operation.
   */
  const T& ModSubFastEq(const T& b, const T& modulus);

  /**
   * Barrett modulus subtraction operation.
   *
   * @param &b is the scalar to subtract.
   * @param &modulus is the modulus to perform operations with.
   * @param &mu is the Barrett value.
   * @return is the result of the modulus subtraction operation.
   */
  T ModSub(const T& b, const T& modulus, const T& mu) const;

  /**
   * Barrett modulus subtraction operation. In-place variant.
   *
   * @param &b is the scalar to subtract.
   * @param &modulus is the modulus to perform operations with.
   * @param &mu is the Barrett value.
   * @return is the result of the modulus subtraction operation.
   */
  const T& ModSubEq(const T& b, const T& modulus, const T& mu);

  /**
   * Modulus multiplication operation.
   *
   * @param &b is the scalar to multiply.
   * @param &modulus is the modulus to perform operations with.
   * @return is the result of the modulus multiplication operation.
   */
  T ModMul(const T& b, const T& modulus) const;

  /**
   * Modulus multiplication operation. In-place variant.
   *
   * @param &b is the scalar to multiply.
   * @param &modulus is the modulus to perform operations with.
   * @return is the result of the modulus multiplication operation.
   */
  const T& ModMulEq(const T& b, const T& modulus);

  /**
   * Barrett modulus multiplication.
   *
   * @param &b is the scalar to multiply.
   * @param &modulus is the modulus to perform operations with.
   * @param &mu is the Barrett value.
   * @return is the result of the modulus multiplication operation.
   */
  T ModMul(const T& b, const T& modulus, const T& mu) const;

  /**
   * Barrett modulus multiplication. In-place variant.
   *
   * @param &b is the scalar to multiply.
   * @param &modulus is the modulus to perform operations with.
   * @param &mu is the Barrett value.
   * @return is the result of the modulus multiplication operation.
   */
  const T& ModMulEq(const T& b, const T& modulus, const T& mu);

  /**
   * Modulus multiplication that assumes the operands are < modulus.
   *
   * @param &b is the scalar to multiply.
   * @param &modulus is the modulus to perform operations with.
   * @return is the result of the modulus multiplication operation.
   */
  T ModMulFast(const T& b, const T& modulus) const<
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值