PALISADE Lattice Crypto Library  1.11.9
A lattice crypto library for software engineers by software engineers.
ilparams.h
Go to the documentation of this file.
1 // @file ilparams.h Wraps parameters for integer lattice operations. Inherits
2 // from ElemParams.
3 // @author TPOC: contact@palisade-crypto.org
4 //
5 // @copyright Copyright (c) 2019, New Jersey Institute of Technology (NJIT)
6 // All rights reserved.
7 // Redistribution and use in source and binary forms, with or without
8 // modification, are permitted provided that the following conditions are met:
9 // 1. Redistributions of source code must retain the above copyright notice,
10 // this list of conditions and the following disclaimer.
11 // 2. Redistributions in binary form must reproduce the above copyright notice,
12 // this list of conditions and the following disclaimer in the documentation
13 // and/or other materials provided with the distribution. THIS SOFTWARE IS
14 // PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
15 // IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
16 // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
17 // EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
18 // INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
19 // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
20 // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
21 // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
23 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 
25 #ifndef LBCRYPTO_LATTICE_ILPARAMS_H
26 #define LBCRYPTO_LATTICE_ILPARAMS_H
27 
28 #include <string>
29 
30 #include "lattice/elemparams.h"
31 #include "math/backend.h"
32 #include "math/nbtheory.h"
33 #include "utils/inttypes.h"
34 
35 namespace lbcrypto {
36 
43 template <typename IntType>
44 class ILParamsImpl : public ElemParams<IntType> {
45  public:
46  typedef IntType Integer;
47 
52  ILParamsImpl() : ElemParams<IntType>(0, 0) {}
53 
65  ILParamsImpl(const usint order, const IntType &modulus,
66  const IntType &rootOfUnity, const IntType &bigModulus = 0,
67  const IntType &bigRootOfUnity = 0)
68  : ElemParams<IntType>(order, modulus, rootOfUnity, bigModulus,
69  bigRootOfUnity) {}
70 
77  ILParamsImpl(const usint order, const IntType &modulus)
78  : ElemParams<IntType>(order, modulus) {
79  this->rootOfUnity = RootOfUnity<IntType>(order, modulus);
80  }
81 
87  ILParamsImpl(const ILParamsImpl &rhs) : ElemParams<IntType>(rhs) {}
88 
95  const ILParamsImpl &operator=(const ILParamsImpl &rhs) {
97  return *this;
98  }
99 
105  ILParamsImpl(const ILParamsImpl &&rhs) : ElemParams<IntType>(rhs) {}
106 
111 
119  bool operator==(const ElemParams<IntType> &rhs) const {
120  if (dynamic_cast<const ILParamsImpl<IntType> *>(&rhs) == nullptr)
121  return false;
122 
124  }
125 
126  private:
127  std::ostream &doprint(std::ostream &out) const {
128  out << "ILParams ";
130  out << std::endl;
131  return out;
132  }
133 
134  public:
135  template <class Archive>
136  void save(Archive &ar, std::uint32_t const version) const {
137  ar(::cereal::base_class<ElemParams<IntType>>(this));
138  }
139 
140  template <class Archive>
141  void load(Archive &ar, std::uint32_t const version) {
142  if (version > SerializedVersion()) {
143  PALISADE_THROW(deserialize_error,
144  "serialized object version " + std::to_string(version) +
145  " is from a later version of the library");
146  }
147  ar(::cereal::base_class<ElemParams<IntType>>(this));
148  }
149 
150  std::string SerializedObjectName() const { return "ILParms"; }
151  static uint32_t SerializedVersion() { return 1; }
152 };
153 
154 } // namespace lbcrypto
155 
156 #endif
ILParamsImpl(const ILParamsImpl &rhs)
Copy constructor.
Definition: ilparams.h:87
bool operator==(const ElemParams< IntType > &rhs) const
Equality operator compares ElemParams (which will be dynamic casted)
Definition: ilparams.h:119
Definition: backend.h:38
Definition: elemparams.h:43
const ElemParams & operator=(const ElemParams &rhs)
Assignment operator using assignment operations of wrapped elements.
Definition: elemparams.h:103
const ILParamsImpl & operator=(const ILParamsImpl &rhs)
Assignment Operator.
Definition: ilparams.h:95
Definition: exception.h:147
ILParamsImpl(const usint order, const IntType &modulus)
Constructor for the case of partially pre-computed parameters.
Definition: ilparams.h:77
ILParamsImpl()
Definition: ilparams.h:52
~ILParamsImpl()
Standard Destructor method.
Definition: ilparams.h:110
Wrapper class to hold the parameters for Element types and their inheritors.
ILParamsImpl(const usint order, const IntType &modulus, const IntType &rootOfUnity, const IntType &bigModulus=0, const IntType &bigRootOfUnity=0)
Constructor for the case of partially pre-computed parameters.
Definition: ilparams.h:65
virtual bool operator==(const ElemParams< IntegerType > &other) const
Equality operator that tests the equality of all wrapped values.
Definition: elemparams.h:183
ILParamsImpl(const ILParamsImpl &&rhs)
Move constructor.
Definition: ilparams.h:105
virtual std::ostream & doprint(std::ostream &out) const
Pretty print operator for the ElemParams type.
Definition: elemparams.h:246
Definition: binfhecontext.h:36