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