viff

changeset 761:c947486e9535

Extend benchmark to actively secure protocols.
author Martin Geisler <mg@daimi.au.dk>
date Fri, 16 May 2008 09:18:54 +0200
parents 591ab6199980
children f65816507ae8
files apps/benchmark.py
diffstat 1 files changed, 39 insertions(+), 9 deletions(-) [+]
line diff
     1.1 --- a/apps/benchmark.py	Thu May 15 09:41:57 2008 +0200
     1.2 +++ b/apps/benchmark.py	Fri May 16 09:18:54 2008 +0200
     1.3 @@ -61,9 +61,10 @@
     1.4  
     1.5  from twisted.internet import reactor
     1.6  
     1.7 -from viff.field import GF
     1.8 +from viff.field import GF, GF256
     1.9  from viff.runtime import Runtime, ActiveRuntime, create_runtime, gather_shares
    1.10  from viff.comparison import Toft05Runtime, Toft07Runtime
    1.11 +from viff.comparison import ActiveToft05Runtime, ActiveToft07Runtime
    1.12  from viff.config import load_config
    1.13  from viff.util import find_prime
    1.14  
    1.15 @@ -92,9 +93,10 @@
    1.16  parser.add_option("-c", "--count", type="int",
    1.17                    help="number of operations")
    1.18  parser.add_option("-o", "--operation", type="choice",
    1.19 -                  choices=["mul", "mul-active", "comp", "compII"],
    1.20 +                  choices=["mul", "mul-active", "comp", "comp-active",
    1.21 +                           "compII", "compII-active"],
    1.22                    help=("operation to benchmark, one of 'mul', 'mul-active', "
    1.23 -                        "'comp', 'compII'"))
    1.24 +                        "'comp', 'comp-active', 'compII', 'compII-active'"))
    1.25  parser.add_option("-p", "--parallel", action="store_true",
    1.26                    help="execute operations in parallel")
    1.27  parser.add_option("-s", "--sequential", action="store_false", dest="parallel",
    1.28 @@ -126,13 +128,35 @@
    1.29          self.rt = rt
    1.30          self.operation = operation
    1.31  
    1.32 -        if isinstance(self.rt, ActiveRuntime) and self.operation == operator.mul:
    1.33 -            # TODO: Make this optional and extend it to other operations.
    1.34 +        if isinstance(self.rt, ActiveRuntime):
    1.35 +            # TODO: Make this optional and maybe automatic. The
    1.36 +            # program descriptions below were found by carefully
    1.37 +            # studying the output reported when the benchmarks were
    1.38 +            # run with no preprocessing. So they are quite brittle.
    1.39              print "Starting preprocessing"
    1.40 -            program_desc = {
    1.41 -                ("generate_triples", (Zp,)):
    1.42 -                    [(i, 1, 0) for i in range(3 + 2*count, 3 + 3*count)]
    1.43 -                }
    1.44 +            if self.operation == operator.mul:
    1.45 +                program_desc = {
    1.46 +                    ("generate_triples", (Zp,)):
    1.47 +                        [(i, 1, 0) for i in range(3 + 2*count, 3 + 3*count)]
    1.48 +                    }
    1.49 +            elif isinstance(self.rt, ActiveToft05Runtime):
    1.50 +                program_desc = {
    1.51 +                    ("generate_triples", (GF256,)):
    1.52 +                    sum([[(c, 64, i, 1, 1, 0) for i in range(2, 33)] +
    1.53 +                         [(c, 64, i, 3, 1, 0) for i in range(17, 33)]
    1.54 +                         for c in range(3 + 2*count, 3 + 3*count)],
    1.55 +                        [])
    1.56 +                    }
    1.57 +            elif isinstance(self.rt, ActiveToft07Runtime):
    1.58 +                program_desc = {
    1.59 +                    ("generate_triples", (Zp,)):
    1.60 +                    sum([[(c, 2, 4, i, 2, 1, 0) for i in range(1, 33)] +
    1.61 +                         [(c, 2, 4, 99, 2, 1, 0)] +
    1.62 +                         [(c, 2, 4, i, 1, 0) for i in range(65, 98)]
    1.63 +                         for c in range(3 + 2*count, 3 + 3*count)],
    1.64 +                        [])
    1.65 +                    }
    1.66 +
    1.67              record_start("preprocessing")
    1.68              preproc = rt.preprocess(program_desc)
    1.69              preproc.addCallback(record_stop, "preprocessing")
    1.70 @@ -225,9 +249,15 @@
    1.71  elif options.operation == "comp":
    1.72      operation = operator.ge
    1.73      runtime_class = Toft05Runtime
    1.74 +elif options.operation == "comp-active":
    1.75 +    operation = operator.ge
    1.76 +    runtime_class = ActiveToft05Runtime
    1.77  elif options.operation == "compII":
    1.78      operation = operator.ge
    1.79      runtime_class = Toft07Runtime
    1.80 +elif options.operation == "compII-active":
    1.81 +    operation = operator.ge
    1.82 +    runtime_class = ActiveToft07Runtime
    1.83  
    1.84  if options.parallel:
    1.85      benchmark = ParallelBenchmark