viff

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 diff
     1.1 --- a/viff/orlandi.py	Thu Oct 29 13:46:21 2009 +0100
     1.2 +++ b/viff/orlandi.py	Thu Oct 29 13:46:21 2009 +0100
     1.3 @@ -28,6 +28,7 @@
     1.4  from hash_broadcast import HashBroadcastMixin
     1.5  
     1.6  try:
     1.7 +    from pypaillier import encrypt_r, decrypt
     1.8      import commitment
     1.9      commitment.set_reference_string(23434347834783478783478L,
    1.10                                      489237823478234783478020L)
    1.11 @@ -36,7 +37,10 @@
    1.12      # import to work. Catching the ImportError here allows the
    1.13      # benchmark and tests to import viff.orlandi without blowing up.
    1.14      # It is only if the OrlandiRuntime is used that things blow up.
    1.15 -    pass
    1.16 +
    1.17 +    # The pypaillier module is not released yet, so we cannot expect
    1.18 +    # the import to work.
    1.19 +    from viff.paillier import encrypt_r, decrypt
    1.20  
    1.21  # import logging
    1.22  # LOG_FILENAME = 'logging_example.out'
     2.1 --- a/viff/test/test_orlandi_runtime.py	Thu Oct 29 13:46:21 2009 +0100
     2.2 +++ b/viff/test/test_orlandi_runtime.py	Thu Oct 29 13:46:21 2009 +0100
     2.3 @@ -19,6 +19,9 @@
     2.4  
     2.5  from viff.test.util import RuntimeTestCase, protocol
     2.6  from viff.runtime import gather_shares, Share
     2.7 +from viff.paillierutil import NaClPaillier
     2.8 +from viff.config import generate_configs
     2.9 +
    2.10  try:
    2.11      from viff.orlandi import OrlandiRuntime, OrlandiShare
    2.12      import commitment
    2.13 @@ -255,6 +258,9 @@
    2.14          return d
    2.15  
    2.16  
    2.17 +keys = None
    2.18 +
    2.19 +
    2.20  class OrlandiAdvancedCommandsTest(RuntimeTestCase):
    2.21      """Test for advanced commands."""
    2.22  
    2.23 @@ -263,7 +269,14 @@
    2.24  
    2.25      runtime_class = OrlandiRuntime
    2.26  
    2.27 -    timeout = 700
    2.28 +    timeout = 25
    2.29 +
    2.30 +    def generate_configs(self, *args):
    2.31 +        global keys
    2.32 +        if not keys:
    2.33 +            keys = generate_configs(*args, paillier=NaClPaillier(1024))
    2.34 +        return keys
    2.35 +        
    2.36  
    2.37      @protocol
    2.38      def test_shift(self, runtime):
    2.39 @@ -623,6 +636,12 @@
    2.40  
    2.41      timeout = 1600
    2.42  
    2.43 +    def generate_configs(self, *args):
    2.44 +        global keys
    2.45 +        if not keys:
    2.46 +            keys = generate_configs(*args, paillier=NaClPaillier(1024))
    2.47 +        return keys
    2.48 +
    2.49      @protocol
    2.50      def test_tripleGen(self, runtime):
    2.51          """Test the triple_gen command."""
     3.1 --- a/viff/test/util.py	Thu Oct 29 13:46:21 2009 +0100
     3.2 +++ b/viff/test/util.py	Thu Oct 29 13:46:21 2009 +0100
     3.3 @@ -111,6 +111,9 @@
     3.4              msg = "Type should be %s, but is %s" % (wanted_type, var.__class__)
     3.5              raise self.failureException(msg)
     3.6  
     3.7 +    def generate_configs(self, *args):
     3.8 +        return generate_configs(*args)
     3.9 +
    3.10      def setUp(self):
    3.11          """Configure and connect three Runtimes.
    3.12  
    3.13 @@ -123,7 +126,7 @@
    3.14          # Our standard 65 bit Blum prime
    3.15          self.Zp = GF(30916444023318367583)
    3.16  
    3.17 -        configs = generate_configs(self.num_players, self.threshold)
    3.18 +        configs = self.generate_configs(self.num_players, self.threshold)
    3.19          self.protocols = {}
    3.20  
    3.21          # initialize the dictionary of random generators