Example #1
0
def main(path, batch_id):
    # create the encryption keys
    skA, pkA = prio.create_keypair()
    skB, pkB = prio.create_keypair()

    # create the client
    cfg = prio.Config(N_DATA, pkA, pkB, bytes(batch_id, 'utf-8'))
    client = prio.Client(cfg)

    # generate test data
    data = generate(batch_id, client)
    with open(path, "w") as f:
        write(f, data)

    # print a command to use
    def clean(s): return s[:-1].decode('utf-8') 
    args = {
        "--pings": path,
        "--pubkey-A": clean(pkA.export_hex()),
        "--pvtkey-A": clean(skA.export_hex()),
        "--pubkey-B": clean(pkB.export_hex()),
        "--pvtkey-B": clean(skB.export_hex()),
    }
    argstr = " \\".join([f"\n\t{k} {v}" for k, v in args.items()])
    print(f"python main.py \\{argstr}")
Example #2
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)
Example #3
0
async def main():
    n_clients = 10
    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()
    logger.info("Done!")
Example #4
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 import prio
import sys

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
p1A = vA.create_verify1()
p1B = vB.create_verify1()
Example #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()
Example #6
0
def serverB_keypair():
    return prio.create_keypair()