viff

changeset 746:e54784ca4f46

Extract function to make a random replicated sharing.
author Martin Geisler <mg@daimi.au.dk>
date Tue, 13 May 2008 13:37:54 +0200
parents eae84e78682e
children 18ef1b1ca1e1
files viff/prss.py
diffstat 1 files changed, 18 insertions(+), 9 deletions(-) [+]
line diff
     1.1 --- a/viff/prss.py	Tue May 13 12:42:13 2008 +0200
     1.2 +++ b/viff/prss.py	Tue May 13 13:37:54 2008 +0200
     1.3 @@ -53,6 +53,19 @@
     1.4  from viff import shamir
     1.5  
     1.6  
     1.7 +def random_replicated_sharing(j, prfs, key):
     1.8 +    """Return a replicated sharing of a random number.
     1.9 +
    1.10 +    The shares are for player *j* based on the pseudo-random functions
    1.11 +    given in *prfs* (a mapping from subsets of players to :class:`PRF`
    1.12 +    instances). The *key* is used when evaluating the PRFs. The result
    1.13 +    is a list of ``(subset, share)`` pairs.
    1.14 +    """
    1.15 +    # The PRFs contain the subsets we need, plus some extra in the
    1.16 +    # case of dealer_keys. That is why we have to check that j is in
    1.17 +    # the subset before using it.
    1.18 +    return [(s, prf(key)) for (s, prf) in prfs.iteritems() if j in s]
    1.19 +
    1.20  def prss(n, j, field, prfs, key):
    1.21      """Return a pseudo-random secret share for a random number.
    1.22  
    1.23 @@ -79,15 +92,11 @@
    1.24      """
    1.25      result = 0
    1.26      all = frozenset(range(1, n+1))
    1.27 -    # The PRFs contain the subsets we need, plus some extra in the
    1.28 -    # case of dealer_keys. That is why we have to check that j is in
    1.29 -    # the subset before using it.
    1.30 -    for subset in prfs.iterkeys():
    1.31 -        if j in subset:
    1.32 -            points = [(field(x), 0) for x in all-subset]
    1.33 -            points.append((0, 1))
    1.34 -            f_in_j = shamir.recombine(points, j)
    1.35 -            result += prfs[subset](key) * f_in_j
    1.36 +    for subset, share in random_replicated_sharing(j, prfs, key):
    1.37 +        points = [(field(x), 0) for x in all-subset]
    1.38 +        points.append((0, 1))
    1.39 +        f_in_j = shamir.recombine(points, j)
    1.40 +        result += share * f_in_j
    1.41  
    1.42      return result
    1.43