viff

changeset 1286:ba17bb67e477

Merged with Martin.
author Janus Dam Nielsen <janus.nielsen@alexandra.dk>
date Fri, 16 Oct 2009 16:10:30 +0200
parents 225b81fa2d1d 513ad56cd8cc
children efbdd4fce829
files
diffstat 2 files changed, 16 insertions(+), 65 deletions(-) [+]
line diff
     1.1 --- a/viff/hash_broadcast.py	Fri Oct 16 15:59:06 2009 +0200
     1.2 +++ b/viff/hash_broadcast.py	Fri Oct 16 16:10:30 2009 +0200
     1.3 @@ -19,7 +19,10 @@
     1.4  
     1.5  from twisted.internet.defer import gatherResults, Deferred, DeferredList
     1.6  
     1.7 -from hashlib import sha1
     1.8 +try:
     1.9 +    from hashlib import sha1
    1.10 +except ImportError:
    1.11 +    from sha import sha as sha1
    1.12  from viff.constants import TEXT, INCONSISTENTHASH, OK, HASH, SIGNAL
    1.13  
    1.14  error_msg = "Player %i, has received an inconsistent hash %s."
     2.1 --- a/viff/test/test_orlandi_runtime.py	Fri Oct 16 15:59:06 2009 +0200
     2.2 +++ b/viff/test/test_orlandi_runtime.py	Fri Oct 16 16:10:30 2009 +0200
     2.3 @@ -19,15 +19,19 @@
     2.4  
     2.5  from viff.test.util import RuntimeTestCase, protocol, BinaryOperatorTestCase
     2.6  from viff.runtime import Share, gather_shares
     2.7 -from viff.orlandi import OrlandiRuntime, OrlandiShare
     2.8 +try:
     2.9 +    from viff.orlandi import OrlandiRuntime, OrlandiShare
    2.10 +    import commitment
    2.11 +except ImportError:
    2.12 +    commitment = None
    2.13 +    OrlandiRuntime = None
    2.14 +    OrlandiShare = None
    2.15  
    2.16  from viff.field import FieldElement, GF
    2.17  from viff.passive import PassiveRuntime
    2.18  
    2.19  from viff.util import rand
    2.20  
    2.21 -# import commitment
    2.22 -
    2.23  
    2.24  def _get_triple(runtime, field):
    2.25      n = field(0)
    2.26 @@ -68,8 +72,6 @@
    2.27          share.addCallback(check)
    2.28          return share
    2.29  
    2.30 -    test_secret_share.skip = "Commitment module is not included in VIFF."
    2.31 -
    2.32      @protocol
    2.33      def test_open_secret_share(self, runtime):
    2.34          """Test sharing and open of a number."""
    2.35 @@ -87,8 +89,6 @@
    2.36          d.addCallback(check)
    2.37          return d
    2.38  
    2.39 -    test_open_secret_share.skip = "Commitment module is not included in VIFF."
    2.40 -
    2.41      @protocol
    2.42      def test_random_share(self, runtime):
    2.43          """Test creation of a random shared number."""
    2.44 @@ -103,8 +103,6 @@
    2.45          d.addCallback(check)
    2.46          return d
    2.47   
    2.48 -    test_random_share.skip = "Commitment module is not included in VIFF."
    2.49 -
    2.50      @protocol
    2.51      def test_sum(self, runtime):
    2.52          """Test addition of two numbers."""
    2.53 @@ -132,8 +130,6 @@
    2.54          d.addCallback(check)
    2.55          return d
    2.56  
    2.57 -    test_sum.skip = "Commitment module is not included in VIFF."
    2.58 -
    2.59      @protocol
    2.60      def test_sum_plus(self, runtime):
    2.61          """Test addition of two numbers."""
    2.62 @@ -161,8 +157,6 @@
    2.63          d.addCallback(check)
    2.64          return d
    2.65  
    2.66 -    test_sum_plus.skip = "Commitment module is not included in VIFF."
    2.67 -
    2.68      @protocol
    2.69      def test_sum_constant(self, runtime):
    2.70          """Test addition of two numbers."""
    2.71 @@ -185,8 +179,6 @@
    2.72          d.addCallback(check)
    2.73          return d
    2.74  
    2.75 -    test_sum_constant.skip = "Commitment module is not included in VIFF."
    2.76 -
    2.77      @protocol
    2.78      def test_sub(self, runtime):
    2.79          """Test subtration of two numbers."""
    2.80 @@ -214,8 +206,6 @@
    2.81          d.addCallback(check)
    2.82          return d
    2.83  
    2.84 -    test_sub.skip = "Commitment module is not included in VIFF."
    2.85 -
    2.86      @protocol
    2.87      def test_sub_minus(self, runtime):
    2.88          """Test subtration of two numbers."""
    2.89 @@ -243,8 +233,6 @@
    2.90          d.addCallback(check)
    2.91          return d
    2.92  
    2.93 -    test_sub_minus.skip = "Commitment module is not included in VIFF."
    2.94 -
    2.95      @protocol
    2.96      def test_sub_constant(self, runtime):
    2.97          """Test subtration of two numbers."""
    2.98 @@ -267,7 +255,6 @@
    2.99          d.addCallback(check)
   2.100          return d
   2.101  
   2.102 -    test_sub_constant.skip = "Commitment module is not included in VIFF."
   2.103  
   2.104  class OrlandiAdvancedCommandsTest(RuntimeTestCase):
   2.105      """Test for advanced commands."""
   2.106 @@ -293,8 +280,6 @@
   2.107          d.addCallback(check)
   2.108          return d
   2.109  
   2.110 -    test_shift.skip = "Commitment module is not included in VIFF."
   2.111 -
   2.112      @protocol
   2.113      def test_shift_two_inputters(self, runtime):
   2.114          """Test addition of the shift command."""
   2.115 @@ -311,8 +296,6 @@
   2.116          d2.addCallback(check)
   2.117          return DeferredList([d1, d2])
   2.118  
   2.119 -    test_shift_two_inputters.skip = "Commitment module is not included in VIFF."
   2.120 -
   2.121      @protocol
   2.122      def test_shift_two_consequtive_inputters(self, runtime):
   2.123          """Test addition of the shift command."""
   2.124 @@ -329,8 +312,6 @@
   2.125          r.addCallback(r1)
   2.126          return r
   2.127  
   2.128 -    test_shift_two_consequtive_inputters.skip = "Commitment module is not included in VIFF."
   2.129 -
   2.130      @protocol
   2.131      def test_shift_two_consequtive_inputters2(self, runtime):
   2.132          """Test addition of the shift command."""
   2.133 @@ -350,8 +331,6 @@
   2.134          r.addCallback(r1)
   2.135          return r
   2.136  
   2.137 -    test_shift_two_consequtive_inputters2.skip = "Commitment module is not included in VIFF."
   2.138 -
   2.139      @protocol
   2.140      def test_input(self, runtime):
   2.141          """Test of many uses of the input command."""
   2.142 @@ -374,8 +353,6 @@
   2.143          shares_ready = gather_shares(a_shares + b_shares)
   2.144          return shares_ready
   2.145  
   2.146 -    test_input.skip = "Commitment module is not included in VIFF."
   2.147 -
   2.148      @protocol
   2.149      def test_basic_multiply(self, runtime):
   2.150          """Test multiplication of two numbers."""
   2.151 @@ -397,8 +374,6 @@
   2.152          d.addCallback(check)
   2.153          return d
   2.154  
   2.155 -    test_basic_multiply.skip = "Commitment module is not included in VIFF."
   2.156 -
   2.157      @protocol
   2.158      def test_mul_mul(self, runtime):
   2.159          """Test multiplication of two numbers."""
   2.160 @@ -419,8 +394,6 @@
   2.161          d.addCallback(check)
   2.162          return d
   2.163  
   2.164 -    test_mul_mul.skip = "Commitment module is not included in VIFF."
   2.165 -
   2.166      @protocol
   2.167      def test_basic_multiply_constant_right(self, runtime):
   2.168          """Test multiplication of two numbers."""
   2.169 @@ -441,8 +414,6 @@
   2.170          d.addCallback(check)
   2.171          return d
   2.172  
   2.173 -    test_basic_multiply_constant_right.skip = "Commitment module is not included in VIFF."
   2.174 -
   2.175      @protocol
   2.176      def test_basic_multiply_constant_left(self, runtime):
   2.177          """Test multiplication of two numbers."""
   2.178 @@ -463,8 +434,6 @@
   2.179          d.addCallback(check)
   2.180          return d
   2.181  
   2.182 -    test_basic_multiply_constant_left.skip = "Commitment module is not included in VIFF."
   2.183 -
   2.184      @protocol
   2.185      def test_constant_multiplication_constant_left(self, runtime):
   2.186          """Test multiplication of two numbers."""
   2.187 @@ -484,8 +453,6 @@
   2.188          d.addCallback(check)
   2.189          return d
   2.190  
   2.191 -    test_constant_multiplication_constant_left.skip = "Commitment module is not included in VIFF."
   2.192 -
   2.193      @protocol
   2.194      def test_constant_multiplication_constant_right(self, runtime):
   2.195          """Test multiplication of two numbers."""
   2.196 @@ -505,8 +472,6 @@
   2.197          d.addCallback(check)
   2.198          return d
   2.199  
   2.200 -    test_constant_multiplication_constant_right.skip = "Commitment module is not included in VIFF."
   2.201 -
   2.202      @protocol
   2.203      def test_constant_multiplication_constant_None(self, runtime):
   2.204          """Test multiplication of two numbers."""
   2.205 @@ -519,8 +484,6 @@
   2.206          x2 = runtime.shift([1], self.Zp, x1)
   2.207          y2 = runtime.shift([1], self.Zp, y1)
   2.208  
   2.209 -    test_constant_multiplication_constant_None.skip = "Commitment module is not included in VIFF."
   2.210 -
   2.211      @protocol
   2.212      def test_sum_poly(self, runtime):
   2.213          """Test implementation of sum_poly."""
   2.214 @@ -539,8 +502,6 @@
   2.215          self.assertEquals(Cx, 29)
   2.216          return x
   2.217  
   2.218 -    test_sum_poly.skip = "Commitment module is not included in VIFF."
   2.219 - 
   2.220      @protocol
   2.221      def test_sum_poly(self, runtime):
   2.222          """Test implementation of sum_poly."""
   2.223 @@ -563,8 +524,6 @@
   2.224          self.assertEquals(Cx, Cf1**3 * Cf2**9 * Cf3**27)
   2.225          return x
   2.226  
   2.227 -    test_sum_poly.skip = "Commitment module is not included in VIFF."
   2.228 -
   2.229      @protocol
   2.230      def test_delta(self, runtime):
   2.231          """Test implementation of compute_delta."""
   2.232 @@ -582,8 +541,6 @@
   2.233   
   2.234          return delta
   2.235  
   2.236 -    test_delta.skip = "Commitment module is not included in VIFF."
   2.237 -
   2.238      @protocol
   2.239      def test_leak_mul(self, runtime):
   2.240          """Test leaktolerant multiplication of two numbers."""
   2.241 @@ -616,11 +573,9 @@
   2.242          self.assertEquals(z2, None)
   2.243          return z2
   2.244  
   2.245 -    test_leak_mul.skip = "Commitment module is not included in VIFF."
   2.246 -
   2.247  class TripleGenTest(RuntimeTestCase):
   2.248      """Test for generation of triples."""
   2.249 -    
   2.250 +
   2.251      # Number of players.
   2.252      num_players = 3
   2.253   
   2.254 @@ -648,8 +603,6 @@
   2.255          d.addCallbacks(open, runtime.error_handler)
   2.256          return d
   2.257  
   2.258 -    test_tripleGen.skip = "Commitment module is not included in VIFF."
   2.259 -
   2.260      @protocol
   2.261      def test_tripleGen2(self, runtime):
   2.262          """Test the triple_gen command."""
   2.263 @@ -676,8 +629,6 @@
   2.264          d.addCallbacks(open, runtime.error_handler)
   2.265          return d
   2.266  
   2.267 -    test_tripleGen2.skip = "Commitment module is not included in VIFF."
   2.268 -    
   2.269      @protocol
   2.270      def test_tripleTest(self, runtime):
   2.271          """Test the triple_test command."""
   2.272 @@ -698,8 +649,6 @@
   2.273          d.addCallbacks(open, runtime.error_handler)
   2.274          return d
   2.275  
   2.276 -    test_tripleTest.skip = "Commitment module is not included in VIFF."
   2.277 -
   2.278      @protocol
   2.279      def test_random_triple(self, runtime):
   2.280          """Test the triple_combiner command."""
   2.281 @@ -730,8 +679,6 @@
   2.282          d.addCallbacks(open, runtime.error_handler)
   2.283          return d
   2.284  
   2.285 -    test_random_triple.skip = "Commitment module is not included in VIFF."
   2.286 -
   2.287      @protocol
   2.288      def test_random_triple3_parallel(self, runtime):
   2.289          """Test the triple_combiner command."""
   2.290 @@ -765,8 +712,6 @@
   2.291          d.addCallbacks(open, runtime.error_handler)
   2.292          return d
   2.293  
   2.294 -    test_random_triple3_parallel.skip = "Commitment module is not included in VIFF."
   2.295 -
   2.296      @protocol
   2.297      def test_random_triple_parallel(self, runtime):
   2.298          """Test the triple_combiner command."""
   2.299 @@ -822,4 +767,7 @@
   2.300          runtime.schedule_callback(shares_ready, cont)
   2.301          return shares_ready
   2.302  
   2.303 -    test_random_triple_parallel.skip = "Commitment module is not included in VIFF."
   2.304 +if not commitment:
   2.305 +    OrlandiAdvancedCommandsTest.skip = "Skipped due to missing commitment module."
   2.306 +    OrlandiBasicCommandsTest.skip = "Skipped due to missing commitment module."
   2.307 +    TripleGenTest.skip = "Skipped due to missing commitment module."