viff

changeset 1546:da966a4620f4

Updated mul and fullmul to reflect the new description.
author Janus Dam Nielsen <janus.nielsen@alexandra.dk>
date Tue, 21 Sep 2010 11:42:36 +0200
parents 8b1b64b3ea5b
children dae353266aa6
files viff/bedoza/bedoza_triple.py viff/bedoza/share.py viff/test/test_bedoza_triple.py
diffstat 3 files changed, 72 insertions(+), 10 deletions(-) [+]
line diff
     1.1 --- a/viff/bedoza/bedoza_triple.py	Mon Sep 20 14:30:03 2010 +0200
     1.2 +++ b/viff/bedoza/bedoza_triple.py	Tue Sep 21 11:42:36 2010 +0200
     1.3 @@ -35,6 +35,8 @@
     1.4  from viff.bedoza.add_macs import add_macs
     1.5  from viff.bedoza.modified_paillier import ModifiedPaillier
     1.6  from viff.bedoza.util import fast_pow
     1.7 +from viff.bedoza.util import _convolute
     1.8 +from viff.bedoza.share import Share
     1.9  
    1.10  from viff.triple import Triple
    1.11  
    1.12 @@ -245,7 +247,7 @@
    1.13              deferred = zis_deferred
    1.14  
    1.15          return deferred
    1.16 -
    1.17 +       
    1.18      def _full_mul(self, a, b):
    1.19          """Multiply each of the PartialShares in the list *a* with the
    1.20          corresponding PartialShare in the list *b*.
    1.21 @@ -279,18 +281,25 @@
    1.22                                                 ais,
    1.23                                                 b_enc_shares[jnx]))
    1.24              
    1.25 -            def compute_shares(list_of_list_of_field_elements, values, result_shares):
    1.26 -                for field_elements in list_of_list_of_field_elements:
    1.27 -                    for inx, field_element in enumerate(field_elements):
    1.28 -                        values[inx] += field_element
    1.29 +            def compute_shares(zils, values, result_shares):
    1.30 +                for zil in zils:
    1.31 +                    for inx, zi in enumerate(zil):
    1.32 +                        values[inx] += zi
    1.33  
    1.34 -                for v, s in zip(values, result_shares):
    1.35 +                return values
    1.36 +            
    1.37 +            d = gatherResults(deferreds)
    1.38 +            d.addCallback(compute_shares, values, result_shares)
    1.39 +            
    1.40 +            def callBackPartialShareContents(partialShareContents, result_shares):
    1.41 +                for v, s in zip(partialShareContents, result_shares):
    1.42                      s.callback(v)
    1.43                  return None
    1.44 -            d = gatherResults(deferreds)
    1.45 -            d.addCallback(compute_shares, values, result_shares)
    1.46 +            
    1.47 +            d.addCallback(lambda values: Share(values, self.runtime, self.paillier))
    1.48 +            d.addCallback(callBackPartialShareContents, result_shares)
    1.49              return d
    1.50 -        result_shares = [Share(self.runtime, self.Zp) for x in a]
    1.51 +        result_shares = [PartialShare(self.runtime, self.Zp) for _ in a]
    1.52          self.runtime.schedule_callback(gatherResults(a + b),
    1.53                                         do_full_mul,
    1.54                                         result_shares)
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/viff/bedoza/share.py	Tue Sep 21 11:42:36 2010 +0200
     2.3 @@ -0,0 +1,53 @@
     2.4 +# Copyright 2010 VIFF Development Team.
     2.5 +#
     2.6 +# This file is part of VIFF, the Virtual Ideal Functionality Framework.
     2.7 +#
     2.8 +# VIFF is free software: you can redistribute it and/or modify it
     2.9 +# under the terms of the GNU Lesser General Public License (LGPL) as
    2.10 +# published by the Free Software Foundation, either version 3 of the
    2.11 +# License, or (at your option) any later version.
    2.12 +#
    2.13 +# VIFF is distributed in the hope that it will be useful, but WITHOUT
    2.14 +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
    2.15 +# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
    2.16 +# Public License for more details.
    2.17 +#
    2.18 +# You should have received a copy of the GNU Lesser General Public
    2.19 +# License along with VIFF. If not, see <http://www.gnu.org/licenses/>.
    2.20 +
    2.21 +from viff.bedoza.shares import PartialShareContents
    2.22 +from viff.bedoza.util import _convolute
    2.23 +
    2.24 +def Share(field_elements, runtime, paillier):
    2.25 +    """Each party input a list of field elements *field_elements*.
    2.26 +    The value of the field elements are encrypted and the encrypted
    2.27 +    values are exchanged.
    2.28 +
    2.29 +    Returns a deferred, which yields a list of PartialShareContents.  
    2.30 +    """
    2.31 +    
    2.32 +    runtime.increment_pc()
    2.33 +
    2.34 +    N_squared_list = [paillier.get_modulus_square(player_id)
    2.35 +                      for player_id in runtime.players]
    2.36 +
    2.37 +    list_of_enc_shares = []
    2.38 +    for field_element in field_elements:
    2.39 +        list_of_enc_shares.append(paillier.encrypt(field_element.value))
    2.40 +        
    2.41 +    list_of_enc_shares = _convolute(runtime, list_of_enc_shares, deserialize=eval)
    2.42 +    def create_partial_share(list_of_enc_shares, field_elements):
    2.43 +
    2.44 +        reordered_encrypted_shares = [[] for _ in list_of_enc_shares[0]]
    2.45 +        for enc_shares in list_of_enc_shares:
    2.46 +            for inx, enc_share in enumerate(enc_shares):
    2.47 +                reordered_encrypted_shares[inx].append(enc_share)
    2.48 +
    2.49 +        partialShareContents = []
    2.50 +        for enc_shares, field_element in zip(reordered_encrypted_shares, field_elements):
    2.51 +            partialShareContents.append(PartialShareContents(field_element, enc_shares, N_squared_list))
    2.52 +        return partialShareContents
    2.53 +    
    2.54 +    runtime.schedule_callback(list_of_enc_shares, create_partial_share, field_elements)
    2.55 +    return list_of_enc_shares
    2.56 +        
     3.1 --- a/viff/test/test_bedoza_triple.py	Mon Sep 20 14:30:03 2010 +0200
     3.2 +++ b/viff/test/test_bedoza_triple.py	Tue Sep 21 11:42:36 2010 +0200
     3.3 @@ -564,7 +564,7 @@
     3.4                  self.assertEquals(6, Zp(sum(ls[2])))
     3.5              values = []
     3.6              for share in shares:
     3.7 -                value = _convolute(runtime, share.value)
     3.8 +                value = _convolute(runtime, share.value.value)
     3.9                  values.append(value)
    3.10              d = gatherResults(values)
    3.11              runtime.schedule_callback(d, test_sum)