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
Example #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)