viff

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 diff
     1.1 --- a/viff/test/bedoza/test_bedoza_triple.py	Mon Sep 27 11:00:54 2010 +0200
     1.2 +++ b/viff/test/bedoza/test_bedoza_triple.py	Mon Sep 27 13:58:24 2010 +0200
     1.3 @@ -91,6 +91,29 @@
     1.4          self.assertEquals(val, decrypted_val)
     1.5  
     1.6      @protocol
     1.7 +    def test_modified_paillier_with_different_randomness_are_not_equal(self, runtime):
     1.8 +        random = Random(3423434)
     1.9 +        n = runtime.players[runtime.id].pubkey['n']
    1.10 +        paillier = ModifiedPaillier(runtime, Random(random.getrandbits(128)))
    1.11 +        val = 47
    1.12 +        random_elm = random.randint(1, long(n))
    1.13 +        encrypted_val_1 = paillier.encrypt(val, random_elm=random_elm)
    1.14 +        encrypted_val_2 = paillier.encrypt(val, random_elm=random_elm)
    1.15 +        self.assertEquals(encrypted_val_1, encrypted_val_2)
    1.16 +
    1.17 +    @protocol
    1.18 +    def test_modified_paillier_with_same_randomness_are_equal(self, runtime):
    1.19 +        random = Random(234333)
    1.20 +        paillier = ModifiedPaillier(runtime, Random(random.getrandbits(128)))
    1.21 +        n = runtime.players[runtime.id].pubkey['n']
    1.22 +        val = 46
    1.23 +        random_elm_1 = random.randint(1, long(n))
    1.24 +        random_elm_2 = (random_elm_1 + 1) % n
    1.25 +        encrypted_val_1 = paillier.encrypt(val, random_elm=random_elm_1)
    1.26 +        encrypted_val_2 = paillier.encrypt(val, random_elm=random_elm_1)
    1.27 +        self.assertEquals(encrypted_val_1, encrypted_val_2)
    1.28 +
    1.29 +    @protocol
    1.30      def test_modified_paillier_can_decrypt_encrypted_zero(self, runtime):
    1.31          paillier = ModifiedPaillier(runtime, Random(338301))
    1.32          val = 0
     2.1 --- a/viff/test/bedoza/test_zero_knowledge.py	Mon Sep 27 11:00:54 2010 +0200
     2.2 +++ b/viff/test/bedoza/test_zero_knowledge.py	Mon Sep 27 13:58:24 2010 +0200
     2.3 @@ -52,6 +52,14 @@
     2.4          self.assertEquals([Zn(v) for v in [1, 2, 3, 8, 13, 12, 3, 5, 1]],
     2.5                            y_pow_E)
     2.6  
     2.7 +    def test_vec_pow_is_correct_2(self):
     2.8 +        s, Zn = 3, GF(17)
     2.9 +        y = [Zn(i) for i in [1, 7, 2]]
    2.10 +        zk = ZKProof(s, None, Zn, 0, None, None)
    2.11 +        zk.e = [0, 1, 1]
    2.12 +        y_pow_E = zk._vec_pow_E(y)
    2.13 +        self.assertEquals([Zn(v) for v in [1, 1, 7, 14, 2]], y_pow_E)
    2.14 +
    2.15      def test_vec_mul_E_is_correct(self):
    2.16          s, Zn = 5, GF(17)
    2.17          y = [Zn(i) for i in range(1, 6)]
    2.18 @@ -61,6 +69,14 @@
    2.19          x_mul_E = zk._vec_mul_E(x)
    2.20          self.assertEquals([v for v in [1, 2, 1, 4, 2, 1, 1, 0, 0]], x_mul_E)
    2.21  
    2.22 +    def test_vec_mul_E_is_correct_2(self):
    2.23 +        s, Zn = 3, GF(17)
    2.24 +        zk = ZKProof(s, None, Zn, 0, None, None)
    2.25 +        zk.e = [0, 1, 1]
    2.26 +        x = [2, -3, 0]
    2.27 +        x_mul_E = zk._vec_mul_E(x)
    2.28 +        self.assertEquals([v for v in [0, 2, -1, -3, 0]], x_mul_E)
    2.29 +
    2.30      @protocol
    2.31      def test_broadcast(self, runtime):
    2.32          zk = ZKProof(0, 2, None, 0, runtime, None)
    2.33 @@ -119,6 +135,18 @@
    2.34              rs.append(r)
    2.35              cs.append(c)
    2.36          return xs, rs, cs
    2.37 +
    2.38 +    def test_generate_Z_and_W_is_correct(self):
    2.39 +        s, Zn = 3, GF(17)
    2.40 +        zk = ZKProof(s, 1, Zn, 0, None, None)
    2.41 +        zk.u = [1, -2, 0, 6, -3]
    2.42 +        zk.v = [3, 5, 2, 1, 7]
    2.43 +        zk.x = [2, -3, 0]
    2.44 +        zk.r = [1, 7, 2]
    2.45 +        zk.e = [0, 1, 1]
    2.46 +        zk._generate_Z_and_W()
    2.47 +        self.assertEquals([1, 0, -1, 3, -3], zk.Z)
    2.48 +        self.assertEquals([3, 5, 14, 14, 14], zk.W)
    2.49              
    2.50  
    2.51  # TODO: Test succeeding proof.