changeset 1439:6d3dc3f181d3

Compute the fixed base element for NaCl paillier.
author Janus Dam Nielsen <janus.nielsen@alexandra.dk>
date Thu, 20 May 2010 10:41:45 +0200
parents 6caded57e489
children 91222852a0a4
files viff/config.py viff/paillierutil.py
diffstat 2 files changed, 25 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/viff/config.py	Thu May 20 10:38:21 2010 +0200
+++ b/viff/config.py	Thu May 20 10:41:45 2010 +0200
@@ -134,7 +134,7 @@
         if 'paillier' in config[player]:
             paillier_type = config[player]['paillier']['type']
             pub_key = config[player]['paillier']['pubkey']
-            pubkey = paillierutil.deserializer(paillier_type, pub_key)
+            pubkey = paillierutil.deserializ_pubkey(paillier_type, pub_key)
         else:
             # old format
             pubkey = tuple(map(long, config[player]['pubkey']))
@@ -142,7 +142,7 @@
         if 'prss_keys' in config[player]:
             if 'paillier' in config[player]:
                 sec_key = config[player]['paillier']['seckey']
-                seckey = paillierutil.deserializer(paillier_type, sec_key)
+                seckey = paillierutil.deserializ_seckey(sec_key)
             else:
                 # old format
                 seckey = tuple(map(long, config[player]['seckey']))
--- a/viff/paillierutil.py	Thu May 20 10:38:21 2010 +0200
+++ b/viff/paillierutil.py	Thu May 20 10:41:45 2010 +0200
@@ -22,6 +22,12 @@
 except ImportError:
     pypaillier = None
 
+try:
+    import tripple
+
+except ImportError:
+    tripple = None
+
 
 class Paillier:
 
@@ -49,12 +55,22 @@
         self.type = 'nacl'
 
     def generate_keys(self):
-        return pypaillier.generate_keys(self.keysize)
-    
+        return pypaillier.generate_keys(self.keysize)  
 
-def deserializer(paillier_type, str):
-        d = {}
+def deserializ_seckey(str):
+    d = {}
+    for k, v in str.items():
+        d[k] = long(v)
+    return d
+
+def deserializ_pubkey(paillier_type, str):
+        pubkey = {}
         for k, v in str.items():
-            d[k] = long(v)
-        return d
-        
+            pubkey[k] = long(v)
+        if paillier_type == "nacl":
+            g1 = pypaillier.encrypt_r(1, 1, pubkey)
+            pubkey['fixed_base'] = tripple.init(g1, pubkey['n_square'])            
+        return pubkey
+
+
+