# HG changeset patch
# User Janus Dam Nielsen <janus.niel...@alexandra.dk>
# Date 1245394852 -7200
# Node ID 1eb98ef76446e9ef06d8d94e31748fe5cfd2ba82
# Parent  29c28d1a8e5f5647fe97d7b01f5924f3ef006301
Implementation of random share command.

diff --git a/viff/orlandi.py b/viff/orlandi.py
--- a/viff/orlandi.py
+++ b/viff/orlandi.py
@@ -270,6 +270,52 @@
         if self.id in receivers:
             return result
 
+    @increment_pc
+    def random_share(self, field):
+        """Generate a random share in the field, field.
+
+        To generate a share of a random element r in Z_{p}, party P_{i} 
+        chooses at random r_{i}, rho_{r,i} in Z_{p} x (Z_{p})^2 and
+        broadcast C_{r}^{i} = Com_{ck}(r_{i}, rho_{r, i}).
+        Every party computes C_{r} = PRODUCT_{i=1}^{n} C_{r}^{i} = Com_{ck}(r, 
rho_{r}),
+        where r_{i} = SUM_{i=1}^{n} r_{i} and rho_{r} = SUM_{i=1}^{n} 
rho_{r,i}.
+
+        Party P_{i} sets [r]_{i} = (r_{i}, rho_{r,i}, C_{r}).
+
+        """
+        # P_{i} chooses at random r_{i}, rho_{r,i} in Z_{p} x (Z_{p})^2
+        ri = field(rand.randint(0, field.modulus - 1))     
+        rhoi1 = field(rand.randint(0, field.modulus - 1))
+        rhoi2 = field(rand.randint(0, field.modulus - 1))
+        # compute C_{r}^{i} = Com_{ck}(r_{i}, rho_{r, i}).
+        Cri = self._Com(ri, (rhoi1, rhoi2))
+        # Broadcast C_{r}^{i}.
+        shares = []
+        for peer_id in self.players:
+            if peer_id == self.id:
+                # Broadcast C_{r}^{i}
+                d = Share(self, field, Cri)
+            else:
+                # Recieve C_{r}^{i}
+                pc = tuple(self.program_counter)
+                self.protocols[peer_id].sendShare(pc, Cri)
+                d = self._expect_share(peer_id, field)
+            shares.append(d)
+
+        def compute_commitment(ls):
+            Cr = field(1)
+            for s, v in ls:
+                Cr *= v
+            return OrlandiShare(self, field, ri, (rhoi1, rhoi2), Cr)
+
+        sls = ShareList(shares)
+        sls.addCallbacks(compute_commitment, self.error_handler)
+
+        # do actual communication
+        self.activate_reactor()
+
+        return sls
+
     def error_handler(self, ex):
         print "Error: ", ex
         return ex
diff --git a/viff/test/test_orlandi_runtime.py 
b/viff/test/test_orlandi_runtime.py
--- a/viff/test/test_orlandi_runtime.py
+++ b/viff/test/test_orlandi_runtime.py
@@ -65,3 +65,16 @@
         d.addCallback(check)
         return d
 
+    @protocol
+    def test_random_share(self, runtime):
+        """Test creation of a random shared number."""
+
+        def check(v):
+            self.assertEquals(True, True)
+        
+        x = runtime.random_share(self.Zp)
+        d = runtime.open(x)
+        d.addCallback(check)
+        return d
+
+
_______________________________________________
viff-devel mailing list (http://viff.dk/)
viff-devel@viff.dk
http://lists.viff.dk/listinfo.cgi/viff-devel-viff.dk

Reply via email to