How to use the umbral.signing.Signer 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 / vectors / generate_test_vectors.py View on Github external
# SETUP #
#########
set_default_curve()
params = default_params()
curve = params.curve

# We create also some Umbral objects for later
delegating_privkey = UmbralPrivateKey.gen_key(params=params)
receiving_privkey = UmbralPrivateKey.gen_key(params=params)
signing_privkey = UmbralPrivateKey.gen_key(params=params)

verifying_key = signing_privkey.get_pubkey()
delegating_key = delegating_privkey.get_pubkey()
receiving_key = receiving_privkey.get_pubkey()

signer = Signer(signing_privkey)

kfrags = pre.generate_kfrags(delegating_privkey=delegating_privkey,
                             receiving_pubkey=receiving_key,
                             threshold=6,
                             N=10,
                             signer=signer,
                             )

plain_data = b'peace at dawn'

ciphertext, capsule = pre.encrypt(delegating_key, plain_data)

capsule.set_correctness_keys(delegating=delegating_key,
                             receiving=receiving_key,
                             verifying=verifying_key)
github nucypher / pyUmbral / tests / functional / test_correctness.py View on Github external
def test_kfrags_signed_without_correctness_keys(alices_keys, bobs_keys, capsule):
    delegating_privkey, signing_privkey = alices_keys
    delegating_pubkey = delegating_privkey.get_pubkey()
    verifying_key = signing_privkey.get_pubkey()

    receiving_privkey, receiving_pubkey = bobs_keys

    kfrags = pre.generate_kfrags(delegating_privkey=delegating_privkey,
                                 signer=Signer(signing_privkey),
                                 receiving_pubkey=receiving_pubkey,
                                 threshold=6,
                                 N=10,
                                 sign_delegating_key=False,
                                 sign_receiving_key=False)

    for kfrag in kfrags:
        # You can verify the KFrag specifying only the verifying key
        assert kfrag.verify(signing_pubkey=verifying_key)

        # ... or if it is set in the capsule, using the capsule
        capsule.set_correctness_keys(verifying=verifying_key)
        assert kfrag.verify_for_capsule(capsule)

        # It should even work when other keys are set in the capsule
        assert kfrag.verify(signing_pubkey=verifying_key,
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 / unit / test_signing.py View on Github external
def test_prehashed_message(execution_number):
    privkey = UmbralPrivateKey.gen_key()
    pubkey = privkey.get_pubkey()
    signer = Signer(private_key=privkey)

    message = b"peace at dawn"
    hash_function = hashes.Hash(DEFAULT_HASH_ALGORITHM(), backend=backend)
    hash_function.update(message)
    prehashed_message = hash_function.finalize()

    signature = signer(message=prehashed_message, is_prehashed=True)

    assert signature.verify(message=prehashed_message,
                            verifying_key=pubkey,
                            is_prehashed=True)
github nucypher / pyUmbral / tests / metrics / reencryption_firehose.py View on Github external
def __produce_kfrags_and_capsule(m: int, n: int) -> Tuple[List[KFrag], Capsule]:

    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)

    kfrags = pre.generate_kfrags(delegating_privkey, receiving_pubkey, m, n, signer)

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

    return kfrags, capsule
github nucypher / pyUmbral / tests / unit / test_capsule_operations.py View on Github external
def test_capsule_as_dict_key(alices_keys, bobs_keys):
    delegating_privkey, signing_privkey = alices_keys
    signer_alice = Signer(signing_privkey)
    delegating_pubkey = delegating_privkey.get_pubkey()
    signing_pubkey = signing_privkey.get_pubkey()

    receiving_privkey, receiving_pubkey = bobs_keys

    plain_data = b'peace at dawn'
    ciphertext, capsule = pre.encrypt(delegating_pubkey, plain_data)

    # We can use the capsule as a key, and successfully lookup using it.
    some_dict = {capsule: "Thing that Bob wants to try per-Capsule"}
    assert some_dict[capsule] == "Thing that Bob wants to try per-Capsule"

    # And if we change the value for this key, all is still well.
    some_dict[capsule] = "Bob has changed his mind."
    assert some_dict[capsule] == "Bob has changed his mind."
    assert len(some_dict.keys()) == 1
github nucypher / pyUmbral / tests / scenario / test_simple_api.py View on Github external
The test covers all the main stages of data sharing with NuCypher:
    key generation, delegation, encryption, decryption by 
    Alice, re-encryption by Ursula, and decryption by Bob. 

    Manually injects umbralparameters for multi-curve testing."""

    # Generation of global parameters
    params = UmbralParameters(curve=curve)

    # Key Generation (Alice)
    delegating_privkey = UmbralPrivateKey.gen_key(params=params)
    delegating_pubkey = delegating_privkey.get_pubkey()

    signing_privkey = UmbralPrivateKey.gen_key(params=params)
    signing_pubkey = signing_privkey.get_pubkey()
    signer = Signer(signing_privkey)

    # Key Generation (Bob)
    receiving_privkey = UmbralPrivateKey.gen_key(params=params)
    receiving_pubkey = receiving_privkey.get_pubkey()

    # Encryption by an unnamed data source
    plain_data = b'peace at dawn'
    ciphertext, capsule = pre.encrypt(delegating_pubkey, plain_data)

    # Decryption by Alice
    cleartext = pre.decrypt(ciphertext, capsule, delegating_privkey)
    assert cleartext == plain_data

    # Split Re-Encryption Key Generation (aka Delegation)
    kfrags = pre.generate_kfrags(delegating_privkey, receiving_pubkey, M, N, signer)
github nucypher / pyUmbral / docs / examples / umbral_simple_api.py View on Github external
from umbral import pre, keys, config, signing

config.set_default_curve()

#2
# Generate an Umbral key pair
# ---------------------------
# First, Let's generate two asymmetric key pairs for Alice:
# A delegating key pair and a Signing key pair.

alices_private_key = keys.UmbralPrivateKey.gen_key()
alices_public_key = alices_private_key.get_pubkey()

alices_signing_key = keys.UmbralPrivateKey.gen_key()
alices_verifying_key = alices_signing_key.get_pubkey()
alices_signer = signing.Signer(private_key=alices_signing_key)

#3
# Encrypt some data for Alice
# ---------------------------
# Now let's encrypt data with Alice's public key.
# Invocation of `pre.encrypt` returns both the `ciphertext`,
# and a `capsule`. Anyone with Alice's public key can perform
# this operation.

plaintext = b'Proxy Re-encryption is cool!'
ciphertext, capsule = pre.encrypt(alices_public_key, plaintext)
print(ciphertext)

#4
# Decrypt data for Alice
# ----------------------