-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathnand.cpp
More file actions
59 lines (51 loc) · 1.65 KB
/
nand.cpp
File metadata and controls
59 lines (51 loc) · 1.65 KB
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
#ifdef USE_PERF
#include <gperftools/profiler.h>
#endif
#include <cassert>
#include <chrono>
#include <iostream>
#include <random>
#include <tfhe++.hpp>
using namespace std;
using namespace TFHEpp;
int main()
{
std::cout << lvl1param::k << std::endl;
constexpr uint32_t num_test = 1000;
random_device seed_gen;
default_random_engine engine(seed_gen());
uniform_int_distribution<uint32_t> binary(0, 1);
SecretKey* sk = new SecretKey();
TFHEpp::EvalKey ek;
ek.emplacebkfft<TFHEpp::lvl01param>(*sk);
ek.emplaceiksk<TFHEpp::lvl10param>(*sk);
vector<uint8_t> pa(num_test);
vector<uint8_t> pb(num_test);
vector<uint8_t> pres(num_test);
for (int i = 0; i < num_test; i++) pa[i] = binary(engine) > 0;
for (int i = 0; i < num_test; i++) pb[i] = binary(engine) > 0;
vector<TLWE<TFHEpp::lvl1param>> ca(num_test);
vector<TLWE<TFHEpp::lvl1param>> cb(num_test);
vector<TLWE<TFHEpp::lvl1param>> cres(num_test);
bootsSymEncrypt(ca, pa, *sk);
bootsSymEncrypt(cb, pb, *sk);
chrono::system_clock::time_point start, end;
#ifdef USE_PERF
ProfilerStart("nand.prof");
#endif
start = chrono::system_clock::now();
for (int test = 0; test < num_test; test++) {
HomNAND(cres[test], ca[test], cb[test], ek);
}
end = chrono::system_clock::now();
#ifdef USE_PERF
ProfilerStop();
#endif
pres = bootsSymDecrypt(cres, *sk);
for (int i = 0; i < num_test; i++) assert(pres[i] == !(pa[i] & pb[i]));
cout << "Passed" << endl;
double elapsed =
std::chrono::duration_cast<std::chrono::milliseconds>(end - start)
.count();
cout << elapsed / num_test << "ms" << endl;
}