Skip to main content

NuCypher's Umbral Proxy Re-Encryption Implementation

Project description

PyPI Package latest release CircleCI build status Commits since latest release Documentation Status Discord

pyUmbral is the reference implementation of the Umbral threshold proxy re-encryption scheme. It is open-source, built with Python, and uses OpenSSL and Cryptography.io.

Using Umbral, Alice (the data owner) can delegate decryption rights to Bob for any ciphertext intended to her, through a re-encryption process performed by a set of semi-trusted proxies or Ursulas. When a threshold of these proxies participate by performing re-encryption, Bob is able to combine these independent re-encryptions and decrypt the original message using his private key.

https://www.nucypher.com/_next/static/images/umbral-d60f22230f2ac92b56c6e7d84794e5c4.svg

pyUmbral is the cryptographic engine behind nucypher, a proxy re-encryption network to empower privacy in decentralized systems.

Usage

Key Generation

As in any public-key cryptosystem, users need a pair of public and private keys. Additionally, users that delegate access to their data (like Alice, in this example) need a signing keypair.

from umbral import pre, keys, signing

# Generate Umbral keys for Alice.
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)

# Generate Umbral keys for Bob.
bobs_private_key = keys.UmbralPrivateKey.gen_key()
bobs_public_key = bobs_private_key.get_pubkey()

Encryption

Now let’s encrypt data with Alice’s public key. Invocation of pre.encrypt returns both the ciphertext and a capsule. Note that anyone with Alice’s public key can perform this operation.

Since data was encrypted with Alice’s public key, Alice can open the capsule and decrypt the ciphertext with her private key.

# Encrypt data with Alice's public key.
plaintext = b'Proxy Re-Encryption is cool!'
ciphertext, capsule = pre.encrypt(alices_public_key, plaintext)

# Decrypt data with Alice's private key.
cleartext = pre.decrypt(ciphertext=ciphertext,
                        capsule=capsule,
                        decrypting_key=alices_private_key)

Re-Encryption Key Fragments

When Alice wants to grant Bob access to open her encrypted messages, she creates re-encryption key fragments, or “kfrags”, which are next sent to N proxies or Ursulas.

# Alice generates "M of N" re-encryption key fragments (or "KFrags") for Bob.
# In this example, 10 out of 20.
kfrags = pre.generate_kfrags(delegating_privkey=alices_private_key,
                             signer=alices_signer,
                             receiving_pubkey=bobs_public_key,
                             threshold=10,
                             N=20)

Re-Encryption

Bob asks several Ursulas to re-encrypt the capsule so he can open it. Each Ursula performs re-encryption on the capsule using the kfrag provided by Alice, obtaining this way a “capsule fragment”, or cfrag.

Bob collects the resulting cfrags from several Ursulas. Bob must gather at least threshold cfrags in order to activate the capsule.

# Several Ursulas perform re-encryption, and Bob collects the resulting `cfrags`.
# He must gather at least `threshold` `cfrags` in order to activate the capsule.

capsule.set_correctness_keys(delegating=alices_public_key,
                             receiving=bobs_public_key,
                             verifying=alices_verifying_key)

cfrags = list()           # Bob's cfrag collection
for kfrag in kfrags[:10]:
  cfrag = pre.reencrypt(kfrag=kfrag, capsule=capsule)
  cfrags.append(cfrag)    # Bob collects a cfrag

Decryption by Bob

Finally, Bob activates the capsule by attaching at least threshold cfrags, and then decrypts the re-encrypted ciphertext.

# Bob activates and opens the capsule
for cfrag in cfrags:
  capsule.attach_cfrag(cfrag)

bob_cleartext = pre.decrypt(ciphertext=ciphertext,
                            capsule=capsule,
                            decrypting_key=bobs_private_key)
assert bob_cleartext == plaintext

See more detailed usage examples in the docs directory.

Quick Installation

To install pyUmbral, simply use pip:

$ pip3 install umbral

Alternatively, you can checkout the repo and install it from there. The NuCypher team uses pipenv for managing pyUmbral’s dependencies. The recommended installation procedure is as follows:

$ sudo pip3 install pipenv
$ pipenv install

Post-installation, you can activate the project virtual environment in your current terminal session by running pipenv shell.

For more information on pipenv, find the official documentation here: https://docs.pipenv.org/.

Academic Whitepaper

The Umbral scheme academic whitepaper and cryptographic specifications are available on GitHub.

“Umbral: A Threshold Proxy Re-Encryption Scheme” by David Nuñez. https://github.com/nucypher/umbral-doc/blob/master/umbral-doc.pdf

Support & Contribute

Security

If you identify vulnerabilities with _any_ nucypher code, please email security@nucypher.com with relevant information to your findings. We will work with researchers to coordinate vulnerability disclosure between our partners and users to ensure successful mitigation of vulnerabilities.

Throughout the reporting process, we expect researchers to honor an embargo period that may vary depending on the severity of the disclosure. This ensures that we have the opportunity to fix any issues, identify further issues (if any), and inform our users.

Sometimes vulnerabilities are of a more sensitive nature and require extra precautions. We are happy to work together to use a more secure medium, such as Signal. Email security@nucypher.com and we will coordinate a communication channel that we’re both comfortable with.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

umbral-0.1.3a2.tar.gz (33.3 kB view details)

Uploaded Source

Built Distribution

umbral-0.1.3a2-py3-none-any.whl (58.8 kB view details)

Uploaded Python 3

File details

Details for the file umbral-0.1.3a2.tar.gz.

File metadata

  • Download URL: umbral-0.1.3a2.tar.gz
  • Upload date:
  • Size: 33.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.33.0 CPython/3.6.9

File hashes

Hashes for umbral-0.1.3a2.tar.gz
Algorithm Hash digest
SHA256 5d17c50d5bdfa78024108931c08ba27bce24ed30d1d7d093d98049084321ca09
MD5 3f566dc07a75f36d9ca1720208137198
BLAKE2b-256 2e66c12ca7ef0346eada9a1ef483ec24c8fae0ccdf86a00b787eacc54f8341f9

See more details on using hashes here.

File details

Details for the file umbral-0.1.3a2-py3-none-any.whl.

File metadata

  • Download URL: umbral-0.1.3a2-py3-none-any.whl
  • Upload date:
  • Size: 58.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.33.0 CPython/3.6.9

File hashes

Hashes for umbral-0.1.3a2-py3-none-any.whl
Algorithm Hash digest
SHA256 a66d2a1c577d9519ab9e2938076f48876ae3594fd1a9eb20f2491d45faf48062
MD5 d20c4d594031d3c9699f266525e89db6
BLAKE2b-256 62192f26b8f6167a9ef43700d7e4cafac382c1116fb97ad6d64a7a70c1422971

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page