viff

changeset 1045:3625745e618a

Faking PRSS with tests.
author Martin Geisler <mg@daimi.au.dk>
date Wed, 10 Dec 2008 12:42:06 +0100
parents ce92e62e21a8
children b283e3136f61
files viff/prss.py viff/test/test_util.py
diffstat 2 files changed, 21 insertions(+), 2 deletions(-) [+]
line diff
     1.1 --- a/viff/prss.py	Wed Dec 10 12:35:12 2008 +0100
     1.2 +++ b/viff/prss.py	Wed Dec 10 12:42:06 2008 +0100
     1.3 @@ -51,6 +51,7 @@
     1.4  
     1.5  from viff import shamir
     1.6  from viff.field import GF256
     1.7 +from viff.util import fake
     1.8  
     1.9  def random_replicated_sharing(j, prfs, key):
    1.10      """Return a replicated sharing of a random number.
    1.11 @@ -81,6 +82,7 @@
    1.12          result += share * f_in_j
    1.13      return result
    1.14  
    1.15 +@fake(lambda n, j, field, prfs, key: field(7))
    1.16  def prss(n, j, field, prfs, key):
    1.17      """Return a pseudo-random secret share for a random number.
    1.18  
    1.19 @@ -108,6 +110,7 @@
    1.20      rep_shares = random_replicated_sharing(j, prfs, key)
    1.21      return convert_replicated_shamir(n, j, field, rep_shares)
    1.22  
    1.23 +@fake(lambda n, j, field, prfs, key: (field(7), GF256(1)))
    1.24  def prss_lsb(n, j, field, prfs, key):
    1.25      """Share a pseudo-random number and its least significant bit.
    1.26  
    1.27 @@ -146,6 +149,7 @@
    1.28      return (convert_replicated_shamir(n, j, field, rep_shares),
    1.29              convert_replicated_shamir(n, j, GF256, lsb_shares))
    1.30  
    1.31 +@fake(lambda n, t, j, field, prfs, key: field(0))
    1.32  def prss_zero(n, t, j, field, prfs, key):
    1.33      """Return a pseudo-random secret zero-sharing of degree 2t.
    1.34  
     2.1 --- a/viff/test/test_util.py	Wed Dec 10 12:35:12 2008 +0100
     2.2 +++ b/viff/test/test_util.py	Wed Dec 10 12:42:06 2008 +0100
     2.3 @@ -20,8 +20,9 @@
     2.4  import os
     2.5  
     2.6  from viff.util import deep_wait
     2.7 -from viff.field import GF
     2.8 +from viff.field import GF, GF256
     2.9  import viff.shamir
    2.10 +import viff.prss
    2.11  
    2.12  from twisted.trial.unittest import TestCase
    2.13  from twisted.internet.defer import Deferred
    2.14 @@ -35,7 +36,7 @@
    2.15  
    2.16      # Modules which will be reloaded with and without VIFF_FAKE set in
    2.17      # the environment.
    2.18 -    _modules = [viff.shamir]
    2.19 +    _modules = [viff.shamir, viff.prss]
    2.20  
    2.21      def setUp(self):
    2.22          self.field = GF(1031)
    2.23 @@ -62,6 +63,20 @@
    2.24          shares = [(1, 1), (2, 10), (3, 1)]
    2.25          self.assertEquals(recombine(shares), 1)
    2.26  
    2.27 +    def test_prss(self):
    2.28 +        share = viff.prss.prss(None, None, self.field, None, None)
    2.29 +        self.assertEquals(share, self.field(7))
    2.30 +
    2.31 +    def test_prss_lsb(self):
    2.32 +        (share, bit) = viff.prss.prss_lsb(None, None, self.field, None, None)
    2.33 +        self.assertEquals(share, self.field(7))
    2.34 +        self.assertEquals(bit, GF256(1))
    2.35 +
    2.36 +    def test_prss_zero(self):
    2.37 +        share = viff.prss.prss_zero(None, None, None, self.field, None, None)
    2.38 +        self.assertEquals(share, self.field(0))
    2.39 +
    2.40 +
    2.41  class DeepWaitTest(TestCase):
    2.42      """Tests for :func:`viff.util.deep_wait`."""
    2.43