online.cpp 41 KB

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