pyUmbral/README.rst

222 lines
7.3 KiB
ReStructuredText
Raw Normal View History

.. role:: bash(code)
:language: bash
=========
2018-02-16 19:27:36 +00:00
pyUmbral
=========
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
2021-06-14 22:11:04 +00:00
.. |commits-since| image:: https://img.shields.io/github/commits-since/nucypher/pyumbral/v0.2.0.svg
2019-01-10 10:16:41 +00:00
:alt: Commits since latest release
2021-06-14 22:11:04 +00:00
:target: https://github.com/nucypher/pyUmbral/compare/v0.2.0...master
2019-01-10 10:16:41 +00:00
.. end-badges
2018-02-16 19:27:36 +00:00
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.
2019-08-12 18:43:14 +00:00
.. image:: docs/source/.static/umbral.svg
:width: 400 px
:align: center
2018-02-16 19:27:36 +00:00
pyUmbral is the cryptographic engine behind nucypher_,
a proxy re-encryption network to empower privacy in decentralized systems.
2018-02-16 19:27:36 +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/
.. _nucypher: https://github.com/nucypher/nucypher
2018-07-29 21:21:56 +00:00
Usage
=====
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.
.. code-block:: python
2018-02-16 19:27:36 +00:00
from umbral import SecretKey, Signer
2018-02-16 19:27:36 +00:00
2018-07-29 21:21:56 +00:00
# Generate Umbral keys for Alice.
2021-03-21 01:19:36 +00:00
alices_secret_key = SecretKey.random()
alices_public_key = alices_secret_key.public_key()
2018-02-16 19:27:36 +00:00
2021-03-21 01:19:36 +00:00
alices_signing_key = SecretKey.random()
alices_signer = Signer(alices_signing_key)
alices_verifying_key = alices_signing_key.public_key()
2018-07-29 21:21:56 +00:00
# Generate Umbral keys for Bob.
2021-03-21 01:19:36 +00:00
bobs_secret_key = SecretKey.random()
bobs_public_key = bobs_secret_key.public_key()
2018-07-29 21:21:56 +00:00
**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
2021-03-21 01:19:36 +00:00
from umbral import encrypt, decrypt_original
# Encrypt data with Alice's public key.
2019-02-19 12:11:11 +00:00
plaintext = b'Proxy Re-Encryption is cool!'
2021-03-21 01:19:36 +00:00
capsule, ciphertext = encrypt(alices_public_key, plaintext)
# Decrypt data with Alice's private key.
2021-03-21 01:19:36 +00:00
cleartext = decrypt_original(alices_secret_key, capsule, ciphertext)
2018-07-29 21:21:56 +00:00
**Re-Encryption Key Fragments**
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*.
.. code-block:: python
2018-02-16 19:27:36 +00:00
2021-03-21 01:19:36 +00:00
from umbral import generate_kfrags
# 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.
2021-03-21 01:19:36 +00:00
kfrags = generate_kfrags(delegating_sk=alices_secret_key,
receiving_pk=bobs_public_key,
signer=alices_signer,
2021-03-21 01:19:36 +00:00
threshold=10,
num_kfrags=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
2021-03-21 01:19:36 +00:00
from umbral import reencrypt
2021-03-21 01:19:36 +00:00
# Several Ursulas perform re-encryption, and Bob collects the resulting `cfrags`.
cfrags = list() # Bob's cfrag collection
for kfrag in kfrags[:10]:
cfrag = pre.reencrypt(capsule=capsule, kfrag=kfrag)
cfrags.append(cfrag) # Bob collects a cfrag
2018-07-29 21:21:56 +00:00
**Decryption by Bob**
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.
.. code-block:: python
2021-03-21 01:19:36 +00:00
from umbral import decrypt_reencrypted
2018-07-29 21:21:56 +00:00
bob_cleartext = pre.decrypt_reencrypted(receiving_sk=bobs_secret_key,
2021-03-21 01:19:36 +00:00
delegating_pk=alices_public_key,
capsule=capsule,
cfrags=cfrags,
ciphertext=ciphertext)
assert bob_cleartext == plaintext
2018-07-29 21:21:56 +00:00
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
Quick Installation
==================
2018-02-16 19:27:36 +00:00
2019-02-19 12:11:11 +00:00
To install pyUmbral, simply use ``pip``:
.. code-block:: bash
$ pip3 install umbral
2021-03-21 01:19:36 +00:00
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.
The recommended installation procedure is as follows:
.. code-block:: bash
2018-02-16 19:27:36 +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
Academic Whitepaper
====================
The Umbral scheme academic whitepaper and cryptographic specifications
2018-03-18 01:44:58 +00:00
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
.. _GitHub: https://github.com/nucypher/umbral-doc/
2018-02-16 19:27:36 +00:00
Support & Contribute
=====================
2018-02-16 19:27:36 +00:00
- Issue Tracker: https://github.com/nucypher/pyUmbral/issues
- Source Code: https://github.com/nucypher/pyUmbral
2018-04-10 03:30:52 +00:00
2019-02-21 01:55:08 +00:00
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.