viff

changeset 1535:b4451e4ac76d

BeDOZa: Use gmpy for modular exponentiation.
author Thomas P Jakobsen <tpj@cs.au.dk>
date Tue, 10 Aug 2010 16:03:54 +0200
parents 315e1117928a
children 4e36cad23bc1
files viff/bedoza/add_macs.py viff/bedoza/bedoza_triple.py viff/bedoza/util.py
diffstat 3 files changed, 9 insertions(+), 3 deletions(-) [+]
line diff
     1.1 --- a/viff/bedoza/add_macs.py	Tue Aug 10 13:19:49 2010 +0200
     1.2 +++ b/viff/bedoza/add_macs.py	Tue Aug 10 16:03:54 2010 +0200
     1.3 @@ -20,7 +20,7 @@
     1.4  from twisted.internet.defer import gatherResults
     1.5  from viff.runtime import Share
     1.6  
     1.7 -from viff.bedoza.util import _send
     1.8 +from viff.bedoza.util import _send, fast_pow
     1.9  from viff.bedoza.keylist import BeDOZaKeyList
    1.10  from viff.bedoza.maclist import BeDOZaMACList
    1.11  
    1.12 @@ -70,7 +70,7 @@
    1.13                  enc_beta = paillier.encrypt(beta, player_id = j + 1)
    1.14                  c_j = partial_share_content.enc_shares[ j ]
    1.15                  n2 = paillier.get_modulus_square( j + 1 )
    1.16 -                c = (pow(c_j, alpha, n2) * enc_beta) % n2
    1.17 +                c = (fast_pow(c_j, alpha, n2) * enc_beta) % n2
    1.18                  player_to_enc_shares[j].append(c)
    1.19                  player_to_mac_keys[j].append(field(beta))
    1.20  
     2.1 --- a/viff/bedoza/bedoza_triple.py	Tue Aug 10 13:19:49 2010 +0200
     2.2 +++ b/viff/bedoza/bedoza_triple.py	Tue Aug 10 16:03:54 2010 +0200
     2.3 @@ -34,6 +34,7 @@
     2.4  from viff.bedoza.maclist import BeDOZaMACList
     2.5  from viff.bedoza.add_macs import add_macs
     2.6  from viff.bedoza.modified_paillier import ModifiedPaillier
     2.7 +from viff.bedoza.util import fast_pow
     2.8  
     2.9  from viff.triple import Triple
    2.10  
    2.11 @@ -210,7 +211,7 @@
    2.12                      all_dis.append(dis)
    2.13                  u = rand.randint(0, self.u_bound)
    2.14                  Ej_u = self.paillier.encrypt(u, jnx)
    2.15 -                cs.append( (pow(cj, ai.value, Nj_square) * Ej_u) % Nj_square )
    2.16 +                cs.append( (fast_pow(cj, ai.value, Nj_square) * Ej_u) % Nj_square )
    2.17                  zi = self.Zp(-u)
    2.18                  zis.append(zi)
    2.19                  dis.append(self.paillier.encrypt(zi.value, inx))
     3.1 --- a/viff/bedoza/util.py	Tue Aug 10 13:19:49 2010 +0200
     3.2 +++ b/viff/bedoza/util.py	Tue Aug 10 16:03:54 2010 +0200
     3.3 @@ -17,6 +17,8 @@
     3.4  
     3.5  from twisted.internet.defer import Deferred, gatherResults
     3.6  
     3.7 +from gmpy import mpz
     3.8 +
     3.9  from viff.constants import TEXT
    3.10  
    3.11  def _send(runtime, vals, serialize=str, deserialize=int):
    3.12 @@ -56,3 +58,6 @@
    3.13      return _send(runtime, vals, 
    3.14                   serialize=lambda x: str(x.value),
    3.15                   deserialize=lambda x: gf_elm.field(int(x)))
    3.16 +
    3.17 +def fast_pow(a, b, modulus):
    3.18 +    return long(pow(mpz(a), b, modulus))