def test_robust_bad_configuration_prime_none(): num_players = 40 reconstruction_threshold = 30 players = get_ids(num_players) with pytest.raises(ValueError): rss.share_authenticated_secret(players, reconstruction_threshold, 5000, secret)
def test_robust_bad_configuration_threshold(): num_players = 2 reconstruction_threshold = 5 players = get_ids(num_players) max_secret_length = len(secret) with pytest.raises(ValueError): rss.share_authenticated_secret(players, reconstruction_threshold, max_secret_length, secret)
def test_robust_bad_configuration_prime_small_secret(): num_players = 5 reconstruction_threshold = 2 players = get_ids(num_players) bad_secret = '\xFF\xFF' max_secret_length = len(bad_secret) - 1 with pytest.raises(ValueError): rss.share_authenticated_secret(players, reconstruction_threshold, max_secret_length, bad_secret)
def share_and_recover(num_players, reconstruction_threshold, secret, end): max_secret_length = len(secret) players = test_authenticated_rss.get_ids(num_players) robust_shares = rss.share_authenticated_secret(players, reconstruction_threshold, max_secret_length, secret) shares = {player: share for (player, share) in robust_shares.items()[:end]} return rss.reconstruct_unauthenticated_secret(num_players, max_secret_length, shares)
def test_min_shares_some_bad(): num_players = 9 reconstruction_threshold = 5 num_bad = 2 max_secret_length = len(secret) players = test_authenticated_rss.get_ids(num_players) robust_shares = rss.share_authenticated_secret(players, reconstruction_threshold, max_secret_length, secret) result = corrupt_and_recover(robust_shares, num_players, num_players, num_bad) assert result is None or result != secret
def get_shares_subset(players, reconstruction_threshold, secret, end): ''' Args: players, a list of random, unique ids reconstruction_threshold, the threshold used for sharing secret, the value to be secret shared end, marks the number of shares to return Returns: a dictionary of length end that maps ids to json_string shares ''' max_secret_length = len(secret) shares_map = rss.share_authenticated_secret(players, reconstruction_threshold, max_secret_length, secret) return {player: shares_map[player] for player in shares_map.keys()[:end]}
def share(secret, player_ids, threshold): """ Construct shares of the given secret such that shares below the threshold yield no information, but shares above the threshold recreate the secret. Args: secret: a binary string or other byte representation of the secret to be shared. player_ids: a list of unique strings, one for each resulting share threshold: the number of shares required to reconstruct the secret. Returns: A map from player_id to a share to give to that player, suitable to be passed into reconstruct Raises: LibraryException: an exception was thrown by the supporting sharing library """ try: return rss.share_authenticated_secret(player_ids, threshold, len(secret), secret) except ValueError: logging.exception("Exception encountered during secret share creation") raise exceptions.LibraryException