Exemplo n.º 1
0
def bench_client_encoding(path):
    runs = 10 ** 2
    timings = []
    for k in tqdm([8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096]):
        _, pubkey = prio.create_keypair()
        cfg = prio.Config(k, pubkey, pubkey, b"test_batch")
        client = prio.Client(cfg)
        data = bytes([1] * k)
        timing = timeit.timeit("client.encode(data)", number=runs, globals=locals())
        timings.append([k, timing])

    data = np.array(timings)
    y = data[:, 1] / runs
    x = data[:, 0]

    fig, ax = plt.subplots()
    plt.title(f"measurement size vs encoding time (n={runs})")
    plt.xlabel("measurement size (bits)")
    plt.ylabel("encoding time (seconds)")
    ax.set_xscale("log", basex=2)
    ax.set_yscale("log", basey=2)
    ax.xaxis.set_major_formatter(matplotlib.ticker.ScalarFormatter())
    ax.yaxis.set_major_formatter(matplotlib.ticker.ScalarFormatter())
    plt.plot(x, y)
    plt.savefig(path)
Exemplo n.º 2
0
def bench_encrypted_sizes(path):
    _, pubkey = prio.create_keypair()

    def size(n):
        cfg = prio.Config(n, pubkey, pubkey, b"test")
        a, b = prio.Client(cfg).encode(bytes([1] * k))
        return [k, len(a), len(b)]

    sizes = []
    for k in tqdm(range(0, 10000, 100)):
        try:
            sizes.append(size(k))
        except:
            print(f"Prio excepted at {k} items")
            break

    fig, ax = plt.subplots()
    ax.set_xscale("log", basex=2)
    ax.set_yscale("log", basey=2)
    ax.xaxis.set_major_formatter(matplotlib.ticker.ScalarFormatter())
    ax.yaxis.set_major_formatter(matplotlib.ticker.ScalarFormatter())
    plt.title("Prio measurement size vs payload size")
    plt.xlabel("measurement size (bits)")
    plt.ylabel("payload size (bytes)")
    plt.plot(*np.array(sizes).T[:2])
    plt.savefig(path)
Exemplo n.º 3
0
def test_client_agg(n_clients):
    seed = prio.PRGSeed()

    skA, pkA = prio.create_keypair()
    skB, pkB = prio.create_keypair()

    # the config is shared across all actors
    config = prio.Config(133, pkA, pkB, b"test_batch")

    sA = prio.Server(config, prio.PRIO_SERVER_A, skA, seed)
    sB = prio.Server(config, prio.PRIO_SERVER_B, skB, seed)

    client = prio.Client(config)

    n_data = config.num_data_fields()
    data_items = bytes([(i % 3 == 1) or (i % 5 == 1) for i in range(n_data)])

    for i in range(n_clients):
        for_server_a, for_server_b = client.encode(data_items)

        # Setup verification
        vA = sA.create_verifier(for_server_a)
        vB = sB.create_verifier(for_server_b)

        # Produce a packet1 and send to the other party
        p1A = vA.create_verify1()
        p1B = vB.create_verify1()

        # Produce packet2 and send to the other party
        p2A = vA.create_verify2(p1A, p1B)
        p2B = vB.create_verify2(p1A, p1B)

        assert vA.is_valid(p2A, p2B)
        assert vB.is_valid(p2A, p2B)

        sA.aggregate(vA)
        sB.aggregate(vB)

    t_a = sA.total_shares()
    t_b = sB.total_shares()

    output = prio.total_share_final(config, t_a, t_b)

    expected = [item * n_clients for item in list(data_items)]
    assert list(output) == expected
Exemplo n.º 4
0
async def main():
    Prio_init()
    n_clients = 4
    n_data = 133
    server_secret = prio.PRGSeed()
    skA, pkA = prio.create_keypair()
    skB, pkB = prio.create_keypair()

    cfg = prio.Config(n_data, pkA, pkB, b"test_batch")
    sA = prio.Server(cfg, prio.PRIO_SERVER_A, skA, server_secret)
    sB = prio.Server(cfg, prio.PRIO_SERVER_B, skB, server_secret)

    data_items = bytes([(i % 3 == 1) or (i % 5 == 1) for i in range(n_data)])

    logger.info("Starting asyncio prio pipeline.")
    client = prio.Client(cfg)
    queue_a = asyncio.Queue()
    queue_b = asyncio.Queue()

    await client_produce(client, data_items, queue_a, queue_b, n_clients)

    consumers = asyncio.ensure_future(
        asyncio.gather(server_consume(sA, queue_a, queue_b),
                       server_consume(sB, queue_b, queue_a)))

    await asyncio.gather(queue_a.join(), queue_b.join())

    t_a = sA.total_shares()
    t_b = sB.total_shares()

    output = prio.total_share_final(cfg, t_a, t_b)

    expected = [item * n_clients for item in list(data_items)]
    assert list(output) == expected

    consumers.cancel()
    Prio_clear()
    logger.info("Done!")
Exemplo n.º 5
0
def test_privatekey():
    pvtkey, pubkey = prio.create_keypair()
    pvtdata = pvtkey.export_bin()
    pubdata = pubkey.export_bin()
    new_pvtkey = prio.PrivateKey().import_bin(pvtdata, pubdata)
    assert pvtdata == new_pvtkey.export_bin()
Exemplo n.º 6
0
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

from prio_processor.prio import wrapper as prio
from prio import PrioContext
import sys

with PrioContext():
    skA, pkA = prio.create_keypair()
    skB, pkB = prio.create_keypair()

    n_data = 133
    batch_id = b"test_batch"
    cfg = prio.Config(n_data, pkA, pkB, batch_id)

    server_secret = prio.PRGSeed()

    sA = prio.Server(cfg, prio.PRIO_SERVER_A, skA, server_secret)
    sB = prio.Server(cfg, prio.PRIO_SERVER_B, skB, server_secret)

    client = prio.Client(cfg)

    data_items = bytes([(i % 3 == 1) or (i % 5 == 1) for i in range(n_data)])
    for_server_a, for_server_b = client.encode(data_items)

    # Setup verification
    vA = sA.create_verifier(for_server_a)
    vB = sB.create_verifier(for_server_b)

    # Produce a packet1 and send to the other party
def serverB_keypair():
    return prio.create_keypair()