viff

changeset 837:99dc1bb4cddf

Generate and load Paillier keys. The names "pubkey" and "seckey" are not perfect since we might want other types of public and secret keys in the future.
author Martin Geisler <mg@daimi.au.dk>
date Sat, 21 Jun 2008 13:02:57 +0200
parents 0422fa73ab29
children bba8a625972a
files viff/config.py
diffstat 1 files changed, 15 insertions(+), 3 deletions(-) [+]
line diff
     1.1 --- a/viff/config.py	Wed Jul 16 00:09:50 2008 +0200
     1.2 +++ b/viff/config.py	Sat Jun 21 13:02:57 2008 +0200
     1.3 @@ -35,16 +35,19 @@
     1.4  
     1.5  from viff.prss import generate_subsets, PRF
     1.6  from viff.util import rand
     1.7 +from viff import paillier
     1.8  
     1.9  
    1.10  class Player:
    1.11      """Wrapper for information about a player in the protocol."""
    1.12  
    1.13 -    def __init__(self, id, host, port, keys=None, dealer_keys=None):
    1.14 +    def __init__(self, id, host, port, pubkey, seckey=None, keys=None, dealer_keys=None):
    1.15          """Initialize a player."""
    1.16          self.id = id
    1.17          self.host = host
    1.18          self.port = port
    1.19 +        self.pubkey = pubkey
    1.20 +        self.seckey = seckey
    1.21          self.keys = keys
    1.22          self.dealer_keys = dealer_keys
    1.23  
    1.24 @@ -123,8 +126,10 @@
    1.25          id = p_unstr(player)
    1.26          host = config[player]['host']
    1.27          port = int(config[player]['port'])
    1.28 +        pubkey = tuple(map(int, config[player]['pubkey']))
    1.29  
    1.30          if 'prss_keys' in config[player]:
    1.31 +            seckey = tuple(map(int, config[player]['seckey']))
    1.32              keys = {}
    1.33              for subset in config[player]['prss_keys']:
    1.34                  keys[s_unstr(subset)] = config[player]['prss_keys'][subset]
    1.35 @@ -138,12 +143,12 @@
    1.36                  for subset in config[player]['prss_dealer_keys'][dealer]:
    1.37                      dealer_keys[d][s_unstr(subset)] = config[player]['prss_dealer_keys'][dealer][subset]
    1.38  
    1.39 -            players[id] = Player(id, host, port, keys, dealer_keys)
    1.40 +            players[id] = Player(id, host, port, pubkey, seckey, keys, dealer_keys)
    1.41  
    1.42              # ID of player for which this config file was made
    1.43              owner_id = id
    1.44          else:
    1.45 -            players[id] = Player(id, host, port)
    1.46 +            players[id] = Player(id, host, port, pubkey)
    1.47  
    1.48      return owner_id, players
    1.49  
    1.50 @@ -183,6 +188,9 @@
    1.51          """Convert a dealer ID to a string."""
    1.52          return "Dealer " + str(dealer)
    1.53  
    1.54 +    # TODO: remove hard-coded key size.
    1.55 +    key_pairs = dict([(p, paillier.generate_keys(1024)) for p in players])
    1.56 +
    1.57      configs = {}
    1.58      for p in players:
    1.59          config = ConfigObj(indent_type='  ')
    1.60 @@ -203,7 +211,11 @@
    1.61              # in the configuration file, making it slightly easier to read
    1.62              config.comments[p_str(p)] = ['']
    1.63  
    1.64 +            config[p_str(p)]['pubkey'] = key_pairs[p][0]
    1.65 +
    1.66              if player == p:
    1.67 +                config[p_str(p)]['seckey'] = key_pairs[p][1]
    1.68 +
    1.69                  # Prepare the config file for the keys
    1.70                  config[p_str(p)]['prss_keys'] = {}
    1.71                  config[p_str(p)]['prss_dealer_keys'] = {}