online.cpp 43 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218
  1. #include <bsd/stdlib.h> // arc4random_buf
  2. #include "online.hpp"
  3. #include "mpcops.hpp"
  4. #include "rdpf.hpp"
  5. #include "duoram.hpp"
  6. #include "cdpf.hpp"
  7. #include "cell.hpp"
  8. static void online_test(MPCIO &mpcio,
  9. const PRACOptions &opts, char **args)
  10. {
  11. nbits_t nbits = VALUE_BITS;
  12. if (*args) {
  13. nbits = atoi(*args);
  14. }
  15. size_t as_memsize = 9;
  16. size_t xs_memsize = 3;
  17. MPCTIO tio(mpcio, 0);
  18. bool is_server = (mpcio.player == 2);
  19. RegAS *A = new RegAS[as_memsize];
  20. RegXS *AX = new RegXS[xs_memsize];
  21. value_t V;
  22. RegBS F0, F1;
  23. RegBS FA, FO;
  24. RegXS X;
  25. if (!is_server) {
  26. A[0].randomize();
  27. A[1].randomize();
  28. F0.randomize();
  29. A[4].randomize();
  30. F1.randomize();
  31. A[6].randomize();
  32. A[7].randomize();
  33. X.randomize();
  34. AX[0].randomize();
  35. AX[1].randomize();
  36. arc4random_buf(&V, sizeof(V));
  37. printf("A:\n"); for (size_t i=0; i<as_memsize; ++i) printf("%3lu: %016lX\n", i, A[i].ashare);
  38. printf("AX:\n"); for (size_t i=0; i<xs_memsize; ++i) printf("%3lu: %016lX\n", i, AX[i].xshare);
  39. printf("V : %016lX\n", V);
  40. printf("F0 : %01X\n", F0.bshare);
  41. printf("F1 : %01X\n", F1.bshare);
  42. printf("X : %016lX\n", X.xshare);
  43. }
  44. std::vector<coro_t> coroutines;
  45. coroutines.emplace_back(
  46. [&tio, &A, nbits](yield_t &yield) {
  47. mpc_mul(tio, yield, A[2], A[0], A[1], nbits);
  48. });
  49. coroutines.emplace_back(
  50. [&tio, &A, V, nbits](yield_t &yield) {
  51. mpc_valuemul(tio, yield, A[3], V, nbits);
  52. });
  53. coroutines.emplace_back(
  54. [&tio, &A, &F0, nbits](yield_t &yield) {
  55. mpc_flagmult(tio, yield, A[5], F0, A[4], nbits);
  56. });
  57. coroutines.emplace_back(
  58. [&tio, &A, &F1, nbits](yield_t &yield) {
  59. mpc_oswap(tio, yield, A[6], A[7], F1, nbits);
  60. });
  61. coroutines.emplace_back(
  62. [&tio, &A, &X, nbits](yield_t &yield) {
  63. mpc_xs_to_as(tio, yield, A[8], X, nbits);
  64. });
  65. coroutines.emplace_back(
  66. [&tio, &AX, &F0, nbits](yield_t &yield) {
  67. mpc_select(tio, yield, AX[2], F0, AX[0], AX[1], nbits);
  68. });
  69. coroutines.emplace_back(
  70. [&tio, &FA, &F0, &F1, nbits](yield_t &yield) {
  71. mpc_and(tio, yield, FA, F0, F1);
  72. });
  73. coroutines.emplace_back(
  74. [&tio, &FO, &F0, &F1, nbits](yield_t &yield) {
  75. mpc_or(tio, yield, FO, F0, F1);
  76. });
  77. run_coroutines(tio, coroutines);
  78. if (!is_server) {
  79. printf("\n");
  80. printf("A:\n"); for (size_t i=0; i<as_memsize; ++i) printf("%3lu: %016lX\n", i, A[i].ashare);
  81. printf("AX:\n"); for (size_t i=0; i<xs_memsize; ++i) printf("%3lu: %016lX\n", i, AX[i].xshare);
  82. }
  83. // Check the answers
  84. if (mpcio.player == 1) {
  85. tio.queue_peer(A, as_memsize*sizeof(RegAS));
  86. tio.queue_peer(AX, xs_memsize*sizeof(RegXS));
  87. tio.queue_peer(&V, sizeof(V));
  88. tio.queue_peer(&F0, sizeof(RegBS));
  89. tio.queue_peer(&F1, sizeof(RegBS));
  90. tio.queue_peer(&FA, sizeof(RegBS));
  91. tio.queue_peer(&FO, sizeof(RegBS));
  92. tio.queue_peer(&X, sizeof(RegXS));
  93. tio.send();
  94. } else if (mpcio.player == 0) {
  95. RegAS *B = new RegAS[as_memsize];
  96. RegXS *BAX = new RegXS[xs_memsize];
  97. RegBS BF0, BF1;
  98. RegBS BFA, BFO;
  99. RegXS BX;
  100. value_t BV;
  101. value_t *S = new value_t[as_memsize];
  102. value_t *Y = new value_t[xs_memsize];
  103. bit_t SF0, SF1;
  104. bit_t SFA, SFO;
  105. value_t SX;
  106. tio.recv_peer(B, as_memsize*sizeof(RegAS));
  107. tio.recv_peer(BAX, xs_memsize*sizeof(RegXS));
  108. tio.recv_peer(&BV, sizeof(BV));
  109. tio.recv_peer(&BF0, sizeof(RegBS));
  110. tio.recv_peer(&BF1, sizeof(RegBS));
  111. tio.recv_peer(&BFA, sizeof(RegBS));
  112. tio.recv_peer(&BFO, sizeof(RegBS));
  113. tio.recv_peer(&BX, sizeof(RegXS));
  114. for(size_t i=0; i<as_memsize; ++i) S[i] = A[i].ashare+B[i].ashare;
  115. for(size_t i=0; i<xs_memsize; ++i) Y[i] = AX[i].xshare^BAX[i].xshare;
  116. SF0 = F0.bshare ^ BF0.bshare;
  117. SF1 = F1.bshare ^ BF1.bshare;
  118. SFA = FA.bshare ^ BFA.bshare;
  119. SFO = FO.bshare ^ BFO.bshare;
  120. SX = X.xshare ^ BX.xshare;
  121. printf("S:\n"); for (size_t i=0; i<as_memsize; ++i) printf("%3lu: %016lX\n", i, S[i]);
  122. printf("Y:\n"); for (size_t i=0; i<xs_memsize; ++i) printf("%3lu: %016lX\n", i, Y[i]);
  123. printf("SF0: %01X\n", SF0);
  124. printf("SF1: %01X\n", SF1);
  125. printf("SFA: %01X\n", SFA);
  126. printf("SFO: %01X\n", SFO);
  127. printf("SX : %016lX\n", SX);
  128. printf("\n%016lx\n", S[0]*S[1]-S[2]);
  129. printf("%016lx\n", (V*BV)-S[3]);
  130. printf("%016lx\n", (SF0*S[4])-S[5]);
  131. printf("%016lx\n", S[8]-SX);
  132. delete[] B;
  133. delete[] S;
  134. }
  135. delete[] A;
  136. delete[] AX;
  137. }
  138. static void lamport_test(MPCIO &mpcio,
  139. const PRACOptions &opts, char **args)
  140. {
  141. // Create a bunch of threads and send a bunch of data to the other
  142. // peer, and receive their data. If an arg is specified, repeat
  143. // that many times. The Lamport clock at the end should be just the
  144. // number of repetitions. Subsequent args are the chunk size and
  145. // the number of chunks per message
  146. size_t niters = 1;
  147. size_t chunksize = 1<<20;
  148. size_t numchunks = 1;
  149. if (*args) {
  150. niters = atoi(*args);
  151. ++args;
  152. }
  153. if (*args) {
  154. chunksize = atoi(*args);
  155. ++args;
  156. }
  157. if (*args) {
  158. numchunks = atoi(*args);
  159. ++args;
  160. }
  161. int num_threads = opts.num_threads;
  162. boost::asio::thread_pool pool(num_threads);
  163. for (int thread_num = 0; thread_num < num_threads; ++thread_num) {
  164. boost::asio::post(pool, [&mpcio, thread_num, niters, chunksize, numchunks] {
  165. MPCTIO tio(mpcio, thread_num);
  166. char *sendbuf = new char[chunksize];
  167. char *recvbuf = new char[chunksize*numchunks];
  168. for (size_t i=0; i<niters; ++i) {
  169. for (size_t chunk=0; chunk<numchunks; ++chunk) {
  170. arc4random_buf(sendbuf, chunksize);
  171. tio.queue_peer(sendbuf, chunksize);
  172. }
  173. tio.send();
  174. tio.recv_peer(recvbuf, chunksize*numchunks);
  175. }
  176. delete[] recvbuf;
  177. delete[] sendbuf;
  178. });
  179. }
  180. pool.join();
  181. }
  182. static void rdpf_test(MPCIO &mpcio,
  183. const PRACOptions &opts, char **args)
  184. {
  185. nbits_t depth=6;
  186. size_t num_iters = 1;
  187. if (*args) {
  188. depth = atoi(*args);
  189. ++args;
  190. }
  191. if (*args) {
  192. num_iters = atoi(*args);
  193. ++args;
  194. }
  195. int num_threads = opts.num_threads;
  196. boost::asio::thread_pool pool(num_threads);
  197. for (int thread_num = 0; thread_num < num_threads; ++thread_num) {
  198. boost::asio::post(pool, [&mpcio, thread_num, depth, num_iters] {
  199. MPCTIO tio(mpcio, thread_num);
  200. run_coroutines(tio, [&tio, depth, num_iters] (yield_t &yield) {
  201. size_t &aes_ops = tio.aes_ops();
  202. for (size_t iter=0; iter < num_iters; ++iter) {
  203. if (tio.player() == 2) {
  204. RDPFPair<1> dp = tio.rdpfpair(yield, depth);
  205. for (int i=0;i<2;++i) {
  206. const RDPF<1> &dpf = dp.dpf[i];
  207. for (address_t x=0;x<(address_t(1)<<depth);++x) {
  208. DPFnode leaf = dpf.leaf(x, aes_ops);
  209. RegBS ub = dpf.unit_bs(leaf);
  210. RegAS ua = dpf.unit_as(leaf);
  211. RegXS sx = dpf.scaled_xs(leaf);
  212. RegAS sa = dpf.scaled_as(leaf);
  213. printf("%04x %x %016lx %016lx %016lx\n", x,
  214. ub.bshare, ua.ashare, sx.xshare, sa.ashare);
  215. }
  216. printf("\n");
  217. }
  218. } else {
  219. RDPFTriple<1> dt = tio.rdpftriple(yield, depth);
  220. for (int i=0;i<3;++i) {
  221. const RDPF<1> &dpf = dt.dpf[i];
  222. RegXS peer_scaled_xor;
  223. RegAS peer_scaled_sum;
  224. if (tio.player() == 1) {
  225. tio.iostream_peer() << dpf.scaled_xor << dpf.scaled_sum;
  226. } else {
  227. tio.iostream_peer() >> peer_scaled_xor >> peer_scaled_sum;
  228. peer_scaled_sum += dpf.scaled_sum;
  229. peer_scaled_xor ^= dpf.scaled_xor;
  230. }
  231. for (address_t x=0;x<(address_t(1)<<depth);++x) {
  232. DPFnode leaf = dpf.leaf(x, aes_ops);
  233. RegBS ub = dpf.unit_bs(leaf);
  234. RegAS ua = dpf.unit_as(leaf);
  235. RegXS sx = dpf.scaled_xs(leaf);
  236. RegAS sa = dpf.scaled_as(leaf);
  237. printf("%04x %x %016lx %016lx %016lx\n", x,
  238. ub.bshare, ua.ashare, sx.xshare, sa.ashare);
  239. if (tio.player() == 1) {
  240. tio.iostream_peer() << ub << ua << sx << sa;
  241. } else {
  242. RegBS peer_ub;
  243. RegAS peer_ua;
  244. RegXS peer_sx;
  245. RegAS peer_sa;
  246. tio.iostream_peer() >> peer_ub >> peer_ua >>
  247. peer_sx >> peer_sa;
  248. ub ^= peer_ub;
  249. ua += peer_ua;
  250. sx ^= peer_sx;
  251. sa += peer_sa;
  252. if (ub.bshare || ua.ashare || sx.xshare || sa.ashare) {
  253. printf("**** %x %016lx %016lx %016lx\n",
  254. ub.bshare, ua.ashare, sx.xshare, sa.ashare);
  255. printf("SCALE %016lx %016lx\n",
  256. peer_scaled_xor.xshare, peer_scaled_sum.ashare);
  257. }
  258. }
  259. }
  260. printf("\n");
  261. }
  262. }
  263. }
  264. });
  265. });
  266. }
  267. pool.join();
  268. }
  269. static void rdpf_timing(MPCIO &mpcio,
  270. const PRACOptions &opts, char **args)
  271. {
  272. nbits_t depth=6;
  273. if (*args) {
  274. depth = atoi(*args);
  275. ++args;
  276. }
  277. int num_threads = opts.num_threads;
  278. boost::asio::thread_pool pool(num_threads);
  279. for (int thread_num = 0; thread_num < num_threads; ++thread_num) {
  280. boost::asio::post(pool, [&mpcio, thread_num, depth] {
  281. MPCTIO tio(mpcio, thread_num);
  282. run_coroutines(tio, [&tio, depth] (yield_t &yield) {
  283. size_t &aes_ops = tio.aes_ops();
  284. if (tio.player() == 2) {
  285. RDPFPair<1> dp = tio.rdpfpair(yield, depth);
  286. for (int i=0;i<2;++i) {
  287. RDPF<1> &dpf = dp.dpf[i];
  288. dpf.expand(aes_ops);
  289. RegXS scaled_xor;
  290. for (address_t x=0;x<(address_t(1)<<depth);++x) {
  291. DPFnode leaf = dpf.leaf(x, aes_ops);
  292. RegXS sx = dpf.scaled_xs(leaf);
  293. scaled_xor ^= sx;
  294. }
  295. printf("%016lx\n%016lx\n", scaled_xor.xshare,
  296. dpf.scaled_xor.xshare);
  297. printf("\n");
  298. }
  299. } else {
  300. RDPFTriple<1> dt = tio.rdpftriple(yield, depth);
  301. for (int i=0;i<3;++i) {
  302. RDPF<1> &dpf = dt.dpf[i];
  303. dpf.expand(aes_ops);
  304. RegXS scaled_xor;
  305. for (address_t x=0;x<(address_t(1)<<depth);++x) {
  306. DPFnode leaf = dpf.leaf(x, aes_ops);
  307. RegXS sx = dpf.scaled_xs(leaf);
  308. scaled_xor ^= sx;
  309. }
  310. printf("%016lx\n%016lx\n", scaled_xor.xshare,
  311. dpf.scaled_xor.xshare);
  312. printf("\n");
  313. }
  314. }
  315. });
  316. });
  317. }
  318. pool.join();
  319. }
  320. static value_t parallel_streameval_rdpf(MPCIO &mpcio, const RDPF<1> &dpf,
  321. address_t start, int num_threads)
  322. {
  323. RegXS scaled_xor[num_threads];
  324. boost::asio::thread_pool pool(num_threads);
  325. address_t totsize = (address_t(1)<<dpf.depth());
  326. address_t threadstart = start;
  327. address_t threadchunk = totsize / num_threads;
  328. address_t threadextra = totsize % num_threads;
  329. for (int thread_num = 0; thread_num < num_threads; ++thread_num) {
  330. address_t threadsize = threadchunk + (address_t(thread_num) < threadextra);
  331. boost::asio::post(pool,
  332. [&mpcio, &dpf, &scaled_xor, thread_num, threadstart, threadsize] {
  333. MPCTIO tio(mpcio, thread_num);
  334. //printf("Thread %d from %X for %X\n", thread_num, threadstart, threadsize);
  335. RegXS local_xor;
  336. size_t local_aes_ops = 0;
  337. auto ev = StreamEval(dpf, threadstart, 0, local_aes_ops);
  338. for (address_t x=0;x<threadsize;++x) {
  339. //if (x%0x10000 == 0) printf("%d", thread_num);
  340. DPFnode leaf = ev.next();
  341. local_xor ^= dpf.scaled_xs(leaf);
  342. }
  343. scaled_xor[thread_num] = local_xor;
  344. tio.aes_ops() += local_aes_ops;
  345. //printf("Thread %d complete\n", thread_num);
  346. });
  347. threadstart = (threadstart + threadsize) % totsize;
  348. }
  349. pool.join();
  350. RegXS res;
  351. for (int thread_num = 0; thread_num < num_threads; ++thread_num) {
  352. res ^= scaled_xor[thread_num];
  353. }
  354. return res.xshare;
  355. }
  356. static void rdpfeval_timing(MPCIO &mpcio,
  357. const PRACOptions &opts, char **args)
  358. {
  359. nbits_t depth=6;
  360. address_t start=0;
  361. if (*args) {
  362. depth = atoi(*args);
  363. ++args;
  364. }
  365. if (*args) {
  366. start = strtoull(*args, NULL, 16);
  367. ++args;
  368. }
  369. int num_threads = opts.num_threads;
  370. MPCTIO tio(mpcio, 0, num_threads);
  371. run_coroutines(tio, [&mpcio, &tio, depth, start, num_threads] (yield_t &yield) {
  372. if (tio.player() == 2) {
  373. RDPFPair<1> dp = tio.rdpfpair(yield, depth);
  374. for (int i=0;i<2;++i) {
  375. RDPF<1> &dpf = dp.dpf[i];
  376. value_t scaled_xor =
  377. parallel_streameval_rdpf(mpcio, dpf, start, num_threads);
  378. printf("%016lx\n%016lx\n", scaled_xor,
  379. dpf.scaled_xor.xshare);
  380. printf("\n");
  381. }
  382. } else {
  383. RDPFTriple<1> dt = tio.rdpftriple(yield, depth);
  384. for (int i=0;i<3;++i) {
  385. RDPF<1> &dpf = dt.dpf[i];
  386. value_t scaled_xor =
  387. parallel_streameval_rdpf(mpcio, dpf, start, num_threads);
  388. printf("%016lx\n%016lx\n", scaled_xor,
  389. dpf.scaled_xor.xshare);
  390. printf("\n");
  391. }
  392. }
  393. });
  394. }
  395. static void par_rdpfeval_timing(MPCIO &mpcio,
  396. const PRACOptions &opts, char **args)
  397. {
  398. nbits_t depth=6;
  399. address_t start=0;
  400. if (*args) {
  401. depth = atoi(*args);
  402. ++args;
  403. }
  404. if (*args) {
  405. start = strtoull(*args, NULL, 16);
  406. ++args;
  407. }
  408. int num_threads = opts.num_threads;
  409. MPCTIO tio(mpcio, 0, num_threads);
  410. run_coroutines(tio, [&tio, depth, start, num_threads] (yield_t &yield) {
  411. if (tio.player() == 2) {
  412. RDPFPair<1> dp = tio.rdpfpair(yield, depth);
  413. for (int i=0;i<2;++i) {
  414. RDPF<1> &dpf = dp.dpf[i];
  415. nbits_t depth = dpf.depth();
  416. auto pe = ParallelEval(dpf, start, 0,
  417. address_t(1)<<depth, num_threads, tio.aes_ops());
  418. RegXS result, init;
  419. result = pe.reduce(init, [&dpf] (int thread_num,
  420. address_t i, const RDPF<1>::node &leaf) {
  421. return dpf.scaled_xs(leaf);
  422. });
  423. printf("%016lx\n%016lx\n", result.xshare,
  424. dpf.scaled_xor.xshare);
  425. printf("\n");
  426. }
  427. } else {
  428. RDPFTriple<1> dt = tio.rdpftriple(yield, depth);
  429. for (int i=0;i<3;++i) {
  430. RDPF<1> &dpf = dt.dpf[i];
  431. nbits_t depth = dpf.depth();
  432. auto pe = ParallelEval(dpf, start, 0,
  433. address_t(1)<<depth, num_threads, tio.aes_ops());
  434. RegXS result, init;
  435. result = pe.reduce(init, [&dpf] (int thread_num,
  436. address_t i, const RDPF<1>::node &leaf) {
  437. return dpf.scaled_xs(leaf);
  438. });
  439. printf("%016lx\n%016lx\n", result.xshare,
  440. dpf.scaled_xor.xshare);
  441. printf("\n");
  442. }
  443. }
  444. });
  445. }
  446. static void tupleeval_timing(MPCIO &mpcio,
  447. const PRACOptions &opts, char **args)
  448. {
  449. nbits_t depth=6;
  450. address_t start=0;
  451. if (*args) {
  452. depth = atoi(*args);
  453. ++args;
  454. }
  455. if (*args) {
  456. start = atoi(*args);
  457. ++args;
  458. }
  459. int num_threads = opts.num_threads;
  460. MPCTIO tio(mpcio, 0, num_threads);
  461. run_coroutines(tio, [&tio, depth, start] (yield_t &yield) {
  462. size_t &aes_ops = tio.aes_ops();
  463. if (tio.player() == 2) {
  464. RDPFPair<1> dp = tio.rdpfpair(yield, depth);
  465. RegXS scaled_xor0, scaled_xor1;
  466. auto ev = StreamEval(dp, start, 0, aes_ops, false);
  467. for (address_t x=0;x<(address_t(1)<<depth);++x) {
  468. auto [L0, L1] = ev.next();
  469. RegXS sx0 = dp.dpf[0].scaled_xs(L0);
  470. RegXS sx1 = dp.dpf[1].scaled_xs(L1);
  471. scaled_xor0 ^= sx0;
  472. scaled_xor1 ^= sx1;
  473. }
  474. printf("%016lx\n%016lx\n", scaled_xor0.xshare,
  475. dp.dpf[0].scaled_xor.xshare);
  476. printf("\n");
  477. printf("%016lx\n%016lx\n", scaled_xor1.xshare,
  478. dp.dpf[1].scaled_xor.xshare);
  479. printf("\n");
  480. } else {
  481. RDPFTriple<1> dt = tio.rdpftriple(yield, depth);
  482. RegXS scaled_xor0, scaled_xor1, scaled_xor2;
  483. auto ev = StreamEval(dt, start, 0, aes_ops, false);
  484. for (address_t x=0;x<(address_t(1)<<depth);++x) {
  485. auto [L0, L1, L2] = ev.next();
  486. RegXS sx0 = dt.dpf[0].scaled_xs(L0);
  487. RegXS sx1 = dt.dpf[1].scaled_xs(L1);
  488. RegXS sx2 = dt.dpf[2].scaled_xs(L2);
  489. scaled_xor0 ^= sx0;
  490. scaled_xor1 ^= sx1;
  491. scaled_xor2 ^= sx2;
  492. }
  493. printf("%016lx\n%016lx\n", scaled_xor0.xshare,
  494. dt.dpf[0].scaled_xor.xshare);
  495. printf("\n");
  496. printf("%016lx\n%016lx\n", scaled_xor1.xshare,
  497. dt.dpf[1].scaled_xor.xshare);
  498. printf("\n");
  499. printf("%016lx\n%016lx\n", scaled_xor2.xshare,
  500. dt.dpf[2].scaled_xor.xshare);
  501. printf("\n");
  502. }
  503. });
  504. }
  505. static void par_tupleeval_timing(MPCIO &mpcio,
  506. const PRACOptions &opts, char **args)
  507. {
  508. nbits_t depth=6;
  509. address_t start=0;
  510. if (*args) {
  511. depth = atoi(*args);
  512. ++args;
  513. }
  514. if (*args) {
  515. start = atoi(*args);
  516. ++args;
  517. }
  518. int num_threads = opts.num_threads;
  519. MPCTIO tio(mpcio, 0, num_threads);
  520. run_coroutines(tio, [&tio, depth, start, num_threads] (yield_t &yield) {
  521. size_t &aes_ops = tio.aes_ops();
  522. if (tio.player() == 2) {
  523. RDPFPair<1> dp = tio.rdpfpair(yield, depth);
  524. auto pe = ParallelEval(dp, start, 0, address_t(1)<<depth,
  525. num_threads, aes_ops);
  526. using V = std::tuple<RegXS,RegXS>;
  527. V result, init;
  528. result = pe.reduce(init, [&dp] (int thread_num, address_t i,
  529. const RDPFPair<1>::node &leaf) {
  530. std::tuple<RegXS,RegXS> scaled;
  531. dp.scaled(scaled, leaf);
  532. return scaled;
  533. });
  534. printf("%016lx\n%016lx\n", std::get<0>(result).xshare,
  535. dp.dpf[0].scaled_xor.xshare);
  536. printf("\n");
  537. printf("%016lx\n%016lx\n", std::get<1>(result).xshare,
  538. dp.dpf[1].scaled_xor.xshare);
  539. printf("\n");
  540. } else {
  541. RDPFTriple<1> dt = tio.rdpftriple(yield, depth);
  542. auto pe = ParallelEval(dt, start, 0, address_t(1)<<depth,
  543. num_threads, aes_ops);
  544. using V = std::tuple<RegXS,RegXS,RegXS>;
  545. V result, init;
  546. result = pe.reduce(init, [&dt] (int thread_num, address_t i,
  547. const RDPFTriple<1>::node &leaf) {
  548. std::tuple<RegXS,RegXS,RegXS> scaled;
  549. dt.scaled(scaled, leaf);
  550. return scaled;
  551. });
  552. printf("%016lx\n%016lx\n", std::get<0>(result).xshare,
  553. dt.dpf[0].scaled_xor.xshare);
  554. printf("\n");
  555. printf("%016lx\n%016lx\n", std::get<1>(result).xshare,
  556. dt.dpf[1].scaled_xor.xshare);
  557. printf("\n");
  558. printf("%016lx\n%016lx\n", std::get<2>(result).xshare,
  559. dt.dpf[2].scaled_xor.xshare);
  560. printf("\n");
  561. }
  562. });
  563. }
  564. // T is RegAS or RegXS for additive or XOR shared database respectively
  565. template <typename T>
  566. static void duoram_test(MPCIO &mpcio,
  567. const PRACOptions &opts, char **args)
  568. {
  569. nbits_t depth=6;
  570. address_t share=arc4random();
  571. if (*args) {
  572. depth = atoi(*args);
  573. ++args;
  574. }
  575. if (*args) {
  576. share = atoi(*args);
  577. ++args;
  578. }
  579. share &= ((address_t(1)<<depth)-1);
  580. MPCTIO tio(mpcio, 0, opts.num_threads);
  581. run_coroutines(tio, [&tio, depth, share] (yield_t &yield) {
  582. size_t size = size_t(1)<<depth;
  583. // size_t &aes_ops = tio.aes_ops();
  584. Duoram<T> oram(tio.player(), size);
  585. auto A = oram.flat(tio, yield);
  586. RegAS aidx, aidx2, aidx3;
  587. aidx.ashare = share;
  588. aidx2.ashare = share + tio.player();
  589. aidx3.ashare = share + 1;
  590. T M;
  591. if (tio.player() == 0) {
  592. M.set(0xbabb0000);
  593. } else {
  594. M.set(0x0000a66e);
  595. }
  596. RegXS xidx;
  597. xidx.xshare = share;
  598. T N;
  599. if (tio.player() == 0) {
  600. N.set(0xdead0000);
  601. } else {
  602. N.set(0x0000beef);
  603. }
  604. // Writing and reading with additively shared indices
  605. printf("Additive Updating\n");
  606. A[aidx] += M;
  607. printf("Additive Reading\n");
  608. T Aa = A[aidx];
  609. // Writing and reading with XOR shared indices
  610. printf("XOR Updating\n");
  611. A[xidx] += N;
  612. printf("XOR Reading\n");
  613. T Ax = A[xidx];
  614. T Ae;
  615. // Writing and reading with explicit indices
  616. if (depth > 2) {
  617. printf("Explicit Updating\n");
  618. A[5] += Aa;
  619. printf("Explicit Reading\n");
  620. Ae = A[6];
  621. }
  622. // Simultaneous independent reads
  623. printf("3 independent reading\n");
  624. std::vector<T> Av = A[std::array {
  625. aidx, aidx2, aidx3
  626. }];
  627. // Simultaneous independent updates
  628. T Aw1, Aw2, Aw3;
  629. Aw1.set(0x101010101010101 * tio.player());
  630. Aw2.set(0x202020202020202 * tio.player());
  631. Aw3.set(0x303030303030303 * tio.player());
  632. printf("3 independent updating\n");
  633. A[std::array { aidx, aidx2, aidx3 }] -=
  634. std::array { Aw1, Aw2, Aw3 };
  635. if (depth <= 10) {
  636. oram.dump();
  637. auto check = A.reconstruct();
  638. if (tio.player() == 0) {
  639. for (address_t i=0;i<size;++i) {
  640. printf("%04x %016lx\n", i, check[i].share());
  641. }
  642. }
  643. }
  644. auto checkread = A.reconstruct(Aa);
  645. auto checkreade = A.reconstruct(Ae);
  646. auto checkreadx = A.reconstruct(Ax);
  647. if (tio.player() == 0) {
  648. printf("Read AS value = %016lx\n", checkread.share());
  649. printf("Read AX value = %016lx\n", checkreadx.share());
  650. printf("Read Ex value = %016lx\n", checkreade.share());
  651. }
  652. for (auto &v : Av) {
  653. auto checkv = A.reconstruct(v);
  654. if (tio.player() == 0) {
  655. printf("Read Av value = %016lx\n", checkv.share());
  656. }
  657. }
  658. });
  659. }
  660. // This measures the same things as the Duoram paper: dependent and
  661. // independent reads, updates, writes, and interleaves
  662. // T is RegAS or RegXS for additive or XOR shared database respectively
  663. template <typename T>
  664. static void duoram(MPCIO &mpcio,
  665. const PRACOptions &opts, char **args)
  666. {
  667. nbits_t depth = 6;
  668. int items = 4;
  669. if (*args) {
  670. depth = atoi(*args);
  671. ++args;
  672. }
  673. if (*args) {
  674. items = atoi(*args);
  675. ++args;
  676. }
  677. MPCTIO tio(mpcio, 0, opts.num_threads);
  678. run_coroutines(tio, [&mpcio, &tio, depth, items] (yield_t &yield) {
  679. size_t size = size_t(1)<<depth;
  680. address_t mask = (depth < ADDRESS_MAX_BITS ?
  681. ((address_t(1)<<depth) - 1) : ~0);
  682. Duoram<T> oram(tio.player(), size);
  683. auto A = oram.flat(tio, yield);
  684. std::cout << "===== DEPENDENT UPDATES =====\n";
  685. mpcio.reset_stats();
  686. tio.reset_lamport();
  687. // Make a linked list of length items
  688. std::vector<T> list_indices;
  689. T prev_index, next_index;
  690. prev_index.randomize(depth);
  691. for (int i=0;i<items;++i) {
  692. next_index.randomize(depth);
  693. A[next_index] += prev_index;
  694. list_indices.push_back(next_index);
  695. prev_index = next_index;
  696. }
  697. tio.sync_lamport();
  698. mpcio.dump_stats(std::cout);
  699. std::cout << "\n===== DEPENDENT READS =====\n";
  700. mpcio.reset_stats();
  701. tio.reset_lamport();
  702. // Read the linked list starting with prev_index
  703. T cur_index = prev_index;
  704. for (int i=0;i<items;++i) {
  705. cur_index = A[cur_index];
  706. }
  707. tio.sync_lamport();
  708. mpcio.dump_stats(std::cout);
  709. std::cout << "\n===== INDEPENDENT READS =====\n";
  710. mpcio.reset_stats();
  711. tio.reset_lamport();
  712. // Read all the entries in the list at once
  713. std::vector<T> read_outputs = A[list_indices];
  714. tio.sync_lamport();
  715. mpcio.dump_stats(std::cout);
  716. std::cout << "\n===== INDEPENDENT UPDATES =====\n";
  717. mpcio.reset_stats();
  718. tio.reset_lamport();
  719. // Make a vector of indices 1 larger than those in list_indices,
  720. // and a vector of values 1 larger than those in outputs
  721. std::vector<T> indep_indices, indep_values;
  722. T one;
  723. one.set(tio.player()); // Sets the shared value to 1
  724. for (int i=0;i<items;++i) {
  725. indep_indices.push_back(list_indices[i]+one);
  726. indep_values.push_back(read_outputs[i]+one);
  727. }
  728. // Update all the indices at once
  729. A[indep_indices] += indep_values;
  730. tio.sync_lamport();
  731. mpcio.dump_stats(std::cout);
  732. std::cout << "\n===== DEPENDENT WRITES =====\n";
  733. mpcio.reset_stats();
  734. tio.reset_lamport();
  735. T two;
  736. two.set(2*tio.player()); // Sets the shared value to 2
  737. // For each address addr that's number i from the end of the
  738. // linked list, write i+1 into location addr+2
  739. for (int i=0;i<items;++i) {
  740. T val;
  741. val.set((i+1)*tio.player());
  742. A[list_indices[i]+two] = val;
  743. }
  744. tio.sync_lamport();
  745. mpcio.dump_stats(std::cout);
  746. std::cout << "\n===== DEPENDENT INTERLEAVED =====\n";
  747. mpcio.reset_stats();
  748. tio.reset_lamport();
  749. T three;
  750. three.set(3*tio.player()); // Sets the shared value to 3
  751. // Follow the linked list and whenever A[addr]=val, set
  752. // A[addr+3]=val+3
  753. cur_index = prev_index;
  754. for (int i=0;i<items;++i) {
  755. T next_index = A[cur_index];
  756. A[cur_index+three] = next_index+three;
  757. cur_index = next_index;
  758. }
  759. tio.sync_lamport();
  760. mpcio.dump_stats(std::cout);
  761. std::cout << "\n";
  762. mpcio.reset_stats();
  763. tio.reset_lamport();
  764. if (depth <= 30) {
  765. auto check = A.reconstruct();
  766. auto head = A.reconstruct(prev_index);
  767. if (tio.player() == 0) {
  768. int width = (depth+3)/4;
  769. printf("Head of linked list: %0*lx\n\n", width,
  770. head.share() & mask);
  771. std::cout << "Non-zero reconstructed database entries:\n";
  772. for (address_t i=0;i<size;++i) {
  773. value_t share = check[i].share() & mask;
  774. if (share) printf("%0*x: %0*lx\n", width, i, width, share);
  775. }
  776. }
  777. }
  778. });
  779. }
  780. static void cdpf_test(MPCIO &mpcio,
  781. const PRACOptions &opts, char **args)
  782. {
  783. value_t query, target;
  784. int iters = 1;
  785. arc4random_buf(&query, sizeof(query));
  786. arc4random_buf(&target, sizeof(target));
  787. if (*args) {
  788. query = strtoull(*args, NULL, 16);
  789. ++args;
  790. }
  791. if (*args) {
  792. target = strtoull(*args, NULL, 16);
  793. ++args;
  794. }
  795. if (*args) {
  796. iters = atoi(*args);
  797. ++args;
  798. }
  799. int num_threads = opts.num_threads;
  800. boost::asio::thread_pool pool(num_threads);
  801. for (int thread_num = 0; thread_num < num_threads; ++thread_num) {
  802. boost::asio::post(pool, [&mpcio, thread_num, query, target, iters] {
  803. MPCTIO tio(mpcio, thread_num);
  804. run_coroutines(tio, [&tio, query, target, iters] (yield_t &yield) {
  805. size_t &aes_ops = tio.aes_ops();
  806. for (int i=0;i<iters;++i) {
  807. if (tio.player() == 2) {
  808. tio.cdpf(yield);
  809. auto [ dpf0, dpf1 ] = CDPF::generate(target, aes_ops);
  810. DPFnode leaf0 = dpf0.leaf(query, aes_ops);
  811. DPFnode leaf1 = dpf1.leaf(query, aes_ops);
  812. printf("DPFXOR_{%016lx}(%016lx} = ", target, query);
  813. dump_node(leaf0 ^ leaf1);
  814. } else {
  815. CDPF dpf = tio.cdpf(yield);
  816. printf("ashare = %016lX\nxshare = %016lX\n",
  817. dpf.as_target.ashare, dpf.xs_target.xshare);
  818. DPFnode leaf = dpf.leaf(query, aes_ops);
  819. printf("DPF(%016lx) = ", query);
  820. dump_node(leaf);
  821. if (tio.player() == 1) {
  822. tio.iostream_peer() << leaf;
  823. } else {
  824. DPFnode peerleaf;
  825. tio.iostream_peer() >> peerleaf;
  826. printf("XOR = ");
  827. dump_node(leaf ^ peerleaf);
  828. }
  829. }
  830. }
  831. });
  832. });
  833. }
  834. pool.join();
  835. }
  836. static int compare_test_one(MPCTIO &tio, yield_t &yield,
  837. value_t target, value_t x)
  838. {
  839. int player = tio.player();
  840. size_t &aes_ops = tio.aes_ops();
  841. int res = 1;
  842. if (player == 2) {
  843. // Create a CDPF pair with the given target
  844. auto [dpf0, dpf1] = CDPF::generate(target, aes_ops);
  845. // Send it and a share of x to the computational parties
  846. RegAS x0, x1;
  847. x0.randomize();
  848. x1.set(x-x0.share());
  849. tio.iostream_p0() << dpf0 << x0;
  850. tio.iostream_p1() << dpf1 << x1;
  851. } else {
  852. CDPF dpf;
  853. RegAS xsh;
  854. tio.iostream_server() >> dpf >> xsh;
  855. auto [lt, eq, gt] = dpf.compare(tio, yield, xsh, aes_ops);
  856. RegBS eeq = dpf.is_zero(tio, yield, xsh, aes_ops);
  857. printf("%016lx %016lx %d %d %d %d ", target, x, lt.bshare,
  858. eq.bshare, gt.bshare, eeq.bshare);
  859. // Check the answer
  860. if (player == 1) {
  861. tio.iostream_peer() << xsh << lt << eq << gt << eeq;
  862. } else {
  863. RegAS peer_xsh;
  864. RegBS peer_lt, peer_eq, peer_gt, peer_eeq;
  865. tio.iostream_peer() >> peer_xsh >> peer_lt >> peer_eq >>
  866. peer_gt >> peer_eeq;
  867. lt ^= peer_lt;
  868. eq ^= peer_eq;
  869. gt ^= peer_gt;
  870. eeq ^= peer_eeq;
  871. xsh += peer_xsh;
  872. int lti = int(lt.bshare);
  873. int eqi = int(eq.bshare);
  874. int gti = int(gt.bshare);
  875. int eeqi = int(eeq.bshare);
  876. x = xsh.share();
  877. printf(": %d %d %d %d ", lti, eqi, gti, eeqi);
  878. bool signbit = (x >> 63);
  879. if (lti + eqi + gti != 1 || eqi != eeqi) {
  880. printf("INCONSISTENT");
  881. res = 0;
  882. } else if (x == 0 && eqi) {
  883. printf("=");
  884. } else if (!signbit && gti) {
  885. printf(">");
  886. } else if (signbit && lti) {
  887. printf("<");
  888. } else {
  889. printf("INCORRECT");
  890. res = 0;
  891. }
  892. }
  893. printf("\n");
  894. }
  895. return res;
  896. }
  897. static int compare_test_target(MPCTIO &tio, yield_t &yield,
  898. value_t target, value_t x)
  899. {
  900. int res = 1;
  901. res &= compare_test_one(tio, yield, target, x);
  902. res &= compare_test_one(tio, yield, target, 0);
  903. res &= compare_test_one(tio, yield, target, 1);
  904. res &= compare_test_one(tio, yield, target, 15);
  905. res &= compare_test_one(tio, yield, target, 16);
  906. res &= compare_test_one(tio, yield, target, 17);
  907. res &= compare_test_one(tio, yield, target, -1);
  908. res &= compare_test_one(tio, yield, target, -15);
  909. res &= compare_test_one(tio, yield, target, -16);
  910. res &= compare_test_one(tio, yield, target, -17);
  911. res &= compare_test_one(tio, yield, target, (value_t(1)<<63));
  912. res &= compare_test_one(tio, yield, target, (value_t(1)<<63)+1);
  913. res &= compare_test_one(tio, yield, target, (value_t(1)<<63)-1);
  914. return res;
  915. }
  916. static void compare_test(MPCIO &mpcio,
  917. const PRACOptions &opts, char **args)
  918. {
  919. value_t target, x;
  920. arc4random_buf(&target, sizeof(target));
  921. arc4random_buf(&x, sizeof(x));
  922. if (*args) {
  923. target = strtoull(*args, NULL, 16);
  924. ++args;
  925. }
  926. if (*args) {
  927. x = strtoull(*args, NULL, 16);
  928. ++args;
  929. }
  930. int num_threads = opts.num_threads;
  931. boost::asio::thread_pool pool(num_threads);
  932. for (int thread_num = 0; thread_num < num_threads; ++thread_num) {
  933. boost::asio::post(pool, [&mpcio, thread_num, target, x] {
  934. MPCTIO tio(mpcio, thread_num);
  935. run_coroutines(tio, [&tio, target, x] (yield_t &yield) {
  936. int res = 1;
  937. res &= compare_test_target(tio, yield, target, x);
  938. res &= compare_test_target(tio, yield, 0, x);
  939. res &= compare_test_target(tio, yield, 1, x);
  940. res &= compare_test_target(tio, yield, 15, x);
  941. res &= compare_test_target(tio, yield, 16, x);
  942. res &= compare_test_target(tio, yield, 17, x);
  943. res &= compare_test_target(tio, yield, -1, x);
  944. res &= compare_test_target(tio, yield, -15, x);
  945. res &= compare_test_target(tio, yield, -16, x);
  946. res &= compare_test_target(tio, yield, -17, x);
  947. res &= compare_test_target(tio, yield, (value_t(1)<<63), x);
  948. res &= compare_test_target(tio, yield, (value_t(1)<<63)+1, x);
  949. res &= compare_test_target(tio, yield, (value_t(1)<<63)-1, x);
  950. if (tio.player() == 0) {
  951. if (res == 1) {
  952. printf("All tests passed!\n");
  953. } else {
  954. printf("TEST FAILURES\n");
  955. }
  956. }
  957. });
  958. });
  959. }
  960. pool.join();
  961. }
  962. static void sort_test(MPCIO &mpcio,
  963. const PRACOptions &opts, char **args)
  964. {
  965. nbits_t depth=6;
  966. if (*args) {
  967. depth = atoi(*args);
  968. ++args;
  969. }
  970. int num_threads = opts.num_threads;
  971. boost::asio::thread_pool pool(num_threads);
  972. for (int thread_num = 0; thread_num < num_threads; ++thread_num) {
  973. boost::asio::post(pool, [&mpcio, thread_num, depth] {
  974. MPCTIO tio(mpcio, thread_num);
  975. run_coroutines(tio, [&tio, depth] (yield_t &yield) {
  976. address_t size = address_t(1)<<depth;
  977. // size_t &aes_ops = tio.aes_ops();
  978. Duoram<RegAS> oram(tio.player(), size);
  979. auto A = oram.flat(tio, yield);
  980. A.explicitonly(true);
  981. // Initialize the memory to random values in parallel
  982. std::vector<coro_t> coroutines;
  983. for (address_t i=0; i<size; ++i) {
  984. coroutines.emplace_back(
  985. [&A, i](yield_t &yield) {
  986. auto Acoro = A.context(yield);
  987. RegAS v;
  988. v.randomize(62);
  989. Acoro[i] += v;
  990. });
  991. }
  992. run_coroutines(yield, coroutines);
  993. A.bitonic_sort(0, depth);
  994. if (depth <= 10) {
  995. oram.dump();
  996. auto check = A.reconstruct();
  997. if (tio.player() == 0) {
  998. for (address_t i=0;i<size;++i) {
  999. printf("%04x %016lx\n", i, check[i].share());
  1000. }
  1001. }
  1002. }
  1003. });
  1004. });
  1005. }
  1006. pool.join();
  1007. }
  1008. static void bsearch_test(MPCIO &mpcio,
  1009. const PRACOptions &opts, char **args)
  1010. {
  1011. value_t target;
  1012. arc4random_buf(&target, sizeof(target));
  1013. target >>= 1;
  1014. nbits_t depth=6;
  1015. if (*args) {
  1016. depth = atoi(*args);
  1017. ++args;
  1018. }
  1019. if (*args) {
  1020. target = strtoull(*args, NULL, 16);
  1021. ++args;
  1022. }
  1023. int num_threads = opts.num_threads;
  1024. boost::asio::thread_pool pool(num_threads);
  1025. for (int thread_num = 0; thread_num < num_threads; ++thread_num) {
  1026. boost::asio::post(pool, [&mpcio, thread_num, depth, target] {
  1027. MPCTIO tio(mpcio, thread_num);
  1028. run_coroutines(tio, [&tio, depth, target] (yield_t &yield) {
  1029. address_t size = address_t(1)<<depth;
  1030. RegAS tshare;
  1031. if (tio.player() == 2) {
  1032. // Send shares of the target to the computational
  1033. // players
  1034. RegAS tshare0, tshare1;
  1035. tshare0.randomize();
  1036. tshare1.set(target-tshare0.share());
  1037. tio.iostream_p0() << tshare0;
  1038. tio.iostream_p1() << tshare1;
  1039. printf("Using target = %016lx\n", target);
  1040. yield();
  1041. } else {
  1042. // Get the share of the target
  1043. tio.iostream_server() >> tshare;
  1044. }
  1045. // Create a random database and sort it
  1046. // size_t &aes_ops = tio.aes_ops();
  1047. Duoram<RegAS> oram(tio.player(), size);
  1048. auto A = oram.flat(tio, yield);
  1049. A.explicitonly(true);
  1050. // Initialize the memory to random values in parallel
  1051. std::vector<coro_t> coroutines;
  1052. for (address_t i=0; i<size; ++i) {
  1053. coroutines.emplace_back(
  1054. [&A, i](yield_t &yield) {
  1055. auto Acoro = A.context(yield);
  1056. RegAS v;
  1057. v.randomize(62);
  1058. Acoro[i] += v;
  1059. });
  1060. }
  1061. run_coroutines(yield, coroutines);
  1062. A.bitonic_sort(0, depth);
  1063. // Binary search for the target
  1064. RegAS tindex = A.obliv_binary_search(tshare);
  1065. // Check the answer
  1066. if (tio.player() == 1) {
  1067. tio.iostream_peer() << tindex;
  1068. } else if (tio.player() == 0) {
  1069. RegAS peer_tindex;
  1070. tio.iostream_peer() >> peer_tindex;
  1071. tindex += peer_tindex;
  1072. }
  1073. if (depth <= 10) {
  1074. auto check = A.reconstruct();
  1075. if (tio.player() == 0) {
  1076. for (address_t i=0;i<size;++i) {
  1077. printf("%04x %016lx\n", i, check[i].share());
  1078. }
  1079. }
  1080. }
  1081. if (tio.player() == 0) {
  1082. printf("Found index = %lx\n", tindex.share());
  1083. }
  1084. });
  1085. });
  1086. }
  1087. pool.join();
  1088. }
  1089. void online_main(MPCIO &mpcio, const PRACOptions &opts, char **args)
  1090. {
  1091. MPCTIO tio(mpcio, 0);
  1092. if (!*args) {
  1093. std::cerr << "Mode is required as the first argument when not preprocessing.\n";
  1094. return;
  1095. } else if (!strcmp(*args, "test")) {
  1096. ++args;
  1097. online_test(mpcio, opts, args);
  1098. } else if (!strcmp(*args, "lamporttest")) {
  1099. ++args;
  1100. lamport_test(mpcio, opts, args);
  1101. } else if (!strcmp(*args, "rdpftest")) {
  1102. ++args;
  1103. rdpf_test(mpcio, opts, args);
  1104. } else if (!strcmp(*args, "rdpftime")) {
  1105. ++args;
  1106. rdpf_timing(mpcio, opts, args);
  1107. } else if (!strcmp(*args, "evaltime")) {
  1108. ++args;
  1109. rdpfeval_timing(mpcio, opts, args);
  1110. } else if (!strcmp(*args, "parevaltime")) {
  1111. ++args;
  1112. par_rdpfeval_timing(mpcio, opts, args);
  1113. } else if (!strcmp(*args, "tupletime")) {
  1114. ++args;
  1115. tupleeval_timing(mpcio, opts, args);
  1116. } else if (!strcmp(*args, "partupletime")) {
  1117. ++args;
  1118. par_tupleeval_timing(mpcio, opts, args);
  1119. } else if (!strcmp(*args, "duotest")) {
  1120. ++args;
  1121. if (opts.use_xor_db) {
  1122. duoram_test<RegXS>(mpcio, opts, args);
  1123. } else {
  1124. duoram_test<RegAS>(mpcio, opts, args);
  1125. }
  1126. } else if (!strcmp(*args, "cdpftest")) {
  1127. ++args;
  1128. cdpf_test(mpcio, opts, args);
  1129. } else if (!strcmp(*args, "cmptest")) {
  1130. ++args;
  1131. compare_test(mpcio, opts, args);
  1132. } else if (!strcmp(*args, "sorttest")) {
  1133. ++args;
  1134. sort_test(mpcio, opts, args);
  1135. } else if (!strcmp(*args, "bsearch")) {
  1136. ++args;
  1137. bsearch_test(mpcio, opts, args);
  1138. } else if (!strcmp(*args, "duoram")) {
  1139. ++args;
  1140. if (opts.use_xor_db) {
  1141. duoram<RegXS>(mpcio, opts, args);
  1142. } else {
  1143. duoram<RegAS>(mpcio, opts, args);
  1144. }
  1145. } else if (!strcmp(*args, "cell")) {
  1146. ++args;
  1147. cell(mpcio, opts, args);
  1148. } else {
  1149. std::cerr << "Unknown mode " << *args << "\n";
  1150. }
  1151. }