changeset 1554:bef695aa76bf

BeDOZa: Fixed zero-knowledge proof.
author Thomas P Jakobsen <tpj@cs.au.dk>
date Mon, 27 Sep 2010 14:54:16 +0200
parents 3105692a258f
children 8c432745702b
files viff/bedoza/zero_knowledge.py viff/test/bedoza/test_zero_knowledge.py
diffstat 2 files changed, 27 insertions(+), 23 deletions(-) [+]
line wrap: on
line diff
--- a/viff/bedoza/zero_knowledge.py	Mon Sep 27 13:58:24 2010 +0200
+++ b/viff/bedoza/zero_knowledge.py	Mon Sep 27 14:54:16 2010 +0200
@@ -83,23 +83,20 @@
             #print 'x', len(self.x)
             #print 'e', len(self.e)
             #print 'u', len(self.u)
-            return
+            return True # TODO
         self._deserialize_proof(serialized_proof)
         self._generate_e()
-        q = self._vec_mul(self.d, self._vec_pow_E(self.c))
-        
-
-
+        S = self._vec_mul(self.d, self._vec_pow_E(self.c))
+        T = [self.paillier.encrypt(self.Z[j], player_id=self.prover_id, random_elm=self.W[j]) for j in range(self.m)]
         #print 'Z', len(self.Z)
         #print 'W', len(self.W)
         
-
         for j in xrange(self.m):
-            pass
-            #print
-            #print '---'
-            #print self.runtime.id,  self.paillier.encrypt_with_randomness(self.Z[j], self.W[j])[1]
-            #print self.runtime.id, q[j]
+            n = self.runtime.players[self.prover_id].pubkey['n']
+            print
+            print '---'
+            print self.runtime.id, j, S[j] % n
+            print self.runtime.id, j, T[j] % n
 
             # TODO: Verify!
 
@@ -113,9 +110,13 @@
             self.v.append(vi)
             self.d.append(di)
 
+
     def _generate_Z_and_W(self):
         self.Z = self._vec_add(self.u, self._vec_mul_E(self.x))
         self.W = self._vec_mul(self.v, self._vec_pow_E(self.r))
+
+        #n = self.runtime.players[self.runtime.id].pubkey['n']
+        #self.Z = [z % n for z in self.Z]
         
     def _get_proof_broadcasted_by_prover(self):
         serialized_proof = None
--- a/viff/test/bedoza/test_zero_knowledge.py	Mon Sep 27 13:58:24 2010 +0200
+++ b/viff/test/bedoza/test_zero_knowledge.py	Mon Sep 27 14:54:16 2010 +0200
@@ -86,17 +86,6 @@
         runtime.schedule_callback(res, verify)
         return res
 
-    @protocol
-    def test_proof(self, runtime):
-        k, s, random, Zn = 5, 5, Random(342344), GF(17)
-
-        paillier = ModifiedPaillier(runtime, Random(random.getrandbits(128)))
-        x, r, c = self._generate_test_ciphertexts(paillier, random, k, s)
-        zk = ZKProof(s, 1, Zn, k, runtime, c, paillier=paillier, random=random, x=x, r=r)
-        zk.e = [1, 0, 0, 1, 1]
-        deferred_proof = zk.start()
-        return deferred_proof
-
     def test_extract_bits(self):
         s = 5
         zk = ZKProof(s, None, None, 0, None, None)
@@ -147,7 +136,21 @@
         zk._generate_Z_and_W()
         self.assertEquals([1, 0, -1, 3, -3], zk.Z)
         self.assertEquals([3, 5, 14, 14, 14], zk.W)
-            
+
+    @protocol
+    def test_proof(self, runtime):
+        k, s, random, Zn = 3, 3, Random(342344 + runtime.id), GF(17)
+        prover_id = 1
+
+        paillier = ModifiedPaillier(runtime, Random(random.getrandbits(128)))
+        x, r, c = self._generate_test_ciphertexts(paillier, random, k, s)
+        if runtime.id == prover_id: 
+            zk = ZKProof(s, prover_id, Zn, k, runtime, c, paillier=paillier, random=random, x=x, r=r)
+        else:
+            zk = ZKProof(s, prover_id, Zn, k, runtime, c, paillier=paillier, random=random)
+
+        deferred_proof = zk.start()
+        return deferred_proof
 
 # TODO: Test succeeding proof.
 # TODO: Test failing proof.