Beispiel #1
0
    def _testShamirRecover(self, minimum, shares, prime, secret, keys):
        if self.debug >= 100:
            print(
                "testShamirRecover(minimum=%d,shares=%d,prime=%d,secret=%s,keys=%s)"
                % (minimum, shares, prime, secret, keys))
        shamir = Shamir(minimum, prime)
        choices = list(range(shares))
        for k in range(minimum):
            i = self.rng.next(len(choices))
            shamir.setKey(choices[i] + 1, keys[choices[i]])
            del choices[i]

        assert shamir.getSecret() == secret
        for i in range(shares):
            assert shamir.getKey(i + 1) == keys[i]
Beispiel #2
0
 def _getShamir(self):
     shamir = Shamir(self.getMinimum(), self.getPrime())
     for i in self._keys:
         shamir.setKey(i, self._keys[i])
     return shamir