ABY Framework  1.0
Arithmetic Bool Yao Framework
 All Classes Files Functions Variables Enumerations Enumerator Macros
booleancircuits.h
Go to the documentation of this file.
1 
18 #ifndef __BOOLEANCIRCUITS_H_
19 #define __BOOLEANCIRCUITS_H_
20 
21 #include "../util/typedefs.h"
22 #include "abycircuit.h"
23 #include <assert.h>
24 #include "circuit.h"
25 
27 class BooleanCircuit: public Circuit {
28 public:
29  BooleanCircuit(ABYCircuit* aby, e_role myrole, e_sharing context) :
30  Circuit(aby, context, myrole, 1, C_BOOLEAN) {
31  Init();
32  }
33  ;
34  ~BooleanCircuit() {
35  //Cleanup();
36  }
37  ;
38 
39  void Init();
40  void Cleanup();
41  void Reset();
42 
43  uint32_t PutANDGate(uint32_t left, uint32_t right);
44  vector<uint32_t> PutANDGate(vector<uint32_t> inleft, vector<uint32_t> inright);
45  share* PutANDGate(share* ina, share* inb);
46 
47  uint32_t PutVectorANDGate(uint32_t choiceinput, uint32_t vectorinput);
48 
49  uint32_t PutXORGate(uint32_t left, uint32_t right);
50  vector<uint32_t> PutXORGate(vector<uint32_t> inleft, vector<uint32_t> inright);
51  share* PutXORGate(share* ina, share* inb);
52 
53  uint32_t PutORGate(uint32_t a, uint32_t b);
54  share* PutORGate(share* a, share* b);
55  vector<uint32_t> PutORGate(vector<uint32_t> a, vector<uint32_t> b);
56 
57  uint32_t PutINGate(uint32_t nvals, e_role src);
58  template<class T> uint32_t PutINGate(uint32_t nvals, T val);
59  uint32_t PutINGate(uint32_t nvals, uint64_t val, e_role role);
60  uint32_t PutINGate(uint32_t ninvals, uint32_t* val, e_role role);
61  share* PutINGate(uint32_t nvals, uint64_t val, uint32_t bitlen, e_role role);
62  share* PutINGate(uint32_t nvals, uint32_t* val, uint32_t bitlen, e_role role);
63  share* PutINGate(uint32_t nvals, uint8_t* val, uint32_t bitlen, e_role role);
64 
65  uint32_t PutOUTGate(uint32_t parent, e_role dst);
66  vector<uint32_t> PutOUTGate(vector<uint32_t> parents, e_role dst);
67  share* PutOUTGate(share* parent, e_role dst);
68 
69  share* PutCONSGate(uint32_t nvals, UGATE_T val, uint32_t bitlen);
70  share* PutCONSGate(uint32_t nvals, uint32_t* val, uint32_t bitlen);
71  share* PutCONSGate(uint32_t nvals, uint8_t* val, uint32_t bitlen);
72  uint32_t PutConstantGate(UGATE_T val, uint32_t nvals = 1);
73 
74  uint32_t GetNumB2YGates() {
75  return m_nB2YGates;
76  }
77  ;
78  uint32_t GetNumA2YGates() {
79  return m_nA2YGates;
80  }
81  ;
82 
83  int GetNumANDGates() {
84  return m_vANDs[0].numgates;
85  }
86  ;
87  int GetANDs(non_lin_vec_ctx*& inptr) {
88  inptr = m_vANDs;
89  return m_nNumANDSizes;
90  }
91  ;
92 
93  share* PutMULGate(share* ina, share* inb);
94  share* PutGEGate(share* ina, share* inb);
95  share* PutEQGate(share* ina, share* inb);
96  share* PutMUXGate(share* ina, share* inb, share* sel);
97 
98  vector<uint32_t> PutMulGate(vector<uint32_t> a, vector<uint32_t> b, uint32_t resbitlen);
99  vector<uint32_t> PutAddGate(vector<uint32_t> left, vector<uint32_t> right, BOOL bCarry = FALSE);
100  share* PutADDGate(share* ina, share* inb);
101 
102  vector<uint32_t> PutSizeOptimizedAddGate(vector<uint32_t> left, vector<uint32_t> right, BOOL bCarry = FALSE);
103  vector<uint32_t> PutDepthOptimizedAddGate(vector<uint32_t> lefta, vector<uint32_t> right, BOOL bCARRY = FALSE);
104 
105  vector<uint32_t> PutSUBGate(vector<uint32_t> a, vector<uint32_t> b);
106  share* PutSUBGate(share* ina, share* inb);
107  vector<uint32_t> PutWideAddGate(vector<vector<uint32_t> > ins, uint32_t resbitlen);
108  uint32_t PutGEGate(vector<uint32_t> a, vector<uint32_t> b);
109  uint32_t PutSizeOptimizedGEGate(vector<uint32_t> a, vector<uint32_t> b);
110  uint32_t PutDepthOptimizedGEGate(vector<uint32_t> a, vector<uint32_t> b);
111  uint32_t PutEQGate(vector<uint32_t> a, vector<uint32_t> b);
112 
113  share* PutANDVecGate(share* ina, share* inb);
114  vector<uint32_t> PutMUXGate(vector<uint32_t> a, vector<uint32_t> b, uint32_t s, BOOL vecand = false);
115  vector<uint32_t> PutVecANDMUXGate(vector<uint32_t> a, vector<uint32_t> b, vector<uint32_t> s);
116  uint32_t PutVecANDMUXGate(uint32_t a, uint32_t b, uint32_t s);
117  uint32_t PutWideGate(e_gatetype type, vector<uint32_t> ins);
118  vector<vector<uint32_t> > PutCondSwapGate(vector<uint32_t> a, vector<uint32_t> b, uint32_t s, BOOL vectorized);
119  vector<uint32_t> PutELM0Gate(vector<uint32_t> val, uint32_t b);
120 
121  vector<uint32_t> LShift(vector<uint32_t> val, uint32_t pos, uint32_t nvals = 1);
122 
123  uint32_t PutIdxGate(uint32_t r, uint32_t maxidx);
124 
125  share* PutRepeaterGate(share* input, uint32_t nvals);
126  uint32_t PutRepeaterGate(uint32_t input, uint32_t nvals);
127  uint32_t PutCombinerGate(vector<uint32_t>& input);
128  uint32_t PutCombineAtPosGate(vector<uint32_t>& input, uint32_t pos);
129 
130  uint32_t PutSubsetGate(uint32_t input, uint32_t* posids, uint32_t nvals);
131  share* PutSubsetGate(share* input, uint32_t* posids, uint32_t nvals);
132 
133  share* PutSplitterGate(share* input);
134  vector<uint32_t> PutSplitterGate(uint32_t input);
135 
136  uint32_t PutCallbackGate(vector<uint32_t> in, uint32_t rounds, void (*callback)(GATE*, void*), void* infos, uint32_t nvals);
137  share* PutCallbackGate(share* in, uint32_t rounds, void (*callback)(GATE*, void*), void* infos, uint32_t nvals);
138 
139  share* PutY2BGate(share* ina);
140  share* PutB2YGate(share* ina);
141 
142  uint32_t PutY2BCONVGate(uint32_t parentid);
143  uint32_t PutB2YCONVGate(uint32_t parentid);
144  vector<uint32_t> PutY2BCONVGate(vector<uint32_t> parentid);
145  vector<uint32_t> PutB2YCONVGate(vector<uint32_t> parentid);
146 
147  vector<uint32_t> PutA2YCONVGate(vector<uint32_t> parentid);
148  share* PutA2YGate(share* ina);
149 
150  share* PutB2AGate(share* ina) {
151  cerr << "B2A not available for Boolean circuits, please use Arithmetic circuits instead" << endl;
152  return new boolshare(0, this);
153  }
154 
155  uint32_t PutINVGate(uint32_t parentid);
156  vector<uint32_t> PutINVGate(vector<uint32_t> parentid);
157  share* PutINVGate(share* parent);
158 
159  share* PutMinGate(share** a, uint32_t nvals);
160  vector<uint32_t> PutMinGate(vector<vector<uint32_t> > a);
161 
162  void PutMinIdxGate(share** a, share** b, uint32_t nvals, share** minval_shr, share** minid_shr);
163  void PutMinIdxGate(vector<vector<uint32_t> > a, vector<vector<uint32_t> > idx,
164  vector<uint32_t>& minval, vector<uint32_t>& minid);
165 
166 private:
167  void UpdateInteractiveQueue(uint32_t);
168  void UpdateLocalQueue(uint32_t gateid);
169 
170  non_lin_vec_ctx* m_vANDs;
171  uint32_t m_nNumANDSizes;
172 
173  uint32_t m_nB2YGates;
174  uint32_t m_nA2YGates;
175 };
176 
177 #endif /* __BOOLEANCIRCUITS_H_ */
Definition: booleancircuits.h:27
e_gatetype
Enumeration which defines the type of the gate in the circuit.
Definition: constants.h:67
Definition: abycircuit.h:122
Definition: circuit.h:258
ABYCircuit class.
Contains the class for generic circuits, which is a super-class of Boolean and Arithmetic circuits...
Circuit(ABYCircuit *aby, e_sharing context, e_role myrole, uint32_t bitlen, e_circuit circ)
Definition: circuit.h:34
e_role
Defines the role of the party or the source / target for certain operations (e.g., input/output)
Definition: constants.h:139
Definition: constants.h:46
Definition: circuit.h:332
Definition: abycircuit.h:144
e_sharing
Enumeration which defines the different sharing which are there in the framework. ...
Definition: constants.h:124
Definition: circuit.h:30
Definition: abycircuit.h:137