def collude_and_recover(num_players, reconstruction_threshold, max_secret_length, shares_subset, num_collude):
    '''
    Args:
        num_players, the number of players that were shared across
        reconstruction_threshold, the threshold for reconstruction
        max_secret_length, the maximum length of the secret that was shared
        shares_subset, a dictionary of a subset of players to json robust shares
        num_corrupt, the number of players that will collude
    Returns:
        the result of robust reconstruction
    '''
    max_secret_length = len(secret)

    colluders = {player: rss._deserialize_robust_share(share) for player, share in shares_subset.items()[:num_collude]}

    for player, player_dict in colluders.items():
        player_dict["share"] /= 2
        for verifier, verifier_dict in colluders.items():
            new_key, new_vector = authentication.generate_check_vector(player_dict["share"], max_secret_length)
            verifier_dict["keys"][player] = new_key
            player_dict["vectors"][verifier] = new_vector

    # assert that these players do in fact collude
    for verifier, verifier_dict in colluders.items():
        for player, player_dict in colluders.items():
            assert authentication.validate(verifier_dict["keys"][player], player_dict["vectors"][verifier],
                                           player_dict["share"], max_secret_length) is True

    shares = combine_testing_dictionaries(shares_subset, jsonify_dict(colluders))
    return rss.reconstruct_authenticated_secret(num_players, reconstruction_threshold, max_secret_length, shares)
def test_generate_batch_validate_single():
    message = 112358132134
    max_length = len(str(message))
    num_macs = 55

    keys, vectors = authentication.generate_batch(num_macs, message, max_length)
    for key, vector in zip(keys, vectors):
        assert authentication.validate(key, vector, message, max_length) is True
def test_check_vector_b():
    message = 112358132134
    max_length = len(str(message))

    for i in range(1000):
        key, vector = authentication.generate_check_vector(message, max_length)

        if (vector[0] == 0):  # verify that b is never zero for many cases
            assert False
        else:
            assert authentication.validate(key, vector, message, max_length) and vector[0] != 0
def test_check_vector_large():
    message = ('123456789012345678901234567890123456789012345678901234567890'
               '123456789012345678901234567890123456789012345678901234567890'
               '123456789012345678901234567890123456789012345678901234567890'
               '123456789012345678901234567890123456789012345678901234567890'
               '123456789012345678901234567890123456789012345678901234567890'
               '123456789012345678901234567890123456789012345678901234567890'
               '12345678901234567890')
    max_length = len(message)

    message = int(message)
    key, vector = authentication.generate_check_vector(message, max_length)
    assert authentication.validate(key, vector, message, max_length) is True
Beispiel #5
0
def _get_player_to_verifies_map(shares_map, keys_for_players, vectors_from_players, max_secret_length):
    '''
    Args:
        shares_map, a mapping of player string ids to integer shares
        keys_for_players, a mapping of player string ids to maps of keys to associate with other players
        vectors_from_players, a mapping of player string ids to maps of vectors associated with this player's share
        max_secret_length, the max length of the share if it were represented as a bytestring
    Returns:
        a mapping from player string id (verifier) to a tuple of players verified by the verifier
    '''
    verifies = defaultdict(list)
    for verifier in shares_map.keys():
        for player, share in shares_map.items():
            if authentication.validate(keys_for_players[verifier][player], vectors_from_players[player][verifier], share, max_secret_length + 1):
                verifies[verifier].append(player)
    # return a dictionary that can be inverted - the value is a tuple (hashable) and sorted (in preparation for equality checks)
    return {verifier: tuple(sorted(players)) for verifier, players in verifies.items()}
def test_check_vector_standard():
    message = 112358132134
    max_length = len(str(message))
    key, vector = authentication.generate_check_vector(message, max_length)
    assert authentication.validate(key, vector, message, max_length) is True