recryption.h
1 /* Copyright (C) 2012-2020 IBM Corp.
2  * This program is Licensed under the Apache License, Version 2.0
3  * (the "License"); you may not use this file except in compliance
4  * with the License. You may obtain a copy of the License at
5  * http://www.apache.org/licenses/LICENSE-2.0
6  * Unless required by applicable law or agreed to in writing, software
7  * distributed under the License is distributed on an "AS IS" BASIS,
8  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
9  * See the License for the specific language governing permissions and
10  * limitations under the License. See accompanying LICENSE file.
11  */
12 #ifndef HELIB_RECRYPTION_H
13 #define HELIB_RECRYPTION_H
18 #include <helib/NumbTh.h>
19 
20 namespace helib {
21 
22 extern long thinRecrypt_initial_level;
23 extern long fhe_force_chen_han;
24 extern long printFlag;
25 
26 class PAlgebraMod;
27 class EncryptedArray;
28 class EvalMap;
29 class ThinEvalMap;
30 class PowerfulDCRT;
31 class Context;
32 class PubKey;
33 
37 {
38 public:
40  NTL::Vec<long> mvec;
41 
43  long e, ePrime;
44 
46  long skHwt;
47 
49  std::shared_ptr<const PAlgebraMod> alMod = nullptr;
50 
52  std::shared_ptr<const EncryptedArray> ea = nullptr;
53 
55 
56  bool alsoThick;
57 
59  std::shared_ptr<const EvalMap> firstMap = nullptr, secondMap = nullptr;
60 
62  std::shared_ptr<const PowerfulDCRT> p2dConv = nullptr;
63 
65  std::vector<NTL::ZZX> unpackSlotEncoding;
66 
68  {
69  skHwt = 0;
70  e = ePrime = 0;
71  build_cache = false;
72  alsoThick = false;
73  }
74 
76  void init(const Context& context,
77  const NTL::Vec<long>& mvec_,
78  bool enableThick, /*init linear transforms for non-thin*/
79  bool build_cache = false,
80  bool minimal = false);
81 
82  bool operator==(const RecryptData& other) const;
83  bool operator!=(const RecryptData& other) const
84  {
85  return !(operator==(other));
86  }
87 
89  static void setAE(long& e, long& ePrime, const Context& context);
90  // VJS-FIXME: this needs to be documented.
91  // It is based on the most recent version of our bootstrapping
92  // paper (see Section 6.2)
93 };
94 
99 {
100 public:
102  std::shared_ptr<const ThinEvalMap> coeffToSlot, slotToCoeff;
103 
105  void init(const Context& context,
106  const NTL::Vec<long>& mvec_,
107  bool alsoThick, /*init linear transforms also for non-thin*/
108  bool build_cache = false,
109  bool minimal = false);
110 };
111 
112 #define HELIB_MIN_CAP_FRAC (2.0 / 3.0)
113 // Used in calculation of "min capacity".
114 // This could be set to 1.0, but just to be on the safe side,
115 // it is set to 2/3. If we did set it to 1, the min capacity
116 // would increase by less than 6/10 of a bit.
117 
118 } // namespace helib
119 
120 #endif // HELIB_RECRYPTION_H
Maintaining the HE scheme parameters.
Definition: Context.h:100
A structure to hold recryption-related data inside the Context.
Definition: recryption.h:37
long e
partition of m into co-prime factors
Definition: recryption.h:43
bool operator==(const RecryptData &other) const
Definition: recryption.cpp:258
std::shared_ptr< const EvalMap > secondMap
Definition: recryption.h:59
long ePrime
Definition: recryption.h:43
std::shared_ptr< const EvalMap > firstMap
linear maps
Definition: recryption.h:59
long skHwt
Hamming weight of recryption secret key.
Definition: recryption.h:46
std::shared_ptr< const PowerfulDCRT > p2dConv
conversion between ZZX and Powerful
Definition: recryption.h:62
bool alsoThick
Definition: recryption.h:56
bool build_cache
Definition: recryption.h:54
static void setAE(long &e, long &ePrime, const Context &context)
Helper function for computing the recryption parameters.
Definition: recryption.cpp:200
bool operator!=(const RecryptData &other) const
Definition: recryption.h:83
void init(const Context &context, const NTL::Vec< long > &mvec_, bool enableThick, bool build_cache=false, bool minimal=false)
Initialize the recryption data in the context.
Definition: recryption.cpp:270
std::shared_ptr< const PAlgebraMod > alMod
for plaintext space p^{e-e'+r}
Definition: recryption.h:49
RecryptData()
Definition: recryption.h:67
NTL::Vec< long > mvec
Some data members that are only used for I/O.
Definition: recryption.h:40
std::vector< NTL::ZZX > unpackSlotEncoding
linPolys for unpacking the slots
Definition: recryption.h:65
std::shared_ptr< const EncryptedArray > ea
for plaintext space p^{e-e'+r}
Definition: recryption.h:52
Same as above, but for "thin" bootstrapping, where the slots are assumed to contain constants.
Definition: recryption.h:99
std::shared_ptr< const ThinEvalMap > slotToCoeff
Definition: recryption.h:102
void init(const Context &context, const NTL::Vec< long > &mvec_, bool alsoThick, bool build_cache=false, bool minimal=false)
Initialize the recryption data in the context.
Definition: recryption.cpp:773
std::shared_ptr< const ThinEvalMap > coeffToSlot
linear maps
Definition: recryption.h:102
Definition: apiAttributes.h:21
long printFlag
long fhe_force_chen_han
Definition: recryption.cpp:791
long thinRecrypt_initial_level