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 wrap: on
line diff
--- a/viff/prss.py	Wed Dec 10 12:35:12 2008 +0100
+++ b/viff/prss.py	Wed Dec 10 12:42:06 2008 +0100
@@ -51,6 +51,7 @@
 
 from viff import shamir
 from viff.field import GF256
+from viff.util import fake
 
 def random_replicated_sharing(j, prfs, key):
     """Return a replicated sharing of a random number.
@@ -81,6 +82,7 @@
         result += share * f_in_j
     return result
 
+@fake(lambda n, j, field, prfs, key: field(7))
 def prss(n, j, field, prfs, key):
     """Return a pseudo-random secret share for a random number.
 
@@ -108,6 +110,7 @@
     rep_shares = random_replicated_sharing(j, prfs, key)
     return convert_replicated_shamir(n, j, field, rep_shares)
 
+@fake(lambda n, j, field, prfs, key: (field(7), GF256(1)))
 def prss_lsb(n, j, field, prfs, key):
     """Share a pseudo-random number and its least significant bit.
 
@@ -146,6 +149,7 @@
     return (convert_replicated_shamir(n, j, field, rep_shares),
             convert_replicated_shamir(n, j, GF256, lsb_shares))
 
+@fake(lambda n, t, j, field, prfs, key: field(0))
 def prss_zero(n, t, j, field, prfs, key):
     """Return a pseudo-random secret zero-sharing of degree 2t.
 
--- a/viff/test/test_util.py	Wed Dec 10 12:35:12 2008 +0100
+++ b/viff/test/test_util.py	Wed Dec 10 12:42:06 2008 +0100
@@ -20,8 +20,9 @@
 import os
 
 from viff.util import deep_wait
-from viff.field import GF
+from viff.field import GF, GF256
 import viff.shamir
+import viff.prss
 
 from twisted.trial.unittest import TestCase
 from twisted.internet.defer import Deferred
@@ -35,7 +36,7 @@
 
     # Modules which will be reloaded with and without VIFF_FAKE set in
     # the environment.
-    _modules = [viff.shamir]
+    _modules = [viff.shamir, viff.prss]
 
     def setUp(self):
         self.field = GF(1031)
@@ -62,6 +63,20 @@
         shares = [(1, 1), (2, 10), (3, 1)]
         self.assertEquals(recombine(shares), 1)
 
+    def test_prss(self):
+        share = viff.prss.prss(None, None, self.field, None, None)
+        self.assertEquals(share, self.field(7))
+
+    def test_prss_lsb(self):
+        (share, bit) = viff.prss.prss_lsb(None, None, self.field, None, None)
+        self.assertEquals(share, self.field(7))
+        self.assertEquals(bit, GF256(1))
+
+    def test_prss_zero(self):
+        share = viff.prss.prss_zero(None, None, None, self.field, None, None)
+        self.assertEquals(share, self.field(0))
+
+
 class DeepWaitTest(TestCase):
     """Tests for :func:`viff.util.deep_wait`."""