changeset 174:0622428b65b2

runpysmcl: first version. A small script for running pysmcl applications in a nice environment
author Sigurd Meldgaard <stm@daimi.au.dk>
date Mon, 14 Dec 2009 11:42:53 +0100
parents 9af426685e68
children c03795ca9975
files pysmcl/functions.py pysmcl/runpysmcl.py pysmcl/setup.py
diffstat 3 files changed, 62 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/pysmcl/functions.py	Mon Dec 14 11:42:53 2009 +0100
@@ -0,0 +1,13 @@
+from twisted.internet.defer import inlineCallbacks
+import pysmcl.setup
+#from viff. import 
+
+def get(runtime, prompt):
+    """ Queries each player for an integer, and returns a list of sharings
+    of the respective values. """
+    print(prompt)
+    a = raw_input()
+    return runtime.shamir_share(runtime.players, pysmcl.setup.Zp, int(a))
+
+def precondition(args):
+    pass
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/pysmcl/runpysmcl.py	Mon Dec 14 11:42:53 2009 +0100
@@ -0,0 +1,45 @@
+from optparse import OptionParser
+from twisted.internet import reactor
+from twisted.internet.defer import inlineCallbacks
+
+from viff.config import load_config
+from viff.comparison import ComparisonToft05Mixin
+from viff.runtime import Runtime, create_runtime, make_runtime_class
+
+
+parser = OptionParser(usage="Usage: %prog [options] pysmcl_program config_file")
+parser.add_option("-a", "--active", action="store_true", help="Use actively "
+                  "secure runtime. Default is only passive security.")
+Runtime.add_options(parser)
+
+(options, args) = parser.parse_args()
+
+print args # TODO remove
+
+if len(args) < 2:
+    parser.error("Not enough arguments")
+
+id, players = load_config(args[1])
+
+if options.active:
+    from viff.active import ActiveRuntime
+    runtime_class = make_runtime_class(ActiveRuntime, mixins=[ComparisonToft05Mixin])
+else:
+    from viff.passive import PassiveRuntime
+    runtime_class = make_runtime_class(PassiveRuntime, mixins=[ComparisonToft05Mixin])
+
+
+pre_runtime = create_runtime(id, players, 1, options, runtime_class)
+
+program_module = {}
+
+exec open(args[0]) in program_module
+
+def protocol(runtime):
+    yield program_module["main"](runtime)
+    yield runtime.synchronize()
+    yield runtime.shutdown()
+
+pre_runtime.addCallback(inlineCallbacks(protocol))
+
+reactor.run()
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/pysmcl/setup.py	Mon Dec 14 11:42:53 2009 +0100
@@ -0,0 +1,4 @@
+from viff.field import GF
+from viff.util import find_prime
+
+Zp = GF(find_prime(2**64, blum=True))