How to use umbral - 10 common examples

To help you get started, we’ve selected a few umbral examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github nucypher / pyUmbral / tests / unit / test_umbral_keys.py View on Github external
def test_gen_key():
    # Pass in the parameters to test that manual param selection works
    umbral_priv_key = UmbralPrivateKey.gen_key()
    assert type(umbral_priv_key) == UmbralPrivateKey

    umbral_pub_key = umbral_priv_key.get_pubkey()
    assert type(umbral_pub_key) == UmbralPublicKey
github nucypher / pyUmbral / tests / fixtures.py View on Github external
def bobs_keys():
    priv = keys.UmbralPrivateKey.gen_key()
    pub = priv.get_pubkey()
    return MockKeyPair(priv, pub)
github nucypher / pyUmbral / tests / metrics / reencryption_benchmark.py View on Github external
def __standard_encryption_api() -> tuple:

    delegating_privkey = keys.UmbralPrivateKey.gen_key(params=PARAMS)
    delegating_pubkey = delegating_privkey.get_pubkey()

    signing_privkey = keys.UmbralPrivateKey.gen_key(params=PARAMS)
    signer = Signer(signing_privkey)

    receiving_privkey = keys.UmbralPrivateKey.gen_key(params=PARAMS)
    receiving_pubkey = receiving_privkey.get_pubkey()

    plain_data = os.urandom(32)
    ciphertext, capsule = pre.encrypt(delegating_pubkey, plain_data)

    capsule.set_correctness_keys(delegating=delegating_pubkey,
                                 receiving=receiving_pubkey,
                                 verifying=signing_privkey.get_pubkey())

    return delegating_privkey, signer, receiving_pubkey, ciphertext, capsule
github nucypher / pyUmbral / tests / metrics / reencryption_benchmark.py View on Github external
def __standard_encryption_api() -> tuple:

    delegating_privkey = keys.UmbralPrivateKey.gen_key(params=PARAMS)
    delegating_pubkey = delegating_privkey.get_pubkey()

    signing_privkey = keys.UmbralPrivateKey.gen_key(params=PARAMS)
    signer = Signer(signing_privkey)

    receiving_privkey = keys.UmbralPrivateKey.gen_key(params=PARAMS)
    receiving_pubkey = receiving_privkey.get_pubkey()

    plain_data = os.urandom(32)
    ciphertext, capsule = pre.encrypt(delegating_pubkey, plain_data)

    capsule.set_correctness_keys(delegating=delegating_pubkey,
                                 receiving=receiving_pubkey,
                                 verifying=signing_privkey.get_pubkey())

    return delegating_privkey, signer, receiving_pubkey, ciphertext, capsule
github nucypher / pyUmbral / tests / metrics / reencryption_firehose.py View on Github external
def __produce_kfrags(M, N) -> list:

    delegating_privkey = keys.UmbralPrivateKey.gen_key(params=PARAMS)

    signing_privkey = keys.UmbralPrivateKey.gen_key(params=PARAMS)
    signer = Signer(signing_privkey)

    receiving_privkey = keys.UmbralPrivateKey.gen_key(params=PARAMS)
    receiving_pubkey = receiving_privkey.get_pubkey()

    kfrags = pre.split_rekey(delegating_privkey, signer, receiving_pubkey, M, N)
    return kfrags
github nucypher / pyUmbral / tests / test_umbral.py View on Github external
def test_simple_api(N, M, curve=default_curve()):
    """Manually injects umbralparameters for multi-curve testing."""
    params = UmbralParameters(curve=curve)

    priv_key_alice = keys.UmbralPrivateKey.gen_key(params=params)
    pub_key_alice = priv_key_alice.get_pubkey()

    priv_key_bob = keys.UmbralPrivateKey.gen_key(params=params)
    pub_key_bob = priv_key_bob.get_pubkey()

    plain_data = b'attack at dawn'
    ciphertext, capsule = pre.encrypt(pub_key_alice, plain_data)

    cleartext = pre.decrypt(capsule, priv_key_alice, ciphertext)
    assert cleartext == plain_data

    rekeys, _unused_vkeys = pre.split_rekey(priv_key_alice, pub_key_bob, M, N, params=params)
    for rekey in rekeys:
        c_frag = pre.reencrypt(rekey, capsule, params=params)
        capsule.attach_cfrag(c_frag)
github nucypher / pyUmbral / tests / test_umbral.py View on Github external
def test_cheating_ursula_replays_old_reencryption(N, M):
    priv_key_alice = keys.UmbralPrivateKey.gen_key()
    pub_key_alice = priv_key_alice.get_pubkey()

    priv_key_bob = keys.UmbralPrivateKey.gen_key()
    pub_key_bob = priv_key_bob.get_pubkey()

    sym_key_alice1, capsule_alice1 = pre._encapsulate(pub_key_alice.point_key)
    sym_key_alice2, capsule_alice2 = pre._encapsulate(pub_key_alice.point_key)

    k_frags, v_keys = pre.split_rekey(priv_key_alice, pub_key_bob, M, N)

    for k_frag in k_frags:
        assert k_frag.is_consistent(v_keys)

    c_frags, challenges = [], []
    for index, k_frag in enumerate(k_frags):
        if index == 0:
            # Let's put the re-encryption of a different Alice ciphertext
            c_frag = pre.reencrypt(k_frag, capsule_alice2)
        else:
github nucypher / pyUmbral / tests / fixtures.py View on Github external
def alices_keys():
    delegating_priv = keys.UmbralPrivateKey.gen_key()
    signing_priv = keys.UmbralPrivateKey.gen_key()
    return delegating_priv, signing_priv
github nucypher / pyUmbral / tests / unit / test_primitives / test_point_serializers.py View on Github external
def generate_test_points_affine(quantity=2):
    points_affine = [
        (SECP256K1, 714, (54495335564072000415434275044935054036617226655045445809732056033758606213450,
                            26274482902044210718566767736429706729731617411738990314884135712590488065008)),
    ]
    for _ in range(quantity):
        args = (SECP256K1, 714, Point.gen_rand(curve=SECP256K1).to_affine())
        points_affine.append(args)
    return points_affine
github nucypher / pyUmbral / tests / unit / test_capsule_correctness_checks.py View on Github external
def test_cannot_attach_cfrag_without_proof():
    """
    However, even when properly attaching keys, we can't attach the CFrag
    if it is unproven.
    """
    params = default_params()

    capsule = Capsule(params,
                      point_e=Point.gen_rand(),
                      point_v=Point.gen_rand(),
                      bn_sig=CurveBN.gen_rand())

    cfrag = CapsuleFrag(point_e1=Point.gen_rand(),
                        point_v1=Point.gen_rand(),
                        kfrag_id=os.urandom(10),
                        point_precursor=Point.gen_rand(),
                        )
    key_details = capsule.set_correctness_keys(
        UmbralPrivateKey.gen_key().get_pubkey(),
        UmbralPrivateKey.gen_key().get_pubkey(),
        UmbralPrivateKey.gen_key().get_pubkey())

    delegating_details, receiving_details, verifying_details = key_details

    assert all((delegating_details, receiving_details, verifying_details))