changeset 1360:3fe6e03541c1

Generate_config_files:Refactored loading and storing of Paillier keys.
author Janus Dam Nielsen <janus.nielsen@alexandra.dk>
date Wed, 28 Oct 2009 14:53:49 +0100
parents 27396792038d
children 736ad1d97024
files apps/generate-config-files.py viff/config.py viff/paillierutil.py
diffstat 3 files changed, 57 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/apps/generate-config-files.py	Wed Oct 28 14:24:49 2009 +0100
+++ b/apps/generate-config-files.py	Wed Oct 28 14:53:49 2009 +0100
@@ -55,7 +55,7 @@
 from optparse import OptionParser
 
 from viff.config import generate_configs
-from viff import paillier
+from viff.paillierutil import ViffPaillier
 
 parser = OptionParser()
 parser.add_option("-p", "--prefix",
@@ -82,7 +82,7 @@
     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, lambda: paillier.generate_keys(options.keysize), addresses,
+configs = generate_configs(options.n, options.t, ViffPaillier(options.keysize), addresses,
                            options.prefix, options.skip_prss)
 
 for config in configs.itervalues():
--- a/viff/config.py	Wed Oct 28 14:24:49 2009 +0100
+++ b/viff/config.py	Wed Oct 28 14:53:49 2009 +0100
@@ -32,7 +32,8 @@
 from viff.libs.configobj import ConfigObj
 from viff.prss import generate_subsets, PRF
 from viff.util import rand
-from viff import paillier
+from viff.paillierutil import ViffPaillier
+from viff import paillierutil
 
 
 class Player:
@@ -129,10 +130,13 @@
         id = p_unstr(player)
         host = config[player]['host']
         port = int(config[player]['port'])
-        pubkey = tuple(map(long, config[player]['pubkey']))
+        paillier_type = config[player]['paillier']['type']
+        pub_key = config[player]['paillier']['pubkey']
+        pubkey = paillierutil.deserializer(paillier_type, pub_key)
 
         if 'prss_keys' in config[player]:
-            seckey = tuple(map(long, config[player]['seckey']))
+            sec_key = config[player]['paillier']['seckey']
+            seckey = paillierutil.deserializer(paillier_type, sec_key)
             keys = {}
             for subset in config[player]['prss_keys']:
                 keys[s_unstr(subset)] = config[player]['prss_keys'][subset]
@@ -156,7 +160,7 @@
     return owner_id, players
 
 
-def generate_configs(n, t, paillier_key_generator=lambda: paillier.generate_keys(1024),
+def generate_configs(n, t, paillier=ViffPaillier(1024),
                      addresses=None, prefix=None, skip_prss=False):
     """Generate player configurations.
 
@@ -193,7 +197,7 @@
         """Convert a dealer ID to a string."""
         return "Dealer " + str(dealer)
 
-    key_pairs = dict([(p, paillier_key_generator()) for p in players])
+    key_pairs = dict([(p, paillier.generate_keys()) for p in players])
 
     configs = {}
     for p in players:
@@ -215,10 +219,12 @@
             # in the configuration file, making it slightly easier to read
             config.comments[p_str(p)] = ['']
 
-            config[p_str(p)]['pubkey'] = key_pairs[p][0]
+            config[p_str(p)]['paillier'] = {}
+            config[p_str(p)]['paillier']['type'] = paillier.type
+            config[p_str(p)]['paillier']['pubkey'] = key_pairs[p][0]
 
             if player == p:
-                config[p_str(p)]['seckey'] = key_pairs[p][1]
+                config[p_str(p)]['paillier']['seckey'] = key_pairs[p][1]
 
                 # Prepare the config file for the keys
                 config[p_str(p)]['prss_keys'] = {}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/viff/paillierutil.py	Wed Oct 28 14:53:49 2009 +0100
@@ -0,0 +1,42 @@
+# Copyright 2007, 2008 VIFF Development Team.
+#
+# This file is part of VIFF, the Virtual Ideal Functionality Framework.
+#
+# VIFF is free software: you can redistribute it and/or modify it
+# under the terms of the GNU Lesser General Public License (LGPL) as
+# published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
+#
+# VIFF is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
+# Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with VIFF. If not, see <http://www.gnu.org/licenses/>.
+
+from viff import paillier
+
+class Paillier:
+
+    def __init__(self, keysize):
+        self.keysize = keysize
+        self.type = 'Unknown'
+
+    def generate_keys(self):
+        pass
+
+
+class ViffPaillier:
+
+    def __init__(self, keysize):
+        self.keysize = keysize
+        self.type = 'viff'
+
+    def generate_keys(self):
+        return paillier.generate_keys(self.keysize)
+    
+
+def deserializer(paillier_type, str):
+    return tuple(map(long, str))
+