ABY Framework  1.0
Arithmetic Bool Yao Framework
 All Classes Files Functions Variables Enumerations Enumerator Macros
abysetup.h
Go to the documentation of this file.
1 
19 #ifndef __ABYSETUP_H__
20 #define __ABYSETUP_H__
21 
22 #include "../util/typedefs.h"
23 #include "../util/crypto/crypto.h"
24 #include "../ot/naor-pinkas.h"
25 #include "../ot/ot-extension.h"
26 #include "../ot/xormasking.h"
27 #include "../ot/arithmtmasking.h"
28 #include "../DJN/djnparty.h"
29 #include "../DGK/dgkparty.h"
30 #include "../util/constants.h"
31 
32 //#define DEBUGSETUP
33 //define BENCH_PRECOMP
34 
35 /* Unification for the required OTs */
36 struct OTSenderVals {
37  CBitVector* X0; //X0 in the OTs
38  CBitVector* X1; //X1 in the OTs
39 };
40 
42  CBitVector* C; //choice bits in the OTs
43  CBitVector* R; //received strings
44 };
45 
46 struct PKMTGenVals {
47  CBitVector* A;
48  CBitVector* B;
49  CBitVector* C;
50  uint32_t numMTs;
51  uint32_t sharebitlen;
52 };
53 
54 union PartyValues {
55  struct OTSenderVals sndval;
56  struct OTReceiverVals rcvval;
57 };
58 
59 struct OTTask {
60  BYTE ottype; //which OT type (G-OT, C-OT, R-OT)
61  uint32_t numOTs; //number of OTs that are performed
62  uint32_t bitlen; //bitlen in the OTs
63  MaskingFunction* mskfct; //the masking function used
64  PartyValues pval; //contains the sender and receivers input and output
65 };
66 
67 struct SendTask {
68  uint64_t sndbytes; //number of bytes to be sent
69  BYTE* sndbuf; //buffer for the result
70 };
71 
72 struct ReceiveTask {
73  uint64_t rcvbytes; //number of bytes to be sent
74  BYTE* rcvbuf; //buffer for the result
75 };
76 
77 class ABYSetup {
78 
79 public:
80  ABYSetup(crypto* crypt, uint32_t numThreads, e_role role, e_mt_gen_alg mtalgo);
81  ~ABYSetup() {
82  Cleanup();
83  }
84 
85  void Reset();
86 
87  BOOL PrepareSetupPhase(vector<CSocket>& sockets);
88  BOOL PerformSetupPhase(vector<CSocket>& sockets);
89 
90  //TODO: the OTTasks are still quite unstraightforward, also combine in an intuitive way with multthreading
91  void AddOTTask(OTTask* task, uint32_t inverse) {
92  m_vOTTasks[inverse].push_back(task);
93  }
94  ;
95 
96  void AddPKMTGenTask(PKMTGenVals* task) {
97  m_vPKMTGenTasks.push_back(task);
98  }
99  ;
100 
101  //Both methods start a new thread but may stop if there is a thread already running
102  void AddSendTask(BYTE* sndbuf, uint64_t sndbytes);
103  void AddReceiveTask(BYTE* rcvbuf, uint64_t rcvbytes);
104 
105  BOOL WaitForTransmissionEnd();
106 
107 private:
108  BOOL Init();
109  void Cleanup();
110 
111  BOOL ThreadRunNPSnd(uint32_t exec);
112  BOOL ThreadRunNPRcv(uint32_t exec);
113 
114  BOOL ThreadRunIKNPSnd(uint32_t exec);
115  BOOL ThreadRunIKNPRcv(uint32_t exec);
116 
117  BOOL ThreadSendData(uint32_t exec);
118  BOOL ThreadReceiveData(uint32_t exec);
119 
120  BOOL ThreadRunPaillierMTGen(uint32_t exec);
121  BOOL ThreadRunDGKMTGen(uint32_t threadid);
122 
123  // OTTask values
124  vector<vector<OTTask*> > m_vOTTasks;
125 
126  vector<PKMTGenVals*> m_vPKMTGenTasks;
127  DJNParty* m_cPaillierMTGen;
128  DGKParty** m_cDGKMTGen;
129 
130  // NTL: Naor-Pinkas OT
131  BaseOT *np;
132  CBitVector m_vU;
133  uint32_t m_nIKNPProgress;
134  BYTE* m_vKeySeeds;
135  BYTE* m_vKeySeedMtx;
136  uint32_t m_nSndVals;
137  uint32_t m_nNumOTThreads;
138  vector<CSocket> m_vSockets;
139  //BYTE* m_aSeed;
140  e_role m_eRole;
141 
142  SendTask m_tsndtask;
143  ReceiveTask m_trcvtask;
144 
145  e_mt_gen_alg m_eMTGenAlg;
146 
147  crypto* m_cCrypt;
148 
149  OTExtSnd *ot_sender;
150  OTExtRec *ot_receiver;
151 
152  /* Thread information */
153 
154  enum EJobType {
155  e_OTExt, e_NP, e_Send, e_Receive, e_Transmit, e_Stop, e_MTPaillier, e_MTDGK,
156  };
157 
158  BOOL WakeupWorkerThreads(EJobType);
159  BOOL WaitWorkerThreads();
160  BOOL ThreadNotifyTaskDone(BOOL);
161 
162  class CWorkerThread: public CThread {
163  public:
164  CWorkerThread(uint32_t i, ABYSetup* callback) :
165  threadid(i), m_pCallback(callback) {
166  }
167  void PutJob(EJobType e) {
168  m_eJob = e;
169  m_evt.Set();
170  }
171  void ThreadMain();
172  uint32_t threadid;
173  ABYSetup* m_pCallback;
174  CEvent m_evt;
175  EJobType m_eJob;
176  };
177 
178  vector<CWorkerThread*> m_vThreads;
179  CEvent m_evt;
180  CLock m_lock;
181 
182  uint32_t m_nWorkingThreads;
183  BOOL m_bWorkerThreadSuccess;
184 
185 };
186 
187 #endif //__ABYSETUP_H__
188 
Definition: abysetup.h:46
Definition: abysetup.h:59
Definition: djnparty.h:31
Definition: crypto.h:58
Definition: ot-extension.h:192
e_mt_gen_alg
Enumeration which defines the method that is used for arithmetic multiplication triple generation...
Definition: constants.h:55
Definition: thread.h:125
Definition: ot-extension.h:67
Definition: abysetup.h:41
Definition: dgkparty.h:31
Definition: abysetup.h:72
Definition: baseOT.h:33
Definition: abysetup.h:36
e_role
Defines the role of the party or the source / target for certain operations (e.g., input/output)
Definition: constants.h:139
Definition: abysetup.h:54
Definition: thread.h:192
Definition: abysetup.h:77
Definition: maskingfunction.h:25
Definition: thread.h:170
Definition: abysetup.h:67
Definition: cbitvector.h:123