changeset 1530:408356ca17f4

BeDOZa: Modified Paillier plaintext space is now centered around zero. This ensures that the implementation matches the description of the modified Paillier encryption scheme.
author Thomas P Jakobsen <tpj@cs.au.dk>
date Fri, 06 Aug 2010 11:34:50 +0200
parents 99f1e90f35e6
children 5ac22a4919ec
files viff/bedoza/modified_paillier.py viff/test/test_bedoza_triple.py
diffstat 2 files changed, 8 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/viff/bedoza/modified_paillier.py	Fri Aug 06 11:21:44 2010 +0200
+++ b/viff/bedoza/modified_paillier.py	Fri Aug 06 11:34:50 2010 +0200
@@ -43,7 +43,7 @@
             return n + x
 
     def _f_inverse(self, y, n):
-        if 0 <= y <= (n + 1) / 2:
+        if 0 <= y <= (n - 1) / 2:
             return y
         else:
             return y - n
@@ -58,10 +58,10 @@
         if not player_id:
             player_id = self.runtime.id
         n = self.runtime.players[player_id].pubkey['n']
-        min = -(n - 1) / 2 + 1
-        max = (n + 1) / 2
+        min = -(n - 1) / 2
+        max = (n - 1) / 2
         assert min <= value <= max, \
-            "paillier: plaintext %d outside legal range [-(n-1)/2+1 ; (n+1)/2] = " \
+            "paillier: plaintext %d outside legal range [-(n-1)/2 ; (n-1)/2] = " \
             "[%d ; %d]"  % (value, min, max)
         pubkey = self.runtime.players[player_id].pubkey
         randomness = self.random.randint(1, long(n))
--- a/viff/test/test_bedoza_triple.py	Fri Aug 06 11:21:44 2010 +0200
+++ b/viff/test/test_bedoza_triple.py	Fri Aug 06 11:34:50 2010 +0200
@@ -147,7 +147,7 @@
     def test_modified_paillier_can_decrypt_encrypted_max_val(self, runtime):
         paillier = ModifiedPaillier(runtime, Random(825604))
         n = runtime.players[runtime.id].pubkey['n']
-        val = (n + 1) / 2
+        val = (n - 1) / 2
         encrypted_val = paillier.encrypt(val)
         decrypted_val = paillier.decrypt(encrypted_val)
         self.assertEquals(val, decrypted_val)
@@ -156,7 +156,7 @@
     def test_modified_paillier_can_decrypt_encrypted_min_val(self, runtime):
         paillier = ModifiedPaillier(runtime, Random(554424))
         n = runtime.players[runtime.id].pubkey['n']
-        val = -(n - 1) / 2 + 1
+        val = -(n - 1) / 2
         encrypted_val = paillier.encrypt(val)
         decrypted_val = paillier.decrypt(encrypted_val)
         self.assertEquals(val, decrypted_val)
@@ -173,14 +173,14 @@
     def test_encrypting_too_large_number_raises_exception(self, runtime):
         paillier = ModifiedPaillier(runtime, Random(825604))
         n = runtime.players[runtime.id].pubkey['n']
-        val = 1 + (n + 1) / 2
+        val = 1 + (n - 1) / 2
         self.assertRaises(AssertionError, paillier.encrypt, val)
 
     @protocol
     def test_encrypting_too_small_number_raises_exception(self, runtime):
         paillier = ModifiedPaillier(runtime, Random(554424))
         n = runtime.players[runtime.id].pubkey['n']
-        val = -(n - 1) / 2
+        val = -(n - 1) / 2 - 1
         self.assertRaises(AssertionError, paillier.encrypt, val)
 
     @protocol