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 wrap: on
line diff
--- a/apps/benchmark.py	Thu Sep 18 20:39:16 2008 +0200
+++ b/apps/benchmark.py	Thu Sep 18 21:00:20 2008 +0200
@@ -70,7 +70,7 @@
 from viff.equality import ProbabilisticEqualityMixin
 from viff.paillier import PaillierRuntime
 from viff.config import load_config
-from viff.util import find_prime
+from viff.util import find_prime, rand
 
 last_timestamp = time.time()
 start = 0
@@ -98,6 +98,8 @@
                   help="lower limit for modulus (can be an expression)")
 parser.add_option("-a", "--active", action="store_true",
                   help="use actively secure runtime")
+parser.add_option("--passive", action="store_false", dest="active",
+                  help="use passively secure runtime")
 parser.add_option("-2", "--twoplayer", action="store_true",
                   help="use twoplayer runtime")
 parser.add_option("--prss", action="store_true",
@@ -113,7 +115,7 @@
 parser.add_option("-s", "--sequential", action="store_false", dest="parallel",
                   help="execute operations in sequence")
 
-parser.set_defaults(modulus="30916444023318367583", count=10,
+parser.set_defaults(modulus=2**65, count=10,
                     active=False, twoplayer=False, prss=True,
                     operation=operations[0], parallel=True)
 
@@ -178,9 +180,18 @@
             self.begin(None)
 
     def begin(self, _):
-        print "Runtime ready, starting protocol"
-        self.a_shares = [self.rt.prss_share_random(Zp) for _ in range(count)]
-        self.b_shares = [self.rt.prss_share_random(Zp) for _ in range(count)]
+        print "Runtime ready, generating shares"
+        self.a_shares = []
+        self.b_shares = []
+        for i in range(count):
+            inputter = (i % len(self.rt.players)) + 1
+            if inputter == self.rt.id:
+                a = rand.randint(0, Zp.modulus)
+                b = rand.randint(0, Zp.modulus)
+            else:
+                a, b = None, None
+            self.a_shares.append(self.rt.shamir_share([inputter], Zp, a))
+            self.b_shares.append(self.rt.shamir_share([inputter], Zp, b))
         shares_ready = gather_shares(self.a_shares + self.b_shares)
         shares_ready.addCallback(self.sync_test)
 
--- a/apps/generate-config-files.py	Thu Sep 18 20:39:16 2008 +0200
+++ b/apps/generate-config-files.py	Thu Sep 18 21:00:20 2008 +0200
@@ -67,8 +67,10 @@
                   help="number of players")
 parser.add_option("-t", "--threshold", dest="t", type="int",
                   help="threshold (it must hold that t < n/2)")
+parser.add_option("--skip-prss", action="store_true",
+                  help="do not generate PRSS keys")
 
-parser.set_defaults(verbose=True, n=3, t=1, prefix='player')
+parser.set_defaults(verbose=True, n=3, t=1, prefix='player', skip_prss=False)
 
 (options, args) = parser.parse_args()
 
@@ -76,7 +78,8 @@
     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, addresses, options.prefix)
+configs = generate_configs(options.n, options.t, addresses, options.prefix,
+                           options.skip_prss)
 
 for config in configs.itervalues():
     config.write()
--- a/viff/config.py	Thu Sep 18 20:39:16 2008 +0200
+++ b/viff/config.py	Thu Sep 18 21:00:20 2008 +0200
@@ -153,12 +153,14 @@
     return owner_id, players
 
 
-def generate_configs(n, t, addresses=None, prefix=None):
+def generate_configs(n, t, addresses=None, prefix=None, skip_prss=False):
     """Generate player configurations.
 
     Generates *n* configuration objects with a threshold of *t*. The
     *addresses* is an optional list of ``(host, port)`` pairs and
-    *prefix* is a filename prefix.
+    *prefix* is a filename prefix. One can avoid generating keys for
+    PRSS by setting *skip_prss* to True. This is useful when the
+    number of players is large.
 
     The configurations are returned as :class:`ConfigObj` instances
     and can be saved to disk if desired.
@@ -166,7 +168,6 @@
     Returns a mapping from player ID to player configuration.
     """
     players = frozenset(range(1, n+1))
-    max_unqualified_subsets = generate_subsets(players, n-t)
 
     def generate_key():
         # TODO: is a 40 byte hex string as good as a 20 byte binary
@@ -223,19 +224,21 @@
                 for d in players:
                     config[p_str(p)]['prss_dealer_keys'][d_str(d)] = {}
 
-    for subset in max_unqualified_subsets:
-        key = generate_key()
-        for player in subset:
-            config = configs[player]
-            config[p_str(player)]['prss_keys'][s_str(subset)] = key
+    if not skip_prss:
+        max_unqualified_subsets = generate_subsets(players, n-t)
+        for subset in max_unqualified_subsets:
+            key = generate_key()
+            for player in subset:
+                config = configs[player]
+                config[p_str(player)]['prss_keys'][s_str(subset)] = key
 
-    for dealer in players:
-        d = d_str(dealer)
-        for subset in max_unqualified_subsets:
-            s = s_str(subset)
-            key = generate_key()
-            for player in (subset | set([dealer])):
-                p = p_str(player)
-                configs[player][p]['prss_dealer_keys'][d][s] = key
+        for dealer in players:
+            d = d_str(dealer)
+            for subset in max_unqualified_subsets:
+                s = s_str(subset)
+                key = generate_key()
+                for player in (subset | set([dealer])):
+                    p = p_str(player)
+                    configs[player][p]['prss_dealer_keys'][d][s] = key
 
     return configs