changeset 1553:3105692a258f

BeDOZa: Added extra test cases.
author Thomas P Jakobsen <tpj@cs.au.dk>
date Mon, 27 Sep 2010 13:58:24 +0200
parents 00e4f1acc454
children bef695aa76bf
files viff/test/bedoza/test_bedoza_triple.py viff/test/bedoza/test_zero_knowledge.py
diffstat 2 files changed, 51 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/viff/test/bedoza/test_bedoza_triple.py	Mon Sep 27 11:00:54 2010 +0200
+++ b/viff/test/bedoza/test_bedoza_triple.py	Mon Sep 27 13:58:24 2010 +0200
@@ -91,6 +91,29 @@
         self.assertEquals(val, decrypted_val)
 
     @protocol
+    def test_modified_paillier_with_different_randomness_are_not_equal(self, runtime):
+        random = Random(3423434)
+        n = runtime.players[runtime.id].pubkey['n']
+        paillier = ModifiedPaillier(runtime, Random(random.getrandbits(128)))
+        val = 47
+        random_elm = random.randint(1, long(n))
+        encrypted_val_1 = paillier.encrypt(val, random_elm=random_elm)
+        encrypted_val_2 = paillier.encrypt(val, random_elm=random_elm)
+        self.assertEquals(encrypted_val_1, encrypted_val_2)
+
+    @protocol
+    def test_modified_paillier_with_same_randomness_are_equal(self, runtime):
+        random = Random(234333)
+        paillier = ModifiedPaillier(runtime, Random(random.getrandbits(128)))
+        n = runtime.players[runtime.id].pubkey['n']
+        val = 46
+        random_elm_1 = random.randint(1, long(n))
+        random_elm_2 = (random_elm_1 + 1) % n
+        encrypted_val_1 = paillier.encrypt(val, random_elm=random_elm_1)
+        encrypted_val_2 = paillier.encrypt(val, random_elm=random_elm_1)
+        self.assertEquals(encrypted_val_1, encrypted_val_2)
+
+    @protocol
     def test_modified_paillier_can_decrypt_encrypted_zero(self, runtime):
         paillier = ModifiedPaillier(runtime, Random(338301))
         val = 0
--- a/viff/test/bedoza/test_zero_knowledge.py	Mon Sep 27 11:00:54 2010 +0200
+++ b/viff/test/bedoza/test_zero_knowledge.py	Mon Sep 27 13:58:24 2010 +0200
@@ -52,6 +52,14 @@
         self.assertEquals([Zn(v) for v in [1, 2, 3, 8, 13, 12, 3, 5, 1]],
                           y_pow_E)
 
+    def test_vec_pow_is_correct_2(self):
+        s, Zn = 3, GF(17)
+        y = [Zn(i) for i in [1, 7, 2]]
+        zk = ZKProof(s, None, Zn, 0, None, None)
+        zk.e = [0, 1, 1]
+        y_pow_E = zk._vec_pow_E(y)
+        self.assertEquals([Zn(v) for v in [1, 1, 7, 14, 2]], y_pow_E)
+
     def test_vec_mul_E_is_correct(self):
         s, Zn = 5, GF(17)
         y = [Zn(i) for i in range(1, 6)]
@@ -61,6 +69,14 @@
         x_mul_E = zk._vec_mul_E(x)
         self.assertEquals([v for v in [1, 2, 1, 4, 2, 1, 1, 0, 0]], x_mul_E)
 
+    def test_vec_mul_E_is_correct_2(self):
+        s, Zn = 3, GF(17)
+        zk = ZKProof(s, None, Zn, 0, None, None)
+        zk.e = [0, 1, 1]
+        x = [2, -3, 0]
+        x_mul_E = zk._vec_mul_E(x)
+        self.assertEquals([v for v in [0, 2, -1, -3, 0]], x_mul_E)
+
     @protocol
     def test_broadcast(self, runtime):
         zk = ZKProof(0, 2, None, 0, runtime, None)
@@ -119,6 +135,18 @@
             rs.append(r)
             cs.append(c)
         return xs, rs, cs
+
+    def test_generate_Z_and_W_is_correct(self):
+        s, Zn = 3, GF(17)
+        zk = ZKProof(s, 1, Zn, 0, None, None)
+        zk.u = [1, -2, 0, 6, -3]
+        zk.v = [3, 5, 2, 1, 7]
+        zk.x = [2, -3, 0]
+        zk.r = [1, 7, 2]
+        zk.e = [0, 1, 1]
+        zk._generate_Z_and_W()
+        self.assertEquals([1, 0, -1, 3, -3], zk.Z)
+        self.assertEquals([3, 5, 14, 14, 14], zk.W)
             
 
 # TODO: Test succeeding proof.