ABY Framework  1.0
Arithmetic Bool Yao Framework
 All Classes Files Functions Variables Enumerations Enumerator Macros
yaokey.h
Go to the documentation of this file.
1 
19 #ifndef __YAOKEY_H_
20 #define __YAOKEY_H_
21 
22 #include "typedefs.h"
23 /* an interface to operations on yaos garbled circuits keys for pre-defined symmetric security sizes */
24 
25 #define _MSB_UINT64_T 0x80000000000000L
26 
27 class YaoKey {
28 public:
29  virtual ~YaoKey() {
30  }
31  ;
32  virtual void XOR(BYTE* out, BYTE* ina, BYTE* inb) = 0;
33  virtual void XOR_DOUBLE_B(BYTE* out, BYTE* ina, BYTE* inb) = 0;
34 };
35 
36 class YaoKeyST: public YaoKey {
37 public:
38  YaoKeyST() {
39  }
40  ;
41  ~YaoKeyST() {
42  }
43  ;
44  void XOR(BYTE* out, BYTE* ina, BYTE* inb) {
45  (((UINT64_T*) (out))[0] = ((UINT64_T*) (ina))[0] ^ ((UINT64_T*) (inb))[0]);
46  (((UINT16_T*) (out))[4] = ((UINT16_T*) (ina))[4] ^ ((UINT16_T*) (inb))[4]);
47  };
48  void XOR_DOUBLE_B(BYTE* out, BYTE* ina, BYTE* inb) {
49 
50  (((UINT64_T*) (out))[0] = ((UINT64_T*) (ina))[0] ^ ((UINT64_T*) (inb))[0]<<1);
51  ((UINT16_T*) (out))[4] = ((UINT16_T*) (ina))[4] ^ ((((UINT16_T*) (inb))[4]<<1) ^ (!!(((UINT64_T*) (inb))[0] & _MSB_UINT64_T)));
52  };
53 
54 
55 };
56 
57 class YaoKeyMT: public YaoKey {
58 public:
59  YaoKeyMT() {
60  }
61  ;
62  ~YaoKeyMT() {
63  }
64  ;
65  void XOR(BYTE* out, BYTE* ina, BYTE* inb) {
66  (((UINT64_T*) (out))[0] = ((UINT64_T*) (ina))[0] ^ ((UINT64_T*) (inb))[0]);
67  (((UINT32_T*) (out))[3] = ((UINT32_T*) (ina))[3] ^ ((UINT32_T*) (inb))[3]);
68  };
69  void XOR_DOUBLE_B(BYTE* out, BYTE* ina, BYTE* inb) {
70  (((UINT64_T*) (out))[0] = ((UINT64_T*) (ina))[0] ^ ((UINT64_T*) (inb))[0]<<1);
71  (((UINT32_T*) (out))[3] = ((UINT32_T*) (ina))[3] ^ ((UINT32_T*) (inb))[3]<<1);
72  (((UINT32_T*) (out))[3] = ((UINT32_T*) (ina))[3] ^ (((UINT32_T*) (inb))[3]<<1) ^ (!!(((UINT64_T*) (inb))[0] & _MSB_UINT64_T)));
73  };
74 };
75 class YaoKeyLT: public YaoKey {
76 public:
77 
78  ~YaoKeyLT() {
79  }
80  ;
81  void XOR(BYTE* out, BYTE* ina, BYTE* inb) {
82  (((UINT64_T*) (out))[0] = ((UINT64_T*) (ina))[0] ^ ((UINT64_T*) (inb))[0]);
83  (((UINT64_T*) (out))[1] = ((UINT64_T*) (ina))[1] ^ ((UINT64_T*) (inb))[1]);
84  };
85  void XOR_DOUBLE_B(BYTE* out, BYTE* ina, BYTE* inb) {
86  (((UINT64_T*) (out))[0] = ((UINT64_T*) (ina))[0] ^ ((UINT64_T*) (inb))[0]<<1);
87  (((UINT64_T*) (out))[1] = ((UINT64_T*) (ina))[1] ^ (((UINT64_T*) (inb))[1]<<1) ^ (!!(((UINT64_T*) (inb))[0] & _MSB_UINT64_T)));
88  };
89 };
90 
91 class YaoKeyXLT: public YaoKey {
92 public:
93 
94  ~YaoKeyXLT() {
95  }
96  ;
97  void XOR(BYTE* out, BYTE* ina, BYTE* inb) {
98  (((UINT64_T*) (out))[0] = ((UINT64_T*) (ina))[0] ^ ((UINT64_T*) (inb))[0]);
99  (((UINT64_T*) (out))[1] = ((UINT64_T*) (ina))[1] ^ ((UINT64_T*) (inb))[1]);
100  (((UINT64_T*) (out))[2] = ((UINT64_T*) (ina))[2] ^ ((UINT64_T*) (inb))[2]);
101 
102  };
103  void XOR_DOUBLE_B(BYTE* out, BYTE* ina, BYTE* inb) {
104  (((UINT64_T*) (out))[0] = ((UINT64_T*) (ina))[0] ^ ((UINT64_T*) (inb))[0]<<1);
105  (((UINT64_T*) (out))[1] = ((UINT64_T*) (ina))[1] ^ (((UINT64_T*) (inb))[1]<<1) ^ (!!(((UINT64_T*) (inb))[0] & _MSB_UINT64_T)));
106  (((UINT64_T*) (out))[2] = ((UINT64_T*) (ina))[2] ^ (((UINT64_T*) (inb))[2]<<1) ^ (!!(((UINT64_T*) (inb))[1] & _MSB_UINT64_T)));
107 
108  };
109 };
110 
111 class YaoKeyXXLT: public YaoKey {
112 public:
113 
114  ~YaoKeyXXLT() {
115  }
116  ;
117  void XOR(BYTE* out, BYTE* ina, BYTE* inb) {
118  (((UINT64_T*) (out))[0] = ((UINT64_T*) (ina))[0] ^ ((UINT64_T*) (inb))[0]);
119  (((UINT64_T*) (out))[1] = ((UINT64_T*) (ina))[1] ^ ((UINT64_T*) (inb))[1]);
120  (((UINT64_T*) (out))[2] = ((UINT64_T*) (ina))[2] ^ ((UINT64_T*) (inb))[2]);
121  (((UINT64_T*) (out))[3] = ((UINT64_T*) (ina))[3] ^ ((UINT64_T*) (inb))[3]);
122  };
123  void XOR_DOUBLE_B(BYTE* out, BYTE* ina, BYTE* inb) {
124  (((UINT64_T*) (out))[0] = ((UINT64_T*) (ina))[0] ^ ((UINT64_T*) (inb))[0]<<1);
125  (((UINT64_T*) (out))[1] = ((UINT64_T*) (ina))[1] ^ (((UINT64_T*) (inb))[1]<<1) ^ (!!(((UINT64_T*) (inb))[0] & _MSB_UINT64_T)));
126  (((UINT64_T*) (out))[2] = ((UINT64_T*) (ina))[2] ^ (((UINT64_T*) (inb))[2]<<1) ^ (!!(((UINT64_T*) (inb))[1] & _MSB_UINT64_T)));
127  (((UINT64_T*) (out))[3] = ((UINT64_T*) (ina))[3] ^ (((UINT64_T*) (inb))[3]<<1) ^ (!!(((UINT64_T*) (inb))[2] & _MSB_UINT64_T)));
128  };
129 };
130 
131 static void InitYaoKey(YaoKey** key, int symbits) {
132  if (symbits == ST.symbits)
133  *key = new YaoKeyST();
134  else if (symbits == MT.symbits)
135  *key = new YaoKeyMT();
136  else if (symbits == LT.symbits)
137  *key = new YaoKeyLT();
138  else if (symbits == XLT.symbits)
139  *key = new YaoKeyXLT();
140  else if (symbits == XXLT.symbits)
141  *key = new YaoKeyXXLT();
142  else
143  *key = new YaoKeyLT();
144  return;
145 }
146 
147 #endif /* __YAOKEY_H_ */
Definition: yaokey.h:36
Definition: yaokey.h:27
Definition: yaokey.h:57
Definition: yaokey.h:75
Definition: yaokey.h:111
Definition: yaokey.h:91
Typedefs Implementation.