viff

changeset 1486:6b448315eedf

BeDOZa: Merged KeyLoader and RandomShareGenerator.
author Janus Dam Nielsen <janus.nielsen@alexandra.dk>
date Mon, 12 Jul 2010 11:31:50 +0200
parents 0e1f9275e7ac
children c6f29ad5c91e
files viff/bedoza.py viff/test/test_bedoza_runtime.py
diffstat 2 files changed, 19 insertions(+), 30 deletions(-) [+]
line diff
     1.1 --- a/viff/bedoza.py	Mon Jul 12 11:02:14 2010 +0200
     1.2 +++ b/viff/bedoza.py	Mon Jul 12 11:31:50 2010 +0200
     1.3 @@ -116,6 +116,7 @@
     1.4  class RandomShareGenerator:
     1.5  
     1.6      def generate_random_shares(self, field, number_of_shares):
     1.7 +        self.init_keys(field)
     1.8          shares = []
     1.9          for i in xrange(0, number_of_shares):
    1.10              if self.id == 1:
    1.11 @@ -130,8 +131,8 @@
    1.12          return shares
    1.13  
    1.14      def generate_share(self, field, value):
    1.15 +        my_keys = self.generate_keys(field)
    1.16          auth_codes = self.generate_auth_codes(self.id, value)
    1.17 -        my_keys = self.generate_keys()
    1.18          return BeDOZaShare(self, field, value, my_keys, auth_codes)
    1.19  
    1.20      def generate_auth_codes(self, playerId, value):
    1.21 @@ -145,18 +146,19 @@
    1.22              auth_codes.append(alpha * v + beta)
    1.23          return BeDOZaMessageList(auth_codes)
    1.24  
    1.25 -    def generate_keys(self):
    1.26 +    def generate_keys(self, field):
    1.27          alpha, betas = self.get_keys()
    1.28          return BeDOZaKeyList(alpha, betas)
    1.29  
    1.30 -class KeyLoader:
    1.31 +    def init_keys(self, field):
    1.32 +        self.keys = {1: (field(2), [field(1), field(2), field(3)]),
    1.33 +                     2: (field(3), [field(4), field(5), field(6)]),
    1.34 +                     3: (field(4), [field(7), field(8), field(9)])}
    1.35  
    1.36 -    def load_keys(self, field):
    1.37 -        return {1: (field(2), [field(1), field(2), field(3)]),
    1.38 -                2: (field(3), [field(4), field(5), field(6)]),
    1.39 -                3: (field(4), [field(7), field(8), field(9)])}
    1.40 +    def get_keys(self):   
    1.41 +        return self.keys[self.id]
    1.42  
    1.43 -class BeDOZaRuntime(SimpleArithmetic, Runtime, HashBroadcastMixin, KeyLoader, RandomShareGenerator):
    1.44 +class BeDOZaRuntime(SimpleArithmetic, Runtime, HashBroadcastMixin, RandomShareGenerator):
    1.45      """The BeDOZa runtime.
    1.46  
    1.47      The runtime is used for sharing values (:meth:`secret_share` or
    1.48 @@ -191,7 +193,6 @@
    1.49  
    1.50          If no more shares are left, generate self.random_share_number new ones.
    1.51          """
    1.52 -        self.keys = self.load_keys(field)
    1.53          if len(self.random_shares) == 0:
    1.54              self.random_shares = self.generate_random_shares(field, self.random_share_number)
    1.55  
    1.56 @@ -432,14 +433,6 @@
    1.57          if self.id in receivers:
    1.58              return result
    1.59  
    1.60 -    def get_keys(self):
    1.61 -        if self.id == 1:
    1.62 -            return self.keys[1]
    1.63 -        if self.id == 2:
    1.64 -            return self.keys[2]
    1.65 -        if self.id == 3:
    1.66 -            return self.keys[3]
    1.67 -
    1.68      def _plus_public(self, x, c, field):
    1.69          (xi, xks, xms) = x
    1.70          if self.id == 1:
    1.71 @@ -507,6 +500,7 @@
    1.72          return (zi, zks, zms)
    1.73  
    1.74      def _get_triple(self, field):
    1.75 +        self.init_keys(field)
    1.76          a, b, c = 0, 0, 0
    1.77          share_a = field(2)
    1.78          share_b = field(4)
     2.1 --- a/viff/test/test_bedoza_runtime.py	Mon Jul 12 11:02:14 2010 +0200
     2.2 +++ b/viff/test/test_bedoza_runtime.py	Mon Jul 12 11:31:50 2010 +0200
     2.3 @@ -40,22 +40,20 @@
     2.4  
     2.5          self.Zp = GF(6277101735386680763835789423176059013767194773182842284081)
     2.6  
     2.7 -        keys = runtime.load_keys(self.Zp)
     2.8 -        keys1 = keys[1]
     2.9 -        keys2 = keys[2]
    2.10 -        keys3 = keys[3]
    2.11 +        runtime.init_keys(self.Zp)
    2.12 +        keys = runtime.get_keys()
    2.13          if runtime.id == 1:
    2.14 -            betas = keys1[1]
    2.15 +            betas = keys[1]
    2.16              self.assertEquals(betas[0], 1)
    2.17              self.assertEquals(betas[1], 2)
    2.18              self.assertEquals(betas[2], 3)
    2.19          if runtime.id == 2:
    2.20 -            betas = keys2[1]
    2.21 +            betas = keys[1]
    2.22              self.assertEquals(betas[0], 4)
    2.23              self.assertEquals(betas[1], 5)
    2.24              self.assertEquals(betas[2], 6)
    2.25          if runtime.id == 3:
    2.26 -            betas = keys3[1]
    2.27 +            betas = keys[1]
    2.28              self.assertEquals(betas[0], 7)
    2.29              self.assertEquals(betas[1], 8)
    2.30              self.assertEquals(betas[2], 9)
    2.31 @@ -66,10 +64,9 @@
    2.32  
    2.33          self.Zp = GF(6277101735386680763835789423176059013767194773182842284081)
    2.34  
    2.35 -        runtime.keys = runtime.load_keys(self.Zp)
    2.36 -
    2.37          v = self.Zp(2)
    2.38 -        alpha = runtime.get_keys()[0]
    2.39 +        runtime.init_keys(self.Zp)
    2.40 +        alpha, betas = runtime.get_keys()
    2.41          codes = self.num_players * [None]
    2.42  
    2.43          for xid in runtime.players.keys():
    2.44 @@ -337,9 +334,7 @@
    2.45          """Test generation of a triple."""
    2.46  
    2.47          self.Zp = GF(6277101735386680763835789423176059013767194773182842284081)
    2.48 -
    2.49 -        runtime.keys = runtime.load_keys(self.Zp)
    2.50 -        
    2.51 +      
    2.52          def check((a, b, c)):
    2.53              self.assertEquals(c, a * b)
    2.54