viff

changeset 1452:b21e08471eb4

BeDOZa: Added a wrapper for lists of authentication codes.
author Janus Dam Nielsen <janus.nielsen@alexandra.dk>
date Tue, 06 Jul 2010 10:46:45 +0200
parents 25c57c4f6947
children 9e90b4355ef7
files viff/bedoza.py viff/test/test_bedoza_runtime.py
diffstat 2 files changed, 40 insertions(+), 4 deletions(-) [+]
line diff
     1.1 --- a/viff/bedoza.py	Mon Jul 05 15:46:31 2010 +0200
     1.2 +++ b/viff/bedoza.py	Tue Jul 06 10:46:45 2010 +0200
     1.3 @@ -66,6 +66,27 @@
     1.4  
     1.5      def __str__(self):
     1.6          return "(%s, %s)" % (self.alpha, str(self.keys))
     1.7 +
     1.8 +class BeDOZaMessageList(object):
     1.9 +
    1.10 +    def __init__(self, auth_codes):
    1.11 +        self.auth_codes = auth_codes
    1.12 +
    1.13 +    def __add__(self, other):
    1.14 +        """Addition."""
    1.15 +        auth_codes = []
    1.16 +        for c1, c2 in zip(self.auth_codes, other.auth_codes):
    1.17 +            auth_codes.append(c1 + c2)
    1.18 +        return BeDOZaMessageList(auth_codes)
    1.19 +
    1.20 +    def __eq__(self, other):
    1.21 +        return self.auth_codes == other.auth_codes
    1.22 +
    1.23 +    def __str__(self):
    1.24 +        return str(self.auth_codes)
    1.25 +
    1.26 +    def __repr__(self):
    1.27 +        return str(self)
    1.28      
    1.29  class RandomShareGenerator:
    1.30  
    1.31 @@ -96,7 +117,7 @@
    1.32          auth_codes = []
    1.33          for alpha, beta in keys:
    1.34              auth_codes.append(alpha * v + beta)
    1.35 -        return auth_codes
    1.36 +        return BeDOZaMessageList(auth_codes)
    1.37  
    1.38      def generate_keys(self):
    1.39          alpha, betas = self.get_keys()
    1.40 @@ -193,7 +214,7 @@
    1.41              pc = tuple(self.program_counter)
    1.42              for other_id in receivers:
    1.43                  self.protocols[other_id].sendShare(pc, xi)
    1.44 -                self.protocols[other_id].sendShare(pc, codes[other_id - 1])
    1.45 +                self.protocols[other_id].sendShare(pc, codes.auth_codes[other_id - 1])
    1.46              if self.id in receivers:
    1.47                  num_players = len(self.players.keys())
    1.48                  values = num_players * [None]
     2.1 --- a/viff/test/test_bedoza_runtime.py	Mon Jul 05 15:46:31 2010 +0200
     2.2 +++ b/viff/test/test_bedoza_runtime.py	Tue Jul 06 10:46:45 2010 +0200
     2.3 @@ -22,7 +22,7 @@
     2.4  from viff.test.util import RuntimeTestCase, protocol
     2.5  from viff.runtime import gather_shares, Share
     2.6  from viff.config import generate_configs
     2.7 -from viff.bedoza import BeDOZaRuntime, BeDOZaShare, BeDOZaKeyList
     2.8 +from viff.bedoza import BeDOZaRuntime, BeDOZaShare, BeDOZaKeyList, BeDOZaMessageList
     2.9  from viff.field import FieldElement, GF
    2.10  from viff.util import rand
    2.11  
    2.12 @@ -74,7 +74,7 @@
    2.13  
    2.14          for xid in runtime.players.keys():
    2.15              keys = map(lambda (alpha, akeys): (alpha, akeys[xid - 1]), runtime.keys.values())
    2.16 -            codes[xid-1] = runtime.authentication_codes(keys, v)
    2.17 +            codes[xid-1] = runtime.authentication_codes(keys, v).auth_codes
    2.18          
    2.19          if runtime.id == 1:
    2.20              my_codes = codes[0]
    2.21 @@ -92,6 +92,21 @@
    2.22              self.assertEquals(my_codes[1], self.Zp(12))
    2.23              self.assertEquals(my_codes[2], self.Zp(17))
    2.24  
    2.25 +    @protocol
    2.26 +    def test_messagelist(self, runtime):
    2.27 +        """Test loading of keys."""
    2.28 +
    2.29 +        Zp = GF(6277101735386680763835789423176059013767194773182842284081)
    2.30 +
    2.31 +        m1 = BeDOZaMessageList([Zp(2), Zp(34)])
    2.32 +        m2 = BeDOZaMessageList([Zp(11), Zp(4)])
    2.33 +        m3 = m1 + m2
    2.34 +        self.assertEquals(m3.auth_codes[0], 13)
    2.35 +        self.assertEquals(m3.auth_codes[1], 38)
    2.36 +        self.assertEquals(len(m3.auth_codes), 2)
    2.37 +        return m3
    2.38 +        
    2.39 +
    2.40  
    2.41  class BeDOZaBasicCommandsTest(RuntimeTestCase):
    2.42      """Test for basic commands."""