viff

changeset 931:4237dbc953fd

Merged.
author Martin Geisler <mg@daimi.au.dk>
date Thu, 18 Sep 2008 21:00:20 +0200
parents e5be3933f67a a1aa8bc840e1
children aca5cdbcf9d8
files apps/benchmark.py
diffstat 3 files changed, 40 insertions(+), 23 deletions(-) [+]
line diff
     1.1 --- a/apps/benchmark.py	Thu Sep 18 20:39:16 2008 +0200
     1.2 +++ b/apps/benchmark.py	Thu Sep 18 21:00:20 2008 +0200
     1.3 @@ -70,7 +70,7 @@
     1.4  from viff.equality import ProbabilisticEqualityMixin
     1.5  from viff.paillier import PaillierRuntime
     1.6  from viff.config import load_config
     1.7 -from viff.util import find_prime
     1.8 +from viff.util import find_prime, rand
     1.9  
    1.10  last_timestamp = time.time()
    1.11  start = 0
    1.12 @@ -98,6 +98,8 @@
    1.13                    help="lower limit for modulus (can be an expression)")
    1.14  parser.add_option("-a", "--active", action="store_true",
    1.15                    help="use actively secure runtime")
    1.16 +parser.add_option("--passive", action="store_false", dest="active",
    1.17 +                  help="use passively secure runtime")
    1.18  parser.add_option("-2", "--twoplayer", action="store_true",
    1.19                    help="use twoplayer runtime")
    1.20  parser.add_option("--prss", action="store_true",
    1.21 @@ -113,7 +115,7 @@
    1.22  parser.add_option("-s", "--sequential", action="store_false", dest="parallel",
    1.23                    help="execute operations in sequence")
    1.24  
    1.25 -parser.set_defaults(modulus="30916444023318367583", count=10,
    1.26 +parser.set_defaults(modulus=2**65, count=10,
    1.27                      active=False, twoplayer=False, prss=True,
    1.28                      operation=operations[0], parallel=True)
    1.29  
    1.30 @@ -178,9 +180,18 @@
    1.31              self.begin(None)
    1.32  
    1.33      def begin(self, _):
    1.34 -        print "Runtime ready, starting protocol"
    1.35 -        self.a_shares = [self.rt.prss_share_random(Zp) for _ in range(count)]
    1.36 -        self.b_shares = [self.rt.prss_share_random(Zp) for _ in range(count)]
    1.37 +        print "Runtime ready, generating shares"
    1.38 +        self.a_shares = []
    1.39 +        self.b_shares = []
    1.40 +        for i in range(count):
    1.41 +            inputter = (i % len(self.rt.players)) + 1
    1.42 +            if inputter == self.rt.id:
    1.43 +                a = rand.randint(0, Zp.modulus)
    1.44 +                b = rand.randint(0, Zp.modulus)
    1.45 +            else:
    1.46 +                a, b = None, None
    1.47 +            self.a_shares.append(self.rt.shamir_share([inputter], Zp, a))
    1.48 +            self.b_shares.append(self.rt.shamir_share([inputter], Zp, b))
    1.49          shares_ready = gather_shares(self.a_shares + self.b_shares)
    1.50          shares_ready.addCallback(self.sync_test)
    1.51  
     2.1 --- a/apps/generate-config-files.py	Thu Sep 18 20:39:16 2008 +0200
     2.2 +++ b/apps/generate-config-files.py	Thu Sep 18 21:00:20 2008 +0200
     2.3 @@ -67,8 +67,10 @@
     2.4                    help="number of players")
     2.5  parser.add_option("-t", "--threshold", dest="t", type="int",
     2.6                    help="threshold (it must hold that t < n/2)")
     2.7 +parser.add_option("--skip-prss", action="store_true",
     2.8 +                  help="do not generate PRSS keys")
     2.9  
    2.10 -parser.set_defaults(verbose=True, n=3, t=1, prefix='player')
    2.11 +parser.set_defaults(verbose=True, n=3, t=1, prefix='player', skip_prss=False)
    2.12  
    2.13  (options, args) = parser.parse_args()
    2.14  
    2.15 @@ -76,7 +78,8 @@
    2.16      parser.error("must supply a hostname:port argument for each player")
    2.17  
    2.18  addresses = [arg.split(':', 1) for arg in args]
    2.19 -configs = generate_configs(options.n, options.t, addresses, options.prefix)
    2.20 +configs = generate_configs(options.n, options.t, addresses, options.prefix,
    2.21 +                           options.skip_prss)
    2.22  
    2.23  for config in configs.itervalues():
    2.24      config.write()
     3.1 --- a/viff/config.py	Thu Sep 18 20:39:16 2008 +0200
     3.2 +++ b/viff/config.py	Thu Sep 18 21:00:20 2008 +0200
     3.3 @@ -153,12 +153,14 @@
     3.4      return owner_id, players
     3.5  
     3.6  
     3.7 -def generate_configs(n, t, addresses=None, prefix=None):
     3.8 +def generate_configs(n, t, addresses=None, prefix=None, skip_prss=False):
     3.9      """Generate player configurations.
    3.10  
    3.11      Generates *n* configuration objects with a threshold of *t*. The
    3.12      *addresses* is an optional list of ``(host, port)`` pairs and
    3.13 -    *prefix* is a filename prefix.
    3.14 +    *prefix* is a filename prefix. One can avoid generating keys for
    3.15 +    PRSS by setting *skip_prss* to True. This is useful when the
    3.16 +    number of players is large.
    3.17  
    3.18      The configurations are returned as :class:`ConfigObj` instances
    3.19      and can be saved to disk if desired.
    3.20 @@ -166,7 +168,6 @@
    3.21      Returns a mapping from player ID to player configuration.
    3.22      """
    3.23      players = frozenset(range(1, n+1))
    3.24 -    max_unqualified_subsets = generate_subsets(players, n-t)
    3.25  
    3.26      def generate_key():
    3.27          # TODO: is a 40 byte hex string as good as a 20 byte binary
    3.28 @@ -223,19 +224,21 @@
    3.29                  for d in players:
    3.30                      config[p_str(p)]['prss_dealer_keys'][d_str(d)] = {}
    3.31  
    3.32 -    for subset in max_unqualified_subsets:
    3.33 -        key = generate_key()
    3.34 -        for player in subset:
    3.35 -            config = configs[player]
    3.36 -            config[p_str(player)]['prss_keys'][s_str(subset)] = key
    3.37 +    if not skip_prss:
    3.38 +        max_unqualified_subsets = generate_subsets(players, n-t)
    3.39 +        for subset in max_unqualified_subsets:
    3.40 +            key = generate_key()
    3.41 +            for player in subset:
    3.42 +                config = configs[player]
    3.43 +                config[p_str(player)]['prss_keys'][s_str(subset)] = key
    3.44  
    3.45 -    for dealer in players:
    3.46 -        d = d_str(dealer)
    3.47 -        for subset in max_unqualified_subsets:
    3.48 -            s = s_str(subset)
    3.49 -            key = generate_key()
    3.50 -            for player in (subset | set([dealer])):
    3.51 -                p = p_str(player)
    3.52 -                configs[player][p]['prss_dealer_keys'][d][s] = key
    3.53 +        for dealer in players:
    3.54 +            d = d_str(dealer)
    3.55 +            for subset in max_unqualified_subsets:
    3.56 +                s = s_str(subset)
    3.57 +                key = generate_key()
    3.58 +                for player in (subset | set([dealer])):
    3.59 +                    p = p_str(player)
    3.60 +                    configs[player][p]['prss_dealer_keys'][d][s] = key
    3.61  
    3.62      return configs