changeset 1361:736ad1d97024

Generate_config_files:Added support NaCl implementation of Paillier.
author Janus Dam Nielsen <janus.nielsen@alexandra.dk>
date Wed, 28 Oct 2009 14:53:51 +0100
parents 3fe6e03541c1
children 361aeb2668fc
files apps/generate-config-files.py viff/paillierutil.py
diffstat 2 files changed, 38 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/apps/generate-config-files.py	Wed Oct 28 14:53:49 2009 +0100
+++ b/apps/generate-config-files.py	Wed Oct 28 14:53:51 2009 +0100
@@ -55,7 +55,17 @@
 from optparse import OptionParser
 
 from viff.config import generate_configs
-from viff.paillierutil import ViffPaillier
+from viff.paillierutil import ViffPaillier, NaClPaillier
+
+try:
+    import pypaillier
+except ImportError:
+    pypaillier = None
+
+paillier_choices = ['viff']
+
+if pypaillier:
+    paillier_choices += ['nacl']
 
 parser = OptionParser()
 parser.add_option("-p", "--prefix",
@@ -68,21 +78,27 @@
                   help="number of players")
 parser.add_option("-k", "--keysize", type="int",
                   help="Specify the key-size for Paillier encryption")
+parser.add_option("--paillier", type="choice", choices=paillier_choices,
+                  help="the implementation of Paillier encryption")
 parser.add_option("-t", "--threshold", dest="t", type="int",
                   help="threshold (it must hold that t < n/2)")
 parser.add_option("--skip-prss", action="store_true",
                   help="do not generate PRSS keys")
 
 parser.set_defaults(verbose=True, n=3, t=1, prefix='player', skip_prss=False,
-                    keysize=1024)
+                    keysize=1024, paillier='viff')
 
 (options, args) = parser.parse_args()
 
+paillier = ViffPaillier(options.keysize)
+if "nacl" == options.paillier:
+    paillier = NaClPaillier(options.keysize)
+
 if len(args) != options.n:
     parser.error("must supply a hostname:port argument for each player")
 
 addresses = [arg.split(':', 1) for arg in args]
-configs = generate_configs(options.n, options.t, ViffPaillier(options.keysize), addresses,
+configs = generate_configs(options.n, options.t, paillier, addresses,
                            options.prefix, options.skip_prss)
 
 for config in configs.itervalues():
--- a/viff/paillierutil.py	Wed Oct 28 14:53:49 2009 +0100
+++ b/viff/paillierutil.py	Wed Oct 28 14:53:51 2009 +0100
@@ -17,6 +17,12 @@
 
 from viff import paillier
 
+try:
+    import pypaillier
+except ImportError:
+    pypaillier = None
+
+
 class Paillier:
 
     def __init__(self, keysize):
@@ -35,8 +41,20 @@
 
     def generate_keys(self):
         return paillier.generate_keys(self.keysize)
+
+class NaClPaillier:
+
+    def __init__(self, keysize):
+        self.keysize = keysize
+        self.type = 'nacl'
+
+    def generate_keys(self):
+        return pypaillier.generate_keys(self.keysize)
     
 
 def deserializer(paillier_type, str):
-    return tuple(map(long, str))
+    if paillier_type == "viff":
+        return tuple(map(long, str))
+    if paillier_type == "nacl":
+        return str.dict()