changeset 1369:7115ba16f72a

Orlandi: Uniform format for Paillier keys.
author Janus Dam Nielsen <janus.nielsen@alexandra.dk>
date Thu, 29 Oct 2009 13:46:21 +0100
parents 4306568ab9c6
children d93acdb61f34
files viff/orlandi.py viff/paillier.py viff/paillierutil.py
diffstat 3 files changed, 16 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/viff/orlandi.py	Thu Oct 29 13:46:21 2009 +0100
+++ b/viff/orlandi.py	Thu Oct 29 13:46:21 2009 +0100
@@ -877,7 +877,7 @@
             pc = tuple(self.program_counter)
             p3 = field.modulus**3
             for pi in self.players.keys():
-                n = self.players[pi].pubkey[0]
+                n = self.players[pi].pubkey['n']
                 nsq = n * n
                 # choose random d_i,j in Z_p^3
                 dij = random_number(p3)
@@ -915,9 +915,9 @@
         r2 = random_number(field.modulus)
 
         # compute alpha_i = Enc_eki(a_i)
-        n, g = self.players[self.id].pubkey
-        alpha_randomness = rand.randint(1, long(n))
-        alphai = encrypt_r(ai.value, alpha_randomness, (n, g))
+        pubkey = self.players[self.id].pubkey
+        alpha_randomness = rand.randint(1, long(pubkey['n']))
+        alphai = encrypt_r(ai.value, alpha_randomness, pubkey)
         # and A_i = Com_ck(a_i, r_i).
         Ai = commitment.commit(ai.value, r1.value, r2.value)
 
@@ -1136,7 +1136,7 @@
                 # 3) the gammaij he received is equal to the gammaij
                 # he now computes based on the values he reveives
                 for j in xrange(len(ais)):
-                    n = self.players[self.id].pubkey[0]
+                    n = self.players[self.id].pubkey['n']
                     nsq = n * n
                     dij = dijs[j]
                     # 5) ... and dij < p^3.
--- a/viff/paillier.py	Thu Oct 29 13:46:21 2009 +0100
+++ b/viff/paillier.py	Thu Oct 29 13:46:21 2009 +0100
@@ -52,20 +52,25 @@
         g = rand.randint(1, long(nsq))
         if gmpy.gcd(L(pow(g, lm, nsq), n), n) == 1: break
 
-    return (n, g), (n, g, lm)
+    return {'n':n, 'g': g}, {'n': n, 'g': g, 'lm': lm}
 
-def encrypt(m, (n, g)):
-    r = rand.randint(1, long(n))
-    return encrypt_r(m, r, (n, g))
+def encrypt(m, pubkey):
+    r = rand.randint(1, long(pubkey['n']))
+    return encrypt_r(m, r, pubkey)
 
-def encrypt_r(m, r, (n, g)):
+def encrypt_r(m, r, pubkey):
+    n = pubkey['n']
+    g = pubkey['g']
     nsq = n*n
     return (pow(g, m, nsq)*pow(r, n, nsq)) % nsq
 
 #: Cache for ciphertext-independent factors.
 _decrypt_factors = {}
 
-def decrypt(c, (n, g, lm)):
+def decrypt(c, seckey):
+    n = seckey['n']
+    g = seckey['g']
+    lm = seckey['lm']
     numer = L(pow(c, lm, n*n), n)
     key = (n, g, lm)
     try:
--- a/viff/paillierutil.py	Thu Oct 29 13:46:21 2009 +0100
+++ b/viff/paillierutil.py	Thu Oct 29 13:46:21 2009 +0100
@@ -53,9 +53,6 @@
     
 
 def deserializer(paillier_type, str):
-    if paillier_type == "viff":
-        return tuple(map(long, str))
-    if paillier_type == "nacl":
         d = {}
         for k, v in str.items():
             d[k] = long(v)