22 #ifndef LBCRYPTO_LATTICE_ELEMPARAMS_H 23 #define LBCRYPTO_LATTICE_ELEMPARAMS_H 29 #include "math/backend.h" 30 #include "math/nbtheory.h" 31 #include "utils/inttypes.h" 32 #include "utils/serializable.h" 42 template <
typename IntegerType>
57 const IntegerType& rUnity = IntegerType(0),
58 const IntegerType& bigCtModulus = IntegerType(0),
59 const IntegerType& bigRUnity = IntegerType(0)) {
60 cyclotomicOrder = order;
62 isPowerOfTwo = ringDimension == cyclotomicOrder / 2;
63 ciphertextModulus = ctModulus;
65 bigCiphertextModulus = bigCtModulus;
66 bigRootOfUnity = bigRUnity;
75 cyclotomicOrder = rhs.cyclotomicOrder;
76 ringDimension = rhs.ringDimension;
77 isPowerOfTwo = rhs.isPowerOfTwo;
78 ciphertextModulus = rhs.ciphertextModulus;
79 rootOfUnity = rhs.rootOfUnity;
80 bigCiphertextModulus = rhs.bigCiphertextModulus;
81 bigRootOfUnity = rhs.bigRootOfUnity;
90 cyclotomicOrder = rhs.cyclotomicOrder;
91 ringDimension = rhs.ringDimension;
92 isPowerOfTwo = rhs.isPowerOfTwo;
93 ciphertextModulus = std::move(rhs.ciphertextModulus);
94 rootOfUnity = std::move(rhs.rootOfUnity);
95 bigCiphertextModulus = std::move(rhs.bigCiphertextModulus);
96 bigRootOfUnity = std::move(rhs.bigRootOfUnity);
104 cyclotomicOrder = rhs.cyclotomicOrder;
105 ringDimension = rhs.ringDimension;
106 isPowerOfTwo = rhs.isPowerOfTwo;
107 ciphertextModulus = rhs.ciphertextModulus;
108 rootOfUnity = rhs.rootOfUnity;
109 bigCiphertextModulus = rhs.bigCiphertextModulus;
110 bigRootOfUnity = rhs.bigRootOfUnity;
146 const IntegerType&
GetModulus()
const {
return ciphertextModulus; }
184 return cyclotomicOrder == other.cyclotomicOrder &&
185 ringDimension == other.ringDimension &&
186 ciphertextModulus == other.ciphertextModulus &&
187 rootOfUnity == other.rootOfUnity &&
188 bigCiphertextModulus == other.bigCiphertextModulus &&
189 bigRootOfUnity == other.bigRootOfUnity;
198 return !(*
this == other);
201 template <
class Archive>
202 void save(Archive& ar, std::uint32_t
const version)
const {
203 ar(::cereal::make_nvp(
"co", cyclotomicOrder));
204 ar(::cereal::make_nvp(
"rd", ringDimension));
205 ar(::cereal::make_nvp(
"2n", isPowerOfTwo));
206 ar(::cereal::make_nvp(
"cm", ciphertextModulus));
207 ar(::cereal::make_nvp(
"ru", rootOfUnity));
208 ar(::cereal::make_nvp(
"bm", bigCiphertextModulus));
209 ar(::cereal::make_nvp(
"br", bigRootOfUnity));
212 template <
class Archive>
213 void load(Archive& ar, std::uint32_t
const version) {
214 if (version > SerializedVersion()) {
216 "serialized object version " + std::to_string(version) +
217 " is from a later version of the library");
219 ar(::cereal::make_nvp(
"co", cyclotomicOrder));
220 ar(::cereal::make_nvp(
"rd", ringDimension));
221 ar(::cereal::make_nvp(
"2n", isPowerOfTwo));
222 ar(::cereal::make_nvp(
"cm", ciphertextModulus));
223 ar(::cereal::make_nvp(
"ru", rootOfUnity));
224 ar(::cereal::make_nvp(
"bm", bigCiphertextModulus));
225 ar(::cereal::make_nvp(
"br", bigRootOfUnity));
228 std::string SerializedObjectName()
const {
return "ElemParams"; }
229 static uint32_t SerializedVersion() {
return 1; }
232 usint cyclotomicOrder;
236 IntegerType ciphertextModulus;
237 IntegerType rootOfUnity;
238 IntegerType bigCiphertextModulus;
239 IntegerType bigRootOfUnity;
246 virtual std::ostream&
doprint(std::ostream& out)
const {
247 out <<
"[m=" << cyclotomicOrder << (isPowerOfTwo ?
"* " :
" ")
248 <<
"n=" << ringDimension <<
" q=" << ciphertextModulus
249 <<
" ru=" << rootOfUnity <<
" bigq=" << bigCiphertextModulus
250 <<
" bigru=" << bigRootOfUnity <<
"]";
usint GetCyclotomicOrder() const
Simple getter method for cyclotomic order.
Definition: elemparams.h:124
Base class for PALISADE serialization.
Definition: serializable.h:76
const IntegerType & GetBigRootOfUnity() const
Simple getter method for the big root of unity.
Definition: elemparams.h:166
usint GetRingDimension() const
Simple ring dimension getter method. The ring dimension is the evaluation of the totient function of ...
Definition: elemparams.h:131
friend std::ostream & operator<<(std::ostream &out, const ElemParams &item)
Output strem operator.
Definition: elemparams.h:174
virtual ~ElemParams()
Simple destructor method.
Definition: elemparams.h:118
uint64_t GetTotient(const uint64_t n)
Definition: nbtheory2.cpp:87
ElemParams(const ElemParams &&rhs)
Copy constructor using move semnantics to copy wrapped elements.
Definition: elemparams.h:89
ElemParams(const ElemParams &rhs)
Copy constructor using assignment to copy wrapped elements.
Definition: elemparams.h:74
Definition: elemparams.h:43
const ElemParams & operator=(const ElemParams &rhs)
Assignment operator using assignment operations of wrapped elements.
Definition: elemparams.h:103
bool operator!=(const ElemParams< IntegerType > &other) const
Inequality operator that tests the equality of all wrapped values.
Definition: elemparams.h:197
Definition: exception.h:147
ElemParams(usint order, const IntegerType &ctModulus, const IntegerType &rUnity=IntegerType(0), const IntegerType &bigCtModulus=IntegerType(0), const IntegerType &bigRUnity=IntegerType(0))
Simple constructor method that takes as input root of unity, big root of unity, cyclotomic order and ...
Definition: elemparams.h:56
bool OrderIsPowerOfTwo() const
Returns True if the cyclotomic order or ring dimension is a power of 2.
Definition: elemparams.h:139
const IntegerType & GetModulus() const
Simple getter method for the ciphertext modulus, not the big ciphertext modulus.
Definition: elemparams.h:146
const IntegerType & GetRootOfUnity() const
Simple getter method for the root of unity, not the big root of unity.
Definition: elemparams.h:160
virtual bool operator==(const ElemParams< IntegerType > &other) const
Equality operator that tests the equality of all wrapped values.
Definition: elemparams.h:183
virtual std::ostream & doprint(std::ostream &out) const
Pretty print operator for the ElemParams type.
Definition: elemparams.h:246
const IntegerType & GetBigModulus() const
Simpler getter method for the big ciphertext modulus. This is not relevant for all applications...
Definition: elemparams.h:153
Definition: binfhecontext.h:36