2018-02-16 20:47:38 +00:00
.. role :: bash(code)
:language: bash
2018-02-17 05:03:24 +00:00
=========
2018-02-16 19:27:36 +00:00
pyUmbral
2018-02-17 05:03:24 +00:00
=========
2018-02-16 20:47:38 +00:00
2019-01-10 10:16:41 +00:00
.. start-badges
2019-02-20 10:01:02 +00:00
|version| |circleci| |commits-since| |docs| |discord|
2019-01-10 10:16:41 +00:00
.. |docs| image :: https://readthedocs.org/projects/pyumbral/badge/?style=flat
:target: https://readthedocs.org/projects/pyumbral
:alt: Documentation Status
.. |discord| image :: https://img.shields.io/discord/411401661714792449.svg?logo=discord
:target: https://discord.gg/xYqyEby
:alt: Discord
.. |circleci| image :: https://img.shields.io/circleci/project/github/nucypher/pyUmbral.svg?logo=circleci
2018-08-06 21:52:32 +00:00
:target: https://circleci.com/gh/nucypher/pyUmbral/tree/master
2019-01-10 10:16:41 +00:00
:alt: CircleCI build status
.. |version| image :: https://img.shields.io/pypi/v/umbral.svg
:alt: PyPI Package latest release
:target: https://pypi.org/project/umbral
.. |commits-since| image :: https://img.shields.io/github/commits-since/nucypher/pyumbral/v0.1.3-alpha.0.svg
:alt: Commits since latest release
:target: https://github.com/nucypher/pyUmbral/compare/v0.1.3-alpha.0...master
.. end-badges
2018-02-16 19:27:36 +00:00
2019-02-19 12:11:11 +00:00
pyUmbral is a Python implementation of David Nuñez's threshold proxy re-encryption scheme: Umbral_.
2018-02-20 22:06:33 +00:00
Implemented with OpenSSL_ and Cryptography.io_, pyUmbral is a referential and open-source cryptography library
2018-02-21 18:08:50 +00:00
extending the traditional cryptological narrative of "Alice and Bob" by introducing a new actor,
2019-02-19 12:11:11 +00:00
*Ursula* , who has the ability to take secrets encrypted for Alice and *re-encrypt* them for Bob,
without being able to learn any information about the original secret.
2018-02-16 19:27:36 +00:00
2019-02-19 12:09:58 +00:00
pyUmbral is the cryptographic engine behind nucypher_,
a proxy re-encryption network to empower privacy in decentralized systems.
2018-02-20 22:06:33 +00:00
.. _Umbral: https://github.com/nucypher/umbral-doc/blob/master/umbral-doc.pdf
.. _Cryptography.io: https://cryptography.io/en/latest/
.. _OpenSSL: https://www.openssl.org/
2019-02-19 12:09:58 +00:00
.. _nucypher: https://github.com/nucypher/nucypher
2018-02-20 22:06:33 +00:00
2018-07-29 21:21:56 +00:00
Usage
=====
2018-02-20 22:06:33 +00:00
2018-07-29 21:21:56 +00:00
**Key Generation**
2018-02-16 19:27:36 +00:00
2019-02-19 12:11:11 +00:00
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.
2018-02-16 20:47:38 +00:00
.. code-block :: python
2018-02-16 19:27:36 +00:00
2018-07-29 21:21:56 +00:00
from umbral import pre, keys, signing
2018-02-16 19:27:36 +00:00
2018-07-29 21:21:56 +00:00
# Generate Umbral keys for Alice.
2018-02-16 20:47:38 +00:00
alices_private_key = keys.UmbralPrivateKey.gen_key()
2018-03-21 05:45:27 +00:00
alices_public_key = alices_private_key.get_pubkey()
2018-02-16 19:27:36 +00:00
2018-07-29 21:21:56 +00:00
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**
2019-02-19 12:11:11 +00:00
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.
2018-07-29 21:21:56 +00:00
.. code-block :: python
2018-02-18 00:24:02 +00:00
# Encrypt data with Alice's public key.
2019-02-19 12:11:11 +00:00
plaintext = b'Proxy Re-Encryption is cool!'
2018-03-21 05:45:27 +00:00
ciphertext, capsule = pre.encrypt(alices_public_key, plaintext)
2018-02-16 20:47:38 +00:00
2018-02-18 00:24:02 +00:00
# Decrypt data with Alice's private key.
2018-07-29 21:21:56 +00:00
cleartext = pre.decrypt(ciphertext=ciphertext,
capsule=capsule,
decrypting_key=alices_private_key)
2018-02-16 20:47:38 +00:00
2018-10-06 16:14:56 +00:00
**Re-Encryption Key Fragments**
2018-02-16 20:47:38 +00:00
2019-02-19 12:11:11 +00:00
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* .
2018-02-16 20:47:38 +00:00
.. code-block :: python
2018-02-16 19:27:36 +00:00
2018-10-06 16:14:56 +00:00
# Alice generates "M of N" re-encryption key fragments (or "KFrags") for Bob.
2018-07-29 21:21:56 +00:00
# In this example, 10 out of 20.
2018-10-06 16:14:56 +00:00
kfrags = pre.generate_kfrags(delegating_privkey=alices_private_key,
signer=alices_signer,
receiving_pubkey=bobs_public_key,
threshold=10,
N=20)
2018-07-29 21:21:56 +00:00
**Re-Encryption**
2019-02-19 12:11:11 +00:00
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.
2018-07-29 21:21:56 +00:00
.. code-block :: python
# 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)
2018-02-16 20:47:38 +00:00
2018-07-29 21:21:56 +00:00
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
2018-02-16 20:47:38 +00:00
2018-07-29 21:21:56 +00:00
**Decryption by Bob**
2018-02-18 00:24:02 +00:00
2019-02-19 12:11:11 +00:00
Finally, Bob activates the capsule by attaching at least `` threshold `` cfrags,
and then decrypts the re-encrypted ciphertext.
2018-02-18 00:24:02 +00:00
.. code-block :: python
2018-07-29 21:21:56 +00:00
# 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.
2018-02-16 19:27:36 +00:00
2018-07-29 21:21:56 +00:00
.. _docs : https://github.com/nucypher/pyUmbral/tree/master/docs
2018-02-16 19:27:36 +00:00
2018-02-17 05:03:24 +00:00
2018-02-16 23:52:24 +00:00
Quick Installation
2018-02-17 05:03:24 +00:00
==================
2018-02-16 19:27:36 +00:00
2019-02-19 12:11:11 +00:00
To install pyUmbral, simply use `` pip `` :
2018-11-16 09:37:32 +00:00
.. code-block :: bash
$ pip3 install umbral
Alternatively, you can checkout the repo and install it from there.
2019-02-19 12:11:11 +00:00
The NuCypher team uses `` pipenv `` for managing pyUmbral's dependencies.
2018-02-16 23:52:24 +00:00
The recommended installation procedure is as follows:
2018-02-16 20:47:38 +00:00
.. code-block :: bash
2018-02-16 19:27:36 +00:00
2018-02-16 20:47:38 +00:00
$ sudo pip3 install pipenv
$ pipenv install
2018-02-16 19:27:36 +00:00
2018-03-18 01:44:58 +00:00
Post-installation, you can activate the project virtual environment
2019-02-19 12:11:11 +00:00
in your current terminal session by running `` pipenv shell `` .
2018-02-16 19:27:36 +00:00
2019-02-19 12:11:11 +00:00
For more information on `` pipenv `` , find the official documentation here: https://docs.pipenv.org/.
2018-02-16 19:27:36 +00:00
2018-02-17 00:17:13 +00:00
2018-02-20 22:06:33 +00:00
Academic Whitepaper
====================
The Umbral scheme academic whitepaper and cryptographic specifications
2018-03-18 01:44:58 +00:00
are available on GitHub_.
2018-02-20 22:06:33 +00:00
2018-03-18 00:23:30 +00:00
"Umbral: A Threshold Proxy Re-Encryption Scheme"
2018-02-20 22:06:33 +00:00
*by David Nuñez*
https://github.com/nucypher/umbral-doc/blob/master/umbral-doc.pdf
2018-02-17 00:17:13 +00:00
2018-02-20 22:06:33 +00:00
.. _GitHub: https://github.com/nucypher/umbral-doc/
2018-02-17 00:17:13 +00:00
2018-02-16 19:27:36 +00:00
Support & Contribute
2018-02-17 05:03:24 +00:00
=====================
2018-02-16 19:27:36 +00:00
2018-02-16 23:52:24 +00:00
- Issue Tracker: https://github.com/nucypher/pyUmbral/issues
2018-02-17 00:17:13 +00:00
- Source Code: https://github.com/nucypher/pyUmbral
2018-04-10 03:30:52 +00:00
OFAC Sanctions Disclaimer
=========================
By using this software, you hereby affirm you are not an individual or entity subject to economic sanctions administered by the U.S. Government or any other applicable authority, including but not limited to, sanctioned party lists administered by the U.S. Treasury Department’ s Office of Foreign Assets Control (OFAC), the U.S. State Department, and the U.S. Commerce Department. You further affirm you are not located in, or ordinarily resident in, any country, territory or region subject to comprehensive economic sanctions administered by OFAC, which are subject to change but currently include Cuba, Iran, North Korea, Syria and the Crimea region.