ABY Framework  1.0
Arithmetic Bool Yao Framework
 All Classes Files Functions Variables Enumerations Enumerator Macros
typedefs.h
Go to the documentation of this file.
1 
19 #ifndef __TYPEDEFS_H__
20 #define __TYPEDEFS_H__
21 
22 #include <sys/time.h>
23 #include <assert.h>
24 
25 #define BATCH
26 #define GENERATE_INPUTS
27 #define INPUT_VECTORS
28 //#define YAO_CIRCUIT
29 //#define USE_VECTOR_AND_GATES
30 //#define ZDEBUG
31 //#define PRINT_PERFORMANCE_STATS
32 
33 #define MAXGATES 32000000
34 
35 #ifndef BATCH
36 //#define PRINT_OUTPUT
37 #endif
38 
39 #define two_pow(e) (((uint64_t) 1) << (e))
40 
41 //TODO: this is bad, fix occurrences of ceil_log2 and replace by ceil_log2_min1 where log(1) = 1 is necessary. For all else use ceil_log2_real
42 static int ceil_log2(int bits) {
43  if (bits == 1)
44  return 1;
45  int targetlevel = 0, bitstemp = bits;
46  while (bitstemp >>= 1)
47  ++targetlevel;
48  return targetlevel + ((1 << targetlevel) < bits);
49 }
50 
51 static int ceil_log2_min1(int bits) {
52  if (bits <= 1)
53  return 1;
54  int targetlevel = 0, bitstemp = bits;
55  while (bitstemp >>= 1)
56  ++targetlevel;
57  return targetlevel + ((1 << targetlevel) < bits);
58 }
59 
60 static int ceil_log2_real(int bits) {
61  if (bits == 1)
62  return 0;
63  int targetlevel = 0, bitstemp = bits;
64  while (bitstemp >>= 1)
65  ++targetlevel;
66  return targetlevel + ((1 << targetlevel) < bits);
67 }
68 
69 static int floor_log2(int bits) {
70  if (bits == 1)
71  return 1;
72  int targetlevel = 0;
73  while (bits >>= 1)
74  ++targetlevel;
75  return targetlevel;
76 }
77 
78 
79 typedef struct SECURITYLEVELS {
80  int statbits;
81  int symbits;
82  int ifcbits;
83  int eccpfbits;
84  int ecckcbits;
85 } seclvl;
86 
87 typedef int BOOL;
88 typedef long LONG;
89 
90 typedef unsigned char BYTE;
91 typedef unsigned short USHORT;
92 typedef unsigned int UINT;
93 typedef unsigned long ULONG;
94 typedef BYTE UINT8_T;
95 typedef USHORT UINT16_T;
96 typedef UINT UINT32_T;
97 typedef unsigned long long UINT64_T;
98 typedef long long SINT64_T;
99 
100 typedef ULONG DWORD;
101 typedef UINT64_T UGATE_T;
102 typedef UINT64_T REGISTER_SIZE;
103 
104 #define GATE_T_BITS (sizeof(UGATE_T) * 8)
105 
106 typedef REGISTER_SIZE REGSIZE;
107 #define LOG2_REGISTER_SIZE ceil_log2(sizeof(REGISTER_SIZE) << 3)
108 
109 #define FILL_BYTES AES_BYTES
110 #define FILL_BITS AES_BITS
111 
112 #define OT_WINDOW_SIZE (AES_BITS*4)
113 #define OT_WINDOW_SIZE_BYTES (AES_BYTES*4)
114 
115 #define MAX_REPLY_BITS 65536 //at most 2^16 bits may be sent in one go
116 
117 #define RETRY_CONNECT 1000
118 #define CONNECT_TIMEO_MILISEC 10000
119 
120 #define SNDVALS 2
121 
122 #define OTEXT_BLOCK_SIZE_BITS AES_BITS
123 #define OTEXT_BLOCK_SIZE_BYTES AES_BYTES
124 
125 #define VECTOR_INTERNAL_SIZE 8
126 
127 #define SERVER_ID 0
128 #define CLIENT_ID 1
129 
130 #define MAX_INT (~0)
131 #if (MAX_INT == 0xFFFFFFFF)
132 #define MACHINE_SIZE_32
133 #elif (MAX_INT == 0xFFFFFFFFFFFFFFFF)
134 #define MACHINE_SIZE_64
135 #else
136 #define MACHINE_SIZE_16
137 #endif
138 
139 template<class T>
140 T rem(T a, T b) {
141  return ((a) > 0) ? (a) % (b) : (a) % (b) + ((b) > 0 ? (b) : (b) * -1);
142 }
143 template<class T>
144 T sub(T a, T b, T m) {
145  return ((b) > (a)) ? (a) + (m) - (b) : (a) - (b);
146 }
147 #ifndef FALSE
148 #define FALSE 0
149 #endif
150 #ifndef TRUE
151 #define TRUE 1
152 #endif
153 #define ZERO_BYTE 0
154 #define MAX_BYTE 0xFF
155 #define MAX_UINT 0xFFFFFFFF
156 
157 #ifdef WIN32
158 #include <WinSock2.h>
159 #include <windows.h>
160 
161 typedef unsigned short USHORT;
162 typedef int socklen_t;
163 #pragma comment(lib, "wsock32.lib")
164 
165 #define SleepMiliSec(x) Sleep(x)
166 
167 #else //WIN32
168 
169 #include <sys/types.h>
170 #include <sys/socket.h>
171 #include <netdb.h>
172 #include <arpa/inet.h>
173 #include <unistd.h>
174 #include <netinet/in.h>
175 #include <stdio.h>
176 #include <stdlib.h>
177 #include <errno.h>
178 #include <netinet/tcp.h>
179 #include "timer.h" //TODO hack, exclude and include only in necessary files
180 
181 typedef int SOCKET;
182 #define INVALID_SOCKET -1
183 
184 #define SleepMiliSec(x) usleep((x)<<10)
185 #endif// WIN32
186 
187 #define ceil_divide(x, y) (( ((x) + (y)-1)/(y)))
188 
189 #define PadToRegisterSize(x) (PadToMultiple(x, OTEXT_BLOCK_SIZE_BITS))
190 #define PadToMultiple(x, y) ( ceil_divide(x, y) * (y))
191 
192 #include <cstring>
193 #include <string>
194 #include <vector>
195 #include <iostream>
196 
197 using namespace std;
198 
199 #endif //__TYPEDEFS_H__
200 
timer Implementation
Definition: typedefs.h:79