-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsscTool.py
executable file
·326 lines (282 loc) · 13.3 KB
/
sscTool.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
#!/usr/bin/env python2
import os, re, sys
import csv
# gui libs and resources
from PyQt4.QtCore import *
from PyQt4.QtGui import *
import ui_ssc_widget
MPC_FILE = 'mpc_v5.csv'
# use multiple inheritance to access both sets of attributes directly.
class SSCWidget(QTabWidget, ui_ssc_widget.Ui_TabWidget):
def __init__(self, protocoldb, parent=None):
super(SSCWidget, self).__init__(parent)
# self.__text = unicode(text)
self.__index = 0
self._protocoldb = protocoldb
self._count = 0
self._listmodel = None
self.setupUi(self) # actually lays out the widget.
# add signal-slot connections
self.connect(self.sliderMaliciousness, SIGNAL("valueChanged(int)"),
self.updateUI)
self.connect(self.sliderAdaptiveness, SIGNAL("valueChanged(int)"),
self.updateUI)
self.connect(self.sliderFairness, SIGNAL("valueChanged(int)"),
self.updateUI)
self.connect(self.sliderSecType, SIGNAL("valueChanged(int)"),
self.updateUI)
self.connect(self.sliderCorruptedParties, SIGNAL("valueChanged(int)"),
self.updateUI)
self.connect(self.sliderOnlineComm, SIGNAL("valueChanged(int)"),
self.updateUI)
self.connect(self.sliderPreprocComm, SIGNAL("valueChanged(int)"),
self.updateUI)
self.connect(self.cbMixedAdversary, SIGNAL("stateChanged(int)"),
self.updateUI)
self.connect(self.cbComposable, SIGNAL("stateChanged(int)"),
self.updateUI)
self.connect(self.cbSynchronous, SIGNAL("stateChanged(int)"),
self.updateUI)
self.connect(self.cbTrustedSetup, SIGNAL("stateChanged(int)"),
self.updateUI)
self.connect(self.cbBroadcast, SIGNAL("stateChanged(int)"),
self.updateUI)
self.connect(self.cbPrivateChannels, SIGNAL("stateChanged(int)"),
self.updateUI)
self.connect(self.cbConstantRounds, SIGNAL("stateChanged(int)"),
self.updateUI)
self.connect(self.cbImplemented, SIGNAL("stateChanged(int)"),
self.updateUI)
#self.connect(self.cbPreprocessing, SIGNAL("stateChanged(int)"),
# self.updateUI)
self.connect(self.radioExact, SIGNAL("toggled(bool)"), self.updateUI)
self.connect(self.radioAtLeast, SIGNAL("toggled(bool)"), self.updateUI)
# wire up the pushbuttons and other clicking events.
self.listView.doubleClicked.connect(self.paperClicked)
self.listView.clicked.connect(self.enableSetSliders)
self.btnSetSliders.clicked.connect(self.setSliders)
self.btnResetSliders.clicked.connect(self.resetSliders)
# LATER: MAC-specific stuff?
self.updateUI()
def enableSetSliders(self, index):
self.btnSetSliders.setEnabled(True)
def paperClicked(self, modelIndex):
paperref = modelIndex.data().toString()
annotation = ""
rowind = 0;
for row in self._protocoldb:
if row['Protocol'] == paperref:
annotation = row['Annotation']
break
rowind += 1
popup = PopupDialog(paperref + ": " + annotation, self)
popup.show()
popup.raise_()
##########################################################
# called on every gadget change, to update the paper list.
##########################################################
def updateUI(self):
results = self.matchProtocols()
# wonder if this will delete it.
self._listmodel = QStandardItemModel(self.listView)
for protocol in results:
self._listmodel.appendRow(QStandardItem(QString(protocol)))
self.listView.setModel(self._listmodel)
# disable slider button until something is clicked.
self.btnSetSliders.setEnabled(False)
def scaleCompare(self, a, b):
if self.radioExact.isChecked(): return a == b
else: return a >= b
# set the sliders to match a protocol being viewed.
def setSliders(self, protocolIndex):
indexes = self.listView.selectedIndexes()
if indexes == []: # probably won't happen...
return
paperref = indexes[0].data().toString()
for row in self._protocoldb:
if row['Protocol'] == paperref:
break
# wait! the environment checkboxes will already be set...
# but I might need to unset them.
if int(row['Broadcast']) == 5: self.cbBroadcast.setChecked(False)
else: self.cbBroadcast.setChecked(True)
if int(row['Asynchro']) == 5: self.cbSynchronous.setChecked(False)
else: self.cbSynchronous.setChecked(True)
if int(row['Setup Assump']) == 5: self.cbTrustedSetup.setChecked(False)
else: self.cbTrustedSetup.setChecked(True)
#if int(row['Comm Preproc']) == 5: self.cbPreprocessing.setChecked(False)
#else: self.cbPreprocessing.setChecked(True)
if int(row['Private channels']) == 5: self.cbPrivateChannels.setChecked(False)
else: self.cbPrivateChannels.setChecked(True)
if row['Impl'] == 'y': self.cbImplemented.setChecked(True)
else: self.cbImplemented.setChecked(False)
if int(row['Rounds']) == 5: self.cbConstantRounds.setChecked(True)
else: self.cbConstantRounds.setChecked(False)
if int(row['Compos-ability']) == 5: self.cbComposable.setChecked(True)
else: self.cbComposable.setChecked(False)
if int(row['Mixed adv']) == 5: self.cbMixedAdversary.setChecked(True)
else: self.cbMixedAdversary.setChecked(False)
self.sliderAdaptiveness.setValue(int(row['Adaptivity']))
self.sliderMaliciousness.setValue(int(row['Malicious-ness']))
self.sliderCorruptedParties.setValue(int(row['# Corrupted']))
self.sliderSecType.setValue(int(row['Security level']))
self.sliderFairness.setValue(int(row['Fairness']))
self.sliderOnlineComm.setValue(int(row['Complexity Level']))
self.sliderPreprocComm.setValue(int(row['Comm Preproc']))
return
##########################################################
# Return a list of protocols matching the sliders.
##########################################################
def matchProtocols(self):
# check impossibility independently (to catch myself)
impossible = False
impossibleString = ""
# Theorem 1. Any unconditional security requires broadcast or private channel.
if (self.sliderSecType.value() > 3 and
not self.cbPrivateChannels.isChecked() and
not self.cbBroadcast.isChecked()) :
impossible = True
impossibleString += "1, "
# Theorem 2. No fairness if dishonest majority and malicious.
if (self.sliderFairness.value() > 3 and
self.sliderCorruptedParties.value() > 3 and
self.sliderMaliciousness.value() == 5):
impossible = True
impossibleString += "2, "
# Theorem 3. If malicious and unconditional security, no guaranteed
# output if more than n/3 corrupted.
if (self.sliderMaliciousness.value() == 5 and
self.sliderSecType.value() > 3 and
self.sliderFairness.value() == 5 and
self.sliderCorruptedParties.value() > 2) :
impossible = True
impossibleString += "3, "
# 2. No more than n/3 maliciously corrupted parties if uncond and no bcast/error.
if (self.sliderMaliciousness.value() == 5 and
self.sliderCorruptedParties.value() > 2 and
self.sliderSecType.value() > 3 and
not self.cbBroadcast.isChecked()):
impossible = True
# 3. UC dishonest majority malicious without setup assumption
# .....without fairness? [GL02]
#if (self.sliderMaliciousness.value() > 3 and
# self.sliderCorruptedParties.value() > 3 and
# self.cbComposable.isChecked() and
# not self.cbTrustedSetup.isChecked()):
# impossible = True
# 4. malicious dishonest majority with fairness
if (self.sliderMaliciousness.value() == 5 and
self.sliderCorruptedParties.value() > 3 and
self.sliderFairness.value() > 2):
impossible = True
results = []
for row in self._protocoldb:
match = True
# slider features
match &= self.scaleCompare(int(row['Malicious-ness']),
self.sliderMaliciousness.value())
match &= self.scaleCompare(int(row['# Corrupted']),
self.sliderCorruptedParties.value())
match &= self.scaleCompare(int(row['Adaptivity']),
self.sliderAdaptiveness.value())
match &= self.scaleCompare(int(row['Security level']),
self.sliderSecType.value())
match &= self.scaleCompare(int(row['Fairness']),
self.sliderFairness.value())
match &= self.scaleCompare(int(row['Complexity Level']),
self.sliderOnlineComm.value())
match &= self.scaleCompare(int(row['Comm Preproc']),
self.sliderPreprocComm.value())
# security binary requirements
match &= (not self.cbComposable.isChecked()) or \
int(row['Compos-ability']) == 5 # Pass04, GL02 are out.
match &= (not self.cbMixedAdversary.isChecked()) or \
int(row['Mixed adv']) == 5
# const round is an efficiency requirement:
match &= (not self.cbConstantRounds.isChecked()) or \
int(row['Rounds']) == 5
# environment features aren't requirements: checked means 'available'
match &= (self.cbBroadcast.isChecked() or
int(row['Broadcast']) == 5)
match &= (self.cbSynchronous.isChecked() or
int(row['Asynchro']) == 5)
match &= (self.cbTrustedSetup.isChecked() or
int(row['Setup Assump']) == 5)
match &= (self.cbPrivateChannels.isChecked() or
int(row['Private channels']) == 5)
match &= (not self.cbImplemented.isChecked()) or row['Impl'] == 'y'
if match: results.append(row['Protocol'])
if (results == []):
self.lblProtocolsFound.setText(QString(""))
else:
self.lblProtocolsFound.setStyleSheet("QLabel { color : green; }")
self.lblProtocolsFound.setText(QString("Protocols found:"))
if (impossible):
self.lblProtocolsFound.setStyleSheet("QLabel { color : red; }")
self.lblProtocolsFound.setText(QString("Known Impossible: " +
impossibleString))
return results
## Put all sliders and checkboxes at the "lowest" positions.
def resetSliders(self):
self.cbBroadcast.setChecked(True)
self.cbPrivateChannels.setChecked(True)
self.cbTrustedSetup.setChecked(True)
self.cbSynchronous.setChecked(True)
self.cbImplemented.setChecked(False)
self.cbComposable.setChecked(False)
self.cbMixedAdversary.setChecked(False)
self.cbConstantRounds.setChecked(False)
self.sliderAdaptiveness.setValue(1)
self.sliderMaliciousness.setValue(1)
self.sliderCorruptedParties.setValue(1)
self.sliderSecType.setValue(1)
self.sliderFairness.setValue(1)
self.sliderOnlineComm.setValue(1)
self.sliderPreprocComm.setValue(1)
self.updateUI()
return
# end class
##############################
# class for popup info dialogs
##############################
class PopupDialog(QDialog):
def __init__(self, textfield, parent=None):
super(PopupDialog, self).__init__(parent)
self.textView = QPlainTextEdit(self)
self.textView.setGeometry(QRect(20, 20, 260, 160))
#self.textView.setEditTriggers(QAbstractItemView.NoEditTriggers)
self.textView.setObjectName("textView")
# set title to paper name and show abstract
self.textView.setPlainText(textfield)
self.textView.setReadOnly(True)
self.resize(300,200)
def showEvent(self, event):
geom = self.frameGeometry()
geom.moveCenter(QCursor.pos())
self.setGeometry(geom)
super(PopupDialog, self).showEvent(event) # no idea.
def keyPressEvent(self, event):
if event.key() == Qt.Key_Escape:
self.hide()
event.accept()
else:
super(PopupDialog, self).keyPressEvent(event)
######
# main
######
def main():
csvdb = []
# make sure it can find the csv file from anywhere.
os.path.join(os.path.dirname(sys.executable))
with open(MPC_FILE, 'rb') as csvfile:
csvreader = csv.DictReader(csvfile, dialect='excel')
print "papers loaded:"
for row in csvreader:
print row['Protocol'], ", ",
csvdb.append(row)
print
app = QApplication(sys.argv)
sscWidget = SSCWidget(csvdb)
sscWidget.show()
app.exec_()
main()