forked from lbibe/code
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
83 lines (65 loc) · 2.29 KB
/
Copy pathmain.cpp
File metadata and controls
83 lines (65 loc) · 2.29 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#include<iostream>
#include <chrono>
#include<thread>
#include<algorithm>
#include<complex>
#include "util/fast_fft.hpp"
#include "ibe/user.hpp"
#include "ibe/trusted_third_party.hpp"
#include<nfl.hpp>
#define sigma_1024_ibe 5
#define zeta_1024_ibe 6360
#define tau_1024_ibe 5
using namespace Ibe;
int main(void) {
// Pool of threads
std::thread pool[2];
mpz_t mod;
mpz_init(mod);
mpz_set(mod, Poly_t::moduli_product());
const uint32_t modulo = mpz_get_ui(mod);
std::cout << "Before TrustedParty" << std::endl;
TrustedParty thirdParty{NFL_POLY_N, NFL_POLY_Q_BITS, modulo, sigma_1024_ibe, 80};
thirdParty.generateMasterKey();
thirdParty.setGaussian(zeta_1024_ibe);
thirdParty.preCompute(2);
std::cout << "Before User" << std::endl;
User sender{NFL_POLY_N, NFL_POLY_Q_BITS, modulo, tau_1024_ibe, 147.47, 80, 17, &thirdParty};
sender.extractPrivateKey();
sender.setEncrypt(505);
Poly_t m = nfl::uniform();
for (auto &m_i : m.poly_obj()) {
m_i %= 2;
}
Poly_t * ciphertext = new Poly_t[(NFL_POLY_Q_BITS + 3)*2];
sender.encrypt(ciphertext, m);
auto lambdaEnc = [&sender, &m](Poly_t * ciphertext, const uint32_t length) {
for(uint32_t i = 0; i < length; ++i) {
sender.encrypt(ciphertext, m);
}
};
pool[0] = std::thread(lambdaEnc, ciphertext, 100);
pool[1] = std::thread(lambdaEnc, ciphertext + NFL_POLY_Q_BITS + 3, 100);
auto start = std::chrono::high_resolution_clock::now();
pool[0].join();
pool[1].join();
auto end = std::chrono::high_resolution_clock::now();
auto timing = std::chrono::duration<double, std::milli>(end - start);
std::cout << "Encryption Time of 200 messages: " << timing.count() << " ms " << std::endl;
Poly_t * decrypted = new Poly_t[2];
sender.decrypt(decrypted, ciphertext);
auto lambdaDec = [&sender, ciphertext](Poly_t * output, const uint32_t length) {
for(uint32_t i = 0; i < length; ++i) {
sender.decrypt(output, ciphertext);
}
};
pool[0] = std::thread(lambdaDec, decrypted, 1000);
pool[1] = std::thread(lambdaDec, decrypted + 1, 1000);
start = std::chrono::high_resolution_clock::now();
pool[0].join();
pool[1].join();
end = std::chrono::high_resolution_clock::now();
timing = std::chrono::duration<double, std::milli>(end - start);
std::cout << "Decryption Time of 2000 ciphertexts: " << timing.count() << " ms " << std::endl;
return 0;
}