viff

changeset 1245:be9c8eb7b4d0

Added option to use preprocessing.
author Marcel Keller <mkeller@cs.au.dk>
date Fri, 11 Sep 2009 19:11:31 +0200
parents f29e998c77c9
children 591451fd23dc cd0f4d7d135b
files apps/aes.py
diffstat 1 files changed, 52 insertions(+), 1 deletions(-) [+]
line diff
     1.1 --- a/apps/aes.py	Fri Sep 11 19:09:31 2009 +0200
     1.2 +++ b/apps/aes.py	Fri Sep 11 19:11:31 2009 +0200
     1.3 @@ -22,6 +22,7 @@
     1.4  
     1.5  import time
     1.6  from optparse import OptionParser
     1.7 +from pprint import pformat
     1.8  
     1.9  import viff.reactor
    1.10  viff.reactor.install()
    1.11 @@ -57,6 +58,8 @@
    1.12  parser.set_defaults(count=1)
    1.13  parser.add_option("-a", "--active", action="store_true", help="Use actively "
    1.14                    "secure runtime. Default is only passive security.")
    1.15 +parser.add_option("-p", "--preproc", action="store_true", help="Use "
    1.16 +                  "preprocessing. Default is no preprocessing.")
    1.17  
    1.18  # Add standard VIFF options.
    1.19  Runtime.add_options(parser)
    1.20 @@ -85,6 +88,19 @@
    1.21      def fin(ciphertext):
    1.22          print "Finished after %f sec." % (time.time() - start)
    1.23          print "Ciphertext:", [hex(c.value) for c in ciphertext]
    1.24 +
    1.25 +        if rt._needed_data and options.preproc:
    1.26 +            print "Missing pre-processed data:"
    1.27 +            for (func, args), pcs in rt._needed_data.iteritems():
    1.28 +                print "* %s%s:" % (func, args)
    1.29 +                print "  " + pformat(pcs).replace("\n", "\n  ")
    1.30 +
    1.31 +        if rt._pool:
    1.32 +            print "Unused pre-processed data:"
    1.33 +            pcs = rt._pool.keys()
    1.34 +            pcs.sort()
    1.35 +            print "  " + pformat(pcs).replace("\n", "\n  ")
    1.36 +
    1.37          rt.shutdown()
    1.38  
    1.39      g = gather_shares(opened_ciphertext)
    1.40 @@ -103,6 +119,37 @@
    1.41      s = rt.synchronize()
    1.42      rt.schedule_complex_callback(s, encrypt, rt, key)
    1.43  
    1.44 +def preprocess(rt):
    1.45 +    if options.active:
    1.46 +        start = time.time()
    1.47 +
    1.48 +        if options.exponentiation is False:
    1.49 +            max = 301
    1.50 +            js = [3 + i * 15 + j for i in range(20) for j in range(7) + [8]]
    1.51 +        elif options.exponentiation == 0:
    1.52 +            max = 321
    1.53 +            js = [2 + i * 16 + j for i in range(20) for j in range(13)]
    1.54 +        elif options.exponentiation == 1 or options.exponentiation == 2:
    1.55 +            max = 261
    1.56 +            js = [1 + i * 13 + j for i in range(20) for j in range(11)]
    1.57 +        elif options.exponentiation == 3:
    1.58 +            max = 301
    1.59 +            js = [1 + i * 15 + j for i in range(20) for j in range(13)]
    1.60 +
    1.61 +        pcs = [(2, 18, k) +  (max,) * i + (j, 1, 0)
    1.62 +               for k in range(1, options.count + 1)
    1.63 +               for i in range(10)
    1.64 +               for j in js]
    1.65 +
    1.66 +        preproc = rt.preprocess({("generate_triples", (GF256,)): pcs})
    1.67 +
    1.68 +        def fin(_):
    1.69 +            print "Finished preprocessing after %f sec." % (time.time() - start)
    1.70 +            return rt
    1.71 +
    1.72 +        preproc.addCallback(fin)
    1.73 +        rt.schedule_complex_callback(preproc, share_key)
    1.74 +
    1.75  if options.active:
    1.76      from viff.active import ActiveRuntime
    1.77      runtime_class = ActiveRuntime
    1.78 @@ -111,6 +158,10 @@
    1.79      runtime_class = PassiveRuntime
    1.80  
    1.81  rt = create_runtime(id, players, 1, options, runtime_class)
    1.82 -rt.addCallback(share_key)
    1.83 +
    1.84 +if options.preproc:
    1.85 +    rt.addCallback(preprocess)
    1.86 +else:
    1.87 +    rt.addCallback(share_key)
    1.88  
    1.89  reactor.run()