changeset 1147:5ac7a2c23337

Cache the coefficients used to construct a PRSS share.
author Marcel Keller <mkeller@cs.au.dk>
date Wed, 25 Feb 2009 21:14:30 +0100
parents ecd0f77f5243
children d522f9b14b49
files viff/prss.py
diffstat 1 files changed, 13 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/viff/prss.py	Wed Feb 25 17:16:38 2009 +0100
+++ b/viff/prss.py	Wed Feb 25 21:14:30 2009 +0100
@@ -66,19 +66,29 @@
     # the subset before using it.
     return [(s, prf(key)) for (s, prf) in prfs.iteritems() if j in s]
 
+#: Cache the coefficients used to construct the share. They depend on the field,
+#: the player concerned, the total number of players, and the subset.
+_f_in_j_cache = {}
+
 def convert_replicated_shamir(n, j, field, rep_shares):
     """Convert a set of replicated shares to a Shamir share.
 
     The conversion is done for player *j* (out of *n*) and will be
     done over *field*.
     """
+    global _f_in_j_cache
     result = 0
     all = frozenset(range(1, n+1))
     for subset, share in rep_shares:
         # TODO: should we cache the f_in_j values?
-        points = [(field(x), 0) for x in all-subset]
-        points.append((0, 1))
-        f_in_j = shamir.recombine(points, j)
+        # Yes, we probably should.
+        if ((field, n, j, subset) in _f_in_j_cache):
+            f_in_j = _f_in_j_cache[(field, n, j, subset)]
+        else:
+            points = [(field(x), 0) for x in all-subset]
+            points.append((0, 1))
+            f_in_j = shamir.recombine(points, j)
+            _f_in_j_cache[(field, n, j, subset)] = f_in_j
         result += share * f_in_j
     return result