ABY Framework  1.0
Arithmetic Bool Yao Framework
 All Classes Files Functions Variables Enumerations Enumerator Macros
abyparty.h
Go to the documentation of this file.
1 
19 #ifndef __ABYPARTY_H__
20 #define __ABYPARTY_H__
21 
22 #include "../util/typedefs.h"
23 #include "../util/crypto/crypto.h"
24 #include "../circuit/abycircuit.h"
25 #include "../util/socket.h"
26 #include "../util/thread.h"
27 #include "../util/cbitvector.h"
28 #include "abysetup.h"
29 #include "../sharing/sharing.h"
30 #include "../sharing/boolsharing.h"
31 #include <vector>
32 #include "../util/timer.h"
33 #include "../sharing/yaoclientsharing.h"
34 #include "../sharing/yaoserversharing.h"
35 #include "../sharing/arithsharing.h"
36 
37 #include "../util/yaokey.h"
38 
39 #include <limits.h>
40 #include "../util/connection.h"
41 
42 //#define ABYDEBUG
43 //#define PRINT_OUTPUT
44 //#define DEBUGABYPARTY
45 //#define BENCHONLINEPHASE
46 //#define PRINT_PERFORMANCE_STATS
47 //#define DEBUGCOMM
48 //#define BATCH
49 
50 using namespace std;
51 
52 class ABYParty {
53 public:
54  ABYParty(e_role pid, char* addr, seclvl seclvl, uint32_t bitlen, uint32_t nthreads, e_mt_gen_alg mg_algo = MT_OT);
55  ~ABYParty();
56 
57  vector<Sharing*>& GetSharings() {
58  return m_vSharings;
59  }
60  CBitVector ExecCircuit();
61  CBitVector ExecSetupPhase();
62  uint32_t GetMyInput(CBitVector& in); //TODO deprecated, used only for benchmarking reasons where input is random
63  uint32_t GetOtherInput(CBitVector &otherin); //used for verification, parties exchange inputs
64 
65  uint32_t GetOutput(CBitVector& out);
66  void Reset();
67 
68  double GetTiming(ABYPHASE phase);
69 
70 private:
71  BOOL Init();
72  void Cleanup();
73 
74  BOOL InitCircuit(uint32_t bitlen);
75 
76  BOOL EstablishConnection();
77 
78  BOOL ABYPartyListen();
79  BOOL ABYPartyConnect();
80 
81  BOOL AssignInputValues();
82  BOOL EvaluateCircuit();
83 
84  void BuildCircuit();
85  void BuildBoolMult(uint32_t bitlen, uint32_t resbitlen, uint32_t nvals);
86  void BuildBoolAdd(uint32_t bitlen, uint32_t nvals);
87 
88  void InstantiateGate(uint32_t gateid);
89  void UsedGate(uint32_t gateid);
90 
91  BOOL PerformInteraction();
92  BOOL ThreadSendValues();
93  BOOL ThreadReceiveValues();
94 
95  BOOL PrintInput();
96  void PrintOutput();
97 
98 #ifdef VERIFYABYRES
99  BOOL VerifyResult();
100 #endif
101 
102  void PrintPerformanceStatistics();
103 
104  e_mt_gen_alg m_eMTGenAlg;
105  ABYSetup* m_pSetup;
106 
107  // Network Communication
108  vector<CSocket> m_vSockets; // sockets for threads
109  e_role m_eRole; // thread id
110  short m_nPort;
111  seclvl m_sSecLvl;
112 
113  uint32_t m_nNumOTThreads;
114 
115  uint32_t m_nHelperThreads;
116 
117  char* m_cAddress;
118 
119  uint32_t m_nDepth;
120 
121  uint32_t m_nMyNumInBits;
122  // Ciruit
123  ABYCircuit* m_pCircuit;
124  GATE* m_pGates;
125 
126  uint32_t m_nSizeOfVal;
127 
128  // Input values
129  CBitVector m_vInputBits;
130 
131  //constant 128-bit seed, IMPORTANT: exclude if used in practice
132  BYTE* m_cConstantInsecureSeed;
133 
134  vector<Sharing*> m_vSharings;
135 
136  crypto* m_cCrypt;
137 
138  enum EPartyJobType {
139  e_Party_Comm, e_Party_Stop,
140  };
141 
142  class CPartyWorkerThread: public CThread {
143  public:
144  CPartyWorkerThread(uint32_t id, ABYParty* callback) :
145  threadid(id), m_pCallback(callback) {
146  }
147  ;
148  void PutJob(EPartyJobType e) {
149  m_eJob = e;
150  m_evt.Set();
151  }
152  void ThreadMain();
153  uint32_t threadid;
154  ABYParty* m_pCallback;
155  CEvent m_evt;
156  EPartyJobType m_eJob;
157  };
158 
159  BOOL WakeupWorkerThreads(EPartyJobType);
160  BOOL WaitWorkerThreads();
161  BOOL ThreadNotifyTaskDone(BOOL);
162 
163  vector<CPartyWorkerThread*> m_vThreads;
164  CEvent m_evt;
165  CLock m_lock;
166 
167  uint32_t m_nWorkingThreads;
168  BOOL m_bWorkerThreadSuccess;
169 
170 };
171 
172 #endif //__ABYPARTY_H__
173 
Definition: crypto.h:58
Definition: abyparty.h:52
Contains all methods that are processed during the setup phase of ABY.
Definition: abycircuit.h:122
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: constants.h:57
e_role
Defines the role of the party or the source / target for certain operations (e.g., input/output)
Definition: constants.h:139
Definition: typedefs.h:79
Definition: abycircuit.h:144
Definition: thread.h:192
Definition: abysetup.h:77
Definition: thread.h:170
Definition: cbitvector.h:123