viff

changeset 1526:a87fd09f8c38

BeDOZa: Split data send in add_macs into chunks that are smaller than 65536 bytes.
author Janus Dam Nielsen <janus.nielsen@alexandra.dk>
date Thu, 29 Jul 2010 11:31:24 +0200
parents 80841840990f
children 7dd55d319d2b
files viff/bedoza/add_macs.py viff/test/test_bedoza_triple.py
diffstat 2 files changed, 42 insertions(+), 12 deletions(-) [+]
line diff
     1.1 --- a/viff/bedoza/add_macs.py	Mon Jul 26 14:46:15 2010 +0200
     1.2 +++ b/viff/bedoza/add_macs.py	Thu Jul 29 11:31:24 2010 +0200
     1.3 @@ -15,6 +15,8 @@
     1.4  # You should have received a copy of the GNU Lesser General Public
     1.5  # License along with VIFF. If not, see <http://www.gnu.org/licenses/>.
     1.6  
     1.7 +import struct
     1.8 +
     1.9  from twisted.internet.defer import gatherResults
    1.10  from viff.runtime import Share
    1.11  
    1.12 @@ -24,6 +26,7 @@
    1.13  
    1.14  from viff.bedoza.shares import BeDOZaShare, BeDOZaShareContents
    1.15  
    1.16 +
    1.17  def add_macs(runtime, field, u_bound, alpha, random, paillier, partial_shares):
    1.18      """Adds macs to the set of PartialBeDOZaShares.
    1.19          
    1.20 @@ -37,27 +40,50 @@
    1.21      runtime.increment_pc() # Huh!?
    1.22  
    1.23      def do_add_macs(partial_share_contents, result_shares):
    1.24 +        """The transmission_restraint_constant is the number of
    1.25 +        encrypted shares we can safely transmit in one call to
    1.26 +        sendData. The sendData method can only transmit up to
    1.27 +        65536 bytes.
    1.28 +        """
    1.29 +        transmission_restraint_constant = 50
    1.30 +        
    1.31          num_players = runtime.num_players
    1.32 -        lists_of_mac_keys = [ [] for x in runtime.players ]
    1.33 -        lists_of_c_list = [ [] for x in runtime.players ]
    1.34 -        for partial_share_content in partial_share_contents:
    1.35 -            for j in xrange(0, num_players):
    1.36 +
    1.37 +        list_of_player_to_enc_shares_lists = []
    1.38 +        
    1.39 +        player_to_mac_keys = [ [] for x in runtime.players]
    1.40 +        player_to_enc_shares = [ [] for x in runtime.players]
    1.41 +        for inx, partial_share_content in enumerate(partial_share_contents):
    1.42 +            if inx % transmission_restraint_constant == 0:
    1.43 +                player_to_enc_shares = [ [] for x in runtime.players]
    1.44 +                list_of_player_to_enc_shares_lists.append(player_to_enc_shares)
    1.45 +            for j in xrange(num_players):
    1.46                  # TODO: This is probably not the fastes way to generate
    1.47                  # the betas.
    1.48                  beta = random.randint(0, u_bound)
    1.49                  # TODO: Outcommented until mod paillier works for negative numbers.
    1.50                  # if rand.choice([True, False]):
    1.51                  #    beta = -beta
    1.52 -                enc_beta = paillier.encrypt(beta, player_id=j + 1)
    1.53 -                c_j = partial_share_content.enc_shares[j]
    1.54 -                n2 = paillier.get_modulus_square(j + 1)
    1.55 +                enc_beta = paillier.encrypt(beta, player_id = j + 1)
    1.56 +                c_j = partial_share_content.enc_shares[ j ]
    1.57 +                n2 = paillier.get_modulus_square( j + 1 )
    1.58                  c = (pow(c_j, alpha, n2) * enc_beta) % n2
    1.59 -                lists_of_c_list[j].append(c)
    1.60 -                lists_of_mac_keys[j].append(field(beta))
    1.61 +                player_to_enc_shares[j].append(c)
    1.62 +                player_to_mac_keys[j].append(field(beta))
    1.63  
    1.64 -        received_cs = _send(runtime, lists_of_c_list, deserialize=eval)
    1.65 +        received_cs = []
    1.66 +        for ls in list_of_player_to_enc_shares_lists:
    1.67 +            received_cs.append(_send(runtime, ls, deserialize=eval))
    1.68 +
    1.69 +        def merge(received_cs):
    1.70 +            r = [ [] for x in xrange(len(received_cs[0]))]
    1.71 +            for ls in received_cs:
    1.72 +                for inx, xs in enumerate(ls):
    1.73 +                    r[inx] += xs
    1.74 +            return r
    1.75  
    1.76          def finish_sharing(recevied_cs, partial_share_contents, lists_of_mac_keys, result_shares):
    1.77 +            recevied_cs = merge(recevied_cs)
    1.78              shares = []               
    1.79              for inx in xrange(0, len(partial_share_contents)):
    1.80                  mac_keys = []
    1.81 @@ -75,7 +101,11 @@
    1.82                                                                  mac_msg_list))
    1.83              return shares
    1.84  
    1.85 -        runtime.schedule_callback(received_cs, finish_sharing, partial_share_contents, lists_of_mac_keys, result_shares)
    1.86 +        runtime.schedule_callback(gatherResults(received_cs),
    1.87 +                                  finish_sharing,
    1.88 +                                  partial_share_contents,
    1.89 +                                  player_to_mac_keys,
    1.90 +                                  result_shares)
    1.91          return received_cs
    1.92  
    1.93      result_shares = [Share(runtime, field) for x in xrange(len(partial_shares))]
     2.1 --- a/viff/test/test_bedoza_triple.py	Mon Jul 26 14:46:15 2010 +0200
     2.2 +++ b/viff/test/test_bedoza_triple.py	Thu Jul 29 11:31:24 2010 +0200
     2.3 @@ -411,7 +411,7 @@
     2.4          random = Random(283883)        
     2.5          triple_generator = TripleGenerator(runtime, p, random)
     2.6  
     2.7 -        triples = triple_generator.generate_triples(5)
     2.8 +        triples = triple_generator.generate_triples(100)
     2.9  
    2.10          def check((a, b, c)):
    2.11              self.assertEquals(c, a * b)