HEaaN
Crypto Lab's great homomorphic encryption library
KeyPack.hpp
Go to the documentation of this file.
1 // //
3 // Copyright (C) 2021-2023 Crypto Lab Inc. //
4 // //
5 // - This file is part of HEaaN homomorphic encryption library. //
6 // - HEaaN cannot be copied and/or distributed without the express permission //
7 // of Crypto Lab Inc. //
8 // //
10 
11 #pragma once
12 
13 #include <memory>
14 
15 #include "HEaaN/Context.hpp"
16 #include "HEaaN/HEaaNExport.hpp"
17 #include "HEaaN/device/Device.hpp"
18 
19 namespace HEaaN {
20 
21 class EncryptionKey;
22 class EvaluationKey;
23 class SparseSecretEncapsulationKey;
24 class KeyPackImpl;
25 
30  friend class KeyGenerator;
31 
32 public:
34  explicit KeyPack(const Context &context);
35 
38  explicit KeyPack(const Context &context, const Context &context_sparse);
39 
43  explicit KeyPack(const Context &context, const std::string &key_dir_path);
44 
54  explicit KeyPack(const Context &context, const Context &context_sparse,
55  const std::string &key_dir_path);
56 
58  // Functions for key loading //
60 
65  void loadEncKey(void);
66  void loadEncKey(std::istream &stream);
67 
72  void loadMultKey(void);
73  void loadMultKey(std::istream &stream);
74 
79  void loadConjKey(void);
80  void loadConjKey(std::istream &stream);
81 
87  void loadLeftRotKey(const u64 rot);
88  void loadLeftRotKey(const u64 rot, std::istream &stream);
89 
95  void loadRightRotKey(const u64 rot);
96  void loadRightRotKey(const u64 rot, std::istream &stream);
97 
102  void loadSparseSecretEncapsulationKey(void);
103  void loadSparseSecretEncapsulationKey(std::istream &stream);
104 
106  // Functions for checking keys in the main memory //
108 
110  bool isEncKeyLoaded(void) const;
111 
113  bool isMultKeyLoaded(void) const;
114 
117  bool isLeftRotKeyLoaded(const u64 rot) const;
118 
121  bool isRightRotKeyLoaded(const u64 rot) const;
122 
124  bool isConjKeyLoaded(void) const;
125 
127  bool isLeftRotKeyFileAvailable(const u64 rot) const;
128 
131  bool isSparseSecretEncapsulationKeyLoaded() const;
132 
134  // Key Getters //
136 
142  std::shared_ptr<EncryptionKey> getEncKey(void) const;
143 
149  std::shared_ptr<EvaluationKey> getMultKey(void) const;
150 
157  std::shared_ptr<EvaluationKey> getLeftRotKey(const u64 rot) const;
158 
165  std::shared_ptr<EvaluationKey> getRightRotKey(const u64 rot) const;
166 
172  std::shared_ptr<EvaluationKey> getConjKey(void) const;
173 
179  std::shared_ptr<SparseSecretEncapsulationKey>
180  getSparseSecretEncapsulationKey(void) const;
181 
183  // Miscellaneous/Utility functions //
185 
187  void setKeyDirPath(const std::string &key_dir_path);
188 
192  void to(const Device &device);
193 
196  void save(std::ostream &stream) const;
197 
202  void load(std::istream &stream);
203 
206  void save(const std::string &dir_path) const;
207 
208 private:
210  std::shared_ptr<KeyPackImpl> impl_;
211 
214 };
215 
217 HEAAN_API void save(const EvaluationKey &key, std::ostream &stream);
218 HEAAN_API void save(const EncryptionKey &key, std::ostream &stream);
219 HEAAN_API void save(const SparseSecretEncapsulationKey &key,
220  std::ostream &stream);
221 
223 HEAAN_API void load(EvaluationKey &key, std::istream &stream);
224 HEAAN_API void load(EncryptionKey &key, std::istream &stream);
225 HEAAN_API void load(SparseSecretEncapsulationKey &key, std::istream &stream);
226 
227 } // namespace HEaaN
HEaaN::KeyPack
Class managing public keys.
Definition: KeyPack.hpp:29
HEaaN::load
HEAAN_API void load(EvaluationKey &key, std::istream &stream)
Load key from a given stream.
HEaaN::KeyPack::num_max_slots_
u64 num_max_slots_
Maximal number of slots for the current context object.
Definition: KeyPack.hpp:213
Device.hpp
HEaaN::u64
std::uint64_t u64
Definition: Integers.hpp:17
HEaaN::Device
Definition: Device.hpp:33
HEaaN::KeyGenerator
A class generating public (encryption/evaluation) keys from a secret key.
Definition: KeyGenerator.hpp:30
HEaaN::KeyPack::impl_
std::shared_ptr< KeyPackImpl > impl_
Pointer to the implementation class.
Definition: KeyPack.hpp:210
HEaaN::Context
std::shared_ptr< ContextContent > Context
Definition: Context.hpp:27
HEaaN::save
HEAAN_API void save(const EvaluationKey &key, std::ostream &stream)
Save key to a given stream.
Context.hpp
HEaaNExport.hpp
HEAAN_API
#define HEAAN_API
Definition: HEaaNExport.hpp:26
HEaaN
Definition: Bootstrapper.hpp:16