changeset 1370:d93acdb61f34

Orlandi: Use NaCl Paillier, if available.
author Janus Dam Nielsen <janus.nielsen@alexandra.dk>
date Thu, 29 Oct 2009 13:46:21 +0100
parents 7115ba16f72a
children 62c4034a06a3
files viff/orlandi.py viff/test/test_orlandi_runtime.py viff/test/util.py
diffstat 3 files changed, 29 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/viff/orlandi.py	Thu Oct 29 13:46:21 2009 +0100
+++ b/viff/orlandi.py	Thu Oct 29 13:46:21 2009 +0100
@@ -28,6 +28,7 @@
 from hash_broadcast import HashBroadcastMixin
 
 try:
+    from pypaillier import encrypt_r, decrypt
     import commitment
     commitment.set_reference_string(23434347834783478783478L,
                                     489237823478234783478020L)
@@ -36,7 +37,10 @@
     # import to work. Catching the ImportError here allows the
     # benchmark and tests to import viff.orlandi without blowing up.
     # It is only if the OrlandiRuntime is used that things blow up.
-    pass
+
+    # The pypaillier module is not released yet, so we cannot expect
+    # the import to work.
+    from viff.paillier import encrypt_r, decrypt
 
 # import logging
 # LOG_FILENAME = 'logging_example.out'
--- a/viff/test/test_orlandi_runtime.py	Thu Oct 29 13:46:21 2009 +0100
+++ b/viff/test/test_orlandi_runtime.py	Thu Oct 29 13:46:21 2009 +0100
@@ -19,6 +19,9 @@
 
 from viff.test.util import RuntimeTestCase, protocol
 from viff.runtime import gather_shares, Share
+from viff.paillierutil import NaClPaillier
+from viff.config import generate_configs
+
 try:
     from viff.orlandi import OrlandiRuntime, OrlandiShare
     import commitment
@@ -255,6 +258,9 @@
         return d
 
 
+keys = None
+
+
 class OrlandiAdvancedCommandsTest(RuntimeTestCase):
     """Test for advanced commands."""
 
@@ -263,7 +269,14 @@
 
     runtime_class = OrlandiRuntime
 
-    timeout = 700
+    timeout = 25
+
+    def generate_configs(self, *args):
+        global keys
+        if not keys:
+            keys = generate_configs(*args, paillier=NaClPaillier(1024))
+        return keys
+        
 
     @protocol
     def test_shift(self, runtime):
@@ -623,6 +636,12 @@
 
     timeout = 1600
 
+    def generate_configs(self, *args):
+        global keys
+        if not keys:
+            keys = generate_configs(*args, paillier=NaClPaillier(1024))
+        return keys
+
     @protocol
     def test_tripleGen(self, runtime):
         """Test the triple_gen command."""
--- a/viff/test/util.py	Thu Oct 29 13:46:21 2009 +0100
+++ b/viff/test/util.py	Thu Oct 29 13:46:21 2009 +0100
@@ -111,6 +111,9 @@
             msg = "Type should be %s, but is %s" % (wanted_type, var.__class__)
             raise self.failureException(msg)
 
+    def generate_configs(self, *args):
+        return generate_configs(*args)
+
     def setUp(self):
         """Configure and connect three Runtimes.
 
@@ -123,7 +126,7 @@
         # Our standard 65 bit Blum prime
         self.Zp = GF(30916444023318367583)
 
-        configs = generate_configs(self.num_players, self.threshold)
+        configs = self.generate_configs(self.num_players, self.threshold)
         self.protocols = {}
 
         # initialize the dictionary of random generators