readvectors.h 7.1 KB

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