viff

changeset 1269:f91b28a6cbbe

Added preprocessing to Orlandi runtime.
author Janus Dam Nielsen <janus.nielsen@alexandra.dk>
date Fri, 09 Oct 2009 13:04:18 +0200
parents 61ac5debba24
children bf991ca28f23
files apps/benchmark.py viff/orlandi.py
diffstat 2 files changed, 23 insertions(+), 14 deletions(-) [+]
line diff
     1.1 --- a/apps/benchmark.py	Fri Oct 09 13:04:18 2009 +0200
     1.2 +++ b/apps/benchmark.py	Fri Oct 09 13:04:18 2009 +0200
     1.3 @@ -152,7 +152,7 @@
     1.4                    help="The program counter to start from when using explicitly provided needed_data. Format: [3,0]")
     1.5  
     1.6  parser.set_defaults(modulus=2**65, threshold=1, count=10,
     1.7 -                    runtime=runtimes.keys()[0], mixins="", num_players=2, prss=True,
     1.8 +                    runtime="PassiveRuntime", mixins="", num_players=2, prss=True,
     1.9                      operation=operations.keys()[0], parallel=True, fake=False, 
    1.10                      args="", needed_data="")
    1.11  
    1.12 @@ -358,9 +358,11 @@
    1.13      needed_data = eval(needed_data)
    1.14  
    1.15  if options.needed_data != "" and options.pc != "":
    1.16 +    print "A1"
    1.17      bases = (benchmark,) + (NeededDataBenchmarkStrategy,) + (object,)
    1.18      options.pc = eval(options.pc)
    1.19  else:
    1.20 +    print "B1"
    1.21      bases = (benchmark,) + (SelfcontainedBenchmarkStrategy,) + (object,)
    1.22  benchmark = type("ExtendedBenchmark", bases, {})
    1.23  
    1.24 @@ -373,13 +375,14 @@
    1.25          for arg in options.args.split(','):
    1.26              id, value = arg.split('=')
    1.27              args[id] = long(value)
    1.28 -        runtime.setArgs(args)
    1.29 +        runtime.set_args(args)
    1.30      return runtime
    1.31  
    1.32  
    1.33  pre_runtime.addCallback(update_args, options)
    1.34  
    1.35  def do_benchmark(runtime, operation, benchmark, *args):
    1.36 +    print "db"
    1.37      benchmark(runtime, operation).benchmark(*args)
    1.38  
    1.39  pre_runtime.addCallback(do_benchmark, operation, benchmark, needed_data, options.pc)
     2.1 --- a/viff/orlandi.py	Fri Oct 09 13:04:18 2009 +0200
     2.2 +++ b/viff/orlandi.py	Fri Oct 09 13:04:18 2009 +0200
     2.3 @@ -17,7 +17,7 @@
     2.4  
     2.5  from twisted.internet.defer import Deferred, DeferredList, gatherResults
     2.6  
     2.7 -from viff.runtime import Runtime, Share, ShareList, gather_shares
     2.8 +from viff.runtime import Runtime, Share, ShareList, gather_shares, preprocess
     2.9  from viff.util import rand
    2.10  from viff.constants import TEXT, PAILLIER
    2.11  from viff.field import FieldElement
    2.12 @@ -598,6 +598,7 @@
    2.13          c = OrlandiShare(self, field, field(value), (field(0), field(0)), Cc)
    2.14          return c
    2.15  
    2.16 +    @preprocess("random_triple")
    2.17      def _get_triple(self, field):
    2.18          c, d = self.random_triple(field, 1)
    2.19          def f(ls):
    2.20 @@ -1025,7 +1026,7 @@
    2.21  
    2.22          return result
    2.23  
    2.24 -    def random_triple(self, field, number_of_requested_triples):
    2.25 +    def random_triple(self, field, quantity=1):
    2.26          """Generate a list of triples ``(a, b, c)`` where ``c = a * b``.
    2.27  
    2.28          The triple ``(a, b, c)`` is secure in the Fcrs-hybrid model.
    2.29 @@ -1035,14 +1036,14 @@
    2.30  
    2.31          M = []
    2.32  
    2.33 -# print "Generating %i triples... relax, have a brak..." % ((1 + self.s_lambda) * (2 * self.d + 1) * number_of_requested_triples)
    2.34 +# print "Generating %i triples... relax, have a break..." % ((1 + self.s_lambda) * (2 * self.d + 1) * quantity)
    2.35  
    2.36 -        for x in xrange((1 + self.s_lambda) * (2 * self.d + 1) * number_of_requested_triples):
    2.37 +        for x in xrange((1 + self.s_lambda) * (2 * self.d + 1) * quantity):
    2.38              M.append(self.triple_test(field))
    2.39  
    2.40          def step3(ls):
    2.41              """Coin-flip a subset test_set of M of size lambda(2d + 1)M."""
    2.42 -            size = self.s_lambda * (2 * self.d + 1) * number_of_requested_triples
    2.43 +            size = self.s_lambda * (2 * self.d + 1) * quantity
    2.44              inx = 0
    2.45              p_half = field.modulus // 2
    2.46              def coin_flip(v, ls, test_set):
    2.47 @@ -1250,18 +1251,18 @@
    2.48              return dls_all
    2.49  
    2.50          def step6(M_without_test_set):
    2.51 -            """Partition M without test_set in number_of_requested_triples
    2.52 +            """Partition M without test_set in quantity
    2.53              random subsets M_i of size (2d + 1).
    2.54              """
    2.55              subsets = []
    2.56              size = 2 * self.d + 1
    2.57 -            for x in xrange(number_of_requested_triples):
    2.58 +            for x in xrange(quantity):
    2.59                  subsets.append([])
    2.60  
    2.61              def put_in_set(v, M_without_test_set, subsets):
    2.62                  if 0 == len(M_without_test_set):
    2.63                      return subsets
    2.64 -                v = v.value % number_of_requested_triples
    2.65 +                v = v.value % quantity
    2.66                  if size > len(subsets[v]):
    2.67                      subsets[v].append(M_without_test_set.pop(0))
    2.68                  r = self.random_share(field)
    2.69 @@ -1311,12 +1312,17 @@
    2.70          self.activate_reactor()
    2.71  
    2.72          s = Share(self, field)
    2.73 -        def f(ls, s):
    2.74 -            s.callback(ls)
    2.75 -        result.addCallbacks(f, self.error_handler, callbackArgs=(s,))
    2.76 -        return number_of_requested_triples, s
    2.77 +        # We add the result to the chains in result.
    2.78 +        result.chainDeferred(s)
    2.79 +
    2.80 +        return quantity, s
    2.81  
    2.82      def error_handler(self, ex):
    2.83          print "Error: ", ex
    2.84          return ex
    2.85  
    2.86 +    def set_args(self, args):
    2.87 +        """args is a dictionary."""
    2.88 +        self.s = args['s']
    2.89 +        self.d = args['d']
    2.90 +        self.s_lambda = args['lambda']