viff

changeset 928:b22ca3a3fffd

Allow skipping PRSS key generation.
author Martin Geisler <mg@daimi.au.dk>
date Wed, 17 Sep 2008 14:50:43 +0200
parents 03fca6f38522
children 1d8345e936a0
files viff/config.py
diffstat 1 files changed, 19 insertions(+), 16 deletions(-) [+]
line diff
     1.1 --- a/viff/config.py	Tue Sep 16 10:10:04 2008 +0200
     1.2 +++ b/viff/config.py	Wed Sep 17 14:50:43 2008 +0200
     1.3 @@ -153,12 +153,14 @@
     1.4      return owner_id, players
     1.5  
     1.6  
     1.7 -def generate_configs(n, t, addresses=None, prefix=None):
     1.8 +def generate_configs(n, t, addresses=None, prefix=None, skip_prss=False):
     1.9      """Generate player configurations.
    1.10  
    1.11      Generates *n* configuration objects with a threshold of *t*. The
    1.12      *addresses* is an optional list of ``(host, port)`` pairs and
    1.13 -    *prefix* is a filename prefix.
    1.14 +    *prefix* is a filename prefix. One can avoid generating keys for
    1.15 +    PRSS by setting *skip_prss* to True. This is useful when the
    1.16 +    number of players is large.
    1.17  
    1.18      The configurations are returned as :class:`ConfigObj` instances
    1.19      and can be saved to disk if desired.
    1.20 @@ -166,7 +168,6 @@
    1.21      Returns a mapping from player ID to player configuration.
    1.22      """
    1.23      players = frozenset(range(1, n+1))
    1.24 -    max_unqualified_subsets = generate_subsets(players, n-t)
    1.25  
    1.26      def generate_key():
    1.27          # TODO: is a 40 byte hex string as good as a 20 byte binary
    1.28 @@ -223,19 +224,21 @@
    1.29                  for d in players:
    1.30                      config[p_str(p)]['prss_dealer_keys'][d_str(d)] = {}
    1.31  
    1.32 -    for subset in max_unqualified_subsets:
    1.33 -        key = generate_key()
    1.34 -        for player in subset:
    1.35 -            config = configs[player]
    1.36 -            config[p_str(player)]['prss_keys'][s_str(subset)] = key
    1.37 +    if not skip_prss:
    1.38 +        max_unqualified_subsets = generate_subsets(players, n-t)
    1.39 +        for subset in max_unqualified_subsets:
    1.40 +            key = generate_key()
    1.41 +            for player in subset:
    1.42 +                config = configs[player]
    1.43 +                config[p_str(player)]['prss_keys'][s_str(subset)] = key
    1.44  
    1.45 -    for dealer in players:
    1.46 -        d = d_str(dealer)
    1.47 -        for subset in max_unqualified_subsets:
    1.48 -            s = s_str(subset)
    1.49 -            key = generate_key()
    1.50 -            for player in (subset | set([dealer])):
    1.51 -                p = p_str(player)
    1.52 -                configs[player][p]['prss_dealer_keys'][d][s] = key
    1.53 +        for dealer in players:
    1.54 +            d = d_str(dealer)
    1.55 +            for subset in max_unqualified_subsets:
    1.56 +                s = s_str(subset)
    1.57 +                key = generate_key()
    1.58 +                for player in (subset | set([dealer])):
    1.59 +                    p = p_str(player)
    1.60 +                    configs[player][p]['prss_dealer_keys'][d][s] = key
    1.61  
    1.62      return configs