viff

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 diff
     1.1 --- a/viff/bedoza/modified_paillier.py	Fri Aug 06 11:21:44 2010 +0200
     1.2 +++ b/viff/bedoza/modified_paillier.py	Fri Aug 06 11:34:50 2010 +0200
     1.3 @@ -43,7 +43,7 @@
     1.4              return n + x
     1.5  
     1.6      def _f_inverse(self, y, n):
     1.7 -        if 0 <= y <= (n + 1) / 2:
     1.8 +        if 0 <= y <= (n - 1) / 2:
     1.9              return y
    1.10          else:
    1.11              return y - n
    1.12 @@ -58,10 +58,10 @@
    1.13          if not player_id:
    1.14              player_id = self.runtime.id
    1.15          n = self.runtime.players[player_id].pubkey['n']
    1.16 -        min = -(n - 1) / 2 + 1
    1.17 -        max = (n + 1) / 2
    1.18 +        min = -(n - 1) / 2
    1.19 +        max = (n - 1) / 2
    1.20          assert min <= value <= max, \
    1.21 -            "paillier: plaintext %d outside legal range [-(n-1)/2+1 ; (n+1)/2] = " \
    1.22 +            "paillier: plaintext %d outside legal range [-(n-1)/2 ; (n-1)/2] = " \
    1.23              "[%d ; %d]"  % (value, min, max)
    1.24          pubkey = self.runtime.players[player_id].pubkey
    1.25          randomness = self.random.randint(1, long(n))
     2.1 --- a/viff/test/test_bedoza_triple.py	Fri Aug 06 11:21:44 2010 +0200
     2.2 +++ b/viff/test/test_bedoza_triple.py	Fri Aug 06 11:34:50 2010 +0200
     2.3 @@ -147,7 +147,7 @@
     2.4      def test_modified_paillier_can_decrypt_encrypted_max_val(self, runtime):
     2.5          paillier = ModifiedPaillier(runtime, Random(825604))
     2.6          n = runtime.players[runtime.id].pubkey['n']
     2.7 -        val = (n + 1) / 2
     2.8 +        val = (n - 1) / 2
     2.9          encrypted_val = paillier.encrypt(val)
    2.10          decrypted_val = paillier.decrypt(encrypted_val)
    2.11          self.assertEquals(val, decrypted_val)
    2.12 @@ -156,7 +156,7 @@
    2.13      def test_modified_paillier_can_decrypt_encrypted_min_val(self, runtime):
    2.14          paillier = ModifiedPaillier(runtime, Random(554424))
    2.15          n = runtime.players[runtime.id].pubkey['n']
    2.16 -        val = -(n - 1) / 2 + 1
    2.17 +        val = -(n - 1) / 2
    2.18          encrypted_val = paillier.encrypt(val)
    2.19          decrypted_val = paillier.decrypt(encrypted_val)
    2.20          self.assertEquals(val, decrypted_val)
    2.21 @@ -173,14 +173,14 @@
    2.22      def test_encrypting_too_large_number_raises_exception(self, runtime):
    2.23          paillier = ModifiedPaillier(runtime, Random(825604))
    2.24          n = runtime.players[runtime.id].pubkey['n']
    2.25 -        val = 1 + (n + 1) / 2
    2.26 +        val = 1 + (n - 1) / 2
    2.27          self.assertRaises(AssertionError, paillier.encrypt, val)
    2.28  
    2.29      @protocol
    2.30      def test_encrypting_too_small_number_raises_exception(self, runtime):
    2.31          paillier = ModifiedPaillier(runtime, Random(554424))
    2.32          n = runtime.players[runtime.id].pubkey['n']
    2.33 -        val = -(n - 1) / 2
    2.34 +        val = -(n - 1) / 2 - 1
    2.35          self.assertRaises(AssertionError, paillier.encrypt, val)
    2.36  
    2.37      @protocol