changeset 839:45dfc10a1363

Test program for Paillier runtime.
author Martin Geisler <mg@daimi.au.dk>
date Tue, 15 Jul 2008 23:11:44 +0200
parents bba8a625972a
children f7e987afbec3
files apps/paillier.py
diffstat 1 files changed, 70 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/apps/paillier.py	Tue Jul 15 23:11:44 2008 +0200
@@ -0,0 +1,70 @@
+#!/usr/bin/python
+
+# Copyright 2008 VIFF Development Team.
+#
+# This file is part of VIFF, the Virtual Ideal Functionality Framework.
+#
+# VIFF is free software: you can redistribute it and/or modify it
+# under the terms of the GNU Lesser General Public License (LGPL) as
+# published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
+#
+# VIFF is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
+# Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with VIFF. If not, see <http://www.gnu.org/licenses/>.
+
+# This test program uses a two-player runtime from viff.paillier based
+# on homomorphic Paillier encryption. The multiplication protocol was
+# proposed by Claudio Orlandi.
+#
+# Each player takes an integer input on the command line after the
+# player configuration file.
+
+import sys
+
+from twisted.internet import reactor
+
+from viff.field import GF
+from viff.runtime import create_runtime, Share
+from viff.paillier import PaillierRuntime
+from viff.config import load_config
+from viff.util import dprint, find_prime
+
+id, players = load_config(sys.argv[1])
+Zp = GF(find_prime(2**64))
+input = int(sys.argv[2])
+
+print "I am player %d and will input %s" % (id, input)
+
+
+def protocol(runtime):
+    print "-" * 64
+    print "Program started"
+    print
+
+    a, b = runtime.share([1, 2], Zp, input)
+    c = a * b
+
+    dprint("a%d: %s", runtime.id, a)
+    dprint("b%d: %s", runtime.id, b)
+    dprint("c%d: %s", runtime.id, c)
+
+    a = runtime.open(a)
+    b = runtime.open(b)
+    c = runtime.open(c)
+
+    dprint("### opened a: %s ###", a)
+    dprint("### opened b: %s ###", b)
+    dprint("### opened c: %s ###", c)
+
+    runtime.wait_for(a, b, c)
+
+pre_runtime = create_runtime(id, players, 1, runtime_class=PaillierRuntime)
+pre_runtime.addCallback(protocol)
+
+print "#### Starting reactor ###"
+reactor.run()