Ejemplo n.º 1
0
 def test_prf(self):
     key = int('0x00112233445566778899aabbccddeeff', 16).to_bytes(16, byteorder='little')
     bound = 1
     F = thresha.PRF(key, bound)
     y = F('test')
     self.assertEqual(y, 0)
     bound = 100
     F = thresha.PRF(key, bound)
     x = ''
     y = F(x.encode())
     self.assertTrue(0 <= y < bound)
     y2 = F(x.encode())
     self.assertEqual(y, y2)
Ejemplo n.º 2
0
    def test_prss(self):
        field = self.f256
        key = int('0x00112233445566778899aabbccddeeff',
                  16).to_bytes(16, byteorder='little')
        bound = 256  # field.modulus
        F = thresha.PRF(key, bound)
        m = 1
        pid = 0
        prfs = {(0, ): F}
        uci = 'test uci'.encode()
        n = 8
        a = F(uci, n)
        shares = thresha.pseudorandom_share(field, m, pid, prfs, uci, n)
        b = thresha.recombine(field, [(1, shares)])
        self.assertEqual(a, [s.value for s in b])
        a = [0] * n
        shares = thresha.pseudorandom_share_zero(field, m, pid, prfs, uci, n)
        b = thresha.recombine(field, [(1, shares)])
        self.assertEqual(a, b)

        m = 3
        pid = 0
        prfs = {(0, 1): F, (0, 2): F}  # reuse dummy PRF
        shares0 = thresha.pseudorandom_share_zero(field, m, pid, prfs, uci, n)
        pid = 1
        prfs = {(0, 1): F, (1, 2): F}  # reuse dummy PRF
        shares1 = thresha.pseudorandom_share_zero(field, m, pid, prfs, uci, n)
        pid = 2
        prfs = {(0, 2): F, (1, 2): F}  # reuse dummy PRF
        shares2 = thresha.pseudorandom_share_zero(field, m, pid, prfs, uci, n)
        b = thresha.recombine(field, [(1, shares0), (2, shares1),
                                      (3, shares2)])
        self.assertEqual(a, b)
Ejemplo n.º 3
0
 def test_prf(self):
     key = b'00112233445566778899aabbccddeeff'
     max = 100
     F = thresha.PRF(key, max)
     x = ''
     y = F(x)
     self.assertTrue(0 <= y < max)
     y2 = F(x)
     self.assertEqual(y, y2)
Ejemplo n.º 4
0
    def prfs(self, bound):
        """PRFs with codomain range(bound) for pseudorandom secret sharing.

        Return a mapping from sets of parties to PRFs.
        """
        f = {}
        for subset, key in self._prss_keys.items():
            if len(subset) == len(self.parties) - self.threshold:
                f[subset] = thresha.PRF(key, bound)
        return f
Ejemplo n.º 5
0
    def prfs(self, bound):
        """PRFs with codomain range(bound) for pseudorandom secret sharing.

        Return a mapping from sets of parties to PRFs.
        """
        try:
            return self._prfs[bound]
        except KeyError:
            self._prfs[bound] = {}
            for subset, key in self.keys.items():
                self._prfs[bound][subset] = thresha.PRF(key, bound)
            return self._prfs[bound]
Ejemplo n.º 6
0
 def test_prss(self):
     field = self.f19
     key = b'00112233445566778899aabbccddeeff'
     max = field.modulus
     F = thresha.PRF(key, max)
     n = 1
     id = 0
     prfs = {frozenset([0]): F}
     uci = 'test uci'
     m = 8
     a = F(uci, m)
     shares = thresha.pseudorandom_share(field, n, id, prfs, uci, m)
     b = thresha.recombine(field, [(1, shares)])
     self.assertEqual(a, b)
     a = [0] * m
     shares = thresha.pseudorandom_share_zero(field, n, id, prfs, uci, m)
     b = thresha.recombine(field, [(1, shares)])
     self.assertEqual(a, b)