Skip to content

Commit ac5dc27

Browse files
committedMay 5, 2023
fix based-OTE PRF errors
1 parent dc45e3e commit ac5dc27

8 files changed

+431938
-431785
lines changed
 

Diff for: ‎CMakeLists.txt

+5-7
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,9 @@ TARGET_LINK_LIBRARIES(mytest ${OPENSSL_LIBRARIES} OpenMP::OpenMP_CXX ${CMAKE_DL_
117117
ADD_EXECUTABLE(mypsu test/mypsuTest.cpp)
118118
TARGET_LINK_LIBRARIES(mypsu ${OPENSSL_LIBRARIES} OpenMP::OpenMP_CXX ${CMAKE_DL_LIBS})
119119

120-
#myfiletest
121-
ADD_EXECUTABLE(myfile test/mytest/fileTest.cpp test/mytest/PirTest.cpp)
122-
TARGET_LINK_LIBRARIES(myfile ${OPENSSL_LIBRARIES} OpenMP::OpenMP_CXX ${CMAKE_DL_LIBS})
120+
#cwPRF psi
121+
ADD_EXECUTABLE(test_psi_from_cwprf test/mytest/test_psi_from_cwprf.cpp )
122+
TARGET_LINK_LIBRARIES(test_psi_from_cwprf ${OPENSSL_LIBRARIES} OpenMP::OpenMP_CXX ${CMAKE_DL_LIBS})
123123

124124
# oprf
125125
ADD_EXECUTABLE(test_oteoprf test/test_oteoprf.cpp)
@@ -195,13 +195,11 @@ if(NOT SEAL_FOUND)
195195
else()
196196
message(STATUS "Microsoft SEAL: ${SEAL_DIR}")
197197
endif()
198-
# 找不到头文件的临时解决方法
199-
#find_path(SEAL_INCLUDE_DIRS seal/seal.h PATH_SUFFIXES SEAL-4.0)
200-
#include_directories(${SEAL_INCLUDE_DIRS})
198+
201199

202200
add_library(sealpir mpc/pir/pir.hpp mpc/pir/pir.cpp mpc/pir/pir_client.hpp mpc/pir/pir_client.cpp mpc/pir/pir_server.hpp
203201
mpc/pir/pir_server.cpp )
204-
# mpc/pir/sealpir_keyword.hpp mpc/pir/seal_pir.hpp
202+
205203

206204
target_link_libraries(sealpir SEAL::seal)
207205

Diff for: ‎README.md

+4
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,10 @@ do the same modification as in MACOS, then compile it according to
152152
* mqrpmt_psu.hpp: union
153153
* mqrpmt_private_id.hpp: private-id protocol based on OTE-based OPRF and cwPRF-based mqRPMT
154154

155+
- /psi
156+
* cwprf_psi.hpp set intersection based on cePRF
157+
* psi_from_oprf.hpp private set intersection based on OTE-based OPRF
158+
155159
- /pir
156160
* pir.hpp pir.cpp SEALPIR sources code
157161
* pir_client.hpp pir_client.cpp SEALPIR Client

Diff for: ‎mpc/psi/psi_from_oprf.hpp

+88-49
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,28 @@
55

66
#include "../oprf/ote_oprf.hpp"
77
#include "../ot/alsz_ote.hpp"
8-
//为什么会出现错误率过高的情况
8+
//基于 bloom的 psi可以使用 直接使用plain的不行
99

1010
namespace OPRFPSI {
11+
std::string uintTostring(std::vector<uint8_t> num) {
12+
std::string str = "";
13+
for (int i = 0; i < num.size(); i++) {
14+
str += std::to_string(static_cast<int>(num[i]));
15+
16+
}
17+
return str;
18+
}
19+
1120
std::vector<block> Receive(NetIO &io, OTEOPRF::PP &pp, std::vector<block> &vec_Y) {
12-
if(vec_Y.size()!= pp.LEN){
21+
if (vec_Y.size() != pp.LEN) {
1322
std::cerr << "|Y| does not match public parameter" << std::endl;
1423
exit(1);
1524
}
1625
auto start_time = std::chrono::steady_clock::now();
17-
std::vector<std::vector<uint8_t>> oprf_value = OTEOPRF::Client(io, pp, vec_Y, vec_Y.size());
26+
std::vector<std::vector<uint8_t>> oprf_key = OTEOPRF::Server(io, pp);
27+
std::vector<std::vector<uint8_t>> oprf_value = OTEOPRF::Evaluate(pp, oprf_key, vec_Y, vec_Y.size());
1828
std::vector<uint8_t> vec_indication_bit(vec_Y.size());
29+
std::vector<block> ans;
1930
std::string choice = "bloom";
2031
if (choice == "bloom") {
2132
BloomFilter filter;
@@ -24,63 +35,73 @@ namespace OPRFPSI {
2435
char *buffer = new char[filter_size];
2536
io.ReceiveBytes(buffer, filter_size);
2637
filter.ReadObject(buffer);
27-
2838
auto bloom_start_time = std::chrono::steady_clock::now();
29-
vec_indication_bit=filter.Contain(oprf_value);
39+
vec_indication_bit = filter.Contain(oprf_value);
3040
auto bloom_end_time = std::chrono::steady_clock::now();
3141
auto running_time1 = bloom_end_time - bloom_start_time;
32-
std::cout << "Receiver excute bloom filter query time "
42+
std::cout << "Receiver excute bloom filter query takes time= "
3343
<< std::chrono::duration<double, std::milli>(running_time1).count() << " ms" << std::endl;
3444
delete[] buffer;
35-
3645
PrintSplitLine('-');
37-
std::cout << "mpOPRF-based PSI: Sender ===> BloomFilter(F_k(x_i)) ===> Receiver ["
46+
std::cout << "mpOPRF-based PSI: Receive <=== BloomFilter(F_k(x_i)) <=== Sender ["
3847
<< (double) (filter_size) / (1 << 20) << " MB]" << std::endl;
48+
for (int i = 0; i < vec_indication_bit.size(); i++) {
49+
if ((int) vec_indication_bit[i] == 1) ans.push_back(vec_Y[i]);
50+
}
51+
auto end_time = std::chrono::steady_clock::now();
52+
auto running_time = end_time - start_time;
53+
std::cout << "mpOPRF-based PSI [bloom filter]: Receiver side takes time "
54+
<< std::chrono::duration<double, std::milli>(running_time).count() << " ms" << std::endl;
3955
}
40-
int count=0;
41-
for(int i=0;i<vec_indication_bit.size();i++){
42-
if((int)vec_indication_bit[i]==1) std::cout<<i<<std::endl,count++;
4356

57+
if (choice == "plain") {
58+
59+
std::vector<std::string> rev_oprf_values(pp.LEN);
60+
std::unordered_set<std::string> S;
61+
//#pragma omp parallel for num_threads(thread_count)
62+
for (auto i = 0; i < pp.LEN; i++) {
63+
int len;
64+
io.ReceiveInteger(len);
65+
std::string str(len,'0');
66+
io.ReceiveString(str);
67+
if(i==1 ) std::cout<<str<<std::endl;
68+
S.insert(str);
69+
//std::cout<<rev_oprf_values[i]<<std::endl;
70+
}
71+
72+
#pragma omp parallel for num_threads(thread_count)
73+
for (auto i = 0; i < pp.LEN; i++) {
74+
if (S.find(uintTostring(oprf_value[i])) == S.end()) vec_indication_bit[i] = 0;
75+
else vec_indication_bit[i] = 1;
76+
}
77+
#pragma omp parallel for num_threads(thread_count)
78+
for (int i = 0; i < vec_indication_bit.size(); i++) {
79+
if ((int) vec_indication_bit[i] == 1) ans[i]=vec_Y[i];
80+
}
81+
auto end_time = std::chrono::steady_clock::now();
82+
auto running_time = end_time - start_time;
83+
std::cout << "mpOPRF-based PSI (plain): Receiver side takes time "
84+
<< std::chrono::duration<double, std::milli>(running_time).count() << " ms" << std::endl;
4485
}
45-
std::cout<<count<<std::endl;
46-
std::vector<block> ans;
47-
for(int i=0;i<vec_indication_bit.size();i++){
48-
if((int)vec_indication_bit[i]==1) ans.push_back(vec_Y[i]);
49-
}
50-
//OT
51-
// auto stime = std::chrono::steady_clock::now();
52-
// ALSZOTE::PP p1;
53-
// p1 = ALSZOTE::Setup(128);
54-
// std::cout<<"start execute OT"<<std::endl;
55-
// std::vector<block> ans = ALSZOTE::OnesidedReceive(io, p1, vec_indication_bit, vec_indication_bit.size());
56-
// auto etime = std::chrono::steady_clock::now();
57-
// auto running_time = etime - stime;
58-
// std::cout << "mpOPRF-based PSI: Receiver OT receive time "
59-
// << std::chrono::duration<double, std::milli>(running_time).count() << " ms" << std::endl;
60-
auto end_time = std::chrono::steady_clock::now();
61-
auto running_time1 = end_time - start_time;
62-
std::cout << "mpOPRF-based PSI: Receiver side takes time "
63-
<< std::chrono::duration<double, std::milli>(running_time1).count() << " ms" << std::endl;
6486
return ans;
6587
}
6688

6789
void Send(NetIO &io, OTEOPRF::PP &pp, std::vector<block> &vec_X) {
68-
if(vec_X.size()!= pp.LEN){
90+
if (vec_X.size() != pp.LEN) {
6991
std::cerr << "|X| does not match public parameter" << std::endl;
7092
exit(1);
7193
}
7294
auto start_time = std::chrono::steady_clock::now();
73-
std::vector<std::vector<uint8_t>> oprf_key = OTEOPRF::Server(io, pp);
74-
std::vector<std::vector<uint8_t>> oprf_value = OTEOPRF::Evaluate(pp, oprf_key, vec_X, vec_X.size());
95+
std::vector<std::vector<uint8_t>> oprf_value = OTEOPRF::Client(io, pp, vec_X, vec_X.size());
96+
//std::vector<std::vector<uint8_t>> oprf_value = OTEOPRF::Evaluate(pp, oprf_key, vec_X, vec_X.size());
7597
std::string choice = "bloom";
7698
if (choice == "bloom") {
77-
BloomFilter filter(pp.LEN, 40);
78-
99+
BloomFilter filter(oprf_value.size(), 40);
79100
auto bloom_start_time = std::chrono::steady_clock::now();
80101
filter.Insert(oprf_value);
81102
auto bloom_end_time = std::chrono::steady_clock::now();
82103
auto running_time1 = bloom_end_time - bloom_start_time;
83-
std::cout << "Receiver execute bloom filter insert time "
104+
std::cout << "Sender execute bloom filter insert takes time= "
84105
<< std::chrono::duration<double, std::milli>(running_time1).count() << " ms" << std::endl;
85106

86107
size_t filter_size = filter.ObjectSize();
@@ -90,23 +111,41 @@ namespace OPRFPSI {
90111
io.SendBytes(buffer, filter_size);
91112
filter.ReadObject(buffer);
92113
delete[] buffer;
114+
std::cout << "mpOPRF-based PSI: Sender ===> BloomFilter(F_k(x_i)) ===> Receiver ["
115+
<< (double) (oprf_value.size() * pp.LEN) / (1 << 20) << " MB]" << std::endl;
116+
PrintSplitLine('-');
117+
auto end_time = std::chrono::steady_clock::now();
118+
auto running_time = end_time - start_time;
119+
std::cout << "mpOPRF-based PSI [bloom filter]: Sender side takes time "
120+
<< std::chrono::duration<double, std::milli>(running_time).count() << " ms" << std::endl;
121+
}
122+
if (choice == "plain") {
123+
124+
for (int i = 0; i < oprf_value.size(); i++) {
93125

126+
std::string str = uintTostring(oprf_value[i]);
127+
if(i==1 ) std::cout<<str<<std::endl;
128+
io.SendInteger(str.size());
129+
io.SendString(str);
130+
}
131+
auto end_time = std::chrono::steady_clock::now();
132+
auto running_time = end_time - start_time;
133+
std::cout << "mpOPRF-based PSI: Sender side takes time "
134+
<< std::chrono::duration<double, std::milli>(running_time).count() << " ms" << std::endl;
94135
}
95136
PrintSplitLine('-');
96-
// auto stime = std::chrono::steady_clock::now();
97-
// ALSZOTE::PP p1;
98-
// p1 = ALSZOTE::Setup(128);
99-
// std::cout<<"start execute OT"<<std::endl;
100-
// ALSZOTE::OnesidedSend(io, p1, vec_X, vec_X.size());
101-
// auto etime = std::chrono::steady_clock::now();
102-
// auto running_time = etime - stime;
103-
// std::cout << "mpOPRF-based PSI: Sender send OT time "
104-
// << std::chrono::duration<double, std::milli>(running_time).count() << " ms" << std::endl;
105-
auto end_time = std::chrono::steady_clock::now();
106-
auto running_time1 = end_time - start_time;
107-
std::cout << "mpOPRF-based PSI [bloom filter]: Sender side takes time "
108-
<< std::chrono::duration<double, std::milli>(running_time1).count() << " ms" << std::endl;
137+
/* auto stime = std::chrono::steady_clock::now();
138+
ALSZOTE::PP p1;
139+
p1 = ALSZOTE::Setup(128);
140+
std::cout<<"start execute OT"<<std::endl;
141+
ALSZOTE::OnesidedSend(io, p1, vec_X, vec_X.size());
142+
auto etime = std::chrono::steady_clock::now();
143+
auto running_time = etime - stime;
144+
std::cout << "mpOPRF-based PSI: Sender send OT time "
145+
<< std::chrono::duration<double, std::milli>(running_time).count() << " ms" << std::endl;*/
146+
109147
}
110148
}
111149

150+
112151
#endif

0 commit comments

Comments
 (0)