http://hg.viff.dk/viff/rev/a45e34e4ebf0
changeset: 1090:a45e34e4ebf0
user: Marcel Keller <[email protected]>
date: Mon Jan 26 10:55:59 2009 +0100
summary: Improved AES example application.
diffstat:
1 file changed, 21 insertions(+), 20 deletions(-)
apps/aes.py | 41 +++++++++++++++++++++--------------------
diffs (70 lines):
diff -r 992c7eee2b3f -r a45e34e4ebf0 apps/aes.py
--- a/apps/aes.py Mon Jan 26 10:02:48 2009 +0100
+++ b/apps/aes.py Mon Jan 26 10:55:59 2009 +0100
@@ -26,6 +26,7 @@
from twisted.internet import reactor
+from viff.field import GF256
from viff.runtime import BasicRuntime, create_runtime, gather_shares
from viff.config import load_config
@@ -50,38 +51,38 @@
id, players = load_config(args[0])
-def encrypt(_, rt):
+def encrypt(_, rt, key):
start = time.time()
print "Started at %f." % start
aes = AES(rt, 192, use_exponentiation=options.exponentiation)
- ciphertext = aes.encrypt("a" * 16, "b" * 24, True)
+ ciphertext = aes.encrypt("a" * 16, key, True)
- opened = []
- result = [0] * 16
+ opened_ciphertext = [rt.open(c) for c in ciphertext]
- for i, c in enumerate(ciphertext):
- o = rt.open(c)
-
- def res(x, i):
- result[i] = hex(x.value)
-
- o.addCallback(res, i)
- opened.append(o)
-
- def fin(g, result):
+ def fin(ciphertext):
print "Finished after %f sec." % (time.time() - start)
- print result
+ print "Ciphertext:", [hex(c.value) for c in ciphertext]
rt.shutdown()
- g = gather_shares(opened)
- g.addCallback(fin, result)
+ g = gather_shares(opened_ciphertext)
+ g.addCallback(fin)
-def sync(rt):
+def share_key(rt):
+ key = []
+
+ for i in range(24):
+ inputter = i % 3 + 1
+
+ if (inputter == id):
+ key.append(rt.input([inputter], GF256, ord("b")))
+ else:
+ key.append(rt.input([inputter], GF256))
+
s = rt.synchronize()
- s.addCallback(encrypt, rt)
+ s.addCallback(encrypt, rt, key)
rt = create_runtime(id, players, 1, options)
-rt.addCallback(sync)
+rt.addCallback(share_key)
reactor.run()
_______________________________________________
viff-commits mailing list
[email protected]
http://lists.viff.dk/listinfo.cgi/viff-commits-viff.dk