25 #ifndef LBCRYPTO_MATH_BIGINTFXD_MUBINVECFXD_H 26 #define LBCRYPTO_MATH_BIGINTFXD_MUBINVECFXD_H 31 #include "utils/inttypes.h" 32 #include "utils/serializable.h" 34 #include "math/bigintfxd/ubintfxd.h" 45 template <
class IntegerType>
59 const IntegerType &modulus) {
72 explicit BigVectorImpl(usint length,
const IntegerType &modulus = 0);
99 std::initializer_list<std::string> rhs);
111 std::initializer_list<uint64_t> rhs);
161 this->m_data[0] = val;
162 if (this->m_modulus != 0) {
163 this->m_data[0] %= this->m_modulus;
165 for (
size_t i = 1; i <
GetLength(); ++i) {
179 IntegerType &
at(
size_t i) {
180 if (!this->IndexCheck(i)) {
183 return this->m_data[i];
186 const IntegerType &
at(
size_t i)
const {
187 if (!this->IndexCheck(i)) {
190 return this->m_data[i];
198 IntegerType &
operator[](
size_t idx) {
return (this->m_data[idx]); }
200 const IntegerType &
operator[](
size_t idx)
const {
201 return (this->m_data[idx]);
224 const IntegerType &
GetModulus()
const {
return this->m_modulus; }
441 const IntegerType &q)
const;
452 const IntegerType &q);
502 template <
class IntegerType_c>
505 auto len = ptr_obj.m_length;
507 for (usint i = 0; i < len; i++) {
508 os << ptr_obj.m_data[i];
509 os << ((i == (len - 1)) ?
"]" :
" ");
511 os <<
" modulus: " << ptr_obj.m_modulus;
517 template <
class Archive>
518 typename std::enable_if<!cereal::traits::is_text_archive<Archive>::value,
520 save(Archive &ar, std::uint32_t
const version)
const {
521 ar(::cereal::make_nvp(
"m", m_modulus));
522 ar(::cereal::make_nvp(
"l", m_length));
523 ar(::cereal::binary_data(m_data,
sizeof(IntegerType) * m_length));
526 template <
class Archive>
527 typename std::enable_if<cereal::traits::is_text_archive<Archive>::value,
529 save(Archive &ar, std::uint32_t
const version)
const {
530 ar(::cereal::make_nvp(
"m", m_modulus));
531 ar(::cereal::make_nvp(
"l", m_length));
532 for (
size_t i = 0; i < m_length; i++) {
537 template <
class Archive>
538 typename std::enable_if<!cereal::traits::is_text_archive<Archive>::value,
540 load(Archive &ar, std::uint32_t
const version) {
541 if (version > SerializedVersion()) {
543 "serialized object version " + std::to_string(version) +
544 " is from a later version of the library");
546 ar(::cereal::make_nvp(
"m", m_modulus));
547 ar(::cereal::make_nvp(
"l", m_length));
548 m_data =
new IntegerType[m_length]();
549 ar(::cereal::binary_data(m_data,
sizeof(IntegerType) * m_length));
552 template <
class Archive>
553 typename std::enable_if<cereal::traits::is_text_archive<Archive>::value,
555 load(Archive &ar, std::uint32_t
const version) {
556 if (version > SerializedVersion()) {
558 "serialized object version " + std::to_string(version) +
559 " is from a later version of the library");
561 ar(::cereal::make_nvp(
"m", m_modulus));
562 ar(::cereal::make_nvp(
"l", m_length));
563 m_data =
new IntegerType[m_length]();
564 for (
size_t i = 0; i < m_length; i++) {
569 std::string SerializedObjectName()
const {
return "FXDInteger"; }
571 static uint32_t SerializedVersion() {
return 1; }
579 IntegerType m_modulus = 0;
582 bool IndexCheck(
size_t length)
const {
583 if (length > this->m_length) {
595 #endif // LBCRYPTO_MATH_BIGINTFXD_MUBINVECFXD_H const BigVectorImpl & operator=(uint64_t val)
Definition: mubintvecfxd.h:160
BigVectorImpl ModExp(const IntegerType &b) const
Definition: mubintvecfxd.cpp:439
const BigVectorImpl & ModEq(const IntegerType &modulus)
Definition: mubintvecfxd.cpp:231
Base class for PALISADE serialization.
Definition: serializable.h:76
void SwitchModulus(const IntegerType &value)
Definition: mubintvecfxd.cpp:195
BigVectorImpl GetDigitAtIndexForBase(usint index, usint base) const
Definition: mubintvecfxd.cpp:573
IntegerType & operator[](size_t idx)
Definition: mubintvecfxd.h:198
BigVectorImpl ModByTwo() const
Definition: mubintvecfxd.cpp:471
const BigVectorImpl & MultiplyAndRoundEq(const IntegerType &p, const IntegerType &q)
Definition: mubintvecfxd.cpp:530
BigVectorImpl DivideAndRound(const IntegerType &q) const
Definition: mubintvecfxd.cpp:547
BigVectorImpl ModMul(const IntegerType &b) const
Definition: mubintvecfxd.cpp:349
const BigVectorImpl & ModMulEq(const IntegerType &b)
Definition: mubintvecfxd.cpp:380
size_t GetLength() const
Definition: mubintvecfxd.h:231
Definition: interface.h:588
BigVectorImpl MultWithOutMod(const BigVectorImpl &b) const
Definition: mubintvecfxd.cpp:499
void SetModulus(const IntegerType &value)
Definition: mubintvecfxd.cpp:185
BigVectorImpl ModAddAtIndex(usint i, const IntegerType &b) const
Definition: mubintvecfxd.cpp:267
Definition: exception.h:147
Definition: exception.h:113
const BigVectorImpl & ModAddEq(const IntegerType &b)
Definition: mubintvecfxd.cpp:257
BigVectorImpl()
Definition: mubintvecfxd.cpp:36
const BigVectorImpl & ModAddAtIndexEq(usint i, const IntegerType &b)
Definition: mubintvecfxd.cpp:275
const BigVectorImpl & ModInverseEq()
Definition: mubintvecfxd.cpp:463
BigVectorImpl ModInverse() const
Definition: mubintvecfxd.cpp:456
const BigVectorImpl & MultWithOutModEq(const BigVectorImpl &b)
Definition: mubintvecfxd.cpp:507
Main class for big integers represented as an array of native (primitive) unsigned integers...
Definition: ubintfxd.h:219
const BigVectorImpl & operator=(const BigVectorImpl &rhs)
Definition: mubintvecfxd.cpp:112
const BigVectorImpl & DivideAndRoundEq(const IntegerType &q)
Definition: mubintvecfxd.cpp:555
BigVectorImpl Mod(const IntegerType &modulus) const
Definition: mubintvecfxd.cpp:223
const BigVectorImpl & ModByTwoEq()
Definition: mubintvecfxd.cpp:478
The class for representing vectors of big binary integers.
Definition: mubintvecfxd.h:46
BigVectorImpl ModAdd(const IntegerType &b) const
Definition: mubintvecfxd.cpp:249
BigVectorImpl ModSub(const IntegerType &b) const
Definition: mubintvecfxd.cpp:309
const BigVectorImpl & ModSubEq(const IntegerType &b)
Definition: mubintvecfxd.cpp:317
friend std::ostream & operator<<(std::ostream &os, const BigVectorImpl< IntegerType_c > &ptr_obj)
Definition: mubintvecfxd.h:503
BigVectorImpl MultiplyAndRound(const IntegerType &p, const IntegerType &q) const
Definition: mubintvecfxd.cpp:521
IntegerType & at(size_t i)
Definition: mubintvecfxd.h:179
virtual ~BigVectorImpl()
Definition: mubintvecfxd.cpp:105
const IntegerType & GetModulus() const
Definition: mubintvecfxd.h:224
const BigVectorImpl & ModExpEq(const IntegerType &b)
Definition: mubintvecfxd.cpp:447