Ejemplo n.º 1
0
 def test_x_equals_0(self):
     """
     Make sure we don't leak the secret (which is at 0.)
     """
     shares = split_secret(b'secret', 2, 2)
     with pytest.raises(ValueError):
         add_share(shares, 0)
Ejemplo n.º 2
0
 def test_x_equals_0(self):
     """
     Make sure we don't leak the secret (which is at 0.)
     """
     shares = split_secret(b'secret', 2, 2)
     with pytest.raises(ValueError):
         add_share(shares, 0)
Ejemplo n.º 3
0
def test_split_and_recover_fast(secret):
    """
    Tests quickly whether the secret can be split and recovered. This test is
    not as exhaustive as `test_split_and_recover` but it hopefully still
    catches anything too obvious during local development.
    """
    shares = split_secret(secret, 2, 3)
    for i in range(2, 4):
        subset = random.sample(shares, i)
        random.shuffle(subset)
        recovered_secret = recover_secret(subset)
        assert recovered_secret == secret
Ejemplo n.º 4
0
def test_split_and_recover_fast(secret):
    """
    Tests quickly whether the secret can be split and recovered. This test is
    not as exhaustive as `test_split_and_recover` but it hopefully still
    catches anything too obvious during local development.
    """
    shares = split_secret(secret, 2, 3)
    for i in range(2, 4):
        subset = random.sample(shares, i)
        random.shuffle(subset)
        recovered_secret = recover_secret(subset)
        assert recovered_secret == secret
Ejemplo n.º 5
0
def test_split_and_recover(_, secret, threshold_and_number_of_shares):
    """
    Tests whether the secret can be split and recovered for some random secret,
    threshold and share. This can take a long time to run (several minutes),
    for large thresholds or shares. For this reason this test is only executed
    when running on continous integration by default.

    Take a look at `test_split_and_recover_fast`, which always runs for a fast
    version of this test.
    """
    threshold, number_of_shares = threshold_and_number_of_shares

    shares = split_secret(secret, threshold, number_of_shares)
    subset = random.sample(shares, threshold)
    random.shuffle(subset)
    recovered_secret = recover_secret(subset)
    assert recovered_secret == secret
Ejemplo n.º 6
0
def test_split_and_recover(_, secret, threshold_and_number_of_shares):
    """
    Tests whether the secret can be split and recovered for some random secret,
    threshold and share. This can take a long time to run (several minutes),
    for large thresholds or shares. For this reason this test is only executed
    when running on continous integration by default.

    Take a look at `test_split_and_recover_fast`, which always runs for a fast
    version of this test.
    """
    threshold, number_of_shares = threshold_and_number_of_shares

    shares = split_secret(secret, threshold, number_of_shares)
    subset = random.sample(shares, threshold)
    random.shuffle(subset)
    recovered_secret = recover_secret(subset)
    assert recovered_secret == secret
Ejemplo n.º 7
0
 def test_less_than_threshold(self):
     shares = split_secret(b'a', 2, 2)
     with pytest.raises(ValueError):
         recover_secret(shares[:1])
Ejemplo n.º 8
0
 def test_incompatible_shares_threshold(self):
     shares_a = split_secret(b'a', 2, 3)
     shares_b = split_secret(b'a', 3, 3)
     with pytest.raises(ValueError):
         recover_secret(shares_a[:1] + shares_b[:2])
Ejemplo n.º 9
0
 def test_share_count_greater_than_255(self):
     with pytest.raises(ValueError):
         split_secret(b'a', 2, 256)
Ejemplo n.º 10
0
 def test_incompatible_shares_threshold(self):
     shares_a = split_secret(b'a', 2, 3)
     shares_b = split_secret(b'a', 3, 3)
     with pytest.raises(ValueError):
         recover_secret(shares_a[:1] + shares_b[:2])
Ejemplo n.º 11
0
 def test_threshold_less_than_2(self):
     with pytest.raises(ValueError):
         split_secret(b'a', 1, 2)
Ejemplo n.º 12
0
 def test_less_than_threshold(self):
     shares = split_secret(b'a', 2, 2)
     with pytest.raises(ValueError):
         recover_secret(shares[:1])
Ejemplo n.º 13
0
 def test_x_greater_than_255(self):
     shares = split_secret(b'secret', 2, 2)
     with pytest.raises(ValueError):
         add_share(shares, 256)
Ejemplo n.º 14
0
 def test_new_share(self):
     shares = split_secret(b'secret', 2, 2)
     third_share = add_share(shares, 3)
     for share in shares:
         recovered_secret = recover_secret([share, third_share])
         assert recovered_secret == b'secret'
Ejemplo n.º 15
0
 def test_new_share(self):
     shares = split_secret(b'secret', 2, 2)
     third_share = add_share(shares, 3)
     for share in shares:
         recovered_secret = recover_secret([share, third_share])
         assert recovered_secret == b'secret'
Ejemplo n.º 16
0
 def test_x_greater_than_255(self):
     shares = split_secret(b'secret', 2, 2)
     with pytest.raises(ValueError):
         add_share(shares, 256)
Ejemplo n.º 17
0
 def test_x_less_than_0(self):
     shares = split_secret(b'secret', 2, 2)
     with pytest.raises(ValueError):
         add_share(shares, -1)
Ejemplo n.º 18
0
 def test_recreate_share(self):
     shares = split_secret(b'secret', 2, 2)
     for i, share in enumerate(shares, 1):
         recreated_share = add_share(shares, i)
         assert recreated_share._ys == share._ys
Ejemplo n.º 19
0
 def test_recreate_share(self):
     shares = split_secret(b'secret', 2, 2)
     for i, share in enumerate(shares, 1):
         recreated_share = add_share(shares, i)
         assert recreated_share._ys == share._ys
Ejemplo n.º 20
0
 def test_empty_secret(self):
     with pytest.raises(ValueError):
         split_secret(b'', 2, 2)
Ejemplo n.º 21
0
 def test_x_less_than_0(self):
     shares = split_secret(b'secret', 2, 2)
     with pytest.raises(ValueError):
         add_share(shares, -1)
Ejemplo n.º 22
0
 def test_threshold_less_than_2(self):
     with pytest.raises(ValueError):
         split_secret(b'a', 1, 2)
Ejemplo n.º 23
0
 def test_threshold_greater_than_255(self):
     with pytest.raises(ValueError):
         split_secret(b'a', 256, 256)
Ejemplo n.º 24
0
 def test_share_count_less_than_threshold(self):
     with pytest.raises(ValueError):
         split_secret(b'a', 3, 2)
Ejemplo n.º 25
0
 def test_empty_secret(self):
     with pytest.raises(ValueError):
         split_secret(b'', 2, 2)
Ejemplo n.º 26
0
 def test_share_count_less_than_threshold(self):
     with pytest.raises(ValueError):
         split_secret(b'a', 3, 2)
Ejemplo n.º 27
0
 def test_threshold_greater_than_255(self):
     with pytest.raises(ValueError):
         split_secret(b'a', 256, 256)
Ejemplo n.º 28
0
 def test_share_count_greater_than_255(self):
     with pytest.raises(ValueError):
         split_secret(b'a', 2, 256)