changeset 747:18ef1b1ca1e1

Function to convert replicated shares to Shamir shares.
author Martin Geisler <mg@daimi.au.dk>
date Tue, 13 May 2008 13:46:20 +0200
parents e54784ca4f46
children fac2d1f8dbe1
files viff/prss.py
diffstat 1 files changed, 17 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/viff/prss.py	Tue May 13 13:37:54 2008 +0200
+++ b/viff/prss.py	Tue May 13 13:46:20 2008 +0200
@@ -66,6 +66,21 @@
     # the subset before using it.
     return [(s, prf(key)) for (s, prf) in prfs.iteritems() if j in s]
 
+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*.
+    """
+    result = 0
+    all = frozenset(range(1, n+1))
+    for subset, share in rep_shares:
+        points = [(field(x), 0) for x in all-subset]
+        points.append((0, 1))
+        f_in_j = shamir.recombine(points, j)
+        result += share * f_in_j
+    return result
+
 def prss(n, j, field, prfs, key):
     """Return a pseudo-random secret share for a random number.
 
@@ -90,16 +105,8 @@
     We see that the sharing is consistent because each subset of two
     players will recombine their shares to ``{24}``.
     """
-    result = 0
-    all = frozenset(range(1, n+1))
-    for subset, share in random_replicated_sharing(j, prfs, key):
-        points = [(field(x), 0) for x in all-subset]
-        points.append((0, 1))
-        f_in_j = shamir.recombine(points, j)
-        result += share * f_in_j
-
-    return result
-
+    rep_shares = random_replicated_sharing(j, prfs, key)
+    return convert_replicated_shamir(n, j, field, rep_shares)
 
 def generate_subsets(orig_set, size):
     """Generates the set of all subsets of a specific size.