viff

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 diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/apps/paillier.py	Tue Jul 15 23:11:44 2008 +0200
     1.3 @@ -0,0 +1,70 @@
     1.4 +#!/usr/bin/python
     1.5 +
     1.6 +# Copyright 2008 VIFF Development Team.
     1.7 +#
     1.8 +# This file is part of VIFF, the Virtual Ideal Functionality Framework.
     1.9 +#
    1.10 +# VIFF is free software: you can redistribute it and/or modify it
    1.11 +# under the terms of the GNU Lesser General Public License (LGPL) as
    1.12 +# published by the Free Software Foundation, either version 3 of the
    1.13 +# License, or (at your option) any later version.
    1.14 +#
    1.15 +# VIFF is distributed in the hope that it will be useful, but WITHOUT
    1.16 +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
    1.17 +# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
    1.18 +# Public License for more details.
    1.19 +#
    1.20 +# You should have received a copy of the GNU Lesser General Public
    1.21 +# License along with VIFF. If not, see <http://www.gnu.org/licenses/>.
    1.22 +
    1.23 +# This test program uses a two-player runtime from viff.paillier based
    1.24 +# on homomorphic Paillier encryption. The multiplication protocol was
    1.25 +# proposed by Claudio Orlandi.
    1.26 +#
    1.27 +# Each player takes an integer input on the command line after the
    1.28 +# player configuration file.
    1.29 +
    1.30 +import sys
    1.31 +
    1.32 +from twisted.internet import reactor
    1.33 +
    1.34 +from viff.field import GF
    1.35 +from viff.runtime import create_runtime, Share
    1.36 +from viff.paillier import PaillierRuntime
    1.37 +from viff.config import load_config
    1.38 +from viff.util import dprint, find_prime
    1.39 +
    1.40 +id, players = load_config(sys.argv[1])
    1.41 +Zp = GF(find_prime(2**64))
    1.42 +input = int(sys.argv[2])
    1.43 +
    1.44 +print "I am player %d and will input %s" % (id, input)
    1.45 +
    1.46 +
    1.47 +def protocol(runtime):
    1.48 +    print "-" * 64
    1.49 +    print "Program started"
    1.50 +    print
    1.51 +
    1.52 +    a, b = runtime.share([1, 2], Zp, input)
    1.53 +    c = a * b
    1.54 +
    1.55 +    dprint("a%d: %s", runtime.id, a)
    1.56 +    dprint("b%d: %s", runtime.id, b)
    1.57 +    dprint("c%d: %s", runtime.id, c)
    1.58 +
    1.59 +    a = runtime.open(a)
    1.60 +    b = runtime.open(b)
    1.61 +    c = runtime.open(c)
    1.62 +
    1.63 +    dprint("### opened a: %s ###", a)
    1.64 +    dprint("### opened b: %s ###", b)
    1.65 +    dprint("### opened c: %s ###", c)
    1.66 +
    1.67 +    runtime.wait_for(a, b, c)
    1.68 +
    1.69 +pre_runtime = create_runtime(id, players, 1, runtime_class=PaillierRuntime)
    1.70 +pre_runtime.addCallback(protocol)
    1.71 +
    1.72 +print "#### Starting reactor ###"
    1.73 +reactor.run()