viff

changeset 1213:7610deb0ebab

Get rid of increment_pc for prss_* These function still need a unique program counter, though, so they now increment it themselves as needed.
author Martin Geisler <mg@cs.au.dk>
date Fri, 18 Sep 2009 14:42:26 +0200
parents 2daaf0e7a1f6
children 34a7d23462a7
files viff/equality.py viff/passive.py
diffstat 2 files changed, 19 insertions(+), 11 deletions(-) [+]
line diff
     1.1 --- a/viff/equality.py	Fri Sep 18 14:41:44 2009 +0200
     1.2 +++ b/viff/equality.py	Fri Sep 18 14:42:26 2009 +0200
     1.3 @@ -20,13 +20,10 @@
     1.4  is mixed with.
     1.5  """
     1.6  
     1.7 -from viff.runtime import increment_pc
     1.8 -
     1.9  class ProbabilisticEqualityMixin:
    1.10      """This class implements probabilistic constant-round secure
    1.11      equality-testing of secret shared numbers."""
    1.12  
    1.13 -    @increment_pc
    1.14      def equal(self, share_x, share_y):
    1.15          """Equality testing with secret shared result.
    1.16  
     2.1 --- a/viff/passive.py	Fri Sep 18 14:41:44 2009 +0200
     2.2 +++ b/viff/passive.py	Fri Sep 18 14:42:26 2009 +0200
     2.3 @@ -22,7 +22,7 @@
     2.4  import operator
     2.5  
     2.6  from viff import shamir
     2.7 -from viff.runtime import Runtime, increment_pc, Share, ShareList, gather_shares
     2.8 +from viff.runtime import Runtime, Share, ShareList, gather_shares
     2.9  from viff.prss import prss, prss_lsb, prss_zero, prss_multi
    2.10  from viff.field import GF256, FieldElement
    2.11  from viff.util import rand, profile
    2.12 @@ -239,6 +239,18 @@
    2.13          else:
    2.14              return share_a + share_b - 2 * share_a * share_b
    2.15  
    2.16 +    def prss_key(self):
    2.17 +        """Create unique key for PRSS.
    2.18 +
    2.19 +        This increments the program counter and returns it as a tuple.
    2.20 +        Each straight-line program (typically a callback attached to
    2.21 +        some :class:`Deferred`) is executed in a context with unique
    2.22 +        starting program counter. This ensures that consequetive calls
    2.23 +        to PRSS-related methods will use unique program counters.
    2.24 +        """
    2.25 +        self.program_counter[-1] += 1
    2.26 +        return tuple(self.program_counter)
    2.27 +
    2.28      def prss_share(self, inputters, field, element=None):
    2.29          """Creates pseudo-random secret sharings.
    2.30  
    2.31 @@ -266,7 +278,7 @@
    2.32          n = self.num_players
    2.33  
    2.34          # Key used for PRSS.
    2.35 -        key = tuple(self.program_counter)
    2.36 +        key = self.prss_key()
    2.37  
    2.38          # The shares for which we have all the keys.
    2.39          all_shares = []
    2.40 @@ -307,7 +319,6 @@
    2.41          else:
    2.42              return result
    2.43  
    2.44 -    @increment_pc
    2.45      def prss_share_random(self, field, binary=False):
    2.46          """Generate shares of a uniformly random element from the field given.
    2.47  
    2.48 @@ -322,7 +333,7 @@
    2.49              modulus = field.modulus
    2.50  
    2.51          # Key used for PRSS.
    2.52 -        prss_key = tuple(self.program_counter)
    2.53 +        prss_key = self.prss_key()
    2.54          prfs = self.players[self.id].prfs(modulus)
    2.55          share = prss(self.num_players, self.id, field, prfs, prss_key)
    2.56  
    2.57 @@ -363,7 +374,7 @@
    2.58              modulus = field.modulus
    2.59  
    2.60          # Key used for PRSS.
    2.61 -        prss_key = tuple(self.program_counter)
    2.62 +        prss_key = self.prss_key()
    2.63          prfs = self.players[self.id].prfs(modulus ** quantity)
    2.64          shares = prss_multi(self.num_players, self.id, field, prfs, prss_key,
    2.65                              modulus, quantity)
    2.66 @@ -375,7 +386,7 @@
    2.67          Communication cost: none.
    2.68          """
    2.69          # Key used for PRSS.
    2.70 -        prss_key = tuple(self.program_counter)
    2.71 +        prss_key = self.prss_key()
    2.72          prfs = self.players[self.id].prfs(field.modulus)
    2.73          zero_share = prss_zero(self.num_players, self.threshold, self.id,
    2.74                                 field, prfs, prss_key)
    2.75 @@ -402,7 +413,7 @@
    2.76          n = self.num_players
    2.77          k = self.options.security_parameter
    2.78          prfs = self.players[self.id].prfs(2**k)
    2.79 -        prss_key = tuple(self.program_counter)
    2.80 +        prss_key = self.prss_key()
    2.81  
    2.82          b_p = self.prss_share_random(field, binary=True)
    2.83          r_p, r_lsb = prss_lsb(n, self.id, field, prfs, prss_key)
    2.84 @@ -420,7 +431,7 @@
    2.85          n = self.num_players
    2.86          k = self.options.security_parameter
    2.87          prfs = self.players[self.id].prfs(2**k)
    2.88 -        prss_key = tuple(self.program_counter)
    2.89 +        prss_key = self.prss_key()
    2.90          inputters = range(1, self.num_players + 1)
    2.91  
    2.92          ri = rand.randint(0, 2**k - 1)