changeset 1546:da966a4620f4

Updated mul and fullmul to reflect the new description.
author Janus Dam Nielsen Tue, 21 Sep 2010 11:42:36 +0200 8b1b64b3ea5b dae353266aa6 viff/bedoza/bedoza_triple.py viff/bedoza/share.py viff/test/test_bedoza_triple.py 3 files changed, 72 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
```--- a/viff/bedoza/bedoza_triple.py	Mon Sep 20 14:30:03 2010 +0200
+++ b/viff/bedoza/bedoza_triple.py	Tue Sep 21 11:42:36 2010 +0200
@@ -35,6 +35,8 @@
from viff.bedoza.modified_paillier import ModifiedPaillier
from viff.bedoza.util import fast_pow
+from viff.bedoza.util import _convolute
+from viff.bedoza.share import Share

from viff.triple import Triple

@@ -245,7 +247,7 @@
deferred = zis_deferred

return deferred
-
+
def _full_mul(self, a, b):
"""Multiply each of the PartialShares in the list *a* with the
corresponding PartialShare in the list *b*.
@@ -279,18 +281,25 @@
ais,
b_enc_shares[jnx]))

-            def compute_shares(list_of_list_of_field_elements, values, result_shares):
-                for field_elements in list_of_list_of_field_elements:
-                    for inx, field_element in enumerate(field_elements):
-                        values[inx] += field_element
+            def compute_shares(zils, values, result_shares):
+                for zil in zils:
+                    for inx, zi in enumerate(zil):
+                        values[inx] += zi

-                for v, s in zip(values, result_shares):
+                return values
+
+            d = gatherResults(deferreds)
+
+            def callBackPartialShareContents(partialShareContents, result_shares):
+                for v, s in zip(partialShareContents, result_shares):
s.callback(v)
return None
-            d = gatherResults(deferreds)
+
+            d.addCallback(lambda values: Share(values, self.runtime, self.paillier))
return d
-        result_shares = [Share(self.runtime, self.Zp) for x in a]
+        result_shares = [PartialShare(self.runtime, self.Zp) for _ in a]
self.runtime.schedule_callback(gatherResults(a + b),
do_full_mul,
result_shares)```
```--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/viff/bedoza/share.py	Tue Sep 21 11:42:36 2010 +0200
@@ -0,0 +1,53 @@
+# Copyright 2010 VIFF Development Team.
+#
+# This file is part of VIFF, the Virtual Ideal Functionality Framework.
+#
+# VIFF is free software: you can redistribute it and/or modify it
+# under the terms of the GNU Lesser General Public License (LGPL) as
+# published by the Free Software Foundation, either version 3 of the
+#
+# VIFF is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
+# Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+
+from viff.bedoza.shares import PartialShareContents
+from viff.bedoza.util import _convolute
+
+def Share(field_elements, runtime, paillier):
+    """Each party input a list of field elements *field_elements*.
+    The value of the field elements are encrypted and the encrypted
+    values are exchanged.
+
+    Returns a deferred, which yields a list of PartialShareContents.
+    """
+
+    runtime.increment_pc()
+
+    N_squared_list = [paillier.get_modulus_square(player_id)
+                      for player_id in runtime.players]
+
+    list_of_enc_shares = []
+    for field_element in field_elements:
+        list_of_enc_shares.append(paillier.encrypt(field_element.value))
+
+    list_of_enc_shares = _convolute(runtime, list_of_enc_shares, deserialize=eval)
+    def create_partial_share(list_of_enc_shares, field_elements):
+
+        reordered_encrypted_shares = [[] for _ in list_of_enc_shares[0]]
+        for enc_shares in list_of_enc_shares:
+            for inx, enc_share in enumerate(enc_shares):
+                reordered_encrypted_shares[inx].append(enc_share)
+
+        partialShareContents = []
+        for enc_shares, field_element in zip(reordered_encrypted_shares, field_elements):
+            partialShareContents.append(PartialShareContents(field_element, enc_shares, N_squared_list))
+        return partialShareContents
+
+    runtime.schedule_callback(list_of_enc_shares, create_partial_share, field_elements)
+    return list_of_enc_shares
+        ```
```--- a/viff/test/test_bedoza_triple.py	Mon Sep 20 14:30:03 2010 +0200
+++ b/viff/test/test_bedoza_triple.py	Tue Sep 21 11:42:36 2010 +0200
@@ -564,7 +564,7 @@
self.assertEquals(6, Zp(sum(ls[2])))
values = []
for share in shares:
-                value = _convolute(runtime, share.value)
+                value = _convolute(runtime, share.value.value)
values.append(value)
d = gatherResults(values)
runtime.schedule_callback(d, test_sum)```