viff

changeset 1509:a6be6cce7046

BeDOZa: fullmul now returns a list of PartialShares.
author Janus Dam Nielsen <janus.nielsen@alexandra.dk>
date Tue, 20 Jul 2010 14:15:11 +0200
parents 891df84eb779
children e1aacaf19a54
files viff/bedoza_triple.py viff/test/test_bedoza_triple.py
diffstat 2 files changed, 21 insertions(+), 25 deletions(-) [+]
line diff
     1.1 --- a/viff/bedoza_triple.py	Tue Jul 20 14:01:16 2010 +0200
     1.2 +++ b/viff/bedoza_triple.py	Tue Jul 20 14:15:11 2010 +0200
     1.3 @@ -386,7 +386,7 @@
     1.4          r.addCallback(wrap, inx, jnx)
     1.5          return r
     1.6  
     1.7 -    def _full_mul(self, a, b):
     1.8 +    def _full_mul(self, a, b, field):
     1.9          """Multiply each of the PartialShares in the list *a* with the
    1.10          corresponding PartialShare in the list *b*.
    1.11          
    1.12 @@ -394,7 +394,7 @@
    1.13          """
    1.14          self.runtime.increment_pc()
    1.15          
    1.16 -        def do_full_mul(shares):
    1.17 +        def do_full_mul(shares, result_shares):
    1.18              """Share content belonging to ai, bi are at:
    1.19              shares[i], shares[len(shares) + i].
    1.20              """
    1.21 @@ -411,7 +411,7 @@
    1.22                                                 a_values,
    1.23                                                 b_enc_shares[jnx]))
    1.24                          
    1.25 -            def compute_shares(partialShareContents, len_shares):
    1.26 +            def compute_shares(partialShareContents, len_shares, result_shares):
    1.27                  num_players = len(self.runtime.players)
    1.28                  pcs = len(partialShareContents[0]) * [None]
    1.29                  for ps in partialShareContents:
    1.30 @@ -420,16 +420,17 @@
    1.31                              pcs[inx] = ps[inx]
    1.32                          else:
    1.33                              pcs[inx] += ps[inx]
    1.34 -                partialShares = [PartialShare(self.runtime,
    1.35 -                                              p.value,
    1.36 -                                              p.enc_shares) for p in pcs]
    1.37 -                return partialShares
    1.38 +                for p, s in zip(pcs, result_shares):
    1.39 +                    s.callback(p)
    1.40 +                return None
    1.41              d = gatherResults(deferreds)
    1.42 -            d.addCallback(compute_shares, len_shares)
    1.43 +            d.addCallback(compute_shares, len_shares, result_shares)
    1.44              return d
    1.45 -        s = gatherResults(a + b)
    1.46 -        self.runtime.schedule_callback(s, do_full_mul)
    1.47 -        return s
    1.48 +        result_shares = [Share(self.runtime, field) for x in a]
    1.49 +        self.runtime.schedule_callback(gatherResults(a + b),
    1.50 +                                       do_full_mul,
    1.51 +                                       result_shares)
    1.52 +        return result_shares
    1.53  
    1.54  
    1.55  # TODO: Represent all numbers by GF objects, Zp, Zn, etc.
     2.1 --- a/viff/test/test_bedoza_triple.py	Tue Jul 20 14:01:16 2010 +0200
     2.2 +++ b/viff/test/test_bedoza_triple.py	Tue Jul 20 14:15:11 2010 +0200
     2.3 @@ -430,7 +430,7 @@
     2.4          share_bs.append(partial_share(random, runtime, GF(p), 3, paillier=paillier))
     2.5  
     2.6  
     2.7 -        share_zs = triple_generator._full_mul(share_as, share_bs)
     2.8 +        share_zs = triple_generator._full_mul(share_as, share_bs, Zp)
     2.9          def check(shares):
    2.10              def test_sum(ls):
    2.11                  self.assertEquals(8, Zp(sum(ls[0])))
    2.12 @@ -444,12 +444,9 @@
    2.13              runtime.schedule_callback(d, test_sum)
    2.14              return d
    2.15              
    2.16 -        def indirection(shares):
    2.17 -            d = gatherResults(shares)
    2.18 -            d.addCallback(check)
    2.19 -            return d
    2.20 -        share_zs.addCallback(indirection)
    2.21 -        return share_zs
    2.22 +        d = gatherResults(share_zs)
    2.23 +        d.addCallback(check)
    2.24 +        return d
    2.25  
    2.26      @protocol
    2.27      def test_fullmul_encrypted_values_are_the_same_as_the_share(self, runtime):
    2.28 @@ -471,7 +468,7 @@
    2.29          share_as.append(partial_share(random, runtime, GF(p), 2, paillier=paillier))
    2.30          share_bs.append(partial_share(random, runtime, GF(p), 3, paillier=paillier))
    2.31  
    2.32 -        share_zs = triple_generator._full_mul(share_as, share_bs)
    2.33 +        share_zs = triple_generator._full_mul(share_as, share_bs, Zp)
    2.34          def check(shares):
    2.35              all_enc_shares = []
    2.36              for share in shares:
    2.37 @@ -487,12 +484,10 @@
    2.38                  all_enc_shares.append(d)
    2.39              return gatherResults(all_enc_shares)
    2.40          
    2.41 -        def indirection(shares):
    2.42 -            d = gatherResults(shares)
    2.43 -            d.addCallback(check)
    2.44 -            return d
    2.45 -        share_zs.addCallback(indirection)
    2.46 -        return share_zs
    2.47 +        d = gatherResults(share_zs)
    2.48 +        d.addCallback(check)
    2.49 +        return d
    2.50 +        
    2.51  
    2.52  
    2.53  missing_package = None