http://hg.viff.dk/viff/rev/5ac7a2c23337
changeset: 1147:5ac7a2c23337
user: Marcel Keller <[email protected]>
date: Wed Feb 25 21:14:30 2009 +0100
summary: Cache the coefficients used to construct a PRSS share.
diffstat:
1 file changed, 13 insertions(+), 3 deletions(-)
viff/prss.py | 16 +++++++++++++---
diffs (36 lines):
diff -r ecd0f77f5243 -r 5ac7a2c23337 viff/prss.py
--- 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
_______________________________________________
viff-commits mailing list
[email protected]
http://lists.viff.dk/listinfo.cgi/viff-commits-viff.dk