Esempio 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)
Esempio 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)
Esempio 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
Esempio 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
Esempio 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
Esempio 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
Esempio n. 7
0
 def test_less_than_threshold(self):
     shares = split_secret(b'a', 2, 2)
     with pytest.raises(ValueError):
         recover_secret(shares[:1])
Esempio 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])
Esempio n. 9
0
 def test_share_count_greater_than_255(self):
     with pytest.raises(ValueError):
         split_secret(b'a', 2, 256)
Esempio 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])
Esempio n. 11
0
 def test_threshold_less_than_2(self):
     with pytest.raises(ValueError):
         split_secret(b'a', 1, 2)
Esempio n. 12
0
 def test_less_than_threshold(self):
     shares = split_secret(b'a', 2, 2)
     with pytest.raises(ValueError):
         recover_secret(shares[:1])
Esempio 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)
Esempio 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'
Esempio 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'
Esempio 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)
Esempio 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)
Esempio 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
Esempio 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
Esempio n. 20
0
 def test_empty_secret(self):
     with pytest.raises(ValueError):
         split_secret(b'', 2, 2)
Esempio 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)
Esempio n. 22
0
 def test_threshold_less_than_2(self):
     with pytest.raises(ValueError):
         split_secret(b'a', 1, 2)
Esempio n. 23
0
 def test_threshold_greater_than_255(self):
     with pytest.raises(ValueError):
         split_secret(b'a', 256, 256)
Esempio n. 24
0
 def test_share_count_less_than_threshold(self):
     with pytest.raises(ValueError):
         split_secret(b'a', 3, 2)
Esempio n. 25
0
 def test_empty_secret(self):
     with pytest.raises(ValueError):
         split_secret(b'', 2, 2)
Esempio n. 26
0
 def test_share_count_less_than_threshold(self):
     with pytest.raises(ValueError):
         split_secret(b'a', 3, 2)
Esempio n. 27
0
 def test_threshold_greater_than_255(self):
     with pytest.raises(ValueError):
         split_secret(b'a', 256, 256)
Esempio n. 28
0
 def test_share_count_greater_than_255(self):
     with pytest.raises(ValueError):
         split_secret(b'a', 2, 256)