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 wrap: on
line diff
--- a/viff/comparison.py	Thu Oct 02 11:20:05 2008 +0200
+++ b/viff/comparison.py	Thu Oct 02 11:46:35 2008 +0200
@@ -52,6 +52,19 @@
         tmp.field = dst_field
         return reduce(self.xor, dst_shares, tmp)
 
+    def decomposed_random_sharing(self, field, bits):
+        bits = [self.prss_share_bit_double(field) for _ in range(bits)]
+        int_bits, bit_bits = zip(*bits)
+
+        def bits_to_int(bits):
+            """Converts a list of bits to an integer."""
+            return sum([2**i * b for i, b in enumerate(bits)])
+
+        int_b = gather_shares(int_bits)
+        int_b.addCallback(bits_to_int)
+
+        return int_b, bit_bits
+
     @profile
     @increment_pc
     def greater_than_equal(self, share_a, share_b):
@@ -75,25 +88,14 @@
         m = l + self.options.security_parameter
         t = m + 1
 
-        # Preprocessing begin
         assert 2**(l+1) + 2**t < field.modulus, "2^(l+1) + 2^t < p must hold"
         assert self.num_players + 2 < 2**l
 
-        bits = [self.prss_share_bit_double(field) for _ in range(m)]
-        int_bits, bit_bits = zip(*bits)
+        a = share_a - share_b + 2**l
+        b, bits = self.decomposed_random_sharing(field, m)
+        T = self.open(2**t - b + a)
 
-        def bits_to_int(bits):
-            """Converts a list of bits to an integer."""
-            return sum([2**i * b for i, b in enumerate(bits)])
-
-        int_b = gather_shares(int_bits)
-        int_b.addCallback(bits_to_int)
-        # Preprocessing done
-
-        a = share_a - share_b + 2**l
-        T = self.open(2**t - int_b + a)
-
-        result = gather_shares((T,) + bit_bits)
+        result = gather_shares((T,) + bits)
         self.schedule_callback(result, self._finish_greater_than_equal, l)
         return result