viff

changeset 611:57f877cd60f8

Example program used by Janus and Michael at PLAS 07. This is just a simple VIFF version of the program they use in the paper. The program should probably be changed so that the players each provide one of the coefficients for the polynomial, instead of having the polynomial hard-coded as it is now. But that is how I read the SMCL code in the paper... I have run in on DAIMI and it takes about 2 seconds to run, which is to be expected since it makes two secure comparisons.
author Martin Geisler <mg@daimi.au.dk>
date Fri, 28 Mar 2008 15:30:28 +0100
parents 2718ac712385
children 7cd68e62366a
files apps/eval_poly.py
diffstat 1 files changed, 86 insertions(+), 0 deletions(-) [+]
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/apps/eval_poly.py	Fri Mar 28 15:30:28 2008 +0100
     1.3 @@ -0,0 +1,86 @@
     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 General Public License as published by
    1.12 +# the Free Software Foundation; either version 2 of the License, or
    1.13 +# (at your option) any later version.
    1.14 +#
    1.15 +# VIFF is distributed in the hope that it will be useful, but
    1.16 +# WITHOUT ANY WARRANTY; without even the implied warranty of
    1.17 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
    1.18 +# General Public License for more details.
    1.19 +#
    1.20 +# You should have received a copy of the GNU General Public License
    1.21 +# along with VIFF in the file COPYING; if not, write to the Free
    1.22 +# Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
    1.23 +# 02110-1301 USA
    1.24 +
    1.25 +# This is an implementation of the example program (Figure 6) used by
    1.26 +# Janus Dam Nielsen and Michael I. Schwartzbach in their paper "A
    1.27 +# Domain-Specific Programming Language for Secure Multiparty
    1.28 +# Computation" presented at the PLAS '07 conference. The program
    1.29 +# evaluates a polynomial securely and reveals the sign of the result.
    1.30 +
    1.31 +from time import time
    1.32 +
    1.33 +from optparse import OptionParser
    1.34 +from twisted.internet import reactor
    1.35 +
    1.36 +from viff.field import GF
    1.37 +from viff.runtime import Runtime, create_runtime
    1.38 +from viff.comparison import Toft07Runtime
    1.39 +from viff.config import load_config
    1.40 +from viff.util import find_prime
    1.41 +
    1.42 +# We start by defining the protocol.
    1.43 +def eval_poly(runtime):
    1.44 +    print "Starting protocol"
    1.45 +    start_time = time()
    1.46 +
    1.47 +    modulus = find_prime(2**65, blum=True)
    1.48 +    Zp = GF(modulus)
    1.49 +
    1.50 +    # In this example we just let Player 1 share the input values.
    1.51 +    if runtime.id == 1:
    1.52 +        x = runtime.shamir_share([1], Zp, 17)
    1.53 +        a = runtime.shamir_share([1], Zp, 42)
    1.54 +        b = runtime.shamir_share([1], Zp, -5)
    1.55 +        c = runtime.shamir_share([1], Zp, 87)
    1.56 +    else:
    1.57 +        x = runtime.shamir_share([1], Zp)
    1.58 +        a = runtime.shamir_share([1], Zp)
    1.59 +        b = runtime.shamir_share([1], Zp)
    1.60 +        c = runtime.shamir_share([1], Zp)
    1.61 +
    1.62 +    # Evaluate the polynomial.
    1.63 +    p = a * (x * x) + b * x + c
    1.64 +
    1.65 +    sign = (p < 0) * -1 + (p > 0) * 1
    1.66 +    output = runtime.open(sign)
    1.67 +    output.addCallback(done, start_time, runtime)
    1.68 +
    1.69 +def done(sign, start_time, runtime):
    1.70 +    print "Sign: %s" % sign
    1.71 +    print "Time taken: %.2f sec" % (time() - start_time)
    1.72 +    runtime.shutdown()
    1.73 +
    1.74 +# Parse command line arguments.
    1.75 +parser = OptionParser()
    1.76 +Runtime.add_options(parser)
    1.77 +options, args = parser.parse_args()
    1.78 +
    1.79 +if len(args) == 0:
    1.80 +    parser.error("you must specify a config file")
    1.81 +else:
    1.82 +    id, players = load_config(args[0])
    1.83 +
    1.84 +# Create a deferred Runtime and ask it to run our protocol when ready.
    1.85 +pre_runtime = create_runtime(id, players, 1, options, Toft07Runtime)
    1.86 +pre_runtime.addCallback(eval_poly)
    1.87 +
    1.88 +# Start the Twisted event loop.
    1.89 +reactor.run()