readvectors.h 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. void concatanate_index(char const * filename, char tmp[100], size_t index)
  2. {
  3. strcpy(tmp, filename);
  4. strcat(tmp, std::to_string(index).c_str());
  5. }
  6. int read_final_correction_word(bool party, DB_t& FCW_read, int i = 0)
  7. {
  8. if(!party)
  9. {
  10. char tmp[100];
  11. concatanate_index("../duoram-online/preprocflags/FCW0", tmp, i);
  12. int const in0 { open(tmp, O_RDONLY ) };
  13. size_t r = read(in0, &FCW_read, sizeof(FCW_read));
  14. close(in0);
  15. if(r < 0) perror("Read error");
  16. }
  17. if(party)
  18. {
  19. char tmp[100];
  20. concatanate_index("../duoram-online/preprocflags/FCW1", tmp, i);
  21. int const in0 { open(tmp, O_RDONLY ) };
  22. size_t r = read(in0, &FCW_read, sizeof(FCW_read));
  23. close(in0);
  24. if(r < 0) perror("Read error");
  25. }
  26. return 0;
  27. }
  28. int read_rand_indx(bool party, DB_t& R, int i = 0)
  29. {
  30. if(!party)
  31. {
  32. char tmp[100];
  33. concatanate_index("../duoram-online/preprocflags/R0", tmp, i);
  34. int const in0 { open(tmp, O_RDONLY ) };
  35. size_t r = read(in0, &R, sizeof(R));
  36. close(in0);
  37. if(r < 0) perror("Read error");
  38. }
  39. if(party)
  40. {
  41. char tmp[100];
  42. concatanate_index("../duoram-online/preprocflags/R1", tmp, i);
  43. int const in0 { open(tmp, O_RDONLY ) };
  44. size_t r = read(in0, &R, sizeof(R));
  45. close(in0);
  46. if(r < 0) perror("Read error");
  47. }
  48. return 0;
  49. }
  50. int read_flags_for_reading(bool party, size_t db_nitems, int i = 0)
  51. {
  52. if(!party)
  53. {
  54. char tmp[100];
  55. concatanate_index("../duoram-online/preprocflags/party0_read_flags_b", tmp, i);
  56. int const in0 { open(tmp, O_RDONLY ) };
  57. size_t r = read(in0, reading_b, sizeof(reading_b));
  58. close(in0);
  59. if(r < 0) perror("Read error");
  60. concatanate_index("../duoram-online/preprocflags/party0_read_flags_c", tmp, i);
  61. int const in1 { open( tmp, O_RDONLY ) };
  62. r = read(in1, reading_c, sizeof(reading_c));
  63. close(in1);
  64. if(r < 0) perror("Read error");
  65. concatanate_index("../duoram-online/preprocflags/party0_read_flags_d", tmp, i);
  66. int const in2 { open( tmp, O_RDONLY ) };
  67. r = read(in2, reading_d, sizeof(reading_d));
  68. close(in2);
  69. if(r < 0) perror("Read error");
  70. }
  71. if(party)
  72. {
  73. char tmp[100];
  74. concatanate_index("../duoram-online/preprocflags/party1_read_flags_b", tmp, i);
  75. int const in0 { open(tmp, O_RDONLY ) };
  76. size_t r = read(in0, reading_b, sizeof(reading_b));
  77. close(in0);
  78. if(r < 0) perror("Read error");
  79. concatanate_index("../duoram-online/preprocflags/party1_read_flags_c", tmp, i);
  80. int const in1 { open(tmp, O_RDONLY ) };
  81. r = read(in1, reading_c, sizeof(reading_c));
  82. close(in1);
  83. if(r < 0) perror("Read error");
  84. concatanate_index("../duoram-online/preprocflags/party1_read_flags_d", tmp, i);
  85. int const in2 { open(tmp, O_RDONLY ) };
  86. r = read(in2, reading_d, sizeof(reading_d));
  87. close(in2);
  88. if(r < 0) perror("Read error");
  89. }
  90. return 0;
  91. }
  92. int read_flags_for_writing(bool party, size_t db_nitems, int i = 0)
  93. {
  94. if(!party)
  95. {
  96. char tmp[100];
  97. concatanate_index("../duoram-online/preprocflags/party0_write_flags_b", tmp, i);
  98. int const in0_w { open(tmp, O_RDONLY ) };
  99. size_t r = read(in0_w, writing_b, sizeof(writing_b));
  100. close(in0_w);
  101. if(r < 0) perror("Read error");
  102. concatanate_index("../duoram-online/preprocflags/party0_write_flags_c", tmp,i);
  103. int const in1_w { open( tmp, O_RDONLY ) };
  104. r = read(in1_w, writing_c, sizeof(writing_c));
  105. close(in1_w);
  106. if(r < 0) perror("Read error");
  107. concatanate_index("../duoram-online/preprocflags/party0_write_flags_d", tmp,i);
  108. int const in2_w { open( tmp, O_RDONLY ) };
  109. r = read(in2_w, writing_d, sizeof(writing_d));
  110. close(in2_w);
  111. if(r < 0) perror("Read error");
  112. }
  113. if(party)
  114. {
  115. char tmp[100];
  116. concatanate_index("../duoram-online/preprocflags/party1_write_flags_b", tmp,i);
  117. int const in0_w { open( tmp, O_RDONLY ) };
  118. size_t r = read(in0_w, writing_b, sizeof(writing_b));
  119. close(in0_w);
  120. if(r < 0) perror("Read error");
  121. concatanate_index("../duoram-online/preprocflags/party1_write_flags_c", tmp, i);
  122. int const in1_w { open(tmp, O_RDONLY ) };
  123. r = read(in1_w, writing_c, sizeof(writing_c));
  124. close(in1_w);
  125. if(r < 0) perror("Read error");
  126. concatanate_index("../duoram-online/preprocflags/party1_write_flags_d", tmp, i);
  127. int const in2_w { open( tmp, O_RDONLY ) };
  128. r = read(in2_w, writing_d, sizeof(writing_d));
  129. close(in2_w);
  130. if(r < 0) perror("Read error");
  131. }
  132. return 0;
  133. }
  134. int read_flags_for_refreshing(size_t db_nitems, int i = 0)
  135. {
  136. char tmp[100];
  137. concatanate_index("../duoram-online/preprocflags/P2_party0_write_flags_c", tmp, i);
  138. int const in1_w { open(tmp, O_RDONLY ) };
  139. size_t r = read(in1_w, writing_c, sizeof(writing_c));
  140. close(in1_w);
  141. if(r < 0) perror("Read error");
  142. concatanate_index("../duoram-online/preprocflags/P2_party1_write_flags_d", tmp, i);
  143. int const in2_w { open(tmp, O_RDONLY ) };
  144. r = read(in2_w, writing_d, sizeof(writing_d));
  145. close(in2_w);
  146. if(r < 0) perror("Read error");
  147. concatanate_index("../duoram-online/preprocflags/P2_party0_write_c", tmp, i);
  148. int const in1_w_ { open(tmp, O_RDONLY ) };
  149. r = read(in1_w_, c, sizeof(c));
  150. close(in1_w_);
  151. if(r < 0) perror("Read error");
  152. concatanate_index("../duoram-online/preprocflags/P2_party1_write_d", tmp, i);
  153. int const in2_w_ { open(tmp, O_RDONLY ) };
  154. r = read(in2_w_, d, sizeof(d));
  155. close(in2_w_);
  156. if(r < 0) perror("Read error");
  157. return 0;
  158. }
  159. int read_flags_for_generating_cancellation_terms(size_t db_nitems, int i = 0)
  160. {
  161. char tmp[100];
  162. concatanate_index("../duoram-online/preprocflags/P2_party1_read_flags_d", tmp, i);
  163. int const in2 { open(tmp, O_RDONLY ) };
  164. size_t r = read(in2, reading_d, sizeof(reading_d));
  165. close(in2);
  166. if(r < 0) perror("Read error");
  167. concatanate_index("../duoram-online/preprocflags/P2_party0_read_flags_c", tmp, i);
  168. int const in2_ { open(tmp, O_RDONLY ) };
  169. r = read(in2_, reading_c, sizeof(reading_c));
  170. close(in2_);
  171. if(r < 0) perror("Read error");
  172. return 0;
  173. }
  174. int read_flags_for_updating(bool party, size_t db_nitems, int i = 0)
  175. {
  176. char tmp[100];
  177. if(!party)
  178. {
  179. concatanate_index("../duoram-online/preprocflags/party0_write_b", tmp, i);
  180. int const in0_w_ { open(tmp, O_RDONLY ) };
  181. size_t r = read(in0_w_, b, sizeof(b));
  182. close(in0_w_);
  183. if(r < 0) perror("Read error");
  184. concatanate_index("../duoram-online/preprocflags/party0_write_c", tmp, i);
  185. int const in1_w_ { open(tmp, O_RDONLY ) };
  186. r = read(in1_w_, c, sizeof(c));
  187. close(in1_w_);
  188. if(r < 0) perror("Read error");
  189. concatanate_index("../duoram-online/preprocflags/party0_write_d", tmp, i);
  190. int const in2_w_ { open(tmp, O_RDONLY ) };
  191. r = read(in2_w_, d, sizeof(d));
  192. close(in2_w_);
  193. if(r < 0) perror("Read error");
  194. }
  195. if(party)
  196. {
  197. concatanate_index("../duoram-online/preprocflags/party1_write_b", tmp, i);
  198. int const in0_w_ { open( tmp, O_RDONLY ) };
  199. size_t r = read(in0_w_, b, sizeof(b));
  200. close(in0_w_);
  201. if(r < 0) perror("Read error");
  202. concatanate_index("../duoram-online/preprocflags/party1_write_c", tmp, i);
  203. int const in1_w_ { open(tmp, O_RDONLY ) };
  204. r = read(in1_w_, c, sizeof(c));
  205. close(in1_w_);
  206. if(r < 0) perror("Read error");
  207. concatanate_index("../duoram-online/preprocflags/party1_write_d", tmp, i);
  208. int const in2_w_ { open(tmp, O_RDONLY ) };
  209. r = read(in2_w_, d, sizeof(d));
  210. close(in2_w_);
  211. if(r < 0) perror("Read error");
  212. }
  213. return 0;
  214. }