emp-toolkit
batcher.h
Go to the documentation of this file.
1 #ifndef BATCHER_H__
2 #define BATCHER_H__
3 #include <vector>
4 #include "backend.h"
5 using std::vector;
6 
7 class Batcher { public:
8  vector<bool> values;
9  vector<int> lens;
10  int len_ptr = 0;
11  block * labels = nullptr;
12  block * label_ptr = nullptr;
13  void add(bool * b, int length) {
14  lens.push_back(length);
15  for(int i = 0; i < length; ++i)
16  values.push_back(b[i]);
17  }
18 
20  if(labels != nullptr)
21  delete[] labels;
22  }
23 
24  template<typename T, typename... Args>
25  void add(Args&&... args) {
26  int length = T::bool_size(std::forward<Args>(args)...);
27  bool * tmp = new bool[length];
28  T::bool_data(tmp, std::forward<Args>(args)...);
29  add(tmp, length);
30  delete []tmp;
31  }
32 
33  void to_bool(bool * b) {
34  for(size_t i = 0; i < values.size(); ++i){
35  b[i] = values[i];
36  }
37  }
38 
39  void make_semi_honest(int party, Backend * be = nullptr) {
40  if(be == nullptr)
41  be = local_backend;
42  bool * bools = new bool[size()];
43  to_bool(bools);
44  label_ptr = labels = new block[size()];
45  local_backend->Feed(labels, party, bools, size());
46  len_ptr = 0;
47  delete[] bools;
48  }
49 
50  void set_blocks(block * b) {
51  this->labels = b;
52  this->label_ptr = b;
53  len_ptr = 0;
54  }
55 
56  template<typename T>
57  T next() {
58  T res = T(lens[len_ptr], label_ptr);
59  label_ptr +=lens[len_ptr];
60  len_ptr ++;
61  return res;
62  }
63 
64  int size() {
65  return values.size();
66  }
67 };
68 #endif
void make_semi_honest(int party, Backend *be=nullptr)
Definition: batcher.h:39
void add(Args &&... args)
Definition: batcher.h:25
__m128i block
Definition: block.h:8
~Batcher()
Definition: batcher.h:19
void add(bool *b, int length)
Definition: batcher.h:13
block * label_ptr
Definition: batcher.h:12
void to_bool(bool *b)
Definition: batcher.h:33
vector< bool > values
Definition: batcher.h:8
block * labels
Definition: batcher.h:11
void Feed(block *lbls, int party, const bool *b, int nel)
Definition: backend.h:12
void set_blocks(block *b)
Definition: batcher.h:50
T next()
Definition: batcher.h:57
vector< int > lens
Definition: batcher.h:9
int len_ptr
Definition: batcher.h:10
Definition: backend.h:8
Backend * local_backend
Definition: backend.cpp:7
Definition: batcher.h:7
int party
Definition: input-check-malicious.cpp:12
int size()
Definition: batcher.h:64