HEaaN
Crypto Lab's great homomorphic encryption library
KeyGenerator.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 #include <optional>
15 #include <string>
16 
17 #include "HEaaN/Context.hpp"
18 #include "HEaaN/HEaaNExport.hpp"
19 #include "HEaaN/KeyPack.hpp"
20 
21 namespace HEaaN {
22 
23 class SecretKey;
24 class KeyGeneratorImpl;
25 
31 public:
37  explicit KeyGenerator(const Context &context, const SecretKey &sk);
38 
43  explicit KeyGenerator(const Context &context, const SecretKey &sk,
44  const KeyPack &pack);
45 
55  explicit KeyGenerator(const Context &context, const Context &context_sparse,
56  const SecretKey &sk);
57 
66  explicit KeyGenerator(const Context &context, const Context &context_sparse,
67  const SecretKey &sk, const KeyPack &pack);
68 
70  // Functions for key generation //
72 
74  void genEncryptionKey(void) const;
75 
77  void genMultiplicationKey(void) const;
78 
80  void genConjugationKey(void) const;
81 
84  void genLeftRotationKey(u64 rot) const;
85 
88  void genRightRotationKey(u64 rot) const;
89 
94  void genRotationKeyBundle(void) const;
95 
101  void genSparseSecretEncapsulationKey(void) const;
102 
110  inline void genCommonKeys(void) const {
111  genEncryptionKey();
112  genMultiplicationKey();
113  genConjugationKey();
114  genRotationKeyBundle();
115  }
116 
123  void genRotKeysForBootstrap(const u64 log_slots) const;
124 
126  // Utility functions //
128 
134  void save(const std::string &dir_path) const;
135 
137  void flush(void);
138 
142  KeyPack getKeyPack() const { return pack_; }
143 
144 private:
146  const std::optional<Context> context_sparse_;
147 
150 
151  std::shared_ptr<KeyGeneratorImpl> impl_;
152 };
153 } // namespace HEaaN
HEaaN::KeyPack
Class managing public keys.
Definition: KeyPack.hpp:29
HEaaN::SecretKey
Secret key class.
Definition: SecretKey.hpp:26
HEaaN::KeyGenerator::genCommonKeys
void genCommonKeys(void) const
Generate commonly used keys.
Definition: KeyGenerator.hpp:110
HEaaN::KeyGenerator::context_sparse_
const std::optional< Context > context_sparse_
Definition: KeyGenerator.hpp:146
HEaaN::u64
std::uint64_t u64
Definition: Integers.hpp:17
HEaaN::KeyGenerator
A class generating public (encryption/evaluation) keys from a secret key.
Definition: KeyGenerator.hpp:30
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::KeyGenerator::impl_
std::shared_ptr< KeyGeneratorImpl > impl_
Definition: KeyGenerator.hpp:151
HEaaN::KeyGenerator::getKeyPack
KeyPack getKeyPack() const
Extract the internal KeyPack object.
Definition: KeyGenerator.hpp:142
HEaaN::KeyGenerator::pack_
KeyPack pack_
The internal keypack object.
Definition: KeyGenerator.hpp:149
HEaaN::KeyGenerator::context_
const Context context_
Definition: KeyGenerator.hpp:145
HEAAN_API
#define HEAAN_API
Definition: HEaaNExport.hpp:26
HEaaN
Definition: Bootstrapper.hpp:16
KeyPack.hpp