forked from MarbleHE/HECO
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwrapper.cpp.inc
106 lines (90 loc) · 2.94 KB
/
wrapper.cpp.inc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#include "seal/ciphertext.h"
#include "seal/evaluator.h"
#include "seal/plaintext.h"
#include <assert.h>
#include <fstream>
#include <iostream>
#include <string.h>
seal::Ciphertext trace();
std::unique_ptr<seal::SEALContext> context = nullptr;
std::unique_ptr<seal::Evaluator> evaluator = nullptr;
inline seal::EncryptionParameters load_parms(std::string parms_file)
{
std::ifstream parms_file_stream;
parms_file_stream.open(parms_file);
seal::EncryptionParameters parms;
parms.load(parms_file_stream);
return parms;
}
inline seal::PublicKey evaluator_load_public_key(std::string data_file, std::string parms_file)
{
context = std::make_unique<seal::SEALContext>(load_parms(parms_file));
evaluator = std::make_unique<seal::Evaluator>(*context);
std::ifstream data_file_stream;
data_file_stream.open(data_file);
seal::PublicKey pk;
pk.load(*context, data_file_stream);
return pk;
}
inline seal::RelinKeys evaluator_load_relin_keys(std::string data_file, std::string parms_file)
{
context = std::make_unique<seal::SEALContext>(load_parms(parms_file));
evaluator = std::make_unique<seal::Evaluator>(*context);
std::ifstream data_file_stream;
data_file_stream.open(data_file);
seal::RelinKeys rks;
rks.load(*context, data_file_stream);
return rks;
}
inline seal::RelinKeys evaluator_load_galois_keys(std::string data_file, std::string parms_file)
{
context = std::make_unique<seal::SEALContext>(load_parms(parms_file));
evaluator = std::make_unique<seal::Evaluator>(*context);
std::ifstream data_file_stream;
data_file_stream.open(data_file);
seal::RelinKeys rks;
rks.load(*context, data_file_stream);
return rks;
}
inline seal::Ciphertext evaluator_load_ctxt(std::string data_file, std::string parms_file)
{
context = std::make_unique<seal::SEALContext>(load_parms(parms_file));
evaluator = std::make_unique<seal::Evaluator>(*context);
std::ifstream data_file_stream;
data_file_stream.open(data_file);
seal::Ciphertext ctx;
ctx.load(*context, data_file_stream);
return ctx;
}
inline void evaluator_save_ctxt(const seal::Ciphertext &c, std::string filename)
{
std::ofstream file;
file.open(filename);
c.save(file);
file.close();
}
inline seal::Ciphertext evaluator_multiply(seal::Ciphertext &a, seal::Ciphertext &b)
{
assert(context && evaluator);
seal::Ciphertext result;
evaluator->multiply(a, b, result);
return result;
}
inline seal::Ciphertext evaluator_relinearize(seal::Ciphertext &a, seal::RelinKeys &b)
{
assert(context && evaluator);
seal::Ciphertext result;
evaluator->relinearize(a, b, result);
return result;
}
inline seal::Ciphertext evaluator_modswitch_to(seal::Ciphertext &a, seal::Ciphertext &b)
{
assert(context && evaluator);
seal::Ciphertext result;
evaluator->mod_switch_to(a, b.parms_id(), result);
return result;
}
int main()
{
evaluator_save_ctxt(trace(), "trace.ctxt");
}