viff

changeset 1201:0fb5d4da2f1e

Merged.
author Marcel Keller <mkeller@cs.au.dk>
date Fri, 17 Jul 2009 16:24:03 +0200
parents 5da110d6e5b2 7f1e95db5c6c
children 90e278d7a950
files viff/runtime.py
diffstat 10 files changed, 57 insertions(+), 16 deletions(-) [+]
line diff
     1.1 --- a/.hgignore	Thu Jul 16 12:25:22 2009 +0200
     1.2 +++ b/.hgignore	Fri Jul 17 16:24:03 2009 +0200
     1.3 @@ -18,6 +18,7 @@
     1.4  
     1.5  # Trial output directory.
     1.6  _trial_temp
     1.7 +dropin.cache
     1.8  
     1.9  # Benchmarking data.
    1.10  profile.data
     2.1 --- a/doc/unit-testing.txt	Thu Jul 16 12:25:22 2009 +0200
     2.2 +++ b/doc/unit-testing.txt	Fri Jul 17 16:24:03 2009 +0200
     2.3 @@ -45,10 +45,10 @@
     2.4  If it fails with an ImportError, then please double-check that your
     2.5  ``PYTHONPATH`` is setup correctly.
     2.6  
     2.7 -Now simply execute ``trial viff`` to run the unit tests. You should
     2.8 -get output similar to this::
     2.9 +Now simply execute ``trial --reactor viff viff`` to run the unit
    2.10 +tests. You should get output similar to this::
    2.11  
    2.12 -  % trial viff
    2.13 +  % trial --reactor viff viff
    2.14    Seeding random generator with random seed 4658
    2.15    Running 65 tests.
    2.16    viff.test.test_active_runtime
    2.17 @@ -149,6 +149,13 @@
    2.18  would be cluttered with long of traceback messages, making it
    2.19  difficult to notice new *unexpected* failures.
    2.20  
    2.21 +.. warning::
    2.22 +
    2.23 +   Always run ``trial`` with the ``--reactor viff`` arguments. This
    2.24 +   ensures that the tests are run with the special VIFF reactor. The
    2.25 +   tests currently cannot be run without this reactor, but we might
    2.26 +   lift this restriction in the future.
    2.27 +
    2.28  
    2.29  Writing Unit Tests
    2.30  ------------------
     3.1 --- a/setup.py	Thu Jul 16 12:25:22 2009 +0200
     3.2 +++ b/setup.py	Fri Jul 17 16:24:03 2009 +0200
     3.3 @@ -84,6 +84,7 @@
     3.4          ],
     3.5        license=viff.__license__,
     3.6        packages=['viff', 'viff.test', 'viff.libs'],
     3.7 +      package_data={'viff': ['../twisted/plugins/viff_reactor.py']},
     3.8        platforms=['any'],
     3.9        classifiers=[
    3.10          'Development Status :: 3 - Alpha',
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/twisted/plugins/viff_reactor.py	Fri Jul 17 16:24:03 2009 +0200
     4.3 @@ -0,0 +1,21 @@
     4.4 +# Copyright 2009 VIFF Development Team.
     4.5 +#
     4.6 +# This file is part of VIFF, the Virtual Ideal Functionality Framework.
     4.7 +#
     4.8 +# VIFF is free software: you can redistribute it and/or modify it
     4.9 +# under the terms of the GNU Lesser General Public License (LGPL) as
    4.10 +# published by the Free Software Foundation, either version 3 of the
    4.11 +# License, or (at your option) any later version.
    4.12 +#
    4.13 +# VIFF is distributed in the hope that it will be useful, but WITHOUT
    4.14 +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
    4.15 +# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
    4.16 +# Public License for more details.
    4.17 +#
    4.18 +# You should have received a copy of the GNU Lesser General Public
    4.19 +# License along with VIFF. If not, see <http://www.gnu.org/licenses/>.
    4.20 +
    4.21 +# This will register the VIFF reactor so that "trial --reactor viff"
    4.22 +# can install it.
    4.23 +from twisted.application.reactors import Reactor
    4.24 +viff = Reactor('viff', 'viff.reactor', 'The re-entrent VIFF reactor.')
     5.1 --- a/viff/paillier.py	Thu Jul 16 12:25:22 2009 +0200
     5.2 +++ b/viff/paillier.py	Fri Jul 17 16:24:03 2009 +0200
     5.3 @@ -56,6 +56,9 @@
     5.4  
     5.5  def encrypt(m, (n, g)):
     5.6      r = rand.randint(1, long(n))
     5.7 +    return encrypt_r(m, r, (n, g))
     5.8 +
     5.9 +def encrypt_r(m, r, (n, g)):
    5.10      nsq = n*n
    5.11      return (pow(g, m, nsq)*pow(r, n, nsq)) % nsq
    5.12  
     6.1 --- a/viff/passive.py	Thu Jul 16 12:25:22 2009 +0200
     6.2 +++ b/viff/passive.py	Fri Jul 17 16:24:03 2009 +0200
     6.3 @@ -19,6 +19,8 @@
     6.4  
     6.5  """Passively secure VIFF runtime."""
     6.6  
     6.7 +import operator
     6.8 +
     6.9  from viff import shamir
    6.10  from viff.runtime import Runtime, increment_pc, Share, ShareList, gather_shares
    6.11  from viff.prss import prss, prss_lsb, prss_zero, prss_multi
    6.12 @@ -163,8 +165,7 @@
    6.13              "Number of coefficients and shares should be equal."
    6.14  
    6.15          def computation(shares, coefficients):
    6.16 -            summands = [shares[i] * coefficients[i] for i in range(len(shares))]
    6.17 -            return reduce(lambda x, y: x + y, summands)
    6.18 +            return sum(map(operator.mul, shares, coefficients))
    6.19  
    6.20          result = gather_shares(shares)
    6.21          result.addCallback(computation, coefficients)
     7.1 --- a/viff/runtime.py	Thu Jul 16 12:25:22 2009 +0200
     7.2 +++ b/viff/runtime.py	Fri Jul 17 16:24:03 2009 +0200
     7.3 @@ -812,7 +812,7 @@
     7.4          """Put deferred and data into the queue if the ViffReactor is running. 
     7.5          Otherwise, just execute the callback."""
     7.6  
     7.7 -        if (self.using_viff_reactor):
     7.8 +        if self.using_viff_reactor:
     7.9              self.deferred_queue.append((deferred, data))
    7.10          else:
    7.11              deferred.callback(data)
    7.12 @@ -844,10 +844,10 @@
    7.13  
    7.14          # setting the number to n makes the reactor called 
    7.15          # only every n-th time
    7.16 -        if (self.activation_counter >= 2):
    7.17 +        if self.activation_counter >= 2:
    7.18              self.depth_counter += 1
    7.19  
    7.20 -            if (self.depth_counter > self.max_depth):
    7.21 +            if self.depth_counter > self.max_depth:
    7.22                  # Record the maximal depth reached.
    7.23                  self.max_depth = self.depth_counter
    7.24  
     8.1 --- a/viff/test/__init__.py	Thu Jul 16 12:25:22 2009 +0200
     8.2 +++ b/viff/test/__init__.py	Fri Jul 17 16:24:03 2009 +0200
     8.3 @@ -1,4 +1,4 @@
     8.4 -# Copyright 2007, 2008 VIFF Development Team.
     8.5 +# Copyright 2007, 2008, 2009 VIFF Development Team.
     8.6  #
     8.7  # This file is part of VIFF, the Virtual Ideal Functionality Framework.
     8.8  #
     8.9 @@ -14,6 +14,3 @@
    8.10  #
    8.11  # You should have received a copy of the GNU Lesser General Public
    8.12  # License along with VIFF. If not, see <http://www.gnu.org/licenses/>.
    8.13 -
    8.14 -import viff.reactor
    8.15 -viff.reactor.install()
     9.1 --- a/viff/test/test_signed_field.py	Thu Jul 16 12:25:22 2009 +0200
     9.2 +++ b/viff/test/test_signed_field.py	Fri Jul 17 16:24:03 2009 +0200
     9.3 @@ -15,9 +15,6 @@
     9.4  # You should have received a copy of the GNU Lesser General Public
     9.5  # License along with VIFF. If not, see <http://www.gnu.org/licenses/>.
     9.6  
     9.7 -# Import system packages.
     9.8 -import sys
     9.9 -
    9.10  from twisted.trial.unittest import TestCase
    9.11  
    9.12  # Import VIFF packages.
    10.1 --- a/viff/test/util.py	Thu Jul 16 12:25:22 2009 +0200
    10.2 +++ b/viff/test/util.py	Fri Jul 17 16:24:03 2009 +0200
    10.3 @@ -111,7 +111,14 @@
    10.4              raise self.failureException(msg)
    10.5  
    10.6      def setUp(self):
    10.7 -        """Configure and connect three Runtimes."""
    10.8 +        """Configure and connect three Runtimes.
    10.9 +
   10.10 +        .. warning::
   10.11 +        
   10.12 +           Subclasses that override this method *must* remember to do
   10.13 +           a super-call to it. Otherwise the runtimes wont be
   10.14 +           connected and :meth:`tearDown` wont work.
   10.15 +        """
   10.16          # Our standard 65 bit Blum prime
   10.17          self.Zp = GF(30916444023318367583)
   10.18  
   10.19 @@ -141,6 +148,12 @@
   10.20          interrupted by a C{TimeoutError}, and so we do it here in all
   10.21          cases to avoid leaving scheduled calls lying around in the
   10.22          reactor.
   10.23 +
   10.24 +        .. warning::
   10.25 +        
   10.26 +           Subclasses that override this method *must* remember to do
   10.27 +           a super-call to it. Otherwise the runtimes wont be
   10.28 +           disconnected and your test case will hang.
   10.29          """
   10.30          for protocol in self.protocols.itervalues():
   10.31              protocol.transport.close()