viff

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 diff
     1.1 --- a/apps/generate-config-files.py	Wed Oct 28 14:24:49 2009 +0100
     1.2 +++ b/apps/generate-config-files.py	Wed Oct 28 14:53:49 2009 +0100
     1.3 @@ -55,7 +55,7 @@
     1.4  from optparse import OptionParser
     1.5  
     1.6  from viff.config import generate_configs
     1.7 -from viff import paillier
     1.8 +from viff.paillierutil import ViffPaillier
     1.9  
    1.10  parser = OptionParser()
    1.11  parser.add_option("-p", "--prefix",
    1.12 @@ -82,7 +82,7 @@
    1.13      parser.error("must supply a hostname:port argument for each player")
    1.14  
    1.15  addresses = [arg.split(':', 1) for arg in args]
    1.16 -configs = generate_configs(options.n, options.t, lambda: paillier.generate_keys(options.keysize), addresses,
    1.17 +configs = generate_configs(options.n, options.t, ViffPaillier(options.keysize), addresses,
    1.18                             options.prefix, options.skip_prss)
    1.19  
    1.20  for config in configs.itervalues():
     2.1 --- a/viff/config.py	Wed Oct 28 14:24:49 2009 +0100
     2.2 +++ b/viff/config.py	Wed Oct 28 14:53:49 2009 +0100
     2.3 @@ -32,7 +32,8 @@
     2.4  from viff.libs.configobj import ConfigObj
     2.5  from viff.prss import generate_subsets, PRF
     2.6  from viff.util import rand
     2.7 -from viff import paillier
     2.8 +from viff.paillierutil import ViffPaillier
     2.9 +from viff import paillierutil
    2.10  
    2.11  
    2.12  class Player:
    2.13 @@ -129,10 +130,13 @@
    2.14          id = p_unstr(player)
    2.15          host = config[player]['host']
    2.16          port = int(config[player]['port'])
    2.17 -        pubkey = tuple(map(long, config[player]['pubkey']))
    2.18 +        paillier_type = config[player]['paillier']['type']
    2.19 +        pub_key = config[player]['paillier']['pubkey']
    2.20 +        pubkey = paillierutil.deserializer(paillier_type, pub_key)
    2.21  
    2.22          if 'prss_keys' in config[player]:
    2.23 -            seckey = tuple(map(long, config[player]['seckey']))
    2.24 +            sec_key = config[player]['paillier']['seckey']
    2.25 +            seckey = paillierutil.deserializer(paillier_type, sec_key)
    2.26              keys = {}
    2.27              for subset in config[player]['prss_keys']:
    2.28                  keys[s_unstr(subset)] = config[player]['prss_keys'][subset]
    2.29 @@ -156,7 +160,7 @@
    2.30      return owner_id, players
    2.31  
    2.32  
    2.33 -def generate_configs(n, t, paillier_key_generator=lambda: paillier.generate_keys(1024),
    2.34 +def generate_configs(n, t, paillier=ViffPaillier(1024),
    2.35                       addresses=None, prefix=None, skip_prss=False):
    2.36      """Generate player configurations.
    2.37  
    2.38 @@ -193,7 +197,7 @@
    2.39          """Convert a dealer ID to a string."""
    2.40          return "Dealer " + str(dealer)
    2.41  
    2.42 -    key_pairs = dict([(p, paillier_key_generator()) for p in players])
    2.43 +    key_pairs = dict([(p, paillier.generate_keys()) for p in players])
    2.44  
    2.45      configs = {}
    2.46      for p in players:
    2.47 @@ -215,10 +219,12 @@
    2.48              # in the configuration file, making it slightly easier to read
    2.49              config.comments[p_str(p)] = ['']
    2.50  
    2.51 -            config[p_str(p)]['pubkey'] = key_pairs[p][0]
    2.52 +            config[p_str(p)]['paillier'] = {}
    2.53 +            config[p_str(p)]['paillier']['type'] = paillier.type
    2.54 +            config[p_str(p)]['paillier']['pubkey'] = key_pairs[p][0]
    2.55  
    2.56              if player == p:
    2.57 -                config[p_str(p)]['seckey'] = key_pairs[p][1]
    2.58 +                config[p_str(p)]['paillier']['seckey'] = key_pairs[p][1]
    2.59  
    2.60                  # Prepare the config file for the keys
    2.61                  config[p_str(p)]['prss_keys'] = {}
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/viff/paillierutil.py	Wed Oct 28 14:53:49 2009 +0100
     3.3 @@ -0,0 +1,42 @@
     3.4 +# Copyright 2007, 2008 VIFF Development Team.
     3.5 +#
     3.6 +# This file is part of VIFF, the Virtual Ideal Functionality Framework.
     3.7 +#
     3.8 +# VIFF is free software: you can redistribute it and/or modify it
     3.9 +# under the terms of the GNU Lesser General Public License (LGPL) as
    3.10 +# published by the Free Software Foundation, either version 3 of the
    3.11 +# License, or (at your option) any later version.
    3.12 +#
    3.13 +# VIFF is distributed in the hope that it will be useful, but WITHOUT
    3.14 +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
    3.15 +# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
    3.16 +# Public License for more details.
    3.17 +#
    3.18 +# You should have received a copy of the GNU Lesser General Public
    3.19 +# License along with VIFF. If not, see <http://www.gnu.org/licenses/>.
    3.20 +
    3.21 +from viff import paillier
    3.22 +
    3.23 +class Paillier:
    3.24 +
    3.25 +    def __init__(self, keysize):
    3.26 +        self.keysize = keysize
    3.27 +        self.type = 'Unknown'
    3.28 +
    3.29 +    def generate_keys(self):
    3.30 +        pass
    3.31 +
    3.32 +
    3.33 +class ViffPaillier:
    3.34 +
    3.35 +    def __init__(self, keysize):
    3.36 +        self.keysize = keysize
    3.37 +        self.type = 'viff'
    3.38 +
    3.39 +    def generate_keys(self):
    3.40 +        return paillier.generate_keys(self.keysize)
    3.41 +    
    3.42 +
    3.43 +def deserializer(paillier_type, str):
    3.44 +    return tuple(map(long, str))
    3.45 +