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 wrap: on
line diff
--- a/viff/bedoza/add_macs.py	Tue Aug 10 13:19:49 2010 +0200
+++ b/viff/bedoza/add_macs.py	Tue Aug 10 16:03:54 2010 +0200
@@ -20,7 +20,7 @@
 from twisted.internet.defer import gatherResults
 from viff.runtime import Share
 
-from viff.bedoza.util import _send
+from viff.bedoza.util import _send, fast_pow
 from viff.bedoza.keylist import BeDOZaKeyList
 from viff.bedoza.maclist import BeDOZaMACList
 
@@ -70,7 +70,7 @@
                 enc_beta = paillier.encrypt(beta, player_id = j + 1)
                 c_j = partial_share_content.enc_shares[ j ]
                 n2 = paillier.get_modulus_square( j + 1 )
-                c = (pow(c_j, alpha, n2) * enc_beta) % n2
+                c = (fast_pow(c_j, alpha, n2) * enc_beta) % n2
                 player_to_enc_shares[j].append(c)
                 player_to_mac_keys[j].append(field(beta))
 
--- a/viff/bedoza/bedoza_triple.py	Tue Aug 10 13:19:49 2010 +0200
+++ b/viff/bedoza/bedoza_triple.py	Tue Aug 10 16:03:54 2010 +0200
@@ -34,6 +34,7 @@
 from viff.bedoza.maclist import BeDOZaMACList
 from viff.bedoza.add_macs import add_macs
 from viff.bedoza.modified_paillier import ModifiedPaillier
+from viff.bedoza.util import fast_pow
 
 from viff.triple import Triple
 
@@ -210,7 +211,7 @@
                     all_dis.append(dis)
                 u = rand.randint(0, self.u_bound)
                 Ej_u = self.paillier.encrypt(u, jnx)
-                cs.append( (pow(cj, ai.value, Nj_square) * Ej_u) % Nj_square )
+                cs.append( (fast_pow(cj, ai.value, Nj_square) * Ej_u) % Nj_square )
                 zi = self.Zp(-u)
                 zis.append(zi)
                 dis.append(self.paillier.encrypt(zi.value, inx))
--- a/viff/bedoza/util.py	Tue Aug 10 13:19:49 2010 +0200
+++ b/viff/bedoza/util.py	Tue Aug 10 16:03:54 2010 +0200
@@ -17,6 +17,8 @@
 
 from twisted.internet.defer import Deferred, gatherResults
 
+from gmpy import mpz
+
 from viff.constants import TEXT
 
 def _send(runtime, vals, serialize=str, deserialize=int):
@@ -56,3 +58,6 @@
     return _send(runtime, vals, 
                  serialize=lambda x: str(x.value),
                  deserialize=lambda x: gf_elm.field(int(x)))
+
+def fast_pow(a, b, modulus):
+    return long(pow(mpz(a), b, modulus))