def __share_secret(self, plain_text, workers):
     number_of_shares = len(workers)
     workers = self.__arrange_workers(list(workers))
     shares = self.generate_shares(plain_text, number_of_shares)
     shares_map = self.__distribute_shares(workers, shares)
     PRZS.setup(workers)
     return shares_map
def test_przs_alpha_2of3(workers):
    alice, bob, james = (
        workers["alice"],
        workers["bob"],
        workers["james"],
    )

    workers_vals = [alice, bob, james]
    PRZS.setup(workers_vals)

    values = [gen_alpha_2of3(worker) for worker in workers_vals]
    assert (values[0][0].get() == values[1][1].get()).all()
def test_przs_alpha_3of3(workers):
    alice, bob, james = (
        workers["alice"],
        workers["bob"],
        workers["james"],
    )

    workers_vals = [alice, bob, james]
    PRZS.setup(workers_vals)

    values = [gen_alpha_3of3(worker).get() for worker in workers_vals]

    sum_values = sum(values)

    assert sum_values.item() % RING_SIZE == 0
Exemple #4
0
def test_generate_seeds(workers):
    bob, alice, james = workers["bob"], workers["alice"], workers["james"]
    players = [bob, alice, james]
    seed_map = PRZS.generate_and_share_seeds(players)
    assert type(seed_map is dict)
    assert list(seed_map.keys()) == [bob, alice, james]
    assert seed_map[bob][0].location is seed_map[bob][1].location is bob
    assert seed_map[bob][0].get() == seed_map[alice][1].get()
Exemple #5
0
def test_get_random_number(workers):
    alice, bob, james = (
        workers["alice"],
        workers["bob"],
        workers["james"],
    )

    workers = [alice, bob, james]

    PRZS.setup(workers)

    paired_workers = list(zip(workers, workers[1:]))
    paired_workers.append((workers[-1], workers[0]))

    shape = (3, 2)

    for worker_cur, worker_next in paired_workers:
        t1 = get_random("cur", shape, worker_cur)
        t2 = get_random("prev", shape, worker_next)

        assert (t1.get() == t2.get()).all()
Exemple #6
0
def test_przs_alpha_2of3(workers):
    alice, bob, james = (
        workers["alice"],
        workers["bob"],
        workers["james"],
    )

    workers_vals = [alice, bob, james]
    PRZS.setup(workers_vals)

    values = [gen_alpha_2of3(worker).get() for worker in workers_vals]
    """
        Worker i holds (alpha_i, and alpha_i-1)
        Here we do:
        ((alpha_i, alpha_i-1), (alpha_i+1, alpha_i))
    """
    paired_values = zip(values, [*values[1:], values[0]])
    for alphas_worker_cur, alphas_worker_next in paired_values:
        alpha_cur, _ = alphas_worker_cur
        _, alpha_prev = alphas_worker_next

        assert alpha_cur == alpha_prev