viff

changeset 1501:522203844397

BeDOZa: Better incapsulation of internal representation for KeyList.
author Janus Dam Nielsen <janus.nielsen@alexandra.dk>
date Thu, 15 Jul 2010 11:37:49 +0200
parents 74ad8413cc11
children af533d7ae315
files viff/bedoza.py
diffstat 1 files changed, 21 insertions(+), 13 deletions(-) [+]
line diff
     1.1 --- a/viff/bedoza.py	Thu Jul 15 11:37:48 2010 +0200
     1.2 +++ b/viff/bedoza.py	Thu Jul 15 11:37:49 2010 +0200
     1.3 @@ -64,18 +64,18 @@
     1.4      def add_public(self, c, my_id):
     1.5          if my_id == 1:
     1.6              self.value = self.value + c
     1.7 -        self.keyList.get_keys()[0] = self.keyList.get_keys()[0] - self.keyList.alpha * c
     1.8 +        self.keyList.set_key(0, self.keyList.get_key(0) - self.keyList.alpha * c)
     1.9          return self
    1.10      
    1.11      def sub_public(self, c, my_id):
    1.12          if my_id == 1:
    1.13              self.value = self.value - c
    1.14 -        self.keyList.get_keys()[0] = self.keyList.get_keys()[0] + self.keyList.alpha * c
    1.15 +        self.keyList.set_key(0, self.keyList.get_key(0) + self.keyList.alpha * c)
    1.16          return self
    1.17  
    1.18      def cmul(self, c):
    1.19          zi = c * self.value
    1.20 -        zks = BeDOZaKeyList(self.keyList.alpha, map(lambda k: c * k, self.keyList.get_keys()))
    1.21 +        zks = self.keyList.cmul(c)
    1.22          zms = BeDOZaMACList(map(lambda m: c * m, self.macs.get_macs()))
    1.23          return BeDOZaShareContents(zi, zks, zms)
    1.24  
    1.25 @@ -106,13 +106,24 @@
    1.26          
    1.27  
    1.28  class BeDOZaKeyList(object):
    1.29 +    """A list of keys, one for each player.
    1.30 +
    1.31 +    We assume that the key for player *i* is stored in
    1.32 +    location *i - 1* in the *keys* list given as argument to the constructor.
    1.33 +    """
    1.34  
    1.35      def __init__(self, alpha, keys):
    1.36          self.alpha = alpha
    1.37          self.keys = keys
    1.38  
    1.39 -    def get_keys(self):
    1.40 -        return self.keys
    1.41 +    def get_key(self, player_id):
    1.42 +        return self.keys[player_id]
    1.43 +
    1.44 +    def set_key(self, player_id, v):
    1.45 +        self.keys[player_id] = v
    1.46 +
    1.47 +    def cmul(self, c):
    1.48 +        return BeDOZaKeyList(self.alpha, map(lambda k: c * k, self.keys))
    1.49  
    1.50      def __add__(self, other):
    1.51          """Addition."""
    1.52 @@ -264,10 +275,10 @@
    1.53              values = num_shares * [0]
    1.54              isOK = num_shares * [True]
    1.55              for iny in xrange(num_shares):
    1.56 -                keys = keyLists[iny].get_keys()
    1.57 +                keyList = keyLists[iny]
    1.58                  for inx, xs in enumerate(player_shares_codes):
    1.59                      xi, mi = xs[iny]
    1.60 -                    beta = keys[inx]
    1.61 +                    beta = keyList.get_key(inx)
    1.62                      values[iny] += xi
    1.63                      mi_prime = self.MAC(alpha, beta, xi)
    1.64                      isOK[iny] = isOK[iny] and mi == mi_prime
    1.65 @@ -341,9 +352,7 @@
    1.66  
    1.67              n = len(self.players)
    1.68              alpha_a = keyList_a.alpha
    1.69 -            keys_a = keyList_a.get_keys()
    1.70              alpha_b = keyList_b.alpha
    1.71 -            keys_b = keyList_b.get_keys()
    1.72  
    1.73              a = 0
    1.74              b = 0
    1.75 @@ -353,8 +362,8 @@
    1.76                  bi = shares_codes[2*n + inx]
    1.77                  mi_a = shares_codes[n + inx]
    1.78                  mi_b = shares_codes[3*n + inx]
    1.79 -                beta_a = keys_a[inx]
    1.80 -                beta_b = keys_b[inx]
    1.81 +                beta_a = keyList_a.get_key(inx)
    1.82 +                beta_b = keyList_b.get_key(inx)
    1.83                  a += ai
    1.84                  b += bi
    1.85                  mi_prime = self.MAC(alpha_a, beta_a, ai)
    1.86 @@ -417,12 +426,11 @@
    1.87              isOK = True
    1.88              n = len(self.players)
    1.89              alpha = keyList.alpha
    1.90 -            keys = keyList.get_keys()
    1.91              x = 0
    1.92              for inx in xrange(0, n):
    1.93                  xi = shares_codes[inx]
    1.94                  mi = shares_codes[n + inx]
    1.95 -                beta = keys[inx]
    1.96 +                beta = keyList.get_key(inx)
    1.97                  x += xi
    1.98                  mi_prime = self.MAC(alpha, beta, xi)
    1.99                  isOK = isOK and mi == mi_prime