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 wrap: on
line diff
--- a/viff/bedoza.py	Mon Jul 05 15:46:31 2010 +0200
+++ b/viff/bedoza.py	Tue Jul 06 10:46:45 2010 +0200
@@ -66,6 +66,27 @@
 
     def __str__(self):
         return "(%s, %s)" % (self.alpha, str(self.keys))
+
+class BeDOZaMessageList(object):
+
+    def __init__(self, auth_codes):
+        self.auth_codes = auth_codes
+
+    def __add__(self, other):
+        """Addition."""
+        auth_codes = []
+        for c1, c2 in zip(self.auth_codes, other.auth_codes):
+            auth_codes.append(c1 + c2)
+        return BeDOZaMessageList(auth_codes)
+
+    def __eq__(self, other):
+        return self.auth_codes == other.auth_codes
+
+    def __str__(self):
+        return str(self.auth_codes)
+
+    def __repr__(self):
+        return str(self)
     
 class RandomShareGenerator:
 
@@ -96,7 +117,7 @@
         auth_codes = []
         for alpha, beta in keys:
             auth_codes.append(alpha * v + beta)
-        return auth_codes
+        return BeDOZaMessageList(auth_codes)
 
     def generate_keys(self):
         alpha, betas = self.get_keys()
@@ -193,7 +214,7 @@
             pc = tuple(self.program_counter)
             for other_id in receivers:
                 self.protocols[other_id].sendShare(pc, xi)
-                self.protocols[other_id].sendShare(pc, codes[other_id - 1])
+                self.protocols[other_id].sendShare(pc, codes.auth_codes[other_id - 1])
             if self.id in receivers:
                 num_players = len(self.players.keys())
                 values = num_players * [None]
--- a/viff/test/test_bedoza_runtime.py	Mon Jul 05 15:46:31 2010 +0200
+++ b/viff/test/test_bedoza_runtime.py	Tue Jul 06 10:46:45 2010 +0200
@@ -22,7 +22,7 @@
 from viff.test.util import RuntimeTestCase, protocol
 from viff.runtime import gather_shares, Share
 from viff.config import generate_configs
-from viff.bedoza import BeDOZaRuntime, BeDOZaShare, BeDOZaKeyList
+from viff.bedoza import BeDOZaRuntime, BeDOZaShare, BeDOZaKeyList, BeDOZaMessageList
 from viff.field import FieldElement, GF
 from viff.util import rand
 
@@ -74,7 +74,7 @@
 
         for xid in runtime.players.keys():
             keys = map(lambda (alpha, akeys): (alpha, akeys[xid - 1]), runtime.keys.values())
-            codes[xid-1] = runtime.authentication_codes(keys, v)
+            codes[xid-1] = runtime.authentication_codes(keys, v).auth_codes
         
         if runtime.id == 1:
             my_codes = codes[0]
@@ -92,6 +92,21 @@
             self.assertEquals(my_codes[1], self.Zp(12))
             self.assertEquals(my_codes[2], self.Zp(17))
 
+    @protocol
+    def test_messagelist(self, runtime):
+        """Test loading of keys."""
+
+        Zp = GF(6277101735386680763835789423176059013767194773182842284081)
+
+        m1 = BeDOZaMessageList([Zp(2), Zp(34)])
+        m2 = BeDOZaMessageList([Zp(11), Zp(4)])
+        m3 = m1 + m2
+        self.assertEquals(m3.auth_codes[0], 13)
+        self.assertEquals(m3.auth_codes[1], 38)
+        self.assertEquals(len(m3.auth_codes), 2)
+        return m3
+        
+
 
 class BeDOZaBasicCommandsTest(RuntimeTestCase):
     """Test for basic commands."""