viff

changeset 1067:aff12eb0e28c

Sequential multiplication test.
author Martin Geisler <mg@daimi.au.dk>
date Tue, 27 Jan 2009 15:52:23 +0100
parents 9f176022087d
children bdab6f30511a
files apps/seq-mul.py
diffstat 1 files changed, 52 insertions(+), 0 deletions(-) [+]
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/apps/seq-mul.py	Tue Jan 27 15:52:23 2009 +0100
     1.3 @@ -0,0 +1,52 @@
     1.4 +#!/usr/bin/python
     1.5 +
     1.6 +# Copyright 2009 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 +from optparse import OptionParser
    1.24 +from twisted.internet import reactor
    1.25 +
    1.26 +from viff.field import GF
    1.27 +from viff.runtime import create_runtime, Runtime
    1.28 +from viff.config import load_config
    1.29 +
    1.30 +parser = OptionParser()
    1.31 +parser.add_option("-c", "--count", type="int", default=100,
    1.32 +                  help="number of multiplications")
    1.33 +Runtime.add_options(parser)
    1.34 +(options, args) = parser.parse_args()
    1.35 +
    1.36 +Zp = GF(1031)
    1.37 +
    1.38 +id, players = load_config(args[0])
    1.39 +
    1.40 +def protocol(rt):
    1.41 +
    1.42 +    def got_result(result):
    1.43 +        print "Product:", result
    1.44 +        rt.shutdown()
    1.45 +
    1.46 +    x = rt.prss_share_random(Zp)
    1.47 +    for _ in xrange(options.count):
    1.48 +        x = x * x
    1.49 +    x = rt.open(x)
    1.50 +    x.addCallback(got_result)
    1.51 +
    1.52 +pre_runtime = create_runtime(id, players, 1, options)
    1.53 +pre_runtime.addCallback(protocol)
    1.54 +
    1.55 +reactor.run()