changeset 639:c99ae4b6b054

Allow a threshold of zero for dummy Shamir sharings.
author Martin Geisler <mg@daimi.au.dk>
date Sat, 05 Apr 2008 00:00:02 +0200
parents 45ce0d082747
children a5f51b2f3fb2
files viff/shamir.py
diffstat 1 files changed, 13 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/viff/shamir.py	Fri Apr 04 23:59:11 2008 +0200
+++ b/viff/shamir.py	Sat Apr 05 00:00:02 2008 +0200
@@ -36,6 +36,18 @@
     >>> recombine(share(secret, 7, 15)[:8]) == secret
     True
 
+    The threshold can range from zero (for a dummy-sharing):
+
+    >>> share(Zp(10), 0, 5)
+    [({1}, {10}), ({2}, {10}), ({3}, {10}), ({4}, {10}), ({5}, {10})]
+
+    up to but not including C{num_players}:
+
+    >>> share(Zp(10), 5, 5)
+    Traceback (most recent call last):
+      ...
+    AssertionError: Threshold out of range
+
     @param secret: the secret to be shared.
     @type secret: a field element
 
@@ -49,7 +61,7 @@
     @return: shares, one for each player.
     @returntype: C{list} of (player id, share) pairs
     """
-    assert threshold > 0 and threshold < num_players
+    assert threshold >= 0 and threshold < num_players, "Threshold out of range"
 
     coef = [secret]
     for j in range(threshold):