filesio.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385
  1. /**
  2. * @brief The function writes the flag vectors into /preprocflags/ directory in duoram-online
  3. *
  4. * @param party
  5. * @param i
  6. * @param db_nitems
  7. * @param flags
  8. * @param outs_
  9. * @param final_correction_word
  10. */
  11. void write_evalfull_outs_into_a_file(bool party, size_t i, size_t db_nitems, int8_t * flags, int64_t * outs_, __m128i final_correction_word, int64_t additve_sharesR)
  12. {
  13. if(!party)
  14. {
  15. char const * p0_filename0;
  16. char tmp[100];
  17. p0_filename0 = "../duoram-online/preprocflags/party0_read_flags_b";
  18. strcpy(tmp, p0_filename0);
  19. strcat(tmp, std::to_string(i).c_str());
  20. int w0 = open( tmp, O_WRONLY | O_CREAT, S_IWRITE | S_IREAD);
  21. int written = write(w0, flags, db_nitems * sizeof(flags[0]));
  22. if(written<0) perror("Write error");
  23. close(w0);
  24. p0_filename0 = "../duoram-online/preprocflags/party0_read_flags_c";
  25. strcpy(tmp, p0_filename0);
  26. strcat(tmp, std::to_string(i).c_str());
  27. int w1 = open( tmp, O_WRONLY | O_CREAT, S_IWRITE | S_IREAD);
  28. written = write(w1, flags, db_nitems * sizeof(flags[0]));
  29. if(written<0) perror("Write error");
  30. close(w1);
  31. p0_filename0 = "../duoram-online/preprocflags/party0_read_flags_d";
  32. strcpy(tmp, p0_filename0);
  33. strcat(tmp, std::to_string(i).c_str());
  34. int w2 = open( tmp, O_WRONLY | O_CREAT, S_IWRITE | S_IREAD);
  35. written = write(w2, flags, db_nitems * sizeof(flags[0]));
  36. if(written<0) perror("Write error");
  37. close(w2);
  38. p0_filename0 = "../duoram-online/preprocflags/party0_write_flags_b";
  39. strcpy(tmp, p0_filename0);
  40. strcat(tmp, std::to_string(i).c_str());
  41. int w4 = open( tmp, O_WRONLY | O_CREAT, S_IWRITE | S_IREAD);
  42. written = write(w4, flags, db_nitems * sizeof(flags[0]));
  43. if(written<0) perror("Write error");
  44. close(w4);
  45. p0_filename0 = "../duoram-online/preprocflags/party0_write_flags_c";
  46. strcpy(tmp, p0_filename0);
  47. strcat(tmp, std::to_string(i).c_str());
  48. int w5 = open( tmp, O_WRONLY | O_CREAT, S_IWRITE | S_IREAD);
  49. written = write(w5, flags, db_nitems * sizeof(flags[0]));
  50. if(written<0) perror("Write error");
  51. close(w5);
  52. p0_filename0 = "../duoram-online/preprocflags/party0_write_flags_d";
  53. strcpy(tmp, p0_filename0);
  54. strcat(tmp, std::to_string(i).c_str());
  55. int w6 = open( tmp, O_WRONLY | O_CREAT, S_IWRITE | S_IREAD);
  56. written = write(w6, flags, db_nitems * sizeof(flags[0]));
  57. if(written<0) perror("Write error");
  58. close(w6);
  59. p0_filename0 = "../duoram-online/preprocflags/party0_write_b";
  60. strcpy(tmp, p0_filename0);
  61. strcat(tmp, std::to_string(i).c_str());
  62. w4 = open( tmp, O_WRONLY | O_CREAT, S_IWRITE | S_IREAD);
  63. written = write(w4, outs_, db_nitems * sizeof(outs_[0]));
  64. if(written<0) perror("Write error");
  65. close(w4);
  66. p0_filename0 = "../duoram-online/preprocflags/party0_write_c";
  67. strcpy(tmp, p0_filename0);
  68. strcat(tmp, std::to_string(i).c_str());
  69. w5 = open( tmp, O_WRONLY | O_CREAT, S_IWRITE | S_IREAD);
  70. written = write(w5, outs_, db_nitems * sizeof(outs_[0]));
  71. if(written<0) perror("Write error");
  72. close(w5);
  73. p0_filename0 = "../duoram-online/preprocflags/party0_write_d";
  74. strcpy(tmp, p0_filename0);
  75. strcat(tmp, std::to_string(i).c_str());
  76. w6 = open( tmp, O_WRONLY | O_CREAT, S_IWRITE | S_IREAD);
  77. written = write(w6, outs_, db_nitems * sizeof(outs_[0]));
  78. if(written<0) perror("Write error");
  79. close(w6);
  80. }
  81. if(party)
  82. {
  83. char const * p0_filename0;
  84. char tmp[100];
  85. p0_filename0 = "../duoram-online/preprocflags/party1_read_flags_b";
  86. strcpy(tmp, p0_filename0);
  87. strcat(tmp, std::to_string(i).c_str());
  88. int w0 = open( tmp, O_WRONLY | O_CREAT, S_IWRITE | S_IREAD);
  89. int written = write(w0, flags, db_nitems * sizeof(flags[0]));
  90. if(written<0) perror("Write error");
  91. close(w0);
  92. p0_filename0 = "../duoram-online/preprocflags/party1_read_flags_c";
  93. strcpy(tmp, p0_filename0);
  94. strcat(tmp, std::to_string(i).c_str());
  95. int w1 = open( tmp, O_WRONLY | O_CREAT, S_IWRITE | S_IREAD);
  96. written = write(w1, flags, db_nitems * sizeof(flags[0]));
  97. if(written<0) perror("Write error");
  98. close(w1);
  99. p0_filename0 = "../duoram-online/preprocflags/party1_read_flags_d";
  100. strcpy(tmp, p0_filename0);
  101. strcat(tmp, std::to_string(i).c_str());
  102. int w2 = open( tmp, O_WRONLY | O_CREAT, S_IWRITE | S_IREAD);
  103. written = write(w2,flags, db_nitems * sizeof(flags[0]));
  104. if(written<0) perror("Write error");
  105. close(w2);
  106. p0_filename0 = "../duoram-online/preprocflags/party1_write_flags_b";
  107. strcpy(tmp, p0_filename0);
  108. strcat(tmp, std::to_string(i).c_str());
  109. int w4 = open( tmp, O_WRONLY | O_CREAT, S_IWRITE | S_IREAD);
  110. written = write(w4,flags, db_nitems * sizeof(flags[0]));
  111. if(written<0) perror("Write error");
  112. close(w4);
  113. p0_filename0 = "../duoram-online/preprocflags/party1_write_flags_c";
  114. strcpy(tmp, p0_filename0);
  115. strcat(tmp, std::to_string(i).c_str());
  116. int w5 = open( tmp, O_WRONLY | O_CREAT, S_IWRITE | S_IREAD);
  117. written = write(w5, flags, db_nitems * sizeof(flags[0]));
  118. if(written<0) perror("Write error");
  119. close(w5);
  120. p0_filename0 = "../duoram-online/preprocflags/party1_write_flags_d";
  121. strcpy(tmp, p0_filename0);
  122. strcat(tmp, std::to_string(i).c_str());
  123. int w6 = open( tmp, O_WRONLY | O_CREAT, S_IWRITE | S_IREAD);
  124. written = write(w6, flags, db_nitems * sizeof(flags[0]));
  125. if(written<0) perror("Write error");
  126. close(w6);
  127. p0_filename0 = "../duoram-online/preprocflags/party1_write_b";
  128. strcpy(tmp, p0_filename0);
  129. strcat(tmp, std::to_string(i).c_str());
  130. w4 = open( tmp, O_WRONLY | O_CREAT, S_IWRITE | S_IREAD);
  131. written = write(w4, outs_, db_nitems * sizeof(outs_[0]));
  132. if(written<0) perror("Write error");
  133. close(w4);
  134. p0_filename0 = "../duoram-online/preprocflags/party1_write_c";
  135. strcpy(tmp, p0_filename0);
  136. strcat(tmp, std::to_string(i).c_str());
  137. w5 = open( tmp, O_WRONLY | O_CREAT, S_IWRITE | S_IREAD);
  138. written = write(w5, outs_, db_nitems * sizeof(outs_[0]));
  139. if(written<0) perror("Write error");
  140. close(w5);
  141. p0_filename0 = "../duoram-online/preprocflags/party1_write_d";
  142. strcpy(tmp, p0_filename0);
  143. strcat(tmp, std::to_string(i).c_str());
  144. w6 = open( tmp, O_WRONLY | O_CREAT, S_IWRITE | S_IREAD);
  145. written = write(w6, outs_, db_nitems * sizeof(outs_[0]));
  146. if(written<0) perror("Write error");
  147. close(w6);
  148. }
  149. if(party)
  150. {
  151. char const * p1_filename0;
  152. char tmp[100];
  153. p1_filename0 = "../duoram-online/preprocflags/FCW1";
  154. strcpy(tmp, p1_filename0);
  155. strcat(tmp, std::to_string(i).c_str());
  156. int w0 = open( tmp, O_WRONLY | O_CREAT, S_IWRITE | S_IREAD);
  157. int written = write(w0, &final_correction_word[0], sizeof(uint64_t));
  158. if(written<0) perror("Write error");
  159. close(w0);
  160. p1_filename0 = "../duoram-online/preprocflags/R1";
  161. strcpy(tmp, p1_filename0);
  162. strcat(tmp, std::to_string(i).c_str());
  163. w0 = open( tmp, O_WRONLY | O_CREAT, S_IWRITE | S_IREAD);
  164. written = write(w0, &additve_sharesR, sizeof(int64_t));
  165. if(written<0) perror("Write error");
  166. close(w0);
  167. }
  168. if(!party)
  169. {
  170. char const * p0_filename0;
  171. char tmp[100];
  172. p0_filename0 = "../duoram-online/preprocflags/FCW0";
  173. strcpy(tmp, p0_filename0);
  174. strcat(tmp, std::to_string(i).c_str());
  175. int w0 = open( tmp, O_WRONLY | O_CREAT, S_IWRITE | S_IREAD);
  176. int written = write(w0, &final_correction_word[0], sizeof(uint64_t));
  177. if(written<0) perror("Write error");
  178. close(w0);
  179. p0_filename0 = "../duoram-online/preprocflags/R0";
  180. strcpy(tmp, p0_filename0);
  181. strcat(tmp, std::to_string(i).c_str());
  182. w0 = open( tmp, O_WRONLY | O_CREAT, S_IWRITE | S_IREAD);
  183. written = write(w0, &additve_sharesR, sizeof(int64_t));
  184. if(written<0) perror("Write error");
  185. close(w0);
  186. }
  187. }
  188. void P2_write_evalfull_outs_into_a_file(bool party, size_t i, size_t db_nitems, int8_t * flags, int64_t * outs_)
  189. {
  190. if(!party)
  191. {
  192. char const * p0_filename0;
  193. char tmp[100];
  194. p0_filename0 = "../duoram-online/preprocflags/P2_party0_read_flags_b";
  195. strcpy(tmp, p0_filename0);
  196. strcat(tmp, std::to_string(i).c_str());
  197. int w0 = open( tmp, O_WRONLY | O_CREAT, S_IWRITE | S_IREAD);
  198. int written = write(w0, flags, db_nitems * sizeof(int8_t));
  199. if(written<0) perror("Write error");
  200. close(w0);
  201. p0_filename0 = "../duoram-online/preprocflags/P2_party0_read_flags_c";
  202. strcpy(tmp, p0_filename0);
  203. strcat(tmp, std::to_string(i).c_str());
  204. int w1 = open( tmp, O_WRONLY | O_CREAT, S_IWRITE | S_IREAD);
  205. written = write(w1, flags, db_nitems * sizeof(int8_t));
  206. if(written<0) perror("Write error");
  207. close(w1);
  208. p0_filename0 = "../duoram-online/preprocflags/P2_party0_read_flags_d";
  209. strcpy(tmp, p0_filename0);
  210. strcat(tmp, std::to_string(i).c_str());
  211. int w2 = open( tmp, O_WRONLY | O_CREAT, S_IWRITE | S_IREAD);
  212. written = write(w2, flags, db_nitems * sizeof(int8_t));
  213. if(written<0) perror("Write error");
  214. close(w2);
  215. p0_filename0 = "../duoram-online/preprocflags/P2_party0_write_flags_b";
  216. strcpy(tmp, p0_filename0);
  217. strcat(tmp, std::to_string(i).c_str());
  218. int w4 = open( tmp, O_WRONLY | O_CREAT, S_IWRITE | S_IREAD);
  219. written = write(w4, flags, db_nitems * sizeof(int8_t));
  220. if(written<0) perror("Write error");
  221. close(w4);
  222. p0_filename0 = "../duoram-online/preprocflags/P2_party0_write_flags_c";
  223. strcpy(tmp, p0_filename0);
  224. strcat(tmp, std::to_string(i).c_str());
  225. int w5 = open( tmp, O_WRONLY | O_CREAT, S_IWRITE | S_IREAD);
  226. written = write(w5, flags, db_nitems * sizeof(int8_t));
  227. if(written<0) perror("Write error");
  228. close(w5);
  229. p0_filename0 = "../duoram-online/preprocflags/P2_party0_write_flags_d";
  230. strcpy(tmp, p0_filename0);
  231. strcat(tmp, std::to_string(i).c_str());
  232. int w6 = open( tmp, O_WRONLY | O_CREAT, S_IWRITE | S_IREAD);
  233. written = write(w6, flags, db_nitems * sizeof(int8_t));
  234. if(written<0) perror("Write error");
  235. close(w6);
  236. p0_filename0 = "../duoram-online/preprocflags/P2_party0_write_b";
  237. strcpy(tmp, p0_filename0);
  238. strcat(tmp, std::to_string(i).c_str());
  239. w4 = open( tmp, O_WRONLY | O_CREAT, S_IWRITE | S_IREAD);
  240. written = write(w4, outs_, db_nitems * sizeof(int64_t));
  241. if(written<0) perror("Write error");
  242. close(w4);
  243. p0_filename0 = "../duoram-online/preprocflags/P2_party0_write_c";
  244. strcpy(tmp, p0_filename0);
  245. strcat(tmp, std::to_string(i).c_str());
  246. w5 = open( tmp, O_WRONLY | O_CREAT, S_IWRITE | S_IREAD);
  247. written = write(w5, outs_, db_nitems * sizeof(int64_t));
  248. if(written<0) perror("Write error");
  249. close(w5);
  250. p0_filename0 = "../duoram-online/preprocflags/P2_party0_write_d";
  251. strcpy(tmp, p0_filename0);
  252. strcat(tmp, std::to_string(i).c_str());
  253. w6 = open( tmp, O_WRONLY | O_CREAT, S_IWRITE | S_IREAD);
  254. written = write(w6, outs_, db_nitems * sizeof(int64_t));
  255. if(written<0) perror("Write error");
  256. close(w6);
  257. }
  258. if(party)
  259. {
  260. char const * p0_filename0;
  261. char tmp[100];
  262. p0_filename0 = "../duoram-online/preprocflags/P2_party1_read_flags_b";
  263. strcpy(tmp, p0_filename0);
  264. strcat(tmp, std::to_string(i).c_str());
  265. int w0 = open( tmp, O_WRONLY | O_CREAT, S_IWRITE | S_IREAD);
  266. int written = write(w0, flags, db_nitems * sizeof(int8_t));
  267. if(written<0) perror("Write error");
  268. close(w0);
  269. p0_filename0 = "../duoram-online/preprocflags/P2_party1_read_flags_c";
  270. strcpy(tmp, p0_filename0);
  271. strcat(tmp, std::to_string(i).c_str());
  272. int w1 = open( tmp, O_WRONLY | O_CREAT, S_IWRITE | S_IREAD);
  273. written = write(w1, flags, db_nitems * sizeof(int8_t));
  274. if(written<0) perror("Write error");
  275. close(w1);
  276. p0_filename0 = "../duoram-online/preprocflags/P2_party1_read_flags_d";
  277. strcpy(tmp, p0_filename0);
  278. strcat(tmp, std::to_string(i).c_str());
  279. int w2 = open( tmp, O_WRONLY | O_CREAT, S_IWRITE | S_IREAD);
  280. written = write(w2,flags, db_nitems * sizeof(int8_t));
  281. if(written<0) perror("Write error");
  282. close(w2);
  283. p0_filename0 = "../duoram-online/preprocflags/P2_party1_write_flags_b";
  284. strcpy(tmp, p0_filename0);
  285. strcat(tmp, std::to_string(i).c_str());
  286. int w4 = open( tmp, O_WRONLY | O_CREAT, S_IWRITE | S_IREAD);
  287. written = write(w4,flags, db_nitems * sizeof(int8_t));
  288. if(written<0) perror("Write error");
  289. close(w4);
  290. p0_filename0 = "../duoram-online/preprocflags/P2_party1_write_flags_c";
  291. strcpy(tmp, p0_filename0);
  292. strcat(tmp, std::to_string(i).c_str());
  293. int w5 = open( tmp, O_WRONLY | O_CREAT, S_IWRITE | S_IREAD);
  294. written = write(w5, flags, db_nitems * sizeof(int8_t));
  295. if(written<0) perror("Write error");
  296. close(w5);
  297. p0_filename0 = "../duoram-online/preprocflags/P2_party1_write_flags_d";
  298. strcpy(tmp, p0_filename0);
  299. strcat(tmp, std::to_string(i).c_str());
  300. int w6 = open( tmp, O_WRONLY | O_CREAT, S_IWRITE | S_IREAD);
  301. written = write(w6, flags, db_nitems * sizeof(int8_t));
  302. if(written<0) perror("Write error");
  303. close(w6);
  304. p0_filename0 = "../duoram-online/preprocflags/P2_party1_write_b";
  305. strcpy(tmp, p0_filename0);
  306. strcat(tmp, std::to_string(i).c_str());
  307. w4 = open( tmp, O_WRONLY | O_CREAT, S_IWRITE | S_IREAD);
  308. written = write(w4, outs_, db_nitems * sizeof(int64_t));
  309. if(written<0) perror("Write error");
  310. close(w4);
  311. //char const * p0_filename0;
  312. p0_filename0 = "../duoram-online/preprocflags/P2_party1_write_c";
  313. strcpy(tmp, p0_filename0);
  314. strcat(tmp, std::to_string(i).c_str());
  315. w5 = open( tmp, O_WRONLY | O_CREAT, S_IWRITE | S_IREAD);
  316. written = write(w5, outs_, db_nitems * sizeof(int64_t));
  317. if(written<0) perror("Write error");
  318. close(w5);
  319. p0_filename0 = "../duoram-online/preprocflags/P2_party1_write_d";
  320. strcpy(tmp, p0_filename0);
  321. strcat(tmp, std::to_string(i).c_str());
  322. w6 = open( tmp, O_WRONLY | O_CREAT, S_IWRITE | S_IREAD);
  323. written = write(w6, outs_, db_nitems * sizeof(int64_t));
  324. if(written<0) perror("Write error");
  325. close(w6);
  326. }
  327. }