-
Notifications
You must be signed in to change notification settings - Fork 5
/
test.py
executable file
·83 lines (70 loc) · 1.96 KB
/
test.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
#!/usr/bin/env python2
from __future__ import print_function
import os, subprocess, sys
CMD = 'obfuscator'
CIRCUIT_PATH = 'circuits'
yellow = '\x1b[33m'
black = '\x1b[0m'
failure_str = '\t\x1b[31mTest Failed\x1b[0m'
success_str = '\t\x1b[32mTest Succeeded\x1b[0m'
schemedict = {
'AGIS': '',
'SZ': '--sahai-zhandry',
'Z': '--zimmerman',
}
def print_test(s):
print('%s%s%s' % (yellow, s, black))
def run(lst):
print('%s' % ' '.join(lst))
return subprocess.call(lst)
def test_circuits(sage, scheme):
print_test('Testing all circuits for scheme %s' % scheme)
lst = [sage, CMD, "obf", "--test-all", CIRCUIT_PATH, "--secparam", "8"]
if scheme != 'AGIS':
lst.append(schemedict[scheme])
return run(lst)
def test_load(sage, scheme):
print_test('Testing load for scheme %s' % scheme)
if scheme == 'Z':
circuit = 'add.acirc'
eval = '0'
else:
circuit = 'and.circ'
eval = '00'
path = os.path.join(CIRCUIT_PATH, circuit)
lst = [sage, CMD, "obf", "--test-circuit", path, "--secparam", "8"]
if scheme != 'AGIS':
lst.append(schemedict[scheme])
r = run(lst)
if r:
return r
lst = [sage, CMD, "obf", "--load-obf", path + ".obf.8", "--eval", eval]
if scheme != 'AGIS':
lst.append(schemedict[scheme])
return run(lst)
def test(f, sage, *args):
if f(sage, *args):
print(failure_str)
else:
print(success_str)
def test_all(sage):
test(test_load, sage, "AGIS")
test(test_load, sage, "SZ")
test(test_load, sage, "Z")
test(test_circuits, sage, "AGIS")
test(test_circuits, sage, "SZ")
test(test_circuits, sage, "Z")
def main():
if len(sys.argv) > 2:
print("Usage: %s [sage-path]" % sys.argv[0])
sys.exit(1)
if len(sys.argv) == 2:
sage = sys.argv[1]
else:
sage = 'sage'
test_all(sage)
if __name__ == '__main__':
try:
main()
except KeyboardInterrupt:
pass