Ejemplo n.º 1
0
def share_secret(num_players, reconstruction_threshold, max_secret_length, secret):
    '''
    Args:
        num_players, the number of shares to be distributed
        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 list of strings, each representing an integer, that can be passed to reconstruct_secret
    Raises:
        ValueError, the input arguments fail validation
    '''
    secret_int = serialization.convert_bytestring_to_int(secret)
    points = _share_secret_int(num_players, reconstruction_threshold, max_secret_length + 1, secret_int)
    return [str(pairing.elegant_pair(*tup)) for tup in points]
Ejemplo 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)
Ejemplo n.º 3
0
def run_pair_unpair(tup):
    z = pairing.elegant_pair(tup[0], tup[1])
    result = pairing.elegant_unpair(z)
    return tup == result