-
Notifications
You must be signed in to change notification settings - Fork 0
/
Save
102 lines (80 loc) · 3.21 KB
/
Save
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
int old_main(int argc, char **argv) {
parse_party_and_port(argv, &role, &port);
if (argc >= 4) address = argv[3];
if (argc >= 5) num_ot = atoi(argv[4]);
if (argc >= 6) bitlen = atoi(argv[5]);
if (argc >= 7) num_threads = atoi(argv[6]);
cout << "Performing " << num_ot << " 1oo2 OTs on " << bitlen
<< "-bit messages with " << num_threads << " threads" << endl;
chrono::high_resolution_clock::time_point time_start, time_end;
time_start = chrono::high_resolution_clock::now();
NetIO *io = new NetIO(role == ALICE ? NULL : address.c_str(), port);
cout << "SetUp IO connection for " << role << endl;
PQOT ot(io, role, num_threads, plain_modulus_bitlen);
time_end = chrono::high_resolution_clock::now();
chrono::microseconds time_context = chrono::duration_cast<
chrono::microseconds>(time_end - time_start);
cout << "Context Initialization Time: " << time_context.count() << " microseconds" << endl;
io->sync();
cout << "sync IO connection for " << role << endl;
uint64_t keygen_comm_start = io->get_total_comm();
time_start = chrono::high_resolution_clock::now();
// Keygen
ot.keygen();
time_end = chrono::high_resolution_clock::now();
uint64_t keygen_comm_end = io->get_total_comm();
uint64_t keygen_comm = keygen_comm_end - keygen_comm_start;
chrono::microseconds time_keygen = chrono::duration_cast<
chrono::microseconds>(time_end - time_start);
cout << "KeyGen Time: " << time_keygen.count() << " microseconds" << endl;
cout << "Keygen Comm: " << keygen_comm << " bytes" << endl;
// Oblivious Transfer
mpz_t *m_0, *m_1;
gmp_randstate_t state;
gmp_randinit_mt(state); // Set Algorithm (mt is the name)
bool *b;
if (role == ALICE) {
m_0 = new mpz_t[num_ot]; // message blocks
m_1 = new mpz_t[num_ot]; // message blocks for
for (int i = 0; i < num_ot; i++) {
mpz_inits(m_0[i], m_1[i], NULL); // init m m0
mpz_urandomb(m_0[i], state, bitlen); // create random value
mpz_urandomb(m_1[i], state, bitlen); // create random value
if( i ==1){
cout << "test "<<num_ot<< endl;
cout << "test" << endl;
cout << m_1[i];
}
}
} else { // role == BOB
m_0 = new mpz_t[num_ot];
b = new bool[num_ot];
for (int i = 0; i < num_ot; i++) {
mpz_init(m_0[i]);
b[i] = rand() & 1; // pick random bit
}
}
io->sync();
uint64_t circuit_comm_start = io->get_total_comm();
time_start = chrono::high_resolution_clock::now();
if (role == ALICE) {
ot.send_ot(m_0, m_1, num_ot, bitlen);
} else { // role == BOB
ot.recv_ot(m_0, b, num_ot, bitlen);
}
bool flag;
if (role == ALICE) {
flag = ot.verify(m_0, m_1, num_ot);
for (int i = 0; i < num_ot; i++) {
mpz_clears(m_0[i], m_1[i], NULL);
}
} else { // role == BOB
flag = ot.verify(m_0, b, num_ot);
for (int i = 0; i < num_ot; i++) {
mpz_clear(m_0[i]);
}
}
assert(flag == true && "Failed Operation");
cout << "Successful Operation" << endl;
return 0;
}