viff

changeset 814:501427acf5e6

Renamed to avoid underscore in filename.
author Martin Geisler <mg@daimi.au.dk>
date Fri, 11 Jul 2008 23:31:24 +0200
parents 33f8fbf147a7
children 197d2d7bcbf7
files apps/eval-poly.py apps/eval_poly.py
diffstat 2 files changed, 84 insertions(+), 84 deletions(-) [+]
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/apps/eval-poly.py	Fri Jul 11 23:31:24 2008 +0200
     1.3 @@ -0,0 +1,84 @@
     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 is an implementation of the example program (Figure 6) used by
    1.24 +# Janus Dam Nielsen and Michael I. Schwartzbach in their paper "A
    1.25 +# Domain-Specific Programming Language for Secure Multiparty
    1.26 +# Computation" presented at the PLAS '07 conference. The program
    1.27 +# evaluates a polynomial securely and reveals the sign of the result.
    1.28 +
    1.29 +from time import time
    1.30 +
    1.31 +from optparse import OptionParser
    1.32 +from twisted.internet import reactor
    1.33 +
    1.34 +from viff.field import GF
    1.35 +from viff.runtime import Runtime, create_runtime
    1.36 +from viff.comparison import Toft07Runtime
    1.37 +from viff.config import load_config
    1.38 +from viff.util import find_prime
    1.39 +
    1.40 +# We start by defining the protocol.
    1.41 +def eval_poly(runtime):
    1.42 +    print "Starting protocol"
    1.43 +    start_time = time()
    1.44 +
    1.45 +    modulus = find_prime(2**65, blum=True)
    1.46 +    Zp = GF(modulus)
    1.47 +
    1.48 +    # In this example we just let Player 1 share the input values.
    1.49 +    if runtime.id == 1:
    1.50 +        x = runtime.shamir_share([1], Zp, 17)
    1.51 +        a = runtime.shamir_share([1], Zp, 42)
    1.52 +        b = runtime.shamir_share([1], Zp, -5)
    1.53 +        c = runtime.shamir_share([1], Zp, 87)
    1.54 +    else:
    1.55 +        x = runtime.shamir_share([1], Zp)
    1.56 +        a = runtime.shamir_share([1], Zp)
    1.57 +        b = runtime.shamir_share([1], Zp)
    1.58 +        c = runtime.shamir_share([1], Zp)
    1.59 +
    1.60 +    # Evaluate the polynomial.
    1.61 +    p = a * (x * x) + b * x + c
    1.62 +
    1.63 +    sign = (p < 0) * -1 + (p > 0) * 1
    1.64 +    output = runtime.open(sign)
    1.65 +    output.addCallback(done, start_time, runtime)
    1.66 +
    1.67 +def done(sign, start_time, runtime):
    1.68 +    print "Sign: %s" % sign
    1.69 +    print "Time taken: %.2f sec" % (time() - start_time)
    1.70 +    runtime.shutdown()
    1.71 +
    1.72 +# Parse command line arguments.
    1.73 +parser = OptionParser()
    1.74 +Runtime.add_options(parser)
    1.75 +options, args = parser.parse_args()
    1.76 +
    1.77 +if len(args) == 0:
    1.78 +    parser.error("you must specify a config file")
    1.79 +else:
    1.80 +    id, players = load_config(args[0])
    1.81 +
    1.82 +# Create a deferred Runtime and ask it to run our protocol when ready.
    1.83 +pre_runtime = create_runtime(id, players, 1, options, Toft07Runtime)
    1.84 +pre_runtime.addCallback(eval_poly)
    1.85 +
    1.86 +# Start the Twisted event loop.
    1.87 +reactor.run()
     2.1 --- a/apps/eval_poly.py	Fri Jun 20 23:55:47 2008 +0200
     2.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.3 @@ -1,84 +0,0 @@
     2.4 -#!/usr/bin/python
     2.5 -
     2.6 -# Copyright 2008 VIFF Development Team.
     2.7 -#
     2.8 -# This file is part of VIFF, the Virtual Ideal Functionality Framework.
     2.9 -#
    2.10 -# VIFF is free software: you can redistribute it and/or modify it
    2.11 -# under the terms of the GNU Lesser General Public License (LGPL) as
    2.12 -# published by the Free Software Foundation, either version 3 of the
    2.13 -# License, or (at your option) any later version.
    2.14 -#
    2.15 -# VIFF is distributed in the hope that it will be useful, but WITHOUT
    2.16 -# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
    2.17 -# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
    2.18 -# Public License for more details.
    2.19 -#
    2.20 -# You should have received a copy of the GNU Lesser General Public
    2.21 -# License along with VIFF. If not, see <http://www.gnu.org/licenses/>.
    2.22 -
    2.23 -# This is an implementation of the example program (Figure 6) used by
    2.24 -# Janus Dam Nielsen and Michael I. Schwartzbach in their paper "A
    2.25 -# Domain-Specific Programming Language for Secure Multiparty
    2.26 -# Computation" presented at the PLAS '07 conference. The program
    2.27 -# evaluates a polynomial securely and reveals the sign of the result.
    2.28 -
    2.29 -from time import time
    2.30 -
    2.31 -from optparse import OptionParser
    2.32 -from twisted.internet import reactor
    2.33 -
    2.34 -from viff.field import GF
    2.35 -from viff.runtime import Runtime, create_runtime
    2.36 -from viff.comparison import Toft07Runtime
    2.37 -from viff.config import load_config
    2.38 -from viff.util import find_prime
    2.39 -
    2.40 -# We start by defining the protocol.
    2.41 -def eval_poly(runtime):
    2.42 -    print "Starting protocol"
    2.43 -    start_time = time()
    2.44 -
    2.45 -    modulus = find_prime(2**65, blum=True)
    2.46 -    Zp = GF(modulus)
    2.47 -
    2.48 -    # In this example we just let Player 1 share the input values.
    2.49 -    if runtime.id == 1:
    2.50 -        x = runtime.shamir_share([1], Zp, 17)
    2.51 -        a = runtime.shamir_share([1], Zp, 42)
    2.52 -        b = runtime.shamir_share([1], Zp, -5)
    2.53 -        c = runtime.shamir_share([1], Zp, 87)
    2.54 -    else:
    2.55 -        x = runtime.shamir_share([1], Zp)
    2.56 -        a = runtime.shamir_share([1], Zp)
    2.57 -        b = runtime.shamir_share([1], Zp)
    2.58 -        c = runtime.shamir_share([1], Zp)
    2.59 -
    2.60 -    # Evaluate the polynomial.
    2.61 -    p = a * (x * x) + b * x + c
    2.62 -
    2.63 -    sign = (p < 0) * -1 + (p > 0) * 1
    2.64 -    output = runtime.open(sign)
    2.65 -    output.addCallback(done, start_time, runtime)
    2.66 -
    2.67 -def done(sign, start_time, runtime):
    2.68 -    print "Sign: %s" % sign
    2.69 -    print "Time taken: %.2f sec" % (time() - start_time)
    2.70 -    runtime.shutdown()
    2.71 -
    2.72 -# Parse command line arguments.
    2.73 -parser = OptionParser()
    2.74 -Runtime.add_options(parser)
    2.75 -options, args = parser.parse_args()
    2.76 -
    2.77 -if len(args) == 0:
    2.78 -    parser.error("you must specify a config file")
    2.79 -else:
    2.80 -    id, players = load_config(args[0])
    2.81 -
    2.82 -# Create a deferred Runtime and ask it to run our protocol when ready.
    2.83 -pre_runtime = create_runtime(id, players, 1, options, Toft07Runtime)
    2.84 -pre_runtime.addCallback(eval_poly)
    2.85 -
    2.86 -# Start the Twisted event loop.
    2.87 -reactor.run()