viff

changeset 1402:8fc8a6057bcd

paillier: fix broken runtime
author Martin Geisler <mg@cs.au.dk>
date Thu, 10 Dec 2009 10:07:35 +0100
parents 4e9747693979
children aa82aa9b79aa
files viff/paillier.py
diffstat 1 files changed, 8 insertions(+), 5 deletions(-) [+]
line diff
     1.1 --- a/viff/paillier.py	Fri Nov 27 16:27:07 2009 +0100
     1.2 +++ b/viff/paillier.py	Thu Dec 10 10:07:35 2009 +0100
     1.3 @@ -68,6 +68,7 @@
     1.4  _decrypt_factors = {}
     1.5  
     1.6  def decrypt(c, seckey):
     1.7 +    c = long(c)
     1.8      n = seckey['n']
     1.9      g = seckey['g']
    1.10      lm = seckey['lm']
    1.11 @@ -170,7 +171,7 @@
    1.12          field = getattr(share_a, "field", getattr(share_b, "field", None))
    1.13  
    1.14          k = self.options.security_parameter
    1.15 -        n = min(self.player.pubkey[0], self.peer.pubkey[0])
    1.16 +        n = min(self.player.pubkey['n'], self.peer.pubkey['n'])
    1.17          assert field.modulus**2 + 2**k < n, \
    1.18              "Need bigger Paillier keys to multiply."
    1.19  
    1.20 @@ -188,8 +189,8 @@
    1.21                  a1, b1 = a, b
    1.22                  enc_a1 = encrypt(a1.value, self.player.pubkey)
    1.23                  enc_b1 = encrypt(b1.value, self.player.pubkey)
    1.24 -                send_data(pc, PAILLIER, enc_a1)
    1.25 -                send_data(pc, PAILLIER, enc_b1)
    1.26 +                send_data(pc, PAILLIER, str(enc_a1))
    1.27 +                send_data(pc, PAILLIER, str(enc_b1))
    1.28  
    1.29                  enc_c1 = Share(self, field)
    1.30                  self._expect_data(self.peer.id, PAILLIER, enc_c1)
    1.31 @@ -201,10 +202,12 @@
    1.32                  a2, b2 = a, b
    1.33                  enc_a1 = Deferred()
    1.34                  self._expect_data(self.peer.id, PAILLIER, enc_a1)
    1.35 +                enc_a1.addCallback(long)
    1.36                  enc_b1 = Deferred()
    1.37                  self._expect_data(self.peer.id, PAILLIER, enc_b1)
    1.38 +                enc_b1.addCallback(long)
    1.39  
    1.40 -                nsq = self.peer.pubkey[0]**2
    1.41 +                nsq = self.peer.pubkey['n']**2
    1.42                  # Calculate a1 * b2 and b1 * a2 inside the encryption.
    1.43                  enc_a1_b2 = enc_a1.addCallback(pow, b2.value, nsq)
    1.44                  enc_b1_a2 = enc_b1.addCallback(pow, a2.value, nsq)
    1.45 @@ -215,7 +218,7 @@
    1.46  
    1.47                  c1 = gatherResults([enc_a1_b2, enc_b1_a2])
    1.48                  c1.addCallback(lambda (a,b): a * b * enc_r)
    1.49 -                c1.addCallback(lambda c: send_data(pc, PAILLIER, c))
    1.50 +                c1.addCallback(lambda c: send_data(pc, PAILLIER, str(c)))
    1.51  
    1.52                  c2 = a2 * b2 - r
    1.53                  return Share(self, field, c2)