24 #ifndef BINFHE_LWECORE_H 25 #define BINFHE_LWECORE_H 31 #include "math/backend.h" 32 #include "math/discretegaussiangenerator.h" 33 #include "utils/serializable.h" 37 typedef int64_t LWEPlaintext;
44 LWECryptoParams() : m_n(0), m_N(0), m_q(0), m_Q(0), m_qKS(0), m_baseKS(0) {}
59 : m_n(n), m_N(N), m_q(q), m_Q(Q), m_qKS(qKS), m_baseKS(baseKS) {
62 if (Q.
GetMSB() > MAX_MODULUS_SIZE) {
64 "ERROR: Maximum size of Q supported for FHEW is 60 bits.";
76 uint32_t digitCount = (uint32_t)std::ceil(
80 for (uint32_t i = 0; i < digitCount; i++) {
81 m_digitsKS.push_back(value);
91 this->m_qKS = rhs.m_qKS;
92 this->m_baseKS = rhs.m_baseKS;
93 this->m_digitsKS = rhs.m_digitsKS;
94 this->m_dgg.SetStd(rhs.m_dgg.GetStd());
98 this->m_n = std::move(rhs.m_n);
99 this->m_N = std::move(rhs.m_N);
100 this->m_q = std::move(rhs.m_q);
101 this->m_Q = std::move(rhs.m_Q);
102 this->m_qKS = std::move(rhs.m_qKS);
103 this->m_baseKS = std::move(rhs.m_baseKS);
104 this->m_digitsKS = std::move(rhs.m_digitsKS);
105 this->m_dgg.SetStd(rhs.m_dgg.GetStd());
113 this->m_qKS = rhs.m_qKS;
114 this->m_baseKS = rhs.m_baseKS;
115 this->m_digitsKS = rhs.m_digitsKS;
116 this->m_dgg.SetStd(rhs.m_dgg.GetStd());
121 this->m_n = std::move(rhs.m_n);
122 this->m_N = std::move(rhs.m_N);
123 this->m_q = std::move(rhs.m_q);
124 this->m_Q = std::move(rhs.m_Q);
125 this->m_qKS = std::move(rhs.m_qKS);
126 this->m_baseKS = std::move(rhs.m_baseKS);
127 this->m_digitsKS = std::move(rhs.m_digitsKS);
128 this->m_dgg.SetStd(rhs.m_dgg.GetStd());
132 uint32_t Getn()
const {
return m_n; }
134 uint32_t GetN()
const {
return m_N; }
142 uint32_t GetBaseKS()
const {
return m_baseKS; }
144 const std::vector<NativeInteger> &GetDigitsKS()
const {
return m_digitsKS; }
151 return m_n == other.m_n && m_N == other.m_N && m_q == other.m_q &&
152 m_Q == other.m_Q && m_dgg.GetStd() == other.m_dgg.GetStd() &&
153 m_baseKS == other.m_baseKS && m_digitsKS == other.m_digitsKS;
157 return !(*
this == other);
160 template <
class Archive>
161 void save(Archive &ar, std::uint32_t
const version)
const {
162 ar(::cereal::make_nvp(
"n", m_n));
163 ar(::cereal::make_nvp(
"N", m_N));
164 ar(::cereal::make_nvp(
"q", m_q));
165 ar(::cereal::make_nvp(
"Q", m_Q));
166 ar(::cereal::make_nvp(
"qSK", m_qKS));
167 ar(::cereal::make_nvp(
"sigma", m_dgg.GetStd()));
168 ar(::cereal::make_nvp(
"bKS", m_baseKS));
171 template <
class Archive>
172 void load(Archive &ar, std::uint32_t
const version) {
173 if (version > SerializedVersion()) {
175 "serialized object version " + std::to_string(version) +
176 " is from a later version of the library");
179 ar(::cereal::make_nvp(
"n", m_n));
180 ar(::cereal::make_nvp(
"N", m_N));
181 ar(::cereal::make_nvp(
"q", m_q));
182 ar(::cereal::make_nvp(
"Q", m_Q));
183 ar(::cereal::make_nvp(
"qSK", m_qKS));
185 ar(::cereal::make_nvp(
"sigma", sigma));
186 this->m_dgg.SetStd(sigma);
187 ar(::cereal::make_nvp(
"bKS", m_baseKS));
192 std::string SerializedObjectName()
const {
return "LWECryptoParams"; }
193 static uint32_t SerializedVersion() {
return 1; }
211 std::vector<NativeInteger> m_digitsKS;
223 : m_a(std::move(a)), m_b(b) {}
229 : m_a(std::move(a)), m_b(b) {}
237 this->m_a = std::move(rhs.m_a);
238 this->m_b = std::move(rhs.m_b);
248 this->m_a = std::move(rhs.m_a);
249 this->m_b = std::move(rhs.m_b);
255 const NativeInteger &GetA(std::size_t i)
const {
return m_a[i]; }
264 return m_a == other.m_a && m_b == other.m_b;
268 return !(*
this == other);
271 template <
class Archive>
272 void save(Archive &ar, std::uint32_t
const version)
const {
273 ar(::cereal::make_nvp(
"a", m_a));
274 ar(::cereal::make_nvp(
"b", m_b));
277 template <
class Archive>
278 void load(Archive &ar, std::uint32_t
const version) {
279 if (version > SerializedVersion()) {
281 "serialized object version " + std::to_string(version) +
282 " is from a later version of the library");
285 ar(::cereal::make_nvp(
"a", m_a));
286 ar(::cereal::make_nvp(
"b", m_b));
289 std::string SerializedObjectName()
const {
return "LWECiphertext"; }
290 static uint32_t SerializedVersion() {
return 1; }
311 this->m_s = std::move(rhs.m_s);
320 this->m_s = std::move(rhs.m_s);
329 return m_s == other.m_s;
333 return !(*
this == other);
336 template <
class Archive>
337 void save(Archive &ar, std::uint32_t
const version)
const {
338 ar(::cereal::make_nvp(
"s", m_s));
341 template <
class Archive>
342 void load(Archive &ar, std::uint32_t
const version) {
343 if (version > SerializedVersion()) {
345 "serialized object version " + std::to_string(version) +
346 " is from a later version of the library");
349 ar(::cereal::make_nvp(
"s", m_s));
352 std::string SerializedObjectName()
const {
return "LWEPrivateKey"; }
353 static uint32_t SerializedVersion() {
return 1; }
367 const std::vector<std::vector<std::vector<LWECiphertextImpl>>> &key)
371 this->m_key = rhs.m_key;
375 this->m_key = std::move(rhs.m_key);
379 this->m_key = rhs.m_key;
384 this->m_key = std::move(rhs.m_key);
388 const std::vector<std::vector<std::vector<LWECiphertextImpl>>> &GetElements()
394 const std::vector<std::vector<std::vector<LWECiphertextImpl>>> &key) {
399 return m_key == other.m_key;
403 return !(*
this == other);
406 template <
class Archive>
407 void save(Archive &ar, std::uint32_t
const version)
const {
408 ar(::cereal::make_nvp(
"k", m_key));
411 template <
class Archive>
412 void load(Archive &ar, std::uint32_t
const version) {
413 if (version > SerializedVersion()) {
415 "serialized object version " + std::to_string(version) +
416 " is from a later version of the library");
419 ar(::cereal::make_nvp(
"k", m_key));
422 std::string SerializedObjectName()
const {
return "LWEPrivateKey"; }
423 static uint32_t SerializedVersion() {
return 1; }
426 std::vector<std::vector<std::vector<LWECiphertextImpl>>> m_key;
LWECryptoParams(uint32_t n, uint32_t N, const NativeInteger &q, const NativeInteger &Q, const NativeInteger &qKS, double std, uint32_t baseKS)
Definition: lwecore.h:57
Base class for PALISADE serialization.
Definition: serializable.h:76
void PreCompute()
Definition: lwecore.h:74
Class that stores all parameters for the LWE scheme.
Definition: lwecore.h:42
usint GetMSB() const
Definition: ubintnat.h:1932
Definition: stl_allocator.h:124
Class that stores a LWE scheme ciphertext; composed of a vector "a" and integer "b".
Definition: lwecore.h:218
Definition: exception.h:147
Class that stores the LWE scheme switching key.
Definition: lwecore.h:362
Definition: mubintvecnat.h:102
Class that stores the LWE scheme secret key; contains a vector.
Definition: lwecore.h:300
The class for Discrete Gaussion Distribution generator.
Definition: discretegaussiangenerator.h:73
Definition: binfhecontext.h:36
Main class for big integers represented as an array of native (primitive) unsigned integers...
Definition: backend.h:60
Definition: exception.h:107
double ConvertToDouble() const
Definition: ubintnat.h:1899