How to use the umbral.keys.UmbralPrivateKey.gen_key function in umbral

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_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 drbh / ncipfs / ncipfs.py View on Github external
config_root=os.path.join(direco),
            is_me=True,
            known_nodes={self.ursula},
            start_learning_now=False,
            federated_only=True,
            learn_on_same_thread=True,
        )
        alice_config.initialize(password=passphrase)
        alice_config.keyring.unlock(password=passphrase)
        alice = alice_config.produce()
        alice_config_file = alice_config.to_configuration_file()
        alice.start_learning_loop(now=True)

        
        enc_privkey = UmbralPrivateKey.gen_key()
        sig_privkey = UmbralPrivateKey.gen_key()

        doctor_privkeys = {
            'enc': enc_privkey.to_bytes().hex(),
            'sig': sig_privkey.to_bytes().hex(),
        }

        DOCTOR_PUBLIC_JSON =  direco + '/recipent.public.json'
        DOCTOR_PRIVATE_JSON = direco + '/recipent.private.json'

        with open(DOCTOR_PRIVATE_JSON, 'w') as f:
            json.dump(doctor_privkeys, f)

        enc_pubkey = enc_privkey.get_pubkey()
        sig_pubkey = sig_privkey.get_pubkey()
        doctor_pubkeys = {
            'enc': enc_pubkey.to_bytes().hex(),