viff

changeset 1216:d325a4ee6625

Merge with Marcel.
author Martin Geisler <mg@cs.au.dk>
date Fri, 18 Sep 2009 16:14:20 +0200
parents f2fce145b9e1 7eb99c27a46e
children 80125f56beaa
files viff/active.py viff/aes.py viff/runtime.py
diffstat 4 files changed, 51 insertions(+), 10 deletions(-) [+]
line diff
     1.1 --- a/apps/aes.py	Fri Sep 18 15:48:52 2009 +0200
     1.2 +++ b/apps/aes.py	Fri Sep 18 16:14:20 2009 +0200
     1.3 @@ -55,6 +55,8 @@
     1.4  parser.add_option("-c", "--count", action="store", type="int",
     1.5                    help="Number of blocks to encrypt. Defaults to 1.")
     1.6  parser.set_defaults(count=1)
     1.7 +parser.add_option("-a", "--active", action="store_true", help="Use actively "
     1.8 +                  "secure runtime. Default is only passive security.")
     1.9  
    1.10  # Add standard VIFF options.
    1.11  Runtime.add_options(parser)
    1.12 @@ -101,7 +103,14 @@
    1.13      s = rt.synchronize()
    1.14      rt.schedule_complex_callback(s, encrypt, rt, key)
    1.15  
    1.16 -rt = create_runtime(id, players, 1, options)
    1.17 +if options.active:
    1.18 +    from viff.active import ActiveRuntime
    1.19 +    runtime_class = ActiveRuntime
    1.20 +else:
    1.21 +    from viff.passive import PassiveRuntime
    1.22 +    runtime_class = PassiveRuntime
    1.23 +
    1.24 +rt = create_runtime(id, players, 1, options, runtime_class)
    1.25  rt.addCallback(share_key)
    1.26  
    1.27  reactor.run()
     2.1 --- a/viff/active.py	Fri Sep 18 15:48:52 2009 +0200
     2.2 +++ b/viff/active.py	Fri Sep 18 16:14:20 2009 +0200
     2.3 @@ -507,7 +507,7 @@
     2.4          # This is the Deferred we will do processing on.
     2.5          triple = self.get_triple(share_x.field)
     2.6          triple.addCallback(gather_shares)
     2.7 -        self.schedule_callback(triple, finish_mul)
     2.8 +        triple = self.schedule_complex_callback(triple, finish_mul)
     2.9          # We add the result to the chains in triple.
    2.10          triple.chainDeferred(result)
    2.11          return result
     3.1 --- a/viff/aes.py	Fri Sep 18 15:48:52 2009 +0200
     3.2 +++ b/viff/aes.py	Fri Sep 18 16:14:20 2009 +0200
     3.3 @@ -107,6 +107,8 @@
     3.4                  self.invert = lambda byte: byte ** 254
     3.5              elif (use_exponentiation == "shortest_chain_with_least_rounds"):
     3.6                  self.invert = self.invert_by_exponentiation_with_less_rounds
     3.7 +            elif (use_exponentiation == "chain_with_least_rounds"):
     3.8 +                self.invert = self.invert_by_exponentiation_with_least_rounds
     3.9              else:
    3.10                  self.invert = self.invert_by_exponentiation
    3.11          else:
    3.12 @@ -117,7 +119,8 @@
    3.13  
    3.14      exponentiation_variants = ["standard_square_and_multiply",
    3.15                                 "shortest_sequential_chain",
    3.16 -                               "shortest_chain_with_least_rounds"]
    3.17 +                               "shortest_chain_with_least_rounds",
    3.18 +                               "chain_with_least_rounds"]
    3.19  
    3.20      def invert_by_masking(self, byte):
    3.21          bits = bit_decompose(byte)
    3.22 @@ -172,13 +175,29 @@
    3.23          byte_4 = byte_2 * byte_2
    3.24          byte_8 = byte_4 * byte_4
    3.25          byte_9 = byte_8 * byte
    3.26 +        byte_18 = byte_9 * byte_9
    3.27 +        byte_19 = byte_18 * byte
    3.28 +        byte_36 = byte_18 * byte_18
    3.29 +        byte_55 = byte_36 * byte_19
    3.30 +        byte_72 = byte_36 * byte_36
    3.31 +        byte_127 = byte_72 * byte_55
    3.32 +        byte_254 = byte_127 * byte_127
    3.33 +        return byte_254
    3.34 +
    3.35 +    def invert_by_exponentiation_with_least_rounds(self, byte):
    3.36 +        byte_2 = byte * byte
    3.37 +        byte_3 = byte_2 * byte
    3.38 +        byte_4 = byte_2 * byte_2
    3.39 +        byte_7 = byte_4 * byte_3
    3.40 +        byte_8 = byte_4 * byte_4
    3.41 +        byte_15 = byte_8 * byte_7
    3.42          byte_16 = byte_8 * byte_8
    3.43 -        byte_25 = byte_16 * byte_9
    3.44 -        byte_50 = byte_25 * byte_25
    3.45 -        byte_54 = byte_50 * byte_4
    3.46 -        byte_100 = byte_50 * byte_50
    3.47 -        byte_200 = byte_100 * byte_100
    3.48 -        byte_254 = byte_200 * byte_54
    3.49 +        byte_31 = byte_16 * byte_15
    3.50 +        byte_32 = byte_16 * byte_16
    3.51 +        byte_63 = byte_32 * byte_31
    3.52 +        byte_64 = byte_32 * byte_32
    3.53 +        byte_127 = byte_64 * byte_63
    3.54 +        byte_254 = byte_127 * byte_127
    3.55          return byte_254
    3.56  
    3.57      # matrix for byte_sub, the last column is the translation vector
     4.1 --- a/viff/runtime.py	Fri Sep 18 15:48:52 2009 +0200
     4.2 +++ b/viff/runtime.py	Fri Sep 18 16:14:20 2009 +0200
     4.3 @@ -288,6 +288,9 @@
     4.4          #: Data expected to be received in the future.
     4.5          self.incoming_data = {}
     4.6          self.waiting_deferreds = {}
     4.7 +        #: Statistics
     4.8 +        self.sent_packets = 0
     4.9 +        self.sent_bytes = 0
    4.10  
    4.11      def connectionMade(self):
    4.12          self.sendString(str(self.factory.runtime.id))
    4.13 @@ -362,7 +365,10 @@
    4.14          data_size = len(data)
    4.15          fmt = "!HHB%dI%ds" % (pc_size, data_size)
    4.16          t = (pc_size, data_size, data_type) + program_counter + (data,)
    4.17 -        self.sendString(struct.pack(fmt, *t))
    4.18 +        packet = struct.pack(fmt, *t)
    4.19 +        self.sendString(packet)
    4.20 +        self.sent_packets += 1
    4.21 +        self.sent_bytes += len(packet)
    4.22  
    4.23      def sendShare(self, program_counter, share):
    4.24          """Send a share.
    4.25 @@ -842,6 +848,13 @@
    4.26              self.depth_counter -= 1
    4.27              self.activation_counter = 0
    4.28  
    4.29 +    def print_transferred_data():
    4.30 +        """Print the amount of transferred data for all connections."""
    4.31 +
    4.32 +        for protocol in self.protocols.itervalues():
    4.33 +            print "Transfer to peer %d: %d bytes in %d packets" % \
    4.34 +                  (protocol.peer_id, protocol.sent_bytes, protocol.sent_packets)
    4.35 +
    4.36  
    4.37  def make_runtime_class(runtime_class=None, mixins=None):
    4.38      """Creates a new runtime class with *runtime_class* as a base