viff

changeset 994:383e6bfb4863

Refactored comparison.
author Martin Geisler <mg@daimi.au.dk>
date Thu, 02 Oct 2008 11:46:35 +0200
parents ed6a1c88de29
children f2921340d625
files viff/comparison.py
diffstat 1 files changed, 17 insertions(+), 15 deletions(-) [+]
line diff
     1.1 --- a/viff/comparison.py	Thu Oct 02 11:20:05 2008 +0200
     1.2 +++ b/viff/comparison.py	Thu Oct 02 11:46:35 2008 +0200
     1.3 @@ -52,6 +52,19 @@
     1.4          tmp.field = dst_field
     1.5          return reduce(self.xor, dst_shares, tmp)
     1.6  
     1.7 +    def decomposed_random_sharing(self, field, bits):
     1.8 +        bits = [self.prss_share_bit_double(field) for _ in range(bits)]
     1.9 +        int_bits, bit_bits = zip(*bits)
    1.10 +
    1.11 +        def bits_to_int(bits):
    1.12 +            """Converts a list of bits to an integer."""
    1.13 +            return sum([2**i * b for i, b in enumerate(bits)])
    1.14 +
    1.15 +        int_b = gather_shares(int_bits)
    1.16 +        int_b.addCallback(bits_to_int)
    1.17 +
    1.18 +        return int_b, bit_bits
    1.19 +
    1.20      @profile
    1.21      @increment_pc
    1.22      def greater_than_equal(self, share_a, share_b):
    1.23 @@ -75,25 +88,14 @@
    1.24          m = l + self.options.security_parameter
    1.25          t = m + 1
    1.26  
    1.27 -        # Preprocessing begin
    1.28          assert 2**(l+1) + 2**t < field.modulus, "2^(l+1) + 2^t < p must hold"
    1.29          assert self.num_players + 2 < 2**l
    1.30  
    1.31 -        bits = [self.prss_share_bit_double(field) for _ in range(m)]
    1.32 -        int_bits, bit_bits = zip(*bits)
    1.33 +        a = share_a - share_b + 2**l
    1.34 +        b, bits = self.decomposed_random_sharing(field, m)
    1.35 +        T = self.open(2**t - b + a)
    1.36  
    1.37 -        def bits_to_int(bits):
    1.38 -            """Converts a list of bits to an integer."""
    1.39 -            return sum([2**i * b for i, b in enumerate(bits)])
    1.40 -
    1.41 -        int_b = gather_shares(int_bits)
    1.42 -        int_b.addCallback(bits_to_int)
    1.43 -        # Preprocessing done
    1.44 -
    1.45 -        a = share_a - share_b + 2**l
    1.46 -        T = self.open(2**t - int_b + a)
    1.47 -
    1.48 -        result = gather_shares((T,) + bit_bits)
    1.49 +        result = gather_shares((T,) + bits)
    1.50          self.schedule_callback(result, self._finish_greater_than_equal, l)
    1.51          return result
    1.52