viff

changeset 1430:0164b895d948

Hash_broadcast: Removed the signal round since it does not improve security.
author Janus Dam Nielsen <janus.nielsen@alexandra.dk>
date Tue, 02 Feb 2010 17:08:16 +0100
parents efa1983063d6
children 4efa3caf521e
files viff/hash_broadcast.py
diffstat 1 files changed, 19 insertions(+), 40 deletions(-) [+]
line diff
     1.1 --- a/viff/hash_broadcast.py	Thu Jan 14 11:36:13 2010 +0100
     1.2 +++ b/viff/hash_broadcast.py	Tue Feb 02 17:08:16 2010 +0100
     1.3 @@ -23,7 +23,7 @@
     1.4      from hashlib import sha1
     1.5  except ImportError:
     1.6      from sha import sha as sha1
     1.7 -from viff.constants import TEXT, INCONSISTENTHASH, OK, HASH, SIGNAL
     1.8 +from viff.constants import TEXT, INCONSISTENTHASH, OK, HASH
     1.9  
    1.10  error_msg = "Player %i, has received an inconsistent hash %s."
    1.11  
    1.12 @@ -31,12 +31,13 @@
    1.13      pass
    1.14  
    1.15  class HashBroadcastMixin:
    1.16 -    """A non-consistent broadcast scheme mainly useful for full threshold security.
    1.17 +    """A weak-crusader broadcast scheme.
    1.18  
    1.19 -    A value is send using `send_value` and when received a hash is generated and
    1.20 -    exchanged among the receivers. If a receiver receives a hash which is not equal
    1.21 -    to the one he generated, then he sends an error signal to the others and 
    1.22 -    they stop the computation. Else he sends an ok signal and the computation continues."""
    1.23 +    A value is send using `send_value` and when received a hash is
    1.24 +    generated and exchanged among the receivers. If a receiver
    1.25 +    receives a hash which is not equal to the one he generated, then
    1.26 +    he aborts. Else he returns the received value and the computation
    1.27 +    continues."""
    1.28  
    1.29      def _send_message(self, pc, sender, receivers, message):
    1.30          for peer_id in receivers:
    1.31 @@ -49,38 +50,20 @@
    1.32          message = []
    1.33          # The hash store
    1.34          g_hashes = {}
    1.35 -        # The signal store
    1.36 -        signals = {}
    1.37  
    1.38 -        def signal_received(signal, peer_id, message, num_receivers, hashes, signals):
    1.39 -            # Store the signal.
    1.40 -            signals[peer_id] = long(signal)
    1.41 -            # If all signals are received then check if they are OK or INCONSISTENTHASH.
    1.42 -            if num_receivers == len(signals.keys()):
    1.43 -                s = reduce(lambda x, y: (OK == y and OK) or INCONSISTENTHASH, signals.values())
    1.44 +        def hash_received(h, unique_pc, peer_id, receivers, a_hashes):
    1.45 +            # Store the hash.
    1.46 +            a_hashes[peer_id] = h
    1.47 +            # If we have received a hash from everybody, then compute check them.
    1.48 +            if len(receivers) == len(a_hashes.keys()):
    1.49 +                # We check if the hashes we received are equal to
    1.50 +                # the hash we computed ourselves.
    1.51 +                s = reduce(lambda x, y: (a_hashes[self.id] == y and x) or INCONSISTENTHASH, [OK] + a_hashes.values())
    1.52                  if OK == s:
    1.53                      # Make the result ready.
    1.54                      result.callback(message[0])
    1.55                  else:
    1.56 -                    raise InconsistentHashException(error_msg % (self.id, hashes))
    1.57 -
    1.58 -        def hash_received(h, unique_pc, peer_id, receivers, a_hashes):
    1.59 -            # Store the hash.
    1.60 -            a_hashes[peer_id] = h
    1.61 -            # If we have received a hash from everybody, then compute the signal and send it.
    1.62 -            if len(receivers) == len(a_hashes.keys()):
    1.63 -                signal = OK
    1.64 -                # First we check if the hashes we received are equal to the hash we computed ourselves.
    1.65 -                for peer_id in receivers:
    1.66 -                    if a_hashes[peer_id] == a_hashes[self.id]:
    1.67 -                        signal = signal
    1.68 -                    else:
    1.69 -                        signal = INCONSISTENTHASH
    1.70 -                # Then we send the SAME signal to everybody. 
    1.71 -                for peer_id in receivers:
    1.72 -                    self.protocols[peer_id].sendData(unique_pc, SIGNAL, str(signal))           
    1.73 -            # The return value does not matter.
    1.74 -            return None
    1.75 +                    raise InconsistentHashException(error_msg % (self.id, a_hashes.values()))
    1.76  
    1.77          def message_received(m, unique_pc, message, receivers, hashes):
    1.78              # Store the message.
    1.79 @@ -93,18 +76,14 @@
    1.80              for peer_id in receivers:
    1.81                  self.protocols[peer_id].sendData(unique_pc, HASH, str(h))
    1.82  
    1.83 -        # Set up receivers for hashes and signals.
    1.84 -        # Note, we use the unique_pc to avoid data to cross method invocation boundaries.
    1.85 +        # Set up receiver for hashes.
    1.86 +        # Note, we use the unique_pc to avoid data to cross
    1.87 +        # method invocation boundaries.
    1.88          for peer_id in receivers:
    1.89              d_hash = Deferred().addCallbacks(hash_received,
    1.90                                               self.error_handler, 
    1.91                                               callbackArgs=(unique_pc, peer_id, receivers, g_hashes))
    1.92              self._expect_data_with_pc(unique_pc, peer_id, HASH, d_hash)
    1.93 -            d_signal = Deferred().addCallbacks(signal_received, 
    1.94 -                                               self.error_handler, 
    1.95 -                                               callbackArgs=(peer_id, message, len(receivers), 
    1.96 -                                                             g_hashes, signals))
    1.97 -            self._expect_data_with_pc(unique_pc, peer_id, SIGNAL, d_signal)
    1.98  
    1.99          # Set up receiving of the message.
   1.100          d_message = Deferred().addCallbacks(message_received,