Exemplo n.º 1
0
def test_int_share_recover():
    num_players = 5
    reconstruction_threshold = 3

    secret = 123456789
    max_secret_length = len(str(secret))
    shares = sss._share_secret_int(num_players, reconstruction_threshold, max_secret_length, secret)
    recovered_secret = sss._reconstruct_secret_int(num_players, max_secret_length, shares[:reconstruction_threshold])
    assert recovered_secret == secret
Exemplo n.º 2
0
def share_authenticated_secret(players, reconstruction_threshold, max_secret_length, secret):
    '''
    Args:
        players, a list of unique string ids for all players
        reconstruction_threshold, the number of shares needed for reconstruction
            any collection of fewer shares will reveal no information about the secret
        max_secret_length, the maximum length of the secret represented as a bytestring (ie, len(secret))
        secret, a bytestring to be Shamir secret shared
    Returns:
        a dictionary of ids (from the players argument) to robust secret shares, which consist of
            a share
            a map of player ids to keys for the shares held by those players
            a map of player ids to vectors for this share
                that can be verified by keys held by those players
    Raises:
        ValueError, the input parameters fail validation (see share_secret of schemes/sss.py)
    '''
    num_players = len(players)
    secret_int = serialization.convert_bytestring_to_int(secret)

    # generate shares of the secret s: ((x_1, s_1), . . . , (x_n, s_n))
    int_shares = [pairing.elegant_pair(*share) for share in
                  sss._share_secret_int(num_players,
                                        reconstruction_threshold,
                                        max_secret_length + 1,  # conversion to an integer adds one byte
                                        secret_int)]

    # assign shares to players
    shares_map = {player: share for (player, share) in zip(players, int_shares)}

    batch_keys, batch_vectors = defaultdict(dict), defaultdict(dict)
    for player in players:  # generate n MAC keys k_ij and vectors t_ij = MAC(k_ij, s_j) per share s_j
        keys, vectors = authentication.generate_batch(num_players, shares_map[player], max_secret_length + 1)
        for player_id, key, vector in zip(players, keys, vectors):
            batch_keys[player][player_id] = key
            batch_vectors[player][player_id] = vector

    return _make_robust_shares(shares_map, batch_keys, batch_vectors)